Пример #1
0
        public bool ValidateValues()
        {
            var messages = new List <string>();

            if (RemotingEnabled && !RemoteHost.NotEmpty())
            {
                messages.Add(Validation.Profiles.Remote.HostnameNotEmpty);
            }

            if (RemotingEnabled && !RemoteUsername.NotEmpty())
            {
                messages.Add(Validation.Profiles.Remote.UsernameNotEmpty);
            }

            if (RemotingEnabled && !RemotePassword.NotEmpty())
            {
                messages.Add(Validation.Profiles.Remote.PasswordNotEmpty);
            }

            if (RemotingEnabled && !RemoteFolder.NotEmpty())
            {
                messages.Add(Validation.Profiles.Remote.FolderNotEmpty);
            }

            return(ShowValidationError(messages));
        }
Пример #2
0
        public Task <IRemoteFolder> GetFolder(string path)
        {
            path = GetPath(path);

            DirectoryInfo directory = new DirectoryInfo(path);

            if (!directory.Exists)
            {
                return(Task.FromResult <IRemoteFolder>(null));
            }

            RemoteFolder folder = new RemoteFolder(path, PathSeparator, _settings.RootPath);

            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                folder.AddFolder(subDirectory.Name);
            }

            foreach (FileInfo file in directory.GetFiles())
            {
                folder.AddFile(file.Name, file.LastWriteTime);
            }

            return(Task.FromResult <IRemoteFolder>(folder));
        }
Пример #3
0
 public FolderResult(RemoteFolder folder, Uri parent)
 {
     Folder         = folder;
     ParentUri      = parent;
     ChildFileTasks = new Task <FileResult>[] { };
     ChildFolders   = new FolderResult[] { };
     ProcessedAt    = DateTimeOffset.Now;
 }
Пример #4
0
        private Task <models.Folder> CreateFolder(RemoteFolder folder, Uri parent)
        {
            var sfFolder = new models.Folder
            {
                Name = folder.Name,
            };

            // set permissions here or after all child uploads are done?
            // probably here so platform doesn't have to propagate down?
            return(RetryAsync(() => api.Items.CreateFolder(parent, sfFolder).ExecuteAsync(), FOLDER_RETRY_COUNT));
        }
Пример #5
0
        private async Task <FolderResult> UploadChildFolder(RemoteFolder folder, Uri parent)
        {
            try
            {
                var sfFolder = await CreateFolder(folder, parent);

                return(await UploadFolder(folder, sfFolder.url));
            }
            catch (Exception ex)
            {
                return(new FolderResult(folder, parent)
                {
                    CreateSucceeded = false, Exception = ex
                });
            }
        }
Пример #6
0
        internal void StartUpload()
        {
            //fill file info to load
            FileRepositoryInstance.CurrentOperations = new List <FileRepository.Manager.Models.FileModel>();
            FilesToUpload.All(OriginFile =>
            {
                FileRepositoryInstance.CurrentOperations.Add(
                    new FileRepository.Manager.Models.FileModel()
                {
                    FilePathLocalSystem  = OriginFile,
                    FilePathRemoteSystem = RemoteFolder.TrimEnd('\\') + "\\" + OriginFile.Substring(OriginFile.LastIndexOf("\\")).TrimStart('\\'),
                    Operation            = FileRepository.Manager.Models.enumOperation.UploadFile
                });

                return(true);
            });
            //start load
            FileRepositoryInstance.StartOperation(false);
        }
Пример #7
0
        public async Task <IRemoteFolder> GetFolder(string path)
        {
            RemoteFolder folder = new RemoteFolder(path, PathSeparator);

            FtpListItem[] list = await _client.Value.GetListingAsync(path);

            foreach (FtpListItem listItem in list)
            {
                if (listItem.Type == FtpFileSystemObjectType.Directory)
                {
                    folder.AddFolder(listItem.Name);
                }
                else
                {
                    folder.AddFile(listItem.Name, listItem.Modified);
                }
            }

            return(folder);
        }
