public async Task <IReadOnlyCollection <Blob> > GetBlobsAsync(IEnumerable <string> ids, CancellationToken cancellationToken = default)
        {
            FtpClient client = await GetClientAsync().ConfigureAwait(false);

            var results = new List <Blob>();

            foreach (string path in ids)
            {
                string cpath      = StoragePath.Normalize(path, true);
                string parentPath = StoragePath.GetParent(cpath);

                FtpListItem[] all = await client.GetListingAsync(parentPath).ConfigureAwait(false);

                FtpListItem foundItem = all.FirstOrDefault(i => i.FullName == cpath);

                if (foundItem == null)
                {
                    results.Add(null);
                    continue;
                }

                var r = new Blob(path)
                {
                    Size = foundItem.Size,
                    LastModificationTime = foundItem.Modified
                };
                results.Add(r);
            }
            return(results);
        }
Beispiel #2
0
        private void MountPath(string path, IBlobStorage storage, bool isMountPoint)
        {
            string containerPath = StoragePath.IsRootPath(path) ? path : StoragePath.GetParent(path);

            if (!_pathToMountBlobs.TryGetValue(containerPath, out HashSet <Blob> blobs))
            {
                blobs = new HashSet <Blob>();
                _pathToMountBlobs[containerPath] = blobs;
            }

            // this is the mount
            if (isMountPoint)
            {
                var mountBlob = new Blob(path, BlobItemKind.Folder)
                {
                    Tag = storage
                };
                mountBlob.TryAddProperties("IsMountPoint", true);
                blobs.Add(mountBlob);
            }
            else
            {
                var intBlob = new Blob(path, BlobItemKind.Folder);
                blobs.Add(intBlob);
            }
        }
        public async Task <IEnumerable <BlobMeta> > GetMetaAsync(IEnumerable <string> ids, CancellationToken cancellationToken = default)
        {
            FtpClient client = await GetClientAsync();

            var results = new List <BlobMeta>();

            foreach (string path in ids)
            {
                string cpath      = StoragePath.Normalize(path, true);
                string parentPath = StoragePath.GetParent(cpath);

                FtpListItem[] all = await client.GetListingAsync(parentPath);

                FtpListItem foundItem = all.FirstOrDefault(i => i.FullName == cpath);

                if (foundItem == null)
                {
                    results.Add(null);
                    continue;
                }

                var meta = new BlobMeta(foundItem.Size, null, foundItem.Modified);
                results.Add(meta);
            }
            return(results);
        }
Beispiel #4
0
        /// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="fullPath"></param>
        /// <param name="kind"></param>
        public Blob(string fullPath, BlobItemKind kind = BlobItemKind.File)
        {
            string path = StoragePath.Normalize(fullPath);

            string[] parts = StoragePath.Split(path);

            Name       = parts.Last();
            FolderPath = StoragePath.GetParent(path);

            Kind = kind;
        }
        private void AddVirtualFolderHierarchy(Blob fileBlob)
        {
            string path = fileBlob.FolderPath;

            while (!StoragePath.IsRootPath(path))
            {
                var vf = new Blob(path, BlobItemKind.Folder);
                _pathToTag[path] = new Tag {
                    blob = vf
                };

                path = StoragePath.GetParent(path);
            }
        }
        private static void AssumeImplicitPrefixes(string absoluteRoot, List <Blob> blobs)
        {
            absoluteRoot = StoragePath.Normalize(absoluteRoot);

            List <Blob> implicitFolders = blobs
                                          .Select(b => b.FullPath)
                                          .Select(p => p.Substring(absoluteRoot.Length))
                                          .Select(p => StoragePath.GetParent(p))
                                          .Where(p => !StoragePath.IsRootPath(p))
                                          .Distinct()
                                          .Select(p => new Blob(p, BlobItemKind.Folder))
                                          .ToList();

            blobs.AddRange(implicitFolders);
        }
Beispiel #7
0
        private async Task RenameAsync()
        {
            string newName = await DialogService.AskStringInputAsync("Rename", "New Name", SelectedBlob.Name);

            if (newName == null)
            {
                return;
            }

            string newPath = StoragePath.Combine(StoragePath.GetParent(SelectedBlob.FullPath), newName);

            EventLog.LogEvent("rename", SelectedBlob.FullPath, newPath);

            await TaskService.ScheduleAsync(new RenameFilesTask(Storage, SelectedBlob, newPath));
        }
Beispiel #8
0
        public override async Task WriteAsync(
            string fullPath, Stream dataStream, bool append = false, CancellationToken cancellationToken = default)
        {
            string path = StoragePath.Normalize(fullPath);

            //import will fail unless all the parent folders exist, so make sure they do
            string parent = StoragePath.GetParent(path);

            if (!StoragePath.IsRootPath(parent))
            {
                await _api.Mkdirs(StoragePath.Normalize(parent)).ConfigureAwait(false);
            }

            GetImportParameters(path, out ExportFormat exportFormat, out Language? language);

            await _api.Import(path, exportFormat, language, dataStream.ToByteArray(), true).ConfigureAwait(false);
        }
Beispiel #9
0
        /// <summary>
        /// Changes full path of this blob without modifying any other property
        /// </summary>
        public void SetFullPath(string fullPath)
        {
            string path = StoragePath.Normalize(fullPath);

            if (StoragePath.IsRootPath(path))
            {
                Name       = StoragePath.RootFolderPath;
                FolderPath = StoragePath.RootFolderPath;
            }
            else
            {
                string[] parts = StoragePath.Split(path);

                Name       = parts.Last();
                FolderPath = StoragePath.GetParent(path);
            }
        }
Beispiel #10
0
        protected override async Task <Blob> GetBlobAsync(string fullPath, CancellationToken cancellationToken)
        {
            CloudFile file = await GetFileReferenceAsync(fullPath, false, cancellationToken).ConfigureAwait(false);

            try
            {
                await file.FetchAttributesAsync(cancellationToken).ConfigureAwait(false);

                return(AzConvert.ToBlob(StoragePath.GetParent(fullPath), file));
            }
            catch (AzStorageException ex) when(ex.RequestInformation.ErrorCode == "ShareNotFound")
            {
                return(null);
            }
            catch (AzStorageException ex) when(ex.RequestInformation.ErrorCode == "ResourceNotFound")
            {
                return(null);
            }
        }
Beispiel #11
0
 public void Get_parent_theory(string path, string expected)
 {
     Assert.Equal(expected, StoragePath.GetParent(path));
 }
Beispiel #12
0
 public void GoLevelUp()
 {
     FolderPath = StoragePath.GetParent(FolderPath);
 }