示例#1
0
        private async Task <OperationResult> Clean(CancellationToken cancellationToken, ProgressViewModel progress, object parameter)
        {
            var parent = Parent;

            if (parent == null)
            {
                return(OperationResult.Failed);
            }

            progress.IsIndeterminate = true;
            return(await Task.Run(() => JobImplementations.Clean(cancellationToken, progress, this, parameter as PinnedPart)));
        }
示例#2
0
        private async Task <OperationResult> Bootstrap(CancellationToken cancellationToken, ProgressViewModel progress, object parameter)
        {
            progress.IsIndeterminate = true;
            if (string.IsNullOrWhiteSpace(SrcPath))
            {
                MessageBox.Show("There is no valid path specified for this source directory", "Builder", MessageBoxButton.OK, MessageBoxImage.None);
                return(OperationResult.Failed);
            }

            if (string.IsNullOrWhiteSpace(Stream))
            {
                MessageBox.Show("There is no valid stream specified for this source directory", "Builder", MessageBoxButton.OK, MessageBoxImage.None);
                return(OperationResult.Failed);
            }

            var path = Path.GetFullPath(SrcPath);

            if (!Directory.Exists(path))
            {
                if (MessageBox.Show($"This will bootstrap  stream '{Stream}' into directory '{path}'.", "Confirmation", MessageBoxButton.OKCancel, MessageBoxImage.Information)
                    != MessageBoxResult.OK)
                {
                    return(OperationResult.Aborted);
                }

                try
                {
                    Directory.CreateDirectory(path);
                }
                catch (Exception e)
                {
                    MessageBox.Show($"Could not create '{path}'. {e.Message}", "Failed", MessageBoxButton.OK, MessageBoxImage.None);
                    return(OperationResult.Failed);
                }
            }
            else if (Directory.EnumerateFileSystemEntries(path).Any())
            {
                if (MessageBox.Show($"Directory '{path}' is not empty. All contents will be deleted before bootstrap. Please confirm.", "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
                    != MessageBoxResult.OK)
                {
                    return(OperationResult.Aborted);
                }

                try
                {
                    await Task.Run(() =>
                    {
                        Directory.Delete(path, true);
                        Directory.CreateDirectory(path);
                    });
                }
                catch (Exception e)
                {
                    MessageBox.Show($"Could not clear '{path}'. {e.Message}", "Failed", MessageBoxButton.OK, MessageBoxImage.None);
                    return(OperationResult.Failed);
                }
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(OperationResult.Aborted);
            }

            return(await Task.Run(() => JobImplementations.Bootstrap(cancellationToken, progress, path, Stream, Parent?.HistoryVM)));
        }