--Aliyun upload Download API interface use
Related Data address: https://help.aliyun.com/document_detail/oss/sdk/dotnet-sdk/install.html?spm=5176.docoss/sdk/dotnet-sdk/ Preface.6.357.shx0qw
1. Before beginning programming need to quote Aliyun.OSS.dll, can download directly in Ali official website, also can install through NuGet.
2. On Ali's official website, there are simple sample codes for uploading and downloading.
3. Through the ordinary Putobject method uploads the file maximum cannot surpass 5GB, otherwise the error, through multipart fragment uploads
The size cannot exceed 48.8TB, there is almost no limit.
4.Multipart fragment uploads can also support breakpoint uploads.
Implementation of breakpoint fragment asynchronous upload:
The basic way to achieve the official website has, the following is their own need to pay attention to or modify a little things
In a fragmented upload, you need to first create a Initiatemultipartuploadrequest instance object, and then use the Initiatemultipartupload method to get a uploadid, which is an ID that exists in Ali for a long time, corresponding to each fragment upload event, unless the upload completed after the completion of the call to complete the fragment upload method Client.completemultipartupload or call to cancel the fragment upload method abortmultipartupload, this ID will disappear. So we can go through the client. Listmultipartuploads method to get all the space on the incomplete fragment upload events, and then through the key to get the last upload corresponding Uploadid, Then, based on the obtained Uploadid call client.listparts method, you can get the last upload of the piece information, get a part of the collection, part of a PartNumber property, this is the last fragment upload successful piece is the first partnumber, can be used to skip The content that has been uploaded is successful, and a etag is used for verification. The end is to use the client. Beginuploadpart on the asynchronous upload to Ali Cloud. Another point to note is that when we get to the last upload successful parts Remember to add these slices to the Partetags collection, otherwise it will not be a breakpoint upload, but the entire file size added to the last uploaded file size.
4. The website also has examples of downloading words, call GetObject method is good.
Implementation of breakpoint download and breakpoint fragment download:
These two functions are modified by the example of the website fragment download.
Breakpoint Download: Just split the download file into two pieces, download the completed piece and the not downloaded piece. Don't say it later.
Breakpoint Fragment Download: This gets the download progress and implements the progress bar. is to download the piece that has not been downloaded and append it to the locally downloaded file.
The use of the--entity Framework (EF): From code classes to databases
1. Installation of the entity Framework
Search the entity Framework in NuGet for installation.
2. Define Entity classes
Adding a specific description to a property, such as [key], is the primary key in the database, [Required], which is required in the database.
3. Define the database Connection object class to inherit the DbContext class
This class represents a database, and the attributes in the class represent the tables in the database.
Class Userdb:dbcontext
{
Public dbset<user> the Users {get; set;}
Public dbset<usergroup> usergroup {get; set;}
}
4. Add the configuration node of the database in the configuration file
<!--EF set up Database-->
<connectionStrings>
<add name= "UserDB" providername= System.Data.SqlClient "connectionstring=" server=.;D Atabase=xineftest; trusted_connection=true; "/>
</connectionStrings>
5. Start creating libraries
UserDB db = new UserDB ();//create library, at which point DB is the library in the database
var ug = new UserGroup ()//create record
{
ID = 1,
GroupName = "Admin"
};
Db. Usergroup.add (UG);//Add a record to the table
Db. SaveChanges ()/Save More Love
--From database to code class
Select the data-ado.net Entity Data model in the new item-the EF designer from the database (VS2015 is this)-Always next, select the objects you want in the database, such as tables, views, and so on, and then the class is generated.
When using EF to access a database at the DAL layer, you need to refer to EF first, or you will get an error
"The type used in the using statement must be implicitly convertible to" System.IDisposable "
When paging is required, you can use a method that has already been encapsulated, skip () and take (), and you must first sort by using the order () method, such as:
Public list<boutique_activity> getactivityinfo (int activitytype, int pageIndex, int pageSize, out int Inttotalcount)
{
list<boutique_activity> listresult = new list<boutique_activity> ();
using (boutiqueactivityentities activityentityies = new Boutiqueactivityentities ())
{
Inttotalcount = ActivityEntityies.Boutique_Activity.Where (t => t.study_type = = Activitytype). Count ();
Listresult = ActivityEntityies.Boutique_Activity.Where (t => t.study_type = = Activitytype). By (T => t.study_date). Skip (PageSize * pageIndex). Take (pageSize). ToList ();
}
return listresult;
}
Where boutiqueactivityentities is generated from EF:
Namespace Weixinh5models
{
using System;
Using System.Data.Entity;
Using System.Data.Entity.Infrastructure;
public partial class Boutiqueactivityentities:dbcontext
{public
boutiqueactivityentities ()
: Base (" Name=boutiqueactivityentities ")
{
}
protected override void Onmodelcreating (Dbmodelbuilder ModelBuilder)
{
throw new unintentionalcodefirstexception ();
}
Public virtual dbset<boutique_activity> boutique_activity {get; set;}}}