示例#1
0
        public async Task BeginDeploy(DeployOptions options, Action <ProgressEventArgs> onProgress)
        {
            try
            {
                var startTime = DateTime.Now;

                OnProgress = onProgress;
                var progress = new Progress <ProgressEventArgs>(OnProgress);

                CTS = new CancellationTokenSource();

                //FIX: Maybe move status management inside Deployment implementation?
                Deployment.Status = DeploymentStatus.Running;

                if (this.Deployment.IsModified)
                {
                    var validationException = await ValidateDeploy(onProgress);

                    if (validationException != null)
                    {
                        throw validationException;
                    }
                }

                //await Task.Factory.StartNew(() => Deployment.StartAsync(progress));
                OnProgress(new ProgressEventArgs(string.Format("Deploying...")));
                await Deployment.StartAsync(progress, options, CTS.Token);

                var deploymentTime = (DateTime.Now - startTime).TotalSeconds;
                var status         = this.Deployment.Targets.Where(x => x.DeploymentState != Database.DatabaseDeploymentState.Success).Count() > 0 ? "with errors" : "successfully";
                OnProgress(new ProgressEventArgs(string.Format("Deployed {1} in {0:0.00} seconds", deploymentTime, status)));
            }
            catch (OperationCanceledException ex)
            {
                Deployment.Status = DeploymentStatus.Cancelled;
                onProgress(new ProgressEventArgs("Cancelled"));
            }
            catch (Exception ex)
            {
                Deployment.Status = DeploymentStatus.Error;
                onProgress(new ProgressEventArgs(ex));
            }
            finally
            {
                CTS = null;
            }
        }
示例#2
0
        public async Task Deploy(DeployOptions options = null)
        {
            if (options == null)
            {
                options = new DeployOptions();
            }

            if (this.Deployment.Status == DeploymentStatus.Running)
            {
                DeploymentEvent?.Invoke(this.Deployment, new ProgressEventArgs(new InvalidOperationException("Deployment is already running.")));
            }
            else
            {
                TakoDeploy = new TakoDeploy(this.Deployment);
                await TakoDeploy.BeginDeploy(options, e => DeploymentEvent?.Invoke(this, e));
            }
        }