public static BaseFileEntry UpdateObjectFromJsonString(String jsonMessage, BaseFileEntry objectToUpdate, IStorageProviderService service, IStorageProviderSession session) { // verify if we have a directory or a file var jc = new JsonHelper(); if (!jc.ParseJsonMessage(jsonMessage)) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidFileOrDirectoryName); var isDir = jc.GetBooleanProperty("is_dir"); // create the entry BaseFileEntry dbentry; Boolean bEntryOk; if (isDir) { if (objectToUpdate == null) dbentry = new BaseDirectoryEntry("Name", 0, DateTime.Now, service, session); else dbentry = objectToUpdate as BaseDirectoryEntry; bEntryOk = BuildDirectyEntry(dbentry as BaseDirectoryEntry, jc, service, session); } else { if (objectToUpdate == null) dbentry = new BaseFileEntry("Name", 0, DateTime.Now, service, session); else dbentry = objectToUpdate; bEntryOk = BuildFileEntry(dbentry, jc); } // parse the childs and fill the entry as self if (!bEntryOk) throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotContactStorageService); // set the is deleted flag try { // try to read the is_deleted property dbentry.IsDeleted = jc.GetBooleanProperty("is_deleted"); } catch (Exception) { // the is_deleted proprty is missing (so it's not a deleted file or folder) dbentry.IsDeleted = false; } // return the child return dbentry; }
private static Boolean BuildDirectyEntry(BaseDirectoryEntry dirEntry, JsonHelper jh, IStorageProviderService service, IStorageProviderSession session) { // build the file entry part if (!BuildFileEntry(dirEntry, jh)) return false; // now take the content var content = jh.GetListProperty("contents"); if (content.Count == 0) return true; // remove all childs dirEntry.ClearChilds(); // add the childs foreach (var jsonContent in content) { // parse the item var jc = new JsonHelper(); if (!jc.ParseJsonMessage(jsonContent)) continue; // check if we have a directory var isDir = jc.GetBooleanProperty("is_dir"); BaseFileEntry fentry; if (isDir) { fentry = new BaseDirectoryEntry("Name", 0, DateTime.Now, service, session); } else { fentry = new BaseFileEntry("Name", 0, DateTime.Now, service, session); } // build the file attributes BuildFileEntry(fentry, jc); // establish parent child realtionship dirEntry.AddChild(fentry); } // set the length dirEntry.Length = dirEntry.Count; // go ahead return true; }