Beispiel #1
0
        public void ShowDialog(DialogField[] fields)
        {
            _progress.FinishProgress();

            foreach (var field in fields)
            {
                ProcessField(field);
            }

            _progress.StartProgress();
        }
Beispiel #2
0
        /// <inheritdoc />
        public async Task <SaveResult> SaveFile(IStateInfo stateInfo, IFileSystem fileSystem, UPath savePath)
        {
            lock (_loadedFilesLock)
            {
                ContractAssertions.IsElementContained(_loadedFiles, stateInfo, "loadedFiles", nameof(stateInfo));
            }

            var isRunning = _progress.IsRunning();

            if (!isRunning)
            {
                _progress.StartProgress();
            }

            var saveResult = await _fileSaver.SaveAsync(stateInfo, fileSystem, savePath, _progress);

            if (!isRunning)
            {
                _progress.FinishProgress();
            }

            return(saveResult);
        }
Beispiel #3
0
        private void ExecuteActionWithProgress(Action action, IProgressContext progress = null)
        {
            var isRunning = progress?.IsRunning();

            if (isRunning.HasValue && !isRunning.Value)
            {
                progress.StartProgress();
            }

            action();

            if (isRunning.HasValue && !isRunning.Value)
            {
                progress.FinishProgress();
            }
        }
Beispiel #4
0
        private async Task ExtractFiles(IList <IArchiveFileInfo> files)
        {
            if (files.Count <= 0)
            {
                _communicator.ReportStatus(true, "No files to extract.");
                return;
            }

            // Select folder
            var extractPath = SelectFolder();

            if (extractPath.IsNull || extractPath.IsEmpty)
            {
                _communicator.ReportStatus(false, "No folder selected.");
                return;
            }

            // Extract elements
            _communicator.ReportStatus(true, string.Empty);

            var destinationFileSystem = FileSystemFactory.CreatePhysicalFileSystem(extractPath, _stateInfo.StreamManager);

            _progress.StartProgress();
            await _asyncOperation.StartAsync(async cts =>
            {
                var count = 0;
                foreach (var file in files)
                {
                    if (cts.IsCancellationRequested)
                    {
                        break;
                    }

                    _progress.ReportProgress("Extract files", count++, files.Count);

                    if (IsFileLocked(file, false))
                    {
                        continue;
                    }

                    Stream newFileStream;
                    try
                    {
                        newFileStream = destinationFileSystem.OpenFile(file.FilePath.GetName(), FileMode.Create, FileAccess.Write);
                    }
                    catch (IOException)
                    {
                        continue;
                    }
                    var currentFileStream = await file.GetFileData();

                    currentFileStream.CopyTo(newFileStream);

                    newFileStream.Close();
                }
            });

            _progress.ReportProgress("Extract files", 1, 1);
            _progress.FinishProgress();

            if (_asyncOperation.WasCancelled)
            {
                _communicator.ReportStatus(false, "File extraction cancelled.");
            }
            else
            {
                _communicator.ReportStatus(true, "File(s) extracted successfully.");
            }
        }