Пример #1
0
        public async Task <int> RunAsync(IProgress <string> progress, CancellationToken ct)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(ct);

            progress.ReportLine(string.Format(UserMessages.DbInitProjectRunner_VerifyingProject, VsProject.Name));
            var launcher = Launcher.Get(VsProject);

            if (launcher == null)
            {
                Launcher.ReportProjectNotSupported(VsProject.Name, progress);
                return(-1);
            }

            progress.ReportLine(string.Format(UserMessages.DbInitProjectRunner_BuildingProject, VsProject.Name));
            await BuildProjectAsync(ct);

            if (DTE.Solution.SolutionBuild.LastBuildInfo != 0)
            {
                progress.ReportLine(string.Format(UserMessages.DbInitProjectRunner_BuildingProjectFailed, VsProject.Name));
                return(-1);
            }
            else
            {
                progress.ReportLine(string.Format(UserMessages.DbInitProjectRunner_BuildingProjectSucceeded, VsProject.Name));
            }

            if (ct.IsCancellationRequested)
            {
                progress.ReportLine(UserMessages.ConsoleWindow_OperationCancelled);
                return(ExitCodes.Cancelled);
            }

            if (Input != null && Input.Count > 0)
            {
                if (DbInitInputWindow.Show(Input) != true)
                {
                    progress.ReportLine(UserMessages.ConsoleWindow_OperationCancelled);
                    return(ExitCodes.Cancelled);
                }
            }

            var    pipeName           = Guid.NewGuid().ToString();
            var    args               = GetArgs(pipeName);
            var    task               = launcher.LaunchAsync(VsProject, args, Input, progress);
            Thread cancellationThread = null;
            var    cancellationTask   = System.Threading.Tasks.Task.Run(() =>
            {
                cancellationThread = Thread.CurrentThread;
                WaitHandle.WaitAny(new[] { ct.WaitHandle });
                RequestCancel(pipeName);
                cancellationThread = null;
            });

            await System.Threading.Tasks.Task.WhenAny(task, cancellationTask);

            if (cancellationThread != null)
            {
                cancellationThread.Abort();
            }
            var result = await task;

            if (result == ExitCodes.Succeeded)
            {
                progress.ReportLine(UserMessages.DbInitProjectRunner_OperationSucceeded);
            }
            else if (result != ExitCodes.Cancelled)
            {
                progress.ReportLine(string.Format(UserMessages.DbInitProjectRunner_OperationFailed, result));
            }
            return(result);
        }
Пример #2
0
 public Presenter(DbInitInputWindow window, DataSet <DbInitInput> input)
 {
     Show(window._dataView, input);
 }