Esempio n. 1
0
        public async Task ReleaseAsync()
        {
            // TODO: Locking on sessionId and isActive

            BuildTasks.Stop();

            if (messageClient.IsConnected)
            {
                if (!string.IsNullOrEmpty(AgentSessionId))
                {
                    var message = new BuildSessionReleaseRequest {
                        SessionId = AgentSessionId,
                    };

                    try {
                        await messageClient.Send(message)
                        .GetResponseAsync();
                    }
                    catch (Exception error) {
                        Log.Error($"Failed to release Agent Session '{AgentSessionId}'! {error.Message}");
                    }
                }

                await messageClient.DisconnectAsync();
            }
        }
Esempio n. 2
0
        public async Task BeginAsync()
        {
            try {
                await messageClient.ConnectAsync(definition.TcpHost, definition.TcpPort);

                Log.Info($"Connected to Agent '{definition.Name}'.");
            }
            catch (Exception error) {
                Log.Error($"Failed to connect to Agent '{definition.Name}'!", error);
                throw new ApplicationException($"Failed to connect to Agent '{definition.Name}'! {error.Message}");
            }

            var message = new BuildSessionBeginRequest {
                ServerSessionId = context.ServerSessionId,
                Project         = context.Project,
                AssemblyFile    = context.AssemblyFilename,
                PreBuild        = context.PreBuild,
                GitRefspec      = context.GitRefspec,
                BuildNumber     = context.BuildNumber,
            };

            try {
                var response = await messageClient.Send(message)
                               .GetResponseAsync <BuildSessionBeginResponse>();

                AgentSessionId = response.SessionId;
            }
            catch (Exception error) {
                throw new ApplicationException($"Failed to start Agent Session! {error.Message}");
            }

            BuildTasks.Start();
        }
Esempio n. 3
0
        public async Task <TaskResult> RunTaskAsync(string taskName)
        {
            context.Output
            .Append("Running Build-Task ", ConsoleColor.DarkCyan)
            .Append(taskName, ConsoleColor.Cyan)
            .Append(" on Agent ", ConsoleColor.DarkCyan)
            .Append(definition.Name, ConsoleColor.Cyan)
            .AppendLine("...", ConsoleColor.DarkCyan);

            var runner = new BuildTaskRunner(messageClient, AgentSessionId);

            runner.OutputEvent += (o, e) => {
                context.Output.AppendRaw(e.Text);
            };

            BuildTasks.Add(runner);

            var result = await runner.Run(taskName);

            if (!result.Successful)
            {
                context.Output
                .AppendLine($"Build-Task '{taskName}' Failed!", ConsoleColor.Red)
                .AppendLine(result.Message, ConsoleColor.DarkYellow);
            }

            context.Output
            .Append("Build-Task ", ConsoleColor.DarkGreen)
            .Append(taskName, ConsoleColor.Green)
            .Append(" completed successfully.", ConsoleColor.DarkGreen);

            return(result);
        }
Esempio n. 4
0
 public void Dispose()
 {
     BuildTasks?.Dispose();
     messageClient?.Dispose();
 }
        /// <summary>
        /// Performs the build operation.
        /// </summary>
        /// <param name="isLocalDeployment">if set to <c>true</c> [is local deployment].</param>
        /// <param name="currentVersionForlocalDeploy">The current version forlocal deploy.</param>
        /// <returns>
        /// true if build is successful
        /// </returns>
        private bool PerformBuildOperation(bool isLocalDeployment, string currentVersionForlocalDeploy = "")
        {
            bool buildSuccessful = true;
            int stepNumber = 10;

            if (isLocalDeployment)
            {
                if (string.IsNullOrEmpty(currentVersionForlocalDeploy))
                {
                    throw new ArgumentNullException("Unable to get next successful version to deploy.");
                }

                try
                {
                    this.AssignCloudArgsNoBuild(currentVersionForlocalDeploy);
                }
                catch (IOException ex)
                {
                    ex.ShowUIException();
                    return false;
                }

                return true;
            }

            // Initialize
            this.backgroundWorker.ReportProgress(++stepNumber, "Initializing build parameters....");
            using (BuildTasks tasks = new BuildTasks(this.buildArgs))
            {
                try
                {
                    this.backgroundWorker.ReportProgress(++stepNumber, "Creating temporary TFS workspace....");
                    tasks.CreateDedicatedTfsWorkSpace();

                    this.backgroundWorker.ReportProgress(++stepNumber, "Downloading code for TFS label....");
                    tasks.GetTfsLabelCodeToLocal(txtTFSLabelName.Text);

                    this.backgroundWorker.ReportProgress(++stepNumber, "Compiling and building solution.....");
                    if (tasks.ExecMsBuild())
                    {
                        using (AdvancedMessageBox adv = new AdvancedMessageBox("Build suceeded but has warnings. Do you want to continue?", ReportStatus.Information, true))
                        {
                            this.Invoke((MethodInvoker)delegate
                            {
                                if (DialogResult.Cancel == adv.ShowDialog(this))
                                {
                                    this.AssignCloudArgsAfterBuild(tasks.MSbuildLogPath, tasks.TFLogPath, tasks.AzurePackagesPath);
                                    throw new OperationCanceledException("Operation cancelled.");
                                }
                            });
                        }
                    }

                    this.AssignCloudArgsAfterBuild(tasks.MSbuildLogPath, tasks.TFLogPath, tasks.AzurePackagesPath);
                    this.ShowRequiredDialogs(tasks.AzurePackagesPath);
                }
                catch (FormatException formatexception)
                {
                    buildSuccessful = false;
                    this.Invoke((MethodInvoker)(() => formatexception.ShowUIException()));
                    this.backgroundWorker.ReportProgress(stepNumber, ReportStatus.Fail);
                }
                catch (OperationCanceledException exception)
                {
                    buildSuccessful = false;
                    this.Invoke((MethodInvoker)(() => exception.ShowUIException()));
                    this.backgroundWorker.ReportProgress(stepNumber, ReportStatus.Fail);
                }
                catch (Exception exception)
                {
                    buildSuccessful = false;
                    this.Invoke((MethodInvoker)(() => exception.ShowGenericException("Error in building application.")));
                    this.backgroundWorker.ReportProgress(stepNumber, ReportStatus.Fail);
                }
                finally
                {
                    // in case there is an exception and we are came here directly then check for log paths to enable.
                    if (this.msbuildLogPath == null)
                    {
                        this.msbuildLogPath = tasks.MSbuildLogPath;
                    }

                    if (this.teamfoundationExeLogPath == null)
                    {
                        this.teamfoundationExeLogPath = tasks.TFLogPath;
                    }

                    this.backgroundWorker.ReportProgress(++stepNumber, "Deleting temporary TFS workspace....");
                    tasks.DeleteDedicatedTfsWorkSpace();
                }
            }

            // enable ths user to see log paths
            this.Invoke((MethodInvoker)delegate
            {
                this.btnViewBuildLog.Enabled = File.Exists(this.msbuildLogPath);
                this.btnViewTFLog.Enabled = File.Exists(this.teamfoundationExeLogPath);
            });

            return buildSuccessful;
        }