Пример #8
0
        private async Task <FolderResult> UploadFolder(RemoteFolder folder, Uri parent)
        {
            var createdAt = DateTimeOffset.Now;
            var fileTasks = parent.AbsoluteUri.Contains("allshared")
                ? new Task <FileResult>[] { }
                : (await folder.GetChildFiles()).Select(file => UploadFile(file, parent)).ToArray();
            var folderTasks = (await folder.GetChildFolders()).Select(childFolder => UploadChildFolder(childFolder, parent)).ToArray();

            await Task.WhenAll(folderTasks);

            var result = new FolderResult(folder, parent) // this parent url is wrong
            {
                CreateSucceeded = true,
                Uri             = parent,
                ChildFileTasks  = fileTasks,
                ChildFolders    = folderTasks.Select(t => t.Result).ToArray(),
                ProcessedAt     = createdAt,
            };

            // result = fileTasks.Select(task => task.Result).Aggregate(result, (folderResult, fileResult) => folderResult.AddChild(fileResult));
            // result = folderTasks.Select(task => task.Result).Aggregate(result, (folderResult, childFolderResult) => folderResult.AddChild(childFolderResult));
            return(result);
        }
Пример #9
0
        public async Task <IRemoteFolder> GetFolder(string path)
        {
            string            url      = $"{FileSystemEndpoints.FolderEndpoint}?path={path}";
            FolderApiResponse response = await GetResponse <FolderApiResponse>(url);

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

            RemoteFolder folder = new RemoteFolder(response.Path, PathSeparator);

            foreach (SubFolderApiResponse subFolder in response.Folders)
            {
                folder.AddFolder(subFolder.Name);
            }

            foreach (FileApiResponse file in response.Files)
            {
                folder.AddFile(file.Name, file.LastModified);
            }

            return(folder);
        }
Пример #10
0
        /// <summary>
        /// Загружает по ftp файлы за переданный интервал
        /// </summary>
        /// <param name="interval">временной интервал</param>
        /// <param name="remoteRoot">удаленный каталог</param>
        /// <param name="localRoot">куда копировать</param>
        /// <param name="token">Токен для отмены</param>
        /// <returns>Возвращает список скопированных  или существующих на сервере файлов</returns>
        public List <IFile> DownloadFilesByInterval(DateInterval interval, string remoteRoot, string localRoot, CancellationTokenSource cts = null)
        {
            // Получаем все каталоги отфильтрованные по диапозону дат [час]
            List <RemoteFolder> remoteFolders = RemoteFolder.GetAllHoursFolders(Client, remoteRoot, interval.BitwinDateFolder);
            var res = new List <IFile>();

            foreach (RemoteFolder remoteFolder in remoteFolders)
            {
                // Папка куда копировать файлы [час]
                foreach (FtpListItem remoteFile in Client.GetListing(remoteFolder.ToString()))
                {
                    cts?.Token.ThrowIfCancellationRequested();

                    if (remoteFile.Type != FtpFileSystemObjectType.File)
                    {
                        continue;
                    }

                    string localFile = remoteFile.FullName.Replace("/", "\\")
                                       .Replace(remoteRoot.Replace("/", "\\"), localRoot.Replace("/", "\\"));

                    // Проверяем файл на соответствие формату
                    IFile f;
                    try
                    {
                        f = FileFactory.Create(remoteFile.Name);
                    }
                    catch (FormatException e)
                    {
                        logger.Error(e, $"{ localFile } haves bad format [ERROR]");
                        continue;
                    }

                    // Копируем файл
                    if (!f.IsComplete) // Файл не полностью записан
                    {
                        logger.Info($" {f} [MISS] - not completed");
                    }
                    else if (!f.IsInInterval(interval)) // Не входит в  интервал
                    {
                        //logger.Info($" {f} [MISS] - Exists in the server");
                    }
                    else if (System.IO.File.Exists(localFile)) // Нет в папке на сервере
                    {
                        logger.Info($" {f} [MISS] - exists in the server");
                        res.Add(f);
                    }
                    else //Переносим файл
                    {
                        try
                        {
                            Client.DownloadFile(localFile, remoteFile.FullName);
                            res.Add(f);
                            logger.Info($"{f} [OK]");
                        }
                        catch (Exception e)
                        {
                            logger.Error(e, $"copy {f} [ERROR]");
                        }
                    }
                }
            }
            return(res);
        }
Пример #11
0
 public OnDiskFileSystem(string path)
 {
     Root = new OnDiskFolder(new DirectoryInfo(path));
 }