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 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); }