コード例 #1
0
        private void UpdateApplication(object sender, EventArgs e)
        {
            Project project = vsMonitorSelection.GetActiveProject();

            if (project != null)
            {
                Guid cloudGuid = GetCurrentCloudGuid(project);
                ProjectDirectories projectDirectories = GetProjectDirectories(project);

                Messenger.Default.Register <NotificationMessageAction <Guid> >(this,
                                                                               message =>
                {
                    if (message.Notification.Equals(Messages.SetUpdateAppData))
                    {
                        message.Execute(cloudGuid);
                    }
                });

                Messenger.Default.Register <NotificationMessageAction <string> >(this,
                                                                                 message =>
                {
                    if (message.Notification.Equals(Messages.SetPushAppDirectory))
                    {
                        message.Execute(projectDirectories.DeployFromPath);
                    }
                });

                var window = new Update();
                var helper = new WindowInteropHelper(window);
                helper.Owner = (IntPtr)(dte.MainWindow.HWnd);
                var result = window.ShowDialog();

                if (result.GetValueOrDefault())
                {
                    UpdateViewModel modelData = null;
                    Messenger.Default.Send(new NotificationMessageAction <UpdateViewModel>(Messages.GetUpdateAppData, model => modelData = model));

                    SetCurrentCloudGuid(project, modelData.SelectedCloud.ID);
                    PerformAction("Update Application", project, modelData.SelectedCloud, projectDirectories, (c, d) =>
                    {
                        var updateResult = c.Update(modelData.SelectedApplication.Name, d);
                        if (updateResult.Success)
                        {
                            c.Restart(new Application()
                            {
                                Name = modelData.SelectedApplication.Name
                            });
                        }
                        return(updateResult);
                    });
                }
            }
        }
コード例 #2
0
        private void PerformAction(string action, Project project, Cloud cloud, ProjectDirectories dir,
                                   Func <IVcapClient, DirectoryInfo, VcapClientResult> function)
        {
            var worker = new BackgroundWorker();

            Messenger.Default.Register <NotificationMessageAction <string> >(this,
                                                                             message =>
            {
                if (message.Notification.Equals(Messages.SetProgressData))
                {
                    message.Execute(action);
                }
            });

            var window     = new ProgressDialog();
            var dispatcher = window.Dispatcher;
            var helper     = new WindowInteropHelper(window);

            helper.Owner = (IntPtr)(dte.MainWindow.HWnd);
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += (s, args) =>
            {
                if (worker.CancellationPending)
                {
                    args.Cancel = true; return;
                }
                Messenger.Default.Send(new ProgressMessage(0, "Starting " + action));
                var site = project.Object as VsWebSite.VSWebSite;

                if (worker.CancellationPending)
                {
                    args.Cancel = true; return;
                }
                if (!Directory.Exists(dir.StagingPath))
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(10, "Creating Staging Path"))));
                    Directory.CreateDirectory(dir.StagingPath);
                }

                if (worker.CancellationPending)
                {
                    args.Cancel = true; return;
                }
                if (Directory.Exists(dir.DeployFromPath))
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(10, "Creating Precompiled Site Path"))));
                    Directory.Delete(dir.DeployFromPath, true);
                }

                if (worker.CancellationPending)
                {
                    args.Cancel = true; return;
                }


                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(30, "Preparing Compiler"))));

                if (site != null)
                {
                    site.PreCompileWeb(dir.DeployFromPath, true);
                }
                else
                {
                    var frameworkPath = (site == null) ? project.GetFrameworkPath() : string.Empty;

                    string objDir = Path.Combine(dir.ProjectDirectory, "obj");
                    if (Directory.Exists(objDir))
                    {
                        Directory.Delete(objDir, true); // NB: this can cause precompile errors
                    }
                    var process = new System.Diagnostics.Process()
                    {
                        StartInfo = new ProcessStartInfo()
                        {
                            FileName               = frameworkPath + "\\aspnet_compiler.exe",
                            Arguments              = String.Format("-nologo -v / -p \"{0}\" -f -u -c \"{1}\"", dir.ProjectDirectory, dir.DeployFromPath),
                            CreateNoWindow         = true,
                            ErrorDialog            = false,
                            UseShellExecute        = false,
                            RedirectStandardOutput = true
                        }
                    };

                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(40, "Precompiling Site"))));
                    process.Start();
                    var output = process.StandardOutput.ReadToEnd();
                    process.WaitForExit();
                    if (false == String.IsNullOrEmpty(output))
                    {
                        dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Asp Compile Error: " + output))));
                        return;
                    }
                }

                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(50, "Logging in to Cloud Foundry"))));
                if (worker.CancellationPending)
                {
                    args.Cancel = true; return;
                }


                var client = new VcapClient(cloud);
                var result = client.Login();

                if (result.Success == false)
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Vcap Login Failure: " + result.Message))));
                    return;
                }
                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(75, "Sending to " + cloud.Url))));
                if (worker.CancellationPending)
                {
                    args.Cancel = true; return;
                }

                var response = function(client, new DirectoryInfo(dir.DeployFromPath));
                if (result.Success == false)
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Vcap Login Failure: " + result.Message))));
                    return;
                }
                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(100, action + " complete."))));
            };

            worker.RunWorkerAsync();
            if (!window.ShowDialog().GetValueOrDefault())
            {
                worker.CancelAsync();
            }
        }
