public void RefreshDirectoryContent(IStorageProviderSession session, ICloudDirectoryEntry directory) { String uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, directory.Id); uri = SignUri(session, uri); WebRequest request = WebRequest.Create(uri); WebResponse response = request.GetResponse(); using (var rs = response.GetResponseStream()) { if (rs == null) throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList); String json = new StreamReader(rs).ReadToEnd(); var childs = SkyDriveJsonParser.ParseListOfEntries(session, json) .Select(x => x as BaseFileEntry).Where(x => x != null).ToArray(); if (childs.Length == 0 || !(directory is BaseDirectoryEntry)) throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList); var directoryBase = directory as BaseDirectoryEntry; directoryBase.AddChilds(childs); } }
public override Uri GetFileSystemObjectUrl(string path, ICloudDirectoryEntry parent) { var ph = new PathHelper(path); var elements = ph.GetPathElements(); var current = parent; for (int i = 0; i < elements.Length; i++) { var child = current.GetChild(elements[i], false); if (i == elements.Length - 1) { if (child == null || child is ICloudDirectoryEntry) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorFileNotFound); } return new Uri(child.GetPropertyValue(GoogleDocsConstants.DownloadUrlProperty)); } if (child == null || !(child is ICloudDirectoryEntry)) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorFileNotFound); } current = (ICloudDirectoryEntry) child; } return null; }
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; }
/// <summary> /// This method returns access ro a specific subfolder addressed via /// unix like file system path, e.g. SubFolder/SubSub /// /// Valid Exceptions are: /// SharpBoxException(nSharpBoxErrorCodes.ErrorInvalidFileOrDirectoryName); /// SharpBoxException(nSharpBoxErrorCodes.ErrorFileNotFound); /// </summary> /// <param name="path">The path to the target subfolder</param> /// <param name="parent">A reference to the parent when a relative path was given</param> /// <returns>Reference to the searched folder</returns> public ICloudDirectoryEntry GetFolder(String path, ICloudDirectoryEntry parent) { var dir = GetFileSystemObject(path, parent) as ICloudDirectoryEntry; if (dir == null) throw new SharpBoxException(SharpBoxErrorCodes.ErrorFileNotFound); return dir; }
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, String nameOrID, ICloudDirectoryEntry parent) { /* In this method name could be either requested resource name or it's ID. * In first case just refresh the parent and then search child with an appropriate. * In second case it does not matter if parent is null or not a parent because we use only resource ID. */ if (SkyDriveHelpers.IsResourceID(nameOrID) || nameOrID.Equals("/") && parent == null) //If request by ID or root folder requested { String uri = SkyDriveHelpers.IsResourceID(nameOrID) ? String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, nameOrID) : SkyDriveConstants.RootAccessUrl; uri = SignUri(session, uri); WebRequest request = WebRequest.Create(uri); WebResponse response = request.GetResponse(); using (var rs = response.GetResponseStream()) { if (rs != null) { String json = new StreamReader(rs).ReadToEnd(); ICloudFileSystemEntry entry = SkyDriveJsonParser.ParseSingleEntry(session, json); return entry; } } } else { String uri = parent != null ? String.Format(SkyDriveConstants.FilesAccessUrlFormat, parent.Id) : SkyDriveConstants.RootAccessUrl + "/files"; uri = SignUri(session, uri); WebRequest request = WebRequest.Create(uri); WebResponse response = request.GetResponse(); using (var rs = response.GetResponseStream()) { if (rs != null) { String json = new StreamReader(rs).ReadToEnd(); var entry = SkyDriveJsonParser.ParseListOfEntries(session, json).FirstOrDefault(x => x.Name.Equals(nameOrID)); if (entry != null && parent != null && parent is BaseDirectoryEntry) (parent as BaseDirectoryEntry).AddChild(entry as BaseFileEntry); return entry; } } } return null; }
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { // build path String path; if (Name.Equals("/")) path = session.ServiceConfiguration.ServiceLocator.LocalPath; else if (parent == null) path = Path.Combine(path = session.ServiceConfiguration.ServiceLocator.LocalPath, Name); else path = new Uri(GetResourceUrl(session, parent, Name)).LocalPath; // check if file exists if (File.Exists(path)) { // create the fileinfo FileInfo fInfo = new FileInfo(path); BaseFileEntry bf = new BaseFileEntry(fInfo.Name, fInfo.Length, fInfo.LastWriteTimeUtc, this, session) {Parent = parent}; // add to parent if (parent != null) (parent as BaseDirectoryEntry).AddChild(bf); // go ahead return bf; } // check if directory exists else if (Directory.Exists(path)) { // build directory info DirectoryInfo dInfo = new DirectoryInfo(path); // build bas dir BaseDirectoryEntry dir = CreateEntryByFileSystemInfo(dInfo, session, parent) as BaseDirectoryEntry; if (Name.Equals("/")) dir.Name = "/"; // add to parent if (parent != null) (parent as BaseDirectoryEntry).AddChild(dir); // refresh the childs RefreshChildsOfDirectory(session, dir); // go ahead return dir; } else return null; }
/// <summary> /// This method ... /// </summary> /// <param name="path"></param> /// <param name="startFolder"></param> /// <param name="throwException"></param> /// <returns></returns> public ICloudDirectoryEntry GetFolder(String path, ICloudDirectoryEntry startFolder, Boolean throwException) { try { return GetFolder(path, startFolder); } catch (SharpBoxException) { if (throwException) throw; return null; } }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="Name"></param> /// <param name="modifiedDate"></param> /// <param name="parent"></param> /// <returns></returns> public static ICloudDirectoryEntry CreateDirectoryEntry(IStorageProviderSession session, string Name, DateTime modifiedDate, ICloudDirectoryEntry parent) { // build up query url var newObj = new BaseDirectoryEntry(Name, 0, modifiedDate, session.Service, session); // case the parent if possible if (parent != null) { var objparent = parent as BaseDirectoryEntry; objparent.AddChild(newObj); } return newObj; }
public bool IsExist(string title, ICloudDirectoryEntry folder) { try { return(SharpBoxProviderInfo.Storage.GetFileSystemObject(title, folder) != null); } catch (ArgumentException) { throw; } catch (Exception) { } return(false); }
/// <summary> /// Starts the asyn get childs call /// </summary> /// <param name="callback"></param> /// <param name="parent"></param> /// <returns></returns> public IAsyncResult BeginGetChildsRequest(AsyncCallback callback, ICloudDirectoryEntry parent) { // build the request data structure BackgroundRequest request = new BackgroundRequest(); request.callback = callback; request.result = new AsyncResultEx(request); request.OperationParameter = parent; // add to threadpool ThreadPool.QueueUserWorkItem(GetChildsRequestCallback, request); // return the result return(request.result); }
protected Folder ToFolder(ICloudDirectoryEntry fsEntry) { if (fsEntry == null) { return(null); } if (fsEntry is ErrorEntry) { //Return error entry return(ToErrorFolder(fsEntry as ErrorEntry)); } //var childFoldersCount = fsEntry.OfType<ICloudDirectoryEntry>().Count();//NOTE: Removed due to performance isssues var isRoot = IsRoot(fsEntry); var folder = new Folder { ID = MakeId(fsEntry), ParentFolderID = isRoot ? null : MakeId(fsEntry.Parent), CreateBy = SharpBoxProviderInfo.Owner, CreateOn = isRoot ? SharpBoxProviderInfo.CreateOn : fsEntry.Modified, FolderType = FolderType.DEFAULT, ModifiedBy = SharpBoxProviderInfo.Owner, ModifiedOn = isRoot ? SharpBoxProviderInfo.CreateOn : fsEntry.Modified, ProviderId = SharpBoxProviderInfo.ID, ProviderKey = SharpBoxProviderInfo.ProviderKey, RootFolderCreator = SharpBoxProviderInfo.Owner, RootFolderId = MakeId(RootFolder()), RootFolderType = SharpBoxProviderInfo.RootFolderType, Shareable = false, Title = MakeTitle(fsEntry), TotalFiles = 0, /*fsEntry.Count - childFoldersCount NOTE: Removed due to performance isssues*/ TotalSubFolders = 0, /*childFoldersCount NOTE: Removed due to performance isssues*/ }; if (folder.CreateOn != DateTime.MinValue && folder.CreateOn.Kind == DateTimeKind.Utc) { folder.CreateOn = TenantUtil.DateTimeFromUtc(folder.CreateOn); } if (folder.ModifiedOn != DateTime.MinValue && folder.ModifiedOn.Kind == DateTimeKind.Utc) { folder.ModifiedOn = TenantUtil.DateTimeFromUtc(folder.ModifiedOn); } return(folder); }
/// <summary> /// This method ... /// </summary> /// <param name="path"></param> /// <param name="startFolder"></param> /// <param name="throwException"></param> /// <returns></returns> public ICloudDirectoryEntry GetFolder(String path, ICloudDirectoryEntry startFolder, Boolean throwException) { try { return(GetFolder(path, startFolder)); } catch (SharpBoxException) { if (throwException) { throw; } return(null); } }
internal static bool RenameFolder(Form1 form, ICloudDirectoryEntry directory, String newFolderName) { String question = String.Format(LanguageUtil.GetCurrentLanguageString("SureRenameFolder", className), directory.Name, newFolderName); if (WindowManager.ShowQuestionBox(form, question) == DialogResult.No) { return(false); } if (form.DropboxCloudStorage.RenameFileSystemEntry(directory, newFolderName) == false) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("WarningRenaming", className)); return(false); } return(true); }
public void UpdateMetaplanBoardScreen(MemoryStream screenshotStream, int retry = 3) { Thread.Sleep(1000); ICloudFileSystemEntry ice; try { ICloudDirectoryEntry targetFolder = Storage.GetFolder("/"); ice = Storage.UploadFile(screenshotStream, "MetaplanBoard_CELTIC.png", targetFolder); } catch (Exception ex) { Utilities.UtilitiesLib.LogError(ex); // if (retry > 0) // UpdateMetaplanBoardScreen(screenshotStream, retry - 1); } }
public override Uri GetFileSystemObjectUrl(string path, ICloudDirectoryEntry parent) { // get the filesystem var entry = GetFileSystemObject(path, parent); // get the download url var url = DropBoxStorageProviderService.GetDownloadFileUrlInternal(this._Session, entry); // get the right session var session = (DropBoxStorageProviderSession) _Session; // generate the oauth url var svc = new OAuthService(); url = svc.GetProtectedResourceUrl(url, session.Context, session.SessionToken as DropBoxToken, null, WebRequestMethodsEx.Http.Get); // go ahead return new Uri(url); }
/// <summary> /// Do the actual upload to Dropbox /// For more details on the available parameters, see: http://sharpbox.codeplex.com/ /// </summary> /// <param name="imageData">byte[] with image data</param> /// <returns>DropboxResponse</returns> public static DropboxInfo UploadToDropbox(byte[] imageData, string title, string filename) { // get the config of dropbox Dropbox.DropBoxConfiguration dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) as Dropbox.DropBoxConfiguration; // instanciate the cloudstorage manager CloudStorage storage = new CloudStorage(); // open the connection to the storage storage.Open(dropBoxConfig, config.DropboxAccessToken); // get the root entry of the cloud storage ICloudDirectoryEntry root = storage.GetRoot(); if (root == null) { Console.WriteLine("No root object found"); } else { // create the file ICloudFileSystemEntry file = storage.CreateFile(root, filename); // build the data stream Stream data = new MemoryStream(imageData); // reset stream data.Position = 0; // upload data file.GetDataTransferAccessor().Transfer(data, nTransferDirection.nUpload, null, null); } // close the cloud storage connection if (storage.IsOpened) { storage.Close(); } return(RetrieveDropboxInfo(filename)); }
internal static bool SaveFileOnDropbox(Form1 form1, Form form, String fileName, String directoryName) { XtraTabControl pagesTabControl = form1.pagesTabControl; ToolStripStatusLabel toolStripStatusLabel = form1.toolStripStatusLabel; ToolStripProgressBar toolStripProgressBar = form1.toolStripProgressBar; ICloudDirectoryEntry directory = DropboxManager.GetDirectory(form1, directoryName); try { Application.DoEvents(); toolStripProgressBar.Value = 0; toolStripProgressBar.Visible = true; toolStripProgressBar.PerformStep(); if (DropboxManager.ExistsChildOnDropbox(directory, fileName)) { if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("OverwriteFileOnDropbox", className)) != DialogResult.Yes) { return(false); } } //Encoding fileEncoding = TabUtil.GetTabTextEncoding(pagesTabControl.SelectedTabPage); toolStripProgressBar.PerformStep(); DropboxManager.SaveFileOnDropbox(form1, directory, fileName, ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage).Text); //, fileEncoding); toolStripProgressBar.PerformStep(); form1.LastDropboxFolder = directoryName; toolStripStatusLabel.Text = String.Format("{0} \"{1}\" {2}", LanguageUtil.GetCurrentLanguageString("File", className), Path.GetFileName(fileName), LanguageUtil.GetCurrentLanguageString("SavedOnDropbox", className)); toolStripProgressBar.PerformStep(); toolStripProgressBar.Visible = false; } catch (Exception exception) { toolStripProgressBar.Visible = false; WindowManager.ShowErrorBox(form, exception.Message, exception); return(false); } return(true); }
internal static void DeleteFolder(Form1 form, ICloudDirectoryEntry directory) { if (!ConfigUtil.GetBoolParameter("EnableDropboxDelete")) { return; } String question = String.Format(LanguageUtil.GetCurrentLanguageString("SureDeleteFolder", className), directory.Name); if (WindowManager.ShowQuestionBox(form, question) == DialogResult.No) { return; } if (!form.DropboxCloudStorage.DeleteFileSystemEntry(directory)) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("WarningDeleting", className)); } }
public override List <FileSystemObject> GetChildren(Directory dir) { ICloudDirectoryEntry de = _client.GetFolder(dir.Path); List <FileSystemObject> children = new List <FileSystemObject>(); foreach (ICloudFileSystemEntry item in de) { if (item is ICloudDirectoryEntry) //directory { children.Add(CreateFileSystemDirectory(item as ICloudDirectoryEntry)); } else //file { children.Add(new File(item.Name, GetFileSystemPath(item), CreateFileSystemDirectory(item.Parent), item.Modified, item.Length)); } } return(children); //return base.GetChildren(dir); }
/// <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); } }
public override Uri GetFileSystemObjectUrl(string path, ICloudDirectoryEntry parent) { // get the filesystem var entry = GetFileSystemObject(path, parent); // get the download url var url = DropBoxStorageProviderService.GetDownloadFileUrlInternal(Session, entry); // get the right session var session = (DropBoxStorageProviderSession)Session; // generate the oauth url var svc = new OAuthService(); url = svc.GetProtectedResourceUrl(url, session.Context, session.SessionToken as DropBoxToken, null, WebRequestMethodsEx.Http.Get); // go ahead return(new Uri(url)); }
/// <summary> /// This method request information about a resource /// </summary> /// <param name="session"></param> /// <param name="Name"></param> /// <param name="parent"></param> /// <returns></returns> public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { // build url String uriString = GetResourceUrl(session, parent, null); uriString = PathHelper.Combine(uriString, Name); // get the data List<BaseFileEntry> childs = null; BaseFileEntry requestResource = RequestResourceFromWebDavShare(session, uriString, out childs); // check errors if (requestResource == null) return null; // rename the root if (Name.Equals("/")) requestResource.Name = "/"; // init parent child relation if (parent != null) { BaseDirectoryEntry parentDir = parent as BaseDirectoryEntry; parentDir.AddChild(requestResource); } // check if we have to add childs if (!(requestResource is BaseDirectoryEntry)) return requestResource; else { BaseDirectoryEntry requestedDir = requestResource as BaseDirectoryEntry; // add the childs foreach (BaseFileEntry child in childs) { requestedDir.AddChild(child); } } // go ahead return requestResource; }
private static SortedDictionary <String, ICloudFileSystemEntry> CreateRemoteFileList(ICloudDirectoryEntry start, Boolean bRescusive) { // result var result = new SortedDictionary <string, ICloudFileSystemEntry>(); // directoryStack var directoryStack = new Stack <ICloudDirectoryEntry>(); // add the start directory to the stack directoryStack.Push(start); // do enumeration until stack is empty while (directoryStack.Count > 0) { ICloudDirectoryEntry current = directoryStack.Pop(); foreach (ICloudFileSystemEntry fsinfo in current) { if (fsinfo is ICloudDirectoryEntry) { // check if recursion allowed if (bRescusive == false) { continue; } // push the directory to stack directoryStack.Push(fsinfo as ICloudDirectoryEntry); } // build the path String path = CloudStorage.GetFullCloudPath(fsinfo, Path.DirectorySeparatorChar); String startpath = CloudStorage.GetFullCloudPath(start, Path.DirectorySeparatorChar); path = path.Remove(0, startpath.Length); // add the entry to our output list result.Add(path, fsinfo); } } return(result); }
public static DropboxInfo RetrieveDropboxInfo(string filename) { LOG.InfoFormat("Retrieving Dropbox info for {0}", filename); DropboxInfo dropBoxInfo = new DropboxInfo(); dropBoxInfo.ID = filename; dropBoxInfo.Title = filename; dropBoxInfo.Timestamp = DateTime.Now; dropBoxInfo.WebUrl = string.Empty; // get the config of dropbox Dropbox.DropBoxConfiguration dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) as Dropbox.DropBoxConfiguration; // instanciate the cloudstorage manager CloudStorage storage = new CloudStorage(); // get the root entry of the cloud storage ICloudDirectoryEntry root = storage.GetRoot(); // open the connection to the storage storage.Open(dropBoxConfig, config.DropboxAccessToken); dropBoxInfo.WebUrl = storage.GetFileSystemObjectUrl(dropBoxInfo.ID, root).ToString(); ICloudFileSystemEntry fileSystemEntry = storage.GetFileSystemObject(dropBoxInfo.ID, root); if (fileSystemEntry != null) { dropBoxInfo.Title = fileSystemEntry.Name; dropBoxInfo.Timestamp = fileSystemEntry.Modified; } // close the cloud storage connection if (storage.IsOpened) { storage.Close(); } return(dropBoxInfo); }
protected ICloudDirectoryEntry GetFolderById(object folderId) { ICloudDirectoryEntry entry = null; Exception e = null; try { entry = SharpBoxProviderInfo.Storage.GetFolder(MakePath(folderId)); } catch (Exception ex) { e = ex; } if (entry == null) { //Create error entry entry = new ErrorDirectoryEntry(e); } return(entry); }
/// <summary> /// This function allows to synchronize a local folder with an folder exists in the cloud storage /// and vice versa. The local folder and the target folder has to be created before. /// </summary> /// <param name="srcFolder"></param> /// <param name="tgtFolder"></param> /// <param name="flags"></param> /// <returns></returns> public Boolean SynchronizeFolder(string srcFolder, string tgtFolder, SyncFolderFlags flags) { // check parameters if (srcFolder == null || tgtFolder == null || flags == SyncFolderFlags.Empty) { return(false); } // build directory info for local folder DirectoryInfo srcFolderInfo = new DirectoryInfo(srcFolder); // build the target folder ICloudDirectoryEntry tgtFolderEntry = GetFolder(tgtFolder); if (tgtFolderEntry == null) { return(false); } // call the sync job return(SynchronizeFolder(srcFolderInfo, tgtFolderEntry, flags)); }
public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { // get credentials ICredentials creds = ((GenericNetworkCredentials)session.SessionToken).GetCredential(null, null); // build the full url String resFull = GetResourceUrl(session, parent, Name); // create the director if (_ftpService.FtpCreateDirectory(resFull, creds)) { // create the filesystem object ICloudDirectoryEntry fsEntry = GenericStorageProviderFactory.CreateDirectoryEntry(session, Name, parent); // go ahead return(fsEntry); } else { return(null); } }
/// <summary> /// This function allows to upload a local file. Remote file will be created with the name specifed by /// the targetFileName argument /// </summary> /// <param name="filePath"></param> /// <param name="targetDirectory"></param> /// <param name="targetFileName"></param> /// <param name="delProgress"></param> /// <returns></returns> public ICloudFileSystemEntry UploadFile(string filePath, string targetDirectory, string targetFileName, FileOperationProgressChanged delProgress) { // check parameters if (String.IsNullOrEmpty(filePath) || String.IsNullOrEmpty(targetFileName) || targetDirectory == null) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters); } // get target container ICloudDirectoryEntry target = GetFolder(targetDirectory); if (target == null) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorFileNotFound); } // upload file using (Stream s = File.OpenRead(filePath)) { return(UploadFile(s, targetFileName, target, delProgress)); } }
protected Folder <string> ToFolder(ICloudDirectoryEntry fsEntry) { if (fsEntry == null) { return(null); } if (fsEntry is ErrorEntry) { //Return error entry return(ToErrorFolder(fsEntry as ErrorEntry)); } //var childFoldersCount = fsEntry.OfType<ICloudDirectoryEntry>().Count();//NOTE: Removed due to performance isssues var isRoot = IsRoot(fsEntry); var folder = GetFolder(); folder.ID = MakeId(fsEntry); folder.ParentFolderID = isRoot ? null : MakeId(fsEntry.Parent); folder.CreateOn = isRoot ? ProviderInfo.CreateOn : fsEntry.Modified; folder.ModifiedOn = isRoot ? ProviderInfo.CreateOn : fsEntry.Modified; folder.RootFolderId = MakeId(RootFolder()); folder.Title = MakeTitle(fsEntry); folder.TotalFiles = 0; /*fsEntry.Count - childFoldersCount NOTE: Removed due to performance isssues*/ folder.TotalSubFolders = 0; /*childFoldersCount NOTE: Removed due to performance isssues*/ if (folder.CreateOn != DateTime.MinValue && folder.CreateOn.Kind == DateTimeKind.Utc) { folder.CreateOn = TenantUtil.DateTimeFromUtc(folder.CreateOn); } if (folder.ModifiedOn != DateTime.MinValue && folder.ModifiedOn.Kind == DateTimeKind.Utc) { folder.ModifiedOn = TenantUtil.DateTimeFromUtc(folder.ModifiedOn); } return(folder); }
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 creates a folder in a given parent folder. /// Override this if your storage support resources having same name in one folder. /// </summary> /// <param name="name"></param> /// <param name="parent"></param> /// <returns></returns> public virtual ICloudDirectoryEntry CreateFolder(string name, ICloudDirectoryEntry parent) { // solve the parent issue if (parent == null) { parent = GetRoot(); if (parent == null) { return(null); } } // Don't support resources having same name in one folder by default var child = parent.FirstOrDefault(x => x.Name.Equals(name) && x is ICloudDirectoryEntry); if (child != null) { return(child as ICloudDirectoryEntry); } return(Service.CreateResource(Session, name, parent) as ICloudDirectoryEntry); }
private void ChildCallback(IAsyncResult result) { List <ICloudFileSystemEntry> fs = m_dropBox.EndGetChildsRequest(result); Deployment.Current.Dispatcher.BeginInvoke(() => { if (fs != null) { parseFilesAndDirectories(fs); while (m_directories.Count > 0) { ICloudDirectoryEntry e = m_directories[0]; m_directories.RemoveAt(0); m_dropBox.BeginGetChildsRequest(ChildCallback, e); } LoadingFileList = false; } else { LoadingFileList = false; } }); }
private DropBoxStorageProviderSession GetRootBySessionExceptionHandled(DropBoxStorageProviderSession session) { try { ICloudDirectoryEntry root = GetRootBySession(session); // return the infos return(root == null ? null : session); } catch (SharpBoxException ex) { // check if the exception an http error 403 if (ex.InnerException is HttpException) { if ((((HttpException)ex.InnerException).GetHttpCode() == 403) || (((HttpException)ex.InnerException).GetHttpCode() == 401)) { throw new UnauthorizedAccessException(); } } // otherwise rethrow the old exception throw ex; } }
protected Folder ToFolder(ICloudDirectoryEntry fsEntry) { if (fsEntry == null) { return(null); } if (fsEntry is ErrorDirectoryEntry) { //Return error entry return(ToErrorFolder(fsEntry as ErrorDirectoryEntry)); } //var childFoldersCount = fsEntry.OfType<ICloudDirectoryEntry>().Count();//NOTE: Removed due to performance isssues var isRoot = IsRoot(fsEntry); return(new Folder { ID = MakeId(fsEntry), ParentFolderID = isRoot ? null : MakeId(fsEntry.Parent), CreateBy = SharpBoxProviderInfo.Owner, CreateOn = isRoot ? SharpBoxProviderInfo.CreateOn : fsEntry.Modified, FolderType = FolderType.DEFAULT, ModifiedBy = SharpBoxProviderInfo.Owner, ModifiedOn = isRoot ? SharpBoxProviderInfo.CreateOn : fsEntry.Modified, ProviderId = SharpBoxProviderInfo.ID, ProviderName = SharpBoxProviderInfo.ProviderName, ProviderUserName = SharpBoxProviderInfo.UserName, RootFolderCreator = SharpBoxProviderInfo.Owner, RootFolderId = MakeId(RootFolder()), RootFolderType = SharpBoxProviderInfo.RootFolderType, Shareable = false, Title = MakeTitle(fsEntry), TotalFiles = 0, /*fsEntry.Count - childFoldersCount NOTE: Removed due to performance isssues*/ TotalSubFolders = 0, /*childFoldersCount NOTE: Removed due to performance isssues*/ }); }
protected IEnumerable<ICloudFileSystemEntry> GetFolderSubfolders(ICloudDirectoryEntry folder) { return folder.Where(x => (x is ICloudDirectoryEntry)); }
protected Folder ToFolder(ICloudDirectoryEntry fsEntry) { if (fsEntry == null) return null; if (fsEntry is ErrorDirectoryEntry) { //Return error entry return ToErrorFolder(fsEntry as ErrorDirectoryEntry); } //var childFoldersCount = fsEntry.OfType<ICloudDirectoryEntry>().Count();//NOTE: Removed due to performance isssues var isRoot = IsRoot(fsEntry); return new Folder { ID = MakeId(fsEntry), ParentFolderID = isRoot ? null : MakeId(fsEntry.Parent), CreateBy = SharpBoxProviderInfo.Owner, CreateOn = isRoot ? SharpBoxProviderInfo.CreateOn : fsEntry.Modified, FolderType = FolderType.DEFAULT, ModifiedBy = SharpBoxProviderInfo.Owner, ModifiedOn = isRoot ? SharpBoxProviderInfo.CreateOn : fsEntry.Modified, ProviderId = SharpBoxProviderInfo.ID, ProviderName = SharpBoxProviderInfo.ProviderName, ProviderUserName = SharpBoxProviderInfo.UserName, RootFolderCreator = SharpBoxProviderInfo.Owner, RootFolderId = MakeId(RootFolder()), RootFolderType = SharpBoxProviderInfo.RootFolderType, Shareable = false, Title = MakeTitle(fsEntry), TotalFiles = 0, /*fsEntry.Count - childFoldersCount NOTE: Removed due to performance isssues*/ TotalSubFolders = 0, /*childFoldersCount NOTE: Removed due to performance isssues*/ }; }
private bool IsRoot(ICloudDirectoryEntry entry) { if (entry != null && entry.Name != null) return string.IsNullOrEmpty(entry.Name.Trim('/')); return false; }
/// <summary> /// Starts the asyn get childs call /// </summary> /// <param name="callback"></param> /// <param name="parent"></param> /// <returns></returns> public IAsyncResult BeginGetChildsRequest(AsyncCallback callback, ICloudDirectoryEntry parent) { // build the request data structure BackgroundRequest request = new BackgroundRequest(); request.callback = callback; request.result = new AsyncResultEx(request); request.OperationParameter = parent; // add to threadpool ThreadPool.QueueUserWorkItem(GetChildsRequestCallback, request); // return the result return request.result; }
public ICloudFileSystemEntry CreateFile(ICloudDirectoryEntry parent, string name) { return _provider.CreateFile(parent, name); }
public ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { var cacheKey = GetSessionKey(session); return(FsCache.Get(cacheKey, GetCacheUrl(session, Name, parent), () => _service.RequestResource(session, Name, parent))); }
public ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent) { FsCache.Reset(GetSessionKey(session), GetCacheUrl(session, null, parent)); return(_service.CreateResource(session, Name, parent)); }
public ICloudDirectoryEntry CreateFolder(string name, ICloudDirectoryEntry parent) { return _provider.CreateFolder(name, parent); }
public bool IsExist(string title, ICloudDirectoryEntry folder) { try { return SharpBoxProviderInfo.Storage.GetFileSystemObject(title, folder) != null; } catch (ArgumentException) { throw; } catch (Exception) { } return false; }
/// <summary> /// This method returns the absolut URL (with all authentication decorators) for a specific file /// system object /// </summary> /// <param name="path"></param> /// <param name="parent"></param> /// <returns></returns> public virtual Uri GetFileSystemObjectUrl(string path, ICloudDirectoryEntry parent) { String url = _Service.GetResourceUrl(_Session, parent, path); return new Uri(url); }
/// <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 file in the cloud storage /// </summary> /// <param name="parent"></param> /// <param name="name"></param> /// <returns></returns> public virtual ICloudFileSystemEntry CreateFile(ICloudDirectoryEntry parent, string name) { // build the parent if (parent == null) parent = GetRoot(); // build the file entry var newEntry = GenericStorageProviderFactory.CreateFileSystemEntry(_Session, name, parent); return newEntry; }
/// <summary> /// This method moves a specifc filesystem object from his current location /// into a new folder /// </summary> /// <param name="fsentry"></param> /// <param name="newParent"></param> /// <returns></returns> public bool CopyFileSystemEntry(ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent) { return _Service.CopyResource(_Session, fsentry, newParent); }
/// <summary> /// This method creates a folder in a given parent folder. /// Override this if your storage support resources having same name in one folder. /// </summary> /// <param name="name"></param> /// <param name="parent"></param> /// <returns></returns> public virtual ICloudDirectoryEntry CreateFolder(string name, ICloudDirectoryEntry parent) { // solve the parent issue if (parent == null) { parent = GetRoot(); if (parent == null) return null; } // Don't support resources having same name in one folder by default var child = parent.FirstOrDefault(x => x.Name.Equals(name) && x is ICloudDirectoryEntry); if (child != null) return child as ICloudDirectoryEntry; return _Service.CreateResource(_Session, name, parent) as ICloudDirectoryEntry; }
private IEnumerable<FileSystemItem> getDirectoryFileSystemItems(ICloudDirectoryEntry directory,string path) { List<FileSystemItem> fileEntries = new List<FileSystemItem>(); foreach (ICloudFileSystemEntry fsentry in directory) { if (fsentry is ICloudDirectoryEntry) fileEntries.Add(new FileSystemItem() { IsDirectory = true, Name = fsentry.Name, Path = concatPath(path, fsentry.Name) }); else fileEntries.Add(new FileSystemItem() { IsDirectory = false, Name = fsentry.Name, Path = concatPath(path, fsentry.Name) }); } return fileEntries; }
private bool CopyFileSystemEntry(ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent) { return _provider.CopyFileSystemEntry(fsentry, newParent); }
/// <summary> /// This method deletes a resource in the storage provider service /// </summary> /// <param name="session"></param> /// <param name="fsentry"></param> /// <param name="newParent"></param> /// <returns></returns> public abstract bool MoveResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent);
private void ListCloudDirectoryEntry(ICloudDirectoryEntry cloudEntry) { foreach (var subCloudEntry in cloudEntry) { if (subCloudEntry is ICloudDirectoryEntry) { workerLoadFolders.ReportProgress(2, subCloudEntry); ListCloudDirectoryEntry((ICloudDirectoryEntry)subCloudEntry); } } }
public override bool CopyResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent) { // build the targte url String uriStringTarget = this.GetResourceUrl(session, newParent, null); uriStringTarget = PathHelper.Combine(uriStringTarget, fsentry.Name); if (!CopyResource(session, fsentry, uriStringTarget)) return false; var newParentObject = newParent as BaseDirectoryEntry; if (newParentObject != null) { newParentObject.AddChild(fsentry as BaseFileEntry); } return true; }
private void AddCloudDirectory(ICloudDirectoryEntry cloudEntry, TreeNode trParent) { TreeNode newNode = null; if (trParent == null) { newNode = viewFolders.Nodes.Add(cloudEntry.GetPropertyValue("path"), cloudEntry.Name); } else { newNode = trParent.Nodes.Add(cloudEntry.GetPropertyValue("path"), cloudEntry.Name); } newNode.Tag = cloudEntry; }
public bool CopyResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent) { FsCache.Reset(GetSessionKey(session), GetCacheUrl(session, null, newParent)); return(_service.CopyResource(session, fsentry, newParent)); }
private ICloudDirectoryEntry CreateFolderEx(string path, ICloudDirectoryEntry entry) { var ph = new PathHelper(path); var pes = ph.GetPathElements(); foreach (var el in pes) { var cur = GetFolder(el, entry, false); if (cur == null) { var newFolder = CreateFolder(el, entry); if (newFolder == null) throw new SharpBoxException(SharpBoxErrorCodes.ErrorCreateOperationFailed); cur = newFolder; } entry = cur; } return entry; }
/// <summary> /// This method request a directory entry from the storage provider service /// </summary> /// <param name="session"></param> /// <param name="Name"></param> /// <param name="parent"></param> /// <returns></returns> public abstract ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent);
public ICloudFileSystemEntry GetFile(string path, ICloudDirectoryEntry startFolder) { var fsEntry = GetFileSystemObject(path, startFolder); if (fsEntry is ICloudDirectoryEntry) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidFileOrDirectoryName); return fsEntry; }
/// <summary> /// This method deletes a resource in the storage provider service /// </summary> /// <param name="session"></param> /// <param name="fsentry"></param> /// <param name="newParent"></param> /// <returns></returns> public virtual bool CopyResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent) { throw new NotSupportedException("This operation is not supported"); }
public ICloudFileSystemEntry GetFileSystemObject(string name, ICloudDirectoryEntry parent) { return _provider.GetFileSystemObject(name, parent); }