コード例 #1
0
 private void registerFileSuccess(HttpWebResponse response)
 {
     if ((int)response.StatusCode == 200) //status code 200 should be only when success
     {
         using (var reader = new StreamReader(response.GetResponseStream()))
         {
             string responseString = reader.ReadToEnd();
             var    parsed         = JSON.Parse(responseString);
             if (parsed["baseUrl"] != null && parsed["token"] != null)
             {
                 string baseUrl    = parsed["baseUrl"];
                 string azureToken = parsed["token"];
                 if (parsed["model"] != null)
                 {
                     this.model = new Model(parsed["model"]["id"], this.sceneId,
                                            parsed["model"]["version_id"], parsed["model"]["version"]);
                     if (parsed["files"] != null)
                     {
                         var files = parsed["files"].AsArray;
                         for (int i = 0; i < files.Count; i++)
                         {
                             ModelFile file = new ModelFile(files[i]["actualName"], files[i]["blobName"],
                                                            files[i]["id"]);
                             this.model.addFile(file);
                         }
                     }
                     for (int i = 0; i < this.model.files.Count; i++)
                     {
                         FileUploadProgressCallback progress = this.uploadFileProgressCallback;
                         FileUploadSuccessCallback  success  = this.uploadFileSuccessCallback;
                         FileUploadErrorCallback    error    = this.uploadFileErrorCallback;
                         string        url      = baseUrl + this.model.files[i].blobName + "?" + azureToken;
                         string        filepath = this.folder + this.model.files[i].actualName;
                         AzureUploader uploader = new AzureUploader(url, filepath, success, progress, error);
                         uploader.startUpload();
                     }
                 }
             }
         }
     }
     response.Close();
 }
コード例 #2
0
 public AzureUploader(string uploadUrl, string filepath, FileUploadSuccessCallback success,
                      FileUploadProgressCallback progress, FileUploadErrorCallback error)
 {
     ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     this.uploadUrl          = uploadUrl;
     this.currentFilePointer = 0;
     this.filepath           = filepath;
     this.blockIds           = new List <string>();
     this.bytesUploaded      = 0;
     this.success            = success;
     this.error    = error;
     this.progress = progress;
     this._lock    = new object();
     try
     {
         this.bytes = System.IO.File.ReadAllBytes(filepath);
         this.totalBytesRemaining = this.bytes.Length;
     }
     catch (Exception e)
     {
         this.error(filepath, e.Message);
     }
 }