Ejemplo n.º 1
0
 /// <summary>
 /// Upload content of object
 /// </summary>
 /// <param name="file">Object content</param>
 /// <param name="usrid">Owner of location. If null or empty logged user is used</param>
 /// <param name="name">Object name</param>
 /// <param name="locationid">Location id where you want to create object</param>
 /// <param name="fposition">Position in stream. It is used when handled exception and continue upload</param>
 /// <param name="handler">Handler which is used for watch upload progress</param>
 /// <param name="br">Bits request object</param>
 /// <param name="resobj">Result object. It is created object given when exception durin uploading process</param>
 static void UploadContent(Stream file, string usrid, string name, string locationid, long fposition, RequestProgressHandler handler, BitsRequest br, object resobj)
 {
     if (br == null)
     {
         Uri url = new Uri("https://cid-" + usrid + ".users.storage.live.com/items/" + locationid + "/" + name);
         br = new BitsRequest {
             Url = url, TotalLength = (int)file.Length
         };
         br.StartSession();
         br.Method = WebRequestMethods.Http.Post;
         try
         {
             Requester.Request <T>(br);
         }
         catch
         { throw; }
     }
     file.Position = fposition;
     while (file.Position < file.Length)
     {
         br.Method = WebRequestMethods.Http.Post;
         long position = file.Position;
         int  c        = br.Count;
         br.SetData(new byte[file.Length - file.Position > br.MaxLength ? br.MaxLength : file.Length - file.Position]);
         file.Read(br.GetData(), 0, br.ContentLength);
         try
         {
             if (handler != null)
             {
                 Requester.Request <T>(br, handler);
             }
             else
             {
                 Requester.Request <T>(br);
             }
         }
         catch (Exception e)
         {
             br.Count = c;
             throw new BitsException("", e, file, position, br, Continue, handler, resobj);
         }
     }
     br.Method = WebRequestMethods.Http.Post;
     br.CommitSession();
     try
     {
         Requester.Request <T>(br);
     }
     catch (Exception e)
     {
         throw new BitsException("", e, file, file.Length, br, Continue, handler, resobj);
     }
 }
Ejemplo n.º 2
0
 public BitsException(string message, Exception exception, Stream file, long position, BitsRequest request, ContinueHandler handler, RequestProgressHandler progressHandler, object result) : base(message, exception)
 {
     this.Position  = position;
     this.Request   = request;
     this.Content   = file;
     this.Continue += handler;
     this.Handler   = progressHandler;
     Result         = result;
 }