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; }
/// <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; }
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 function allows to create full folder pathes in the cloud storage /// </summary> /// <param name="path"></param> /// <param name="entry"></param> /// <returns></returns> public ICloudDirectoryEntry CreateFolderEx(String path, ICloudDirectoryEntry entry) { // get the path elemtens var ph = new PathHelper(path); String[] pes = ph.GetPathElements(); // check which elements are existing foreach (String el in pes) { // check if subfolder exists, if it doesn't, create it ICloudDirectoryEntry cur = GetFolder(el, entry, false); // create if needed if (cur == null) { ICloudDirectoryEntry newFolder = CreateFolder(el, entry); if (newFolder == null) throw new SharpBoxException(SharpBoxErrorCodes.ErrorCreateOperationFailed); else cur = newFolder; } // go ahead entry = cur; } // return return entry; }