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 override bool CopyResource(IStorageProviderSession session, ICloudFileSystemEntry entry, ICloudDirectoryEntry copyTo) { if (entry.Name.Equals("/")) { return(false); } if (entry is ICloudDirectoryEntry) { // skydrive allowes to copy only files so we will recursively create/copy entries var newEntry = CreateResource(session, entry.Name, copyTo) as ICloudDirectoryEntry; return(newEntry != null && (entry as ICloudDirectoryEntry).Aggregate(true, (current, subEntry) => current && CopyResource(session, subEntry, newEntry))); } var uri = String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, entry.GetPropertyValue(SkyDriveConstants.InnerIDKey)); var data = String.Format("{{destination: \"{0}\"}}", copyTo.GetPropertyValue(SkyDriveConstants.InnerIDKey)); var json = SkyDriveRequestHelper.PerformRequest(session, uri, "COPY", data, false); if (json != null && !SkyDriveJsonParser.ContainsError(json, false)) { var copyToBase = copyTo as BaseDirectoryEntry; if (copyToBase != null) { copyToBase.AddChild(entry as BaseFileEntry); } return(true); } return(false); }
public override bool MoveResource(IStorageProviderSession session, ICloudFileSystemEntry entry, ICloudDirectoryEntry moveTo) { if (entry.Name.Equals("/")) { return(false); } var uri = String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, entry.GetPropertyValue(SkyDriveConstants.InnerIDKey)); var data = String.Format("{{destination: \"{0}\"}}", moveTo.GetPropertyValue(SkyDriveConstants.InnerIDKey)); var json = SkyDriveRequestHelper.PerformRequest(session, uri, "MOVE", data, false); if (!SkyDriveJsonParser.ContainsError(json, false)) { var parent = entry.Parent as BaseDirectoryEntry; if (parent != null) { parent.RemoveChildById(entry.GetPropertyValue(SkyDriveConstants.InnerIDKey)); } var moveToBase = moveTo as BaseDirectoryEntry; if (moveToBase != null) { moveToBase.AddChild(entry as BaseFileEntry); } return(true); } return(false); }
public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, String name, ICloudDirectoryEntry parent) { if (name.Contains("/")) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidFileOrDirectoryName); } var uri = parent != null ? String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, parent.GetPropertyValue(SkyDriveConstants.InnerIDKey)) : SkyDriveConstants.RootAccessUrl; var data = String.Format("{{name: \"{0}\"}}", name); var json = SkyDriveRequestHelper.PerformRequest(session, uri, "POST", data, false); var entry = SkyDriveJsonParser.ParseSingleEntry(session, json); var parentBase = parent as BaseDirectoryEntry; if (parentBase != null && entry != null) { parentBase.AddChild(entry as BaseFileEntry); } return(entry); }
public void RefreshDirectoryContent(IStorageProviderSession session, ICloudDirectoryEntry directory) { if (!(directory is BaseDirectoryEntry)) { return; } var uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, directory.GetPropertyValue(SkyDriveConstants.InnerIDKey)); (directory as BaseDirectoryEntry).AddChilds(RequestContentByUrl(session, uri).Cast <BaseFileEntry>()); }
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.HasResourceID(nameOrID) || nameOrID.Equals("/") && parent == null) //If request by ID or root folder requested { var id = SkyDriveHelpers.GetResourceID(nameOrID); String uri = id != String.Empty ? String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, id) : SkyDriveConstants.RootAccessUrl; if (SkyDriveHelpers.IsFolderID(id)) { var contents = new List<ICloudFileSystemEntry>(); BaseDirectoryEntry entry = null; /*var completeContent = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(state => { contents.AddRange(RequestContentByUrl(session, uri + "/files")); ((AutoResetEvent) state).Set(); }, completeContent); var completeEntry = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(state => { entry = RequestResourseByUrl(session, uri) as BaseDirectoryEntry; ((AutoResetEvent) state).Set(); }, completeEntry); WaitHandle.WaitAll(new WaitHandle[] {completeContent, completeEntry});*/ entry = RequestResourseByUrl(session, uri) as BaseDirectoryEntry; contents.AddRange(RequestContentByUrl(session, uri + "/files")); if (entry != null && contents.Any()) entry.AddChilds(contents.Cast<BaseFileEntry>()); return entry; } return RequestResourseByUrl(session, uri); } else { String uri; if (SkyDriveHelpers.HasParentID(nameOrID)) uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, SkyDriveHelpers.GetParentID(nameOrID)); else if (parent != null) uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, parent.GetPropertyValue(SkyDriveConstants.InnerIDKey)); else uri = SkyDriveConstants.RootAccessUrl + "/files"; nameOrID = Path.GetFileName(nameOrID); var entry = RequestContentByUrl(session, uri).FirstOrDefault(x => x.Name.Equals(nameOrID)); return entry; } }
public override bool CopyResource(IStorageProviderSession session, ICloudFileSystemEntry entry, ICloudDirectoryEntry copyTo) { if (entry.Name.Equals("/")) return false; if (entry is ICloudDirectoryEntry) { // skydrive allowes to copy only files so we will recursively create/copy entries var newEntry = CreateResource(session, entry.Name, copyTo) as ICloudDirectoryEntry; return newEntry != null && (entry as ICloudDirectoryEntry).Aggregate(true, (current, subEntry) => current && CopyResource(session, subEntry, newEntry)); } String uri = String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, entry.GetPropertyValue(SkyDriveConstants.InnerIDKey)); String data = String.Format("{{destination: \"{0}\"}}", copyTo.GetPropertyValue(SkyDriveConstants.InnerIDKey)); String json = SkyDriveRequestHelper.PerformRequest(session, uri, "COPY", data, false); if (json != null && !SkyDriveJsonParser.ContainsError(json, false)) { var copyToBase = copyTo as BaseDirectoryEntry; if (copyToBase != null) copyToBase.AddChild(entry as BaseFileEntry); return true; } return false; }
public void RefreshDirectoryContent(IStorageProviderSession session, ICloudDirectoryEntry directory) { if (!(directory is BaseDirectoryEntry)) return; String uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, directory.GetPropertyValue(SkyDriveConstants.InnerIDKey)); (directory as BaseDirectoryEntry).AddChilds(RequestContentByUrl(session, uri).Cast<BaseFileEntry>()); }
public override bool MoveResource(IStorageProviderSession session, ICloudFileSystemEntry entry, ICloudDirectoryEntry moveTo) { if (entry.Name.Equals("/")) return false; String uri = String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, entry.GetPropertyValue(SkyDriveConstants.InnerIDKey)); String data = String.Format("{{destination: \"{0}\"}}", moveTo.GetPropertyValue(SkyDriveConstants.InnerIDKey)); String json = SkyDriveRequestHelper.PerformRequest(session, uri, "MOVE", data, false); if (!SkyDriveJsonParser.ContainsError(json, false)) { var parent = entry.Parent as BaseDirectoryEntry; if (parent != null) parent.RemoveChildById(entry.GetPropertyValue(SkyDriveConstants.InnerIDKey)); var moveToBase = moveTo as BaseDirectoryEntry; if (moveToBase != null) moveToBase.AddChild(entry as BaseFileEntry); return true; } return false; }
public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, String name, ICloudDirectoryEntry parent) { if (name.Contains("/")) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidFileOrDirectoryName); String uri = parent != null ? String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, parent.GetPropertyValue(SkyDriveConstants.InnerIDKey)) : SkyDriveConstants.RootAccessUrl; String data = String.Format("{{name: \"{0}\"}}", name); String json = SkyDriveRequestHelper.PerformRequest(session, uri, "POST", data, false); var entry = SkyDriveJsonParser.ParseSingleEntry(session, json); var parentBase = parent as BaseDirectoryEntry; if (parentBase != null && entry != null) parentBase.AddChild(entry as BaseFileEntry); return entry; }
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.HasResourceID(nameOrID) || nameOrID.Equals("/") && parent == null) //If request by ID or root folder requested { var id = SkyDriveHelpers.GetResourceID(nameOrID); var uri = id != String.Empty ? String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, id) : SkyDriveConstants.RootAccessUrl; if (SkyDriveHelpers.IsFolderID(id)) { var contents = new List <ICloudFileSystemEntry>(); BaseDirectoryEntry entry = null; /*var completeContent = new AutoResetEvent(false); * ThreadPool.QueueUserWorkItem(state => * { * contents.AddRange(RequestContentByUrl(session, uri + "/files")); * ((AutoResetEvent) state).Set(); * }, completeContent); * * var completeEntry = new AutoResetEvent(false); * ThreadPool.QueueUserWorkItem(state => * { * entry = RequestResourseByUrl(session, uri) as BaseDirectoryEntry; * ((AutoResetEvent) state).Set(); * }, completeEntry); * * WaitHandle.WaitAll(new WaitHandle[] {completeContent, completeEntry});*/ entry = RequestResourseByUrl(session, uri) as BaseDirectoryEntry; contents.AddRange(RequestContentByUrl(session, uri + "/files")); if (entry != null && contents.Any()) { entry.AddChilds(contents.Cast <BaseFileEntry>()); } return(entry); } return(RequestResourseByUrl(session, uri)); } else { String uri; if (SkyDriveHelpers.HasParentID(nameOrID)) { uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, SkyDriveHelpers.GetParentID(nameOrID)); } else if (parent != null) { uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, parent.GetPropertyValue(SkyDriveConstants.InnerIDKey)); } else { uri = SkyDriveConstants.RootAccessUrl + "/files"; } nameOrID = Path.GetFileName(nameOrID); var entry = RequestContentByUrl(session, uri).FirstOrDefault(x => x.Name.Equals(nameOrID)); return(entry); } }