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 static IEnumerable <BaseFileEntry> ParseEntriesXml(IStorageProviderSession session, String xml) { var doc = XDocument.Load(new StringReader(xml)); var entries = doc.Descendants(XName.Get("entry", GoogleDocsConstants.AtomNamespace)); var fsEntries = new List <BaseFileEntry>(); foreach (var entry in entries) { var resourceId = entry.Element(XName.Get("resourceId", GoogleDocsConstants.GdNamespace)).ValueOrEmpty().Replace(':', '_'); var title = entry.Element(XName.Get("title", GoogleDocsConstants.AtomNamespace)).ValueOrEmpty(); var updated = entry.Element(XName.Get("updated", GoogleDocsConstants.AtomNamespace)).ValueOrEmpty(); var etag = entry.Attribute(XName.Get("etag", GoogleDocsConstants.GdNamespace)).ValueOrEmpty(); var kind = entry.Elements(XName.Get("category", GoogleDocsConstants.AtomNamespace)).Single(x => x.Attribute("scheme").ValueOrEmpty().Equals(GoogleDocsConstants.SchemeKind)).Attribute("label").ValueOrEmpty(); BaseFileEntry fsEntry = kind.Equals("folder") ? new BaseDirectoryEntry(title, 0, Convert.ToDateTime(updated).ToUniversalTime(), session.Service, session) : new BaseFileEntry(title, 0, Convert.ToDateTime(updated).ToUniversalTime(), session.Service, session); fsEntry.Id = resourceId; fsEntry.SetPropertyValue(GoogleDocsConstants.EtagProperty, etag); fsEntry.SetPropertyValue(GoogleDocsConstants.KindProperty, kind); if (kind.Equals("folder")) { var uploadUrl = entry.Elements(XName.Get("link", GoogleDocsConstants.AtomNamespace)).FirstOrDefault(x => x.Attribute("rel").ValueOrEmpty().Equals(GoogleDocsConstants.SchemeResCreateMedia)).AttributeOrNull("href").ValueOrEmpty(); fsEntry.SetPropertyValue(GoogleDocsConstants.ResCreateMediaProperty, uploadUrl); } else { var length = entry.Element(XName.Get("quotaBytesUsed", GoogleDocsConstants.GdNamespace)).ValueOrEmpty(); var downloadUrl = entry.Elements(XName.Get("content", GoogleDocsConstants.AtomNamespace)).FirstOrDefault().AttributeOrNull("src").ValueOrEmpty(); var editUrl = entry.Elements(XName.Get("link", GoogleDocsConstants.AtomNamespace)).FirstOrDefault(x => x.Attribute("rel").ValueOrEmpty().Equals(GoogleDocsConstants.SchemeResEditMedia)).AttributeOrNull("href").ValueOrEmpty(); fsEntry.Length = Convert.ToInt64(length); fsEntry.SetPropertyValue(GoogleDocsConstants.DownloadUrlProperty, downloadUrl); if (!String.IsNullOrEmpty(editUrl)) { fsEntry.SetPropertyValue(GoogleDocsConstants.ResEditMediaProperty, editUrl); } var ext = GoogleDocsResourceHelper.GetExtensionByKind(kind); if (!String.IsNullOrEmpty(ext)) { fsEntry.Name += '.' + ext; } } //var parents = entry.Elements(XName.Get("link", GoogleDocsConstants.AtomNamespace)) // .Where(x => x.AttributeOrNull("rel").ValueOrEmpty().Equals(GoogleDocsConstants.SchemeParent)) // .Select(x => // { // var parentUrl = x.ValueOrEmpty(); // var index = parentUrl.LastIndexOf('/'); // return parentUrl.Substring(index).Replace(':', '_').Replace("%3A", "_"); // }); //fsEntry.SetPropertyValue(GoogleDocsConstants.ParentsProperty, String.Join(",", parents.ToArray())); fsEntries.Add(fsEntry); } return(fsEntries); }