private static Boolean BuildFileEntry(BaseFileEntry fileEntry, JsonHelper jh) { /* * "revision": 29251, "thumb_exists": false, "bytes": 37941660, "modified": "Tue, 01 Jun 2010 14:45:09 +0000", "path": "/Public/2010_06_01 15_53_48_336.nvl", "is_dir": false, "icon": "page_white", "mime_type": "application/octet-stream", "size": "36.2MB" * */ // set the size fileEntry.Length = Convert.ToInt64(jh.GetProperty("bytes")); // set the modified time fileEntry.Modified = jh.GetDateTimeProperty("modified"); // build the displayname var DropBoxPath = jh.GetProperty("path"); var arr = DropBoxPath.Split('/'); fileEntry.Name = arr.Length > 0 ? arr[arr.Length - 1] : DropBoxPath; if (DropBoxPath.Equals("/")) { fileEntry.Id = "/"; fileEntry.ParentID = null; } else { fileEntry.Id = DropBoxPath.Trim('/'); fileEntry.ParentID = DropBoxResourceIDHelpers.GetParentID(DropBoxPath); } // set the hash property if possible var hashValue = jh.GetProperty("hash"); if (hashValue.Length > 0) fileEntry.SetPropertyValue("hash", hashValue); // set the path property fileEntry.SetPropertyValue("path", DropBoxPath.Equals("/") ? "" : DropBoxPath); // set the revision value if possible var revValue = jh.GetProperty("rev"); if (revValue.Length > 0) { fileEntry.SetPropertyValue("rev", revValue); } // go ahead return true; }
public override void UploadChunk(IStorageProviderSession session, IResumableUploadSession uploadSession, Stream stream, long chunkLength) { if (uploadSession.Status == ResumableUploadSessionStatus.Completed || uploadSession.Status == ResumableUploadSessionStatus.Aborted) throw new InvalidOperationException("Upload session was either completed or aborted."); if (stream == null) throw new ArgumentNullException("stream"); var requestParams = new Dictionary<string, string>(); if (uploadSession.Status == ResumableUploadSessionStatus.Started) { requestParams.Add("upload_id", uploadSession.GetItem<string>("UploadId")); requestParams.Add("offset", uploadSession.BytesTransfered.ToString()); } var request = new OAuthService().CreateWebRequest(GetUrlString(DropBoxChunkedUpload, session.ServiceConfiguration), "PUT", null, null, ((DropBoxStorageProviderSession)session).Context, (DropBoxToken)session.SessionToken, requestParams); request.ContentLength = chunkLength; using (var requestStream = request.GetRequestStream()) { stream.CopyTo(requestStream); } using (var response = request.GetResponse()) using (var responseStream = response.GetResponseStream()) { if (responseStream == null) return; var json = new JsonHelper(); json.ParseJsonMessage(new StreamReader(responseStream).ReadToEnd()); var uplSession = (ResumableUploadSession)uploadSession; uplSession["UploadId"] = json.GetProperty("upload_id"); uplSession["Expired"] = json.GetDateTimeProperty("expired"); uplSession.BytesTransfered += chunkLength; uplSession.Status = ResumableUploadSessionStatus.Started; if (uplSession.BytesToTransfer == uploadSession.BytesTransfered) { CommitUploadSession(session, uploadSession); } } }