There is class Connection for connection to Windows Live. You need client_id and client_secrect which you will get when you will register your application in MS site. There are static properties:
Connection.client_id = client_id;
Connection.client_secret = client_secret;
Connection.redirect_uri = redirect_uri; // I set this to "https://login.live.com/oauth20_desktop.srf";
Connection.connection = new Connection(); //created object connection
Connection.Expired += Connection_Expired; //set this for information when access token expired
There is Connection.code property. How to give code for login is describe on this page: https://msdn.microsoft.com/en-us/library/hh826543.aspx?f=255&MSPPError=-2147217396
If you have refresh token, you can set property Connection.connection.refresh_token. If this property is set it has higher priority than code property.
If you have set this properties you can call Connection.Login(); method. This metod will login into Windows Live.
There is method which refer to Connection.Expired event. When access token expires event is fired and you can login again to renew acces token.
private void Connection_Expired(object sender, EventArgs e)
{
Connection.Login();}
Now you are login in.
There is class File in WLiveObjects namespace. This class has static method Create(T fileobj, Stream file, OverWriteOption owoption, RequestProgressHandler handler).
RequestProgressHandler handler = new RequestProgressHandler();
handler.ProgressChange += UploadProgress;Create(file, fs, option, handler);
It will be better encapsulated in try catch block. There could be exception type of BITSException. This type of exception has method Continue. It is very easy to continue in upload when connection was broken by this method. Calling is simple:
((BITSException)exception).Continue((BITSException)exception); //exception object is parameter of method.
It could be very simple in code:
File fresult=null;
try
{
fresult = File.Create(file, fs, option, handler);
}
catch(BITSException e)
{
BITSException bex = e;
do
{
bool error = false;
try
{
bex.Continue(bex);
}
catch(BITSException b)
{
bex = b;
bex.Continue(bex);
error = true;
}
}while(error);
fresult = (File)bex.Result;
}
There is method which refer to delegate in handler. When there is change in upload progress upload mechanism will call this method by handler.ProgressChange(int bytes transfered, double percent)
void UploadProgress(int bytes, double proc)
{
Console.WriteLine(“{0};{1}”proc, bytes);
}