Ejemplo n.º 1
0
        async Task UploadFileToShare(FilePathSourceAndTarget pathes)
        {
            var source = pathes.Get().SourcePath;
            var target = pathes.Get().TargetPath;

            Contract.Requires(source != null && !string.IsNullOrEmpty(source.FullName) && !source.Equals(target));

            CommonExtensions.Logger(LogTypes.Info, $"Идет отправка файла {source.FullName} -> {target.FullName}");
            //  StatusText?.Invoke(this, new TextEventArgs($"Идет отправка файла {source.FullName} -> {target.FullName}"));

            try
            {
                await Task.Run(() => fileSystem.File.Copy(source.FullName, target.FullName, true));

                CommonExtensions.Logger(LogTypes.Info, $"Файл '{target.FullName}' на сервер доставлен успешно.");
                StatusFinishedUploading?.Invoke(this, new BoolEventArgs(true));
                StatusText?.Invoke(this, new TextEventArgs($"Файл '{target.FullName}' на сервер доставлен успешно."));
            }
            catch (Exception err)
            {
                CommonExtensions.Logger(LogTypes.Info, $"Отправка файла '{target.FullName}' на сервер выполнена с ошибками! {err.ToString()}");
                StatusFinishedUploading?.Invoke(this, new BoolEventArgs(false));
                StatusText?.Invoke(this, new TextEventArgs($"Отправка файла '{target.FullName}' на сервер выполнена с ошибками! {err.ToString()}"));
            }
        }
Ejemplo n.º 2
0
 FilePathSourceAndTarget[] MakeArrayFilePathesFromTwoListsOfFilePathes(List <IFileInfo> source, List <IFileInfo> target)
 {
     FilePathSourceAndTarget[] couples = new FilePathSourceAndTarget[source.Count];
     for (int i = 0; i < source.Count; i++)
     {
         couples[i] = new FilePathSourceAndTarget(source[i], target[i]);
     }
     return(couples);
 }
Ejemplo n.º 3
0
        public async Task ClearShare(FilePathSourceAndTarget pathes)
        {
            var source = pathes.Get().SourcePath;
            var target = pathes.Get().TargetPath;

            Contract.Requires(source != null && !string.IsNullOrEmpty(source.FullName) && !source.Equals(target));

            try
            {
                await Task.Run(() => target.Delete());

                CommonExtensions.Logger(LogTypes.Info, $"Файл {target.FullName} удален успешно");
            }
            catch (Exception err)
            {
                CommonExtensions.Logger(LogTypes.Info, $"Файл {target.FullName} удалить не удалось: {err.ToString()}");
                uploadingError = true;
            } //@"\\server\folder\Myfile.txt"

            await Task.WhenAll();
        }