private bool MoveOrRenameOrCopyItem(DropBoxStorageProviderSession session, BaseFileEntry orgEntry, String toPath, bool copy) { // build the path for resource var resourcePath = DropBoxResourceIDHelpers.GetResourcePath(orgEntry); // request the json object via oauth var parameters = new Dictionary <string, string> { { "from_path", resourcePath }, { "root", GetRootToken(session) }, { "to_path", toPath } }; try { // move or rename the entry int code; var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(copy ? DropBoxCopyItem : DropBoxMoveItem, session.ServiceConfiguration), parameters, this, session, out code); // update the entry DropBoxRequestParser.UpdateObjectFromJsonString(res, orgEntry, this, session); } catch (Exception) { return(false); } orgEntry.Id = toPath; return(true); }
public override bool DeleteResource(IStorageProviderSession session, ICloudFileSystemEntry entry) { var resourcePath = DropBoxResourceIDHelpers.GetResourcePath(entry); var parameters = new Dictionary <string, string> { { "path", resourcePath }, { "root", GetRootToken(session as DropBoxStorageProviderSession) } }; try { int code; DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxDeleteItem, session.ServiceConfiguration), parameters, this, session, out code); var parent = entry.Parent as BaseDirectoryEntry; if (parent != null) { parent.RemoveChildById(entry.Id); } } catch (Exception) { return(false); } return(true); }
public override bool DeleteResource(IStorageProviderSession session, ICloudFileSystemEntry entry) { // build the path for resource String resourcePath = GenericHelper.GetResourcePath(entry); // request the json object via oauth var parameters = new Dictionary <string, string> { { "path", resourcePath }, { "root", GetRootToken(session as DropBoxStorageProviderSession) } }; try { // remove int code; DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxDeleteItem, session.ServiceConfiguration), parameters, this, session, out code); // remove from parent BaseDirectoryEntry parentDir = entry.Parent as BaseDirectoryEntry; parentDir.RemoveChild(entry as BaseFileEntry); } catch (Exception) { return(false); } return(true); }
public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string name, ICloudDirectoryEntry parent) { String path = DropBoxResourceIDHelpers.GetResourcePath(parent, name); var parameters = new Dictionary <string, string> { { "path", path }, { "root", GetRootToken(session as DropBoxStorageProviderSession) } }; int code; var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxCreateFolder, session.ServiceConfiguration), parameters, this, session, out code); if (res.Length != 0) { var entry = DropBoxRequestParser.CreateObjectsFromJsonString(res, this, session); if (parent != null && parent is BaseDirectoryEntry && parent.Id.Equals(entry.ParentID)) { (parent as BaseDirectoryEntry).AddChild(entry); } return(entry); } return(null); }
public DropBoxAccountInfo GetAccountInfo(IStorageProviderSession session) { // request the json object via oauth int code; var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxGetAccountInfo, session.ServiceConfiguration), this, session, out code); // parse the jason stuff return(new DropBoxAccountInfo(res)); }
public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource) { // build url String uriString = GetResourceUrlInternal(session, resource); // request the data from url int code; var res = DropBoxRequestParser.RequestResourceByUrl(uriString, this, session, out code); // check error if (res.Length == 0) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList); } // build the entry and subchilds DropBoxRequestParser.UpdateObjectFromJsonString(res, resource as BaseFileEntry, this, session); }
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string name, ICloudDirectoryEntry parent) { var path = DropBoxResourceIDHelpers.GetResourcePath(parent, name); var uriString = GetResourceUrlInternal(session, path); int code; var res = DropBoxRequestParser.RequestResourceByUrl(uriString, this, session, out code); if (res.Length == 0) { if (code != (int)HttpStatusCode.OK) { throw new SharpBoxException( code == (int)HttpStatusCode.NotFound ? SharpBoxErrorCodes.ErrorFileNotFound : SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList, new HttpException(Convert.ToInt32(code), "HTTP Error")); } throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList); } // build the entry and subchilds var entry = DropBoxRequestParser.CreateObjectsFromJsonString(res, this, session); var hash = entry.GetPropertyValue("hash"); if (!string.IsNullOrEmpty(hash)) { DropBoxRequestParser.Addhash(uriString, hash, res, session); } // check if it was a deleted file if (entry.IsDeleted) { return(null); } // set the parent if (parent is BaseDirectoryEntry && parent.Id.Equals(entry.ParentID)) { (parent as BaseDirectoryEntry).AddChild(entry); } return(entry); }
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { // build url String uriString = GetResourceUrlInternal(session, parent); if (!Name.Equals("/") && Name.Length > 0) { uriString = PathHelper.Combine(uriString, HttpUtilityEx.UrlEncodeUTF8(Name)); } // request the data from url int code; var res = DropBoxRequestParser.RequestResourceByUrl(uriString, this, session, out code); // check error if (res.Length == 0) { if (code != (int)HttpStatusCode.OK) { HttpException hex = new HttpException(Convert.ToInt32(code), "HTTP Error"); throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList, hex); } else { throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList); } } // build the entry and subchilds BaseFileEntry entry = DropBoxRequestParser.CreateObjectsFromJsonString(res, this, session); // check if it was a deleted file if (entry.IsDeleted) { return(null); } // set the parent entry.Parent = parent; // go ahead return(entry); }
public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource) { var path = GetResourceUrlInternal(session, DropBoxResourceIDHelpers.GetResourcePath(resource)); int code; var res = DropBoxRequestParser.RequestResourceByUrl(path, this, session, out code); if (res.Length == 0) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList); } // build the entry and subchilds DropBoxRequestParser.UpdateObjectFromJsonString(res, resource as BaseFileEntry, this, session); var hash = resource.GetPropertyValue("hash"); if (!string.IsNullOrEmpty(hash)) { DropBoxRequestParser.Addhash(path, hash, res, session); } }
public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { // get the parent BaseDirectoryEntry parentDir = parent as BaseDirectoryEntry; // build new folder object var newFolder = new BaseDirectoryEntry(Name, 0, DateTime.Now, this, session); parentDir.AddChild(newFolder); // build the path for resource String resourcePath = GenericHelper.GetResourcePath(newFolder); // build the json parameters var parameters = new Dictionary <string, string> { { "path", resourcePath }, { "root", GetRootToken(session as DropBoxStorageProviderSession) } }; // request the json object via oauth int code; var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxCreateFolder, session.ServiceConfiguration), parameters, this, session, out code); if (res.Length == 0) { parentDir.RemoveChild(newFolder); return(null); } else { // update the folder object DropBoxRequestParser.UpdateObjectFromJsonString(res, newFolder, this, session); } // go ahead return(newFolder); }