/// <summary> /// This method returns a filesystem object, this can be files or folders /// </summary> /// <param name="path"></param> /// <param name="parent"></param> /// <returns></returns> public ICloudFileSystemEntry GetFileSystemObject(string path, ICloudDirectoryEntry parent) { /* * This section generates for every higher object the object tree */ PathHelper ph = new PathHelper(path); String[] elements = ph.GetPathElements(); // create the virtual root ICloudDirectoryEntry current = parent ?? GetRoot(); // build the root // check if we request only the root if (path.Equals("/")) { return(current); } if (_Service.SupportsDirectRetrieve) { //Request directly return(_Service.RequestResource(_Session, path.TrimStart('/'), current)); } // create the path tree for (int i = 0; i <= elements.Length - 1; i++) { String elem = elements[i]; if (i == elements.Length - 1) { return(current.GetChild(elem, false)); } try { current = current.GetChild(elem, true) as ICloudDirectoryEntry; } catch (SharpBoxException e) { // if not found, create a virtual one if (e.ErrorCode == SharpBoxErrorCodes.ErrorFileNotFound) { current = GenericStorageProviderFactory.CreateDirectoryEntry(_Session, elem, current); } else { throw; } } } // looks like an error return(null); }
/// <summary> /// This method creates a folder in a given parent folder /// </summary> /// <param name="name"></param> /// <param name="parent"></param> /// <returns></returns> public ICloudDirectoryEntry CreateFolder(string name, ICloudDirectoryEntry parent) { // solve the parent issue if (parent == null) { parent = GetRoot(); if (parent == null) { return(null); } } // double check if the folder which has to be created // is in the folder var childDir = parent.GetChild(name, false); if (childDir != null) { return(childDir as ICloudDirectoryEntry); } // request the object var res = _Service.CreateResource(_Session, name, parent); if (res == null) { return(null); } // go ahead return(res as ICloudDirectoryEntry); }
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { //declare the requested entry ICloudFileSystemEntry fsEntry = null; // lets have a look if we are on the root node if (parent == null) { // just create the root entry fsEntry = GenericStorageProviderFactory.CreateDirectoryEntry(session, Name, parent); } else { // ok we have a parent, let's retrieve the resource // from his child list fsEntry = parent.GetChild(Name, false); } // now that we create the entry just update the chuld if (fsEntry != null && fsEntry is ICloudDirectoryEntry) { RefreshResource(session, fsEntry as ICloudDirectoryEntry); } // go ahead return(fsEntry); }
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { //declare the requested entry ICloudFileSystemEntry fsEntry = null; // lets have a look if we are on the root node if (parent == null) { // just create the root entry fsEntry = GenericStorageProviderFactory.CreateDirectoryEntry(session, Name, parent); } else { // ok we have a parent, let's retrieve the resource // from his child list fsEntry = parent.GetChild(Name, false); } // now that we create the entry just update the chuld if (fsEntry != null && fsEntry is ICloudDirectoryEntry) RefreshResource(session, fsEntry as ICloudDirectoryEntry); // go ahead return fsEntry; }
internal static bool ExistsChildOnDropbox(ICloudDirectoryEntry directory, String childName) { try { ICloudFileSystemEntry file = directory.GetChild(childName); return(file != null); } catch (Exception) { return(false); } }
/// <summary> /// This method returns a data stream which allows to downloads the /// file data /// </summary> /// <param name="name"></param> /// <param name="parent"></param> /// <param name="targetStream"></param> /// <returns></returns> public void DownloadFile(String name, ICloudDirectoryEntry parent, Stream targetStream) { // check parameters if (parent == null || name == null) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters); } // get the file entry var file = parent.GetChild(name, true); // download the data file.GetDataTransferAccessor().Transfer(targetStream, nTransferDirection.nDownload); }
/// <summary> /// This functions allows to download a specific file /// /// Valid Exceptions are: /// SharpBoxException(nSharpBoxErrorCodes.ErrorFileNotFound); /// </summary> /// <param name="parent"></param> /// <param name="name"></param> /// <param name="targetPath"></param> /// <param name="delProgress"></param> /// <returns></returns> public void DownloadFile(ICloudDirectoryEntry parent, String name, String targetPath, FileOperationProgressChanged delProgress) { // check parameters if (parent == null || name == null || targetPath == null) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters); } // expand environment in target path targetPath = Environment.ExpandEnvironmentVariables(targetPath); // get the file entry var file = parent.GetChild(name, true); using (var targetData = new FileStream(Path.Combine(targetPath, file.Name), FileMode.Create, FileAccess.Write, FileShare.None)) { file.GetDataTransferAccessor().Transfer(targetData, nTransferDirection.nDownload, delProgress, null); } }
internal static bool RenameFile(Form1 form, ICloudDirectoryEntry directory, String fileName, String newFileName) { String question = String.Format(LanguageUtil.GetCurrentLanguageString("SureRenameFile", className), fileName, newFileName); if (WindowManager.ShowQuestionBox(form, question) == DialogResult.No) { return(false); } ICloudFileSystemEntry file = directory.GetChild(fileName); if (form.DropboxCloudStorage.RenameFileSystemEntry(file, newFileName) == false) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("WarningRenaming", className)); return(false); } return(true); }
internal static void DeleteFile(Form1 form, ICloudDirectoryEntry directory, String fileName) { if (!ConfigUtil.GetBoolParameter("EnableDropboxDelete")) { return; } String question = String.Format(LanguageUtil.GetCurrentLanguageString("SureDeleteFile", className), fileName); if (WindowManager.ShowQuestionBox(form, question) == DialogResult.No) { return; } ICloudFileSystemEntry file = directory.GetChild(fileName); if (!form.DropboxCloudStorage.DeleteFileSystemEntry(file)) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("WarningDeleting", className)); } }
internal static String GetFileFromDropbox(ICloudDirectoryEntry directory, String fileName, out bool fileExists) { fileExists = false; if (!ExistsChildOnDropbox(directory, fileName)) { return(String.Empty); } ICloudFileSystemEntry file = directory.GetChild(fileName); String content; using (Stream streamFile = file.GetDataTransferAccessor().GetDownloadStream()) { using (StreamReader reader = new StreamReader(streamFile, Encoding.UTF8)) { content = reader.ReadToEnd(); } } fileExists = true; return(content); }
/// <summary> /// This method returns a filesystem object, this can be files or folders /// </summary> /// <param name="path"></param> /// <param name="parent"></param> /// <returns></returns> public ICloudFileSystemEntry GetFileSystemObject(string path, ICloudDirectoryEntry parent) { /* * This section generates for every higher object the object tree */ PathHelper ph = new PathHelper(path); String[] elements = ph.GetPathElements(); // create the virtual root ICloudDirectoryEntry current = parent; // build the root if (current == null) { current = GetRoot(); } // check if we request only the root if (path.Equals("/")) { return(current); } // create the path tree for (int i = 0; i <= elements.Length - 1; i++) { String elem = elements[i]; if (i == elements.Length - 1) { // get requested object ICloudFileSystemEntry requestedObject = _Service.RequestResource(_Session, elem, current); // go ahead on error if (requestedObject == null) { return(null); } else { // go ahead return(requestedObject); } } else { try { // try to get the child current = current.GetChild(elem) as ICloudDirectoryEntry; } catch (SharpBoxException e) { // if not found, create a virtual one if (e.ErrorCode == SharpBoxErrorCodes.ErrorFileNotFound) { current = GenericStorageProviderFactory.CreateDirectoryEntry(_Session, elem, current); } else { throw e; } } } } // looks like an error return(null); }
/// <summary> /// This method returns a data stream which allows to downloads the /// file data /// </summary> /// <param name="name"></param> /// <param name="parent"></param> /// <param name="targetStream"></param> /// <returns></returns> public void DownloadFile(String name, ICloudDirectoryEntry parent, Stream targetStream) { // check parameters if (parent == null || name == null) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters); // get the file entry ICloudFileSystemEntry file = parent.GetChild(name, true); // download the data file.GetDataTransferAccessor().Transfer(targetStream, nTransferDirection.nDownload); }
/// <summary> /// This functions allows to download a specific file /// /// Valid Exceptions are: /// SharpBoxException(nSharpBoxErrorCodes.ErrorFileNotFound); /// </summary> /// <param name="parent"></param> /// <param name="name"></param> /// <param name="targetPath"></param> /// <param name="delProgress"></param> /// <returns></returns> public void DownloadFile(ICloudDirectoryEntry parent, String name, String targetPath, FileOperationProgressChanged delProgress) { // check parameters if (parent == null || name == null || targetPath == null) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters); #if !WINDOWS_PHONE && !ANDROID // expand environment in target path targetPath = Environment.ExpandEnvironmentVariables(targetPath); #endif // get the file entry ICloudFileSystemEntry file = parent.GetChild(name, true); using (var targetData = new FileStream(Path.Combine(targetPath, file.Name), FileMode.Create, FileAccess.Write, FileShare.None)) { file.GetDataTransferAccessor().Transfer(targetData, nTransferDirection.nDownload, delProgress, null); } }
/// <summary> /// This method creates a folder in a given parent folder /// </summary> /// <param name="name"></param> /// <param name="parent"></param> /// <returns></returns> public ICloudDirectoryEntry CreateFolder(string name, ICloudDirectoryEntry parent) { // solve the parent issue if (parent == null) { parent = GetRoot(); if (parent == null) return null; } // double check if the folder which has to be created // is in the folder var childDir = parent.GetChild(name, false); if (childDir != null) return childDir as ICloudDirectoryEntry; // request the object var res = _Service.CreateResource(_Session, name, parent); if (res == null) return null; // go ahead return res as ICloudDirectoryEntry; }