예제 #1
0
        private async Task <AmazonNode> GetRoot()
        {
            if (root != null)
            {
                return(root);
            }

            var meta = await GetMetadataUrl().ConfigureAwait(false);

            var url    = $"{meta}nodes?filters=isRoot:true";
            var result = await http.GetJsonAsync <Children>(url).ConfigureAwait(false);

            if (result.count == 0)
            {
                throw new InvalidOperationException("Could not retrieve root");
            }

            if (result.count > 1)
            {
                throw new InvalidOperationException("Multiple roots?");
            }

            root = result.data[0];
            if (root == null)
            {
                throw new InvalidOperationException("Root is null");
            }

            return(root);
        }
예제 #2
0
 /// <summary>
 /// Construct FSItem using information from AmazonNode
 /// </summary>
 /// <param name="node">Amazon Node info</param>
 /// <returns>New constructed item</returns>
 private static FSItem.Builder FromNode(AmazonNode node)
 {
     return(new FSItem.Builder
     {
         Length = node.contentProperties?.size ?? 0,
         Id = node.id,
         IsDir = node.kind == AmazonNodeKind.FOLDER,
         CreationTime = node.createdDate,
         LastAccessTime = node.modifiedDate,
         LastWriteTime = node.modifiedDate,
         ParentIds = new ConcurrentBag <string>(node.parents),
         Name = node.name
     });
 }
예제 #3
0
 /// <summary>
 /// Construct FSItem using information from AmazonNode
 /// </summary>
 /// <param name="itemPath">Item path</param>
 /// <param name="node">Amazon Node info</param>
 /// <returns>New constructed item</returns>
 public static FSItem FromNode(string itemPath, AmazonNode node)
 {
     return(new FSItem
     {
         Length = node.size ?? 0,
         Id = node.isfolder ? node.folderid.ToString() : node.fileid.ToString(),
         Path = itemPath,
         IsDir = node.isfolder,
         CreationTime = node.created,
         LastAccessTime = node.modified,
         LastWriteTime = node.modified,
         // ParentIds = new ConcurrentBag<string>(node.parents)
     });
 }
예제 #4
0
 /// <summary>
 /// Construct FSItem using information from AmazonNode
 /// </summary>
 /// <param name="itemPath">Item path</param>
 /// <param name="node">Amazon Node info</param>
 /// <returns>New constructed item</returns>
 public static FSItem FromNode(string itemPath, AmazonNode node)
 {
     return(new FSItem
     {
         Length = node.contentProperties?.size ?? 0,
         Id = node.id,
         Path = itemPath,
         IsDir = node.kind == AmazonNodeKind.FOLDER,
         CreationTime = node.createdDate,
         LastAccessTime = node.modifiedDate,
         LastWriteTime = node.modifiedDate,
         ParentIds = new ConcurrentBag <string>(node.parents)
     });
 }
        public static async Task <AmazonNode> GetNodeByPath(this Azi.Amazon.CloudDrive.IAmazonDrive api, string path)
        {
            var        parts  = path.Split('/');
            AmazonNode node   = null;
            string     parent = null;

            foreach (var part in parts)
            {
                node = await api.Nodes.GetChild(parent, part);

                if (node == null)
                {
                    return(null);
                }
                parent = node.id;
            }

            return(node);
        }
예제 #6
0
        private async Task <AmazonNode> GetRoot()
        {
            if (root != null)
            {
                return(root);
            }

            var url    = BuildMethodUrl("listfolder");
            var result = await http.GetJsonAsync <Children>($"{url}&folderid=0").ConfigureAwait(false);

            if (result.result != 0 || result.metadata == null)
            {
                throw new InvalidOperationException("Could not retrieve root");
            }

            root = result.metadata;

            return(root);
        }
예제 #7
0
        /// <summary>
        /// Requests for Root folder node info. Cached without expiration.
        /// </summary>
        /// <returns>Root folder node info</returns>
        public async Task <AmazonNode> GetRoot()
        {
            if (root != null)
            {
                return(root);
            }

            var url    = "{0}nodes?filters=isRoot:true";
            var result = await http.GetJsonAsync <Children>(string.Format(url, await amazon.GetMetadataUrl().ConfigureAwait(false))).ConfigureAwait(false);

            if (result.count == 0)
            {
                return(null);
            }
            root = result.data[0];
            if (root == null)
            {
                throw new InvalidOperationException("Could not retrieve root");
            }
            return(root);
        }
예제 #8
0
        private static StorageProviderItem CreateStorageProviderItem(StorageProviderItem parent, AmazonNode item)
        {
            var result = new StorageProviderItem
            {
                Name = item.name,
                Id   = item.id,
                ParentReferenceId    = parent.Id,
                LastModifiedDateTime = item.modifiedDate
            };

            switch (item.kind)
            {
            case AmazonNodeKind.FILE:
                result.Type = StorageProviderItemType.File;
                break;

            case AmazonNodeKind.FOLDER:
                result.Type = StorageProviderItemType.Folder;
                break;

            default:
                result.Type = StorageProviderItemType.Unknown;
                break;
            }

            return(result);
        }
예제 #9
0
 public static FSItem FromRoot(AmazonNode amazonNode)
 {
     return(FromNode("\\", amazonNode));
 }
예제 #10
0
        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="parent"></param>
        /// <param name="allowExisting"></param>
        /// <returns></returns>
        public async Task <FSItem> CreateDirectory(string filePath, FSItem parent = null, bool allowExisting = true)
        {
            if (filePath == "\\" || filePath == ".." || filePath == ".")
            {
                return(null);
            }
            var dir = Path.GetDirectoryName(filePath);

            if (dir == ".." || dir == ".")
            {
                return(null);
            }

            if (parent == null)
            {
                parent = await FetchNode(dir);

                if (parent == null)
                {
                    return(null);
                }
            }

            var        name = Path.GetFileName(filePath);
            AmazonNode node = null;

            try
            {
                node = await amazon.Nodes.CreateFolder(parent.Id, name);
            }
            catch (Azi.Tools.HttpWebException x)
            {
                if (x.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    if (!allowExisting)
                    {
                        throw;
                    }
                }
                else
                {
                    throw;
                }
            }

            if (node == null) // in case of duplicate; other cases are re-thrown
            {
                node = await amazon.Nodes.GetNodeByPath(filePath, true);
            }

            if (node == null)
            {
                throw new InvalidOperationException("Could not retrieve node information " + filePath);
            }

            var item = FSItem.FromNode(filePath, node);

            CacheStorage.AddItem(item);

            return(item);
        }