コード例 #3
0
        private void PerformAction(string action, Project project, Cloud cloud, ProjectDirectories dir,
            Func<IVcapClient, DirectoryInfo, VcapClientResult> function)
        {
            var worker = new BackgroundWorker();

            Messenger.Default.Register<NotificationMessageAction<string>>(this,
                message =>
                {
                    if (message.Notification.Equals(Messages.SetProgressData))
                        message.Execute(action);
                });

            var window = new ProgressDialog();
            var dispatcher = window.Dispatcher;
            var helper = new WindowInteropHelper(window);
            helper.Owner = (IntPtr)(dte.MainWindow.HWnd);
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += (s, args) =>
            {
                if (worker.CancellationPending) { args.Cancel = true; return; }
                Messenger.Default.Send(new ProgressMessage(0, "Starting " + action));
                var site = project.Object as VsWebSite.VSWebSite;

                if (worker.CancellationPending) { args.Cancel = true; return; }
                if (!Directory.Exists(dir.StagingPath))
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(10, "Creating Staging Path"))));
                    Directory.CreateDirectory(dir.StagingPath);
                }

                if (worker.CancellationPending) { args.Cancel = true; return; }
                if (Directory.Exists(dir.DeployFromPath))
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(10, "Creating Precompiled Site Path"))));
                    Directory.Delete(dir.DeployFromPath, true);
                }

                if (worker.CancellationPending) { args.Cancel = true; return; }

                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(30, "Preparing Compiler"))));

                if (site != null)
                    site.PreCompileWeb(dir.DeployFromPath, true);
                else
                {
                    var frameworkPath = (site == null) ? project.GetFrameworkPath() : string.Empty;

                    string objDir = Path.Combine(dir.ProjectDirectory, "obj");
                    if (Directory.Exists(objDir))
                    {
                        Directory.Delete(objDir, true); // NB: this can cause precompile errors
                    }
                    var process = new System.Diagnostics.Process()
                    {
                        StartInfo = new ProcessStartInfo()
                        {

                            FileName = frameworkPath + "\\aspnet_compiler.exe",
                            Arguments = String.Format("-nologo -v / -p \"{0}\" -f -u -c \"{1}\"", dir.ProjectDirectory, dir.DeployFromPath),
                            CreateNoWindow = true,
                            ErrorDialog = false,
                            UseShellExecute = false,
                            RedirectStandardOutput = true
                        }
                    };

                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(40, "Precompiling Site"))));
                    process.Start();
                    var output = process.StandardOutput.ReadToEnd();
                    process.WaitForExit();
                    if (false == String.IsNullOrEmpty(output))
                    {
                        dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Asp Compile Error: " + output))));
                        return;
                    }
                }

                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(50, "Logging in to Cloud Foundry"))));
                if (worker.CancellationPending) { args.Cancel = true; return; }

                var client = new VcapClient(cloud);
                var result = client.Login();

                if (result.Success == false)
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Vcap Login Failure: " + result.Message))));
                    return;
                }
                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(75, "Sending to " + cloud.Url))));
                if (worker.CancellationPending) { args.Cancel = true; return; }

                var response = function(client, new DirectoryInfo(dir.DeployFromPath));
                if (result.Success == false)
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Vcap Login Failure: " + result.Message))));
                    return;
                }
                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(100, action + " complete."))));
            };

            worker.RunWorkerAsync();
            if (!window.ShowDialog().GetValueOrDefault())
                worker.CancelAsync();
        }