Пример #1
0
        public static List <ILocalDirectoryItemViewModel> CreatDirectoryItemViewModels(ILocalDirectory localDirectory)
        {
            var directoryItems = new List <ILocalDirectoryItemViewModel>();

            foreach (var file in localDirectory.GetFilesAsync().Result)
            {
                directoryItems.Add(CreateFileViewModel(file));
            }

            foreach (var folder in localDirectory.GetFoldersAsync().Result)
            {
                directoryItems.Add(CreateFileViewModel(folder));
            }

            return(directoryItems);
        }
Пример #2
0
        private Task UploadDirectory(IFtpClient client, ILocalDirectory storagefolder, string remoteDirectoryPath)
        {
            return(Task.Run(() =>
            {
                return storagefolder.GetFilesAsync().Result;
            })
                   .ContinueWith(fileTask =>
            {
                var files = fileTask.Result;

                if (files != null && files.Any())
                {
                    foreach (var file in files)
                    {
                        UploadFile(client, file, remoteDirectoryPath, false).Wait();
                    }
                }
            }).ContinueWith(folderTask =>
            {
                return storagefolder.GetFoldersAsync().Result;
            })
                   .ContinueWith(folderTask =>
            {
                var folders = folderTask.Result;

                if (folders == null || !folders.Any())
                {
                    return;
                }

                foreach (var folder in folders)
                {
                    var newDirectoryPath = remoteDirectoryPath + "/" + folder.Name;
                    client.CreateDirectory(newDirectoryPath);
                    UploadDirectory(client, folder, newDirectoryPath).Wait();
                }
            }));
        }