コード例 #1
0
        /// <summary>
        /// Outputs an error.
        /// </summary>
        /// <param name="error">
        /// The error.
        /// </param>
        public void HandleError(BuildErrorEventArgs error)
        {
            string template = Environment.NewLine + "Error: \"{0}\"" + newLineIndent + "in file {1} line {2}" + newLineIndent + "in project {3}" + Environment.NewLine;
            string message  = string.Format(template, error.Message, error.File, error.LineNumber, error.ProjectFile);

            NotificationWriter.Write(message);
        }
コード例 #2
0
        /// <summary>
        /// Outputs a warning.
        /// </summary>
        /// <param name="warning">
        /// The warning.
        /// </param>
        public void HandleWarning(BuildWarningEventArgs warning)
        {
            string template = "Warning: \"{0}\"" + newLineIndent + "in file {1} line {2}" + newLineIndent + "in project {3}";
            string message  = string.Format(template, warning.Message, warning.File, warning.LineNumber, warning.ProjectFile);

            NotificationWriter.Write(message);
        }
コード例 #3
0
 /// <summary>
 /// Handle a raised message.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="importance">
 /// The importance.
 /// </param>
 public void HandleMessage(string message, MessageImportance importance = MessageImportance.Normal)
 {
     if (this.OutputMessage(importance))
     {
         NotificationWriter.Write(message);
     }
 }
コード例 #4
0
        /// <summary>
        /// Handles the Deploy button.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnDeploy(object sender, EventArgs e)
        {
            var commit = new OnCommitArgs()
            {
                Hash    = this.GetLatestCommitHash(),
                Message = "Re-deploy"
            };

            NotificationWriter.Clear();
            this.Deploy(commit);
        }
コード例 #5
0
        /// <summary>
        /// Deploys dev websites on a successful commit
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="commit">
        /// The commit.
        /// </param>
        private void DeploySuccessfulCommit(object sender, OnCommitArgs commit)
        {
            if (commit.Success)
            {
                commit.Hash = this.GetLatestCommitHash();
                NotificationWriter.Clear();
                NotificationWriter.Write("Commit " + commit.Hash + " successful");
                this.Deploy(commit);
            }

            // Unsubscribe from successful commit event
            BlinkboxSccHooks.OnCommit -= this.DeploySuccessfulCommit;
        }
コード例 #6
0
        /// <summary>
        /// Runs a command in the git tfs commandline environment.
        /// </summary>
        /// <param name="command">
        /// The command.
        /// </param>
        /// <param name="workingDirectory">
        /// The working directory.
        /// </param>
        public static void RunGitTfsCommand(string command, string workingDirectory)
        {
            var process = new System.Diagnostics.Process();

            process.StartInfo = new ProcessStartInfo("cmd.exe", "/k git tfs " + command);
            process.StartInfo.UseShellExecute  = false;
            process.StartInfo.CreateNoWindow   = true;
            process.StartInfo.WorkingDirectory = workingDirectory;
            process.StartInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;

            // Write output to the pending changes window
            NotificationWriter.Clear();
            NotificationWriter.NewSection("Git-Tfs " + command);
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.OutputDataReceived += (sender, args) => NotificationWriter.Write(args.Data);
            process.ErrorDataReceived  += (sender, args) => NotificationWriter.Write(args.Data);

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
        }
コード例 #7
0
        /// <summary>
        /// Builds and deploys.
        /// </summary>
        /// <param name="commit">
        /// The commit. Supplied if called after a successful commit, otherwise a new instance is created.
        /// </param>
        /// <returns>
        /// true if the deploy was successful.
        /// </returns>
        private bool Deploy(OnCommitArgs commit)
        {
            NotificationWriter.Write("Begin build and deploy to " + commit.Hash);

            try
            {
                // Look for a deploy project
                var buildProjectFileName = this.GetSolutionDirectory() + "\\" + BlinkboxSccOptions.Current.PostCommitDeployProjectName;
                if (!File.Exists(buildProjectFileName))
                {
                    MessageBox.Show("build project not found", "Deploy abandoned", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }

                NotificationWriter.Write("Deploy project found at " + buildProjectFileName);

                // Initisalise our own project collection which can be cleaned up after the build. This is to prevent caching of the project.
                using (var projectCollection = new ProjectCollection(Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.ToolsetLocations))
                {
                    var commitComment = Regex.Replace(commit.Message, @"\r|\n|\t", string.Empty);
                    commitComment = HttpUtility.UrlEncode(commitComment.Substring(0, commitComment.Length > 80 ? 80 : commitComment.Length));

                    // Global properties need to be set before the projects are instantiated.
                    var globalProperties = new Dictionary <string, string>
                    {
                        { BlinkboxSccOptions.Current.CommitGuidPropertyName, commit.Hash },
                        { BlinkboxSccOptions.Current.CommitCommentPropertyName, commitComment }
                    };
                    var msbuildProject = new ProjectInstance(buildProjectFileName, globalProperties, "4.0", projectCollection);

                    // Build it
                    WriteToStatusBar("Building " + Path.GetFileNameWithoutExtension(msbuildProject.FullPath));
                    var buildRequest = new BuildRequestData(msbuildProject, new string[] { });

                    var buildParams = new BuildParameters(projectCollection);
                    buildParams.Loggers = new List <ILogger>()
                    {
                        new BuildNotificationLogger()
                        {
                            Verbosity = LoggerVerbosity.Minimal
                        }
                    };

                    var result = BuildManager.DefaultBuildManager.Build(buildParams, buildRequest);

                    if (result.OverallResult == BuildResultCode.Failure)
                    {
                        string message = result.Exception == null
                            ? "An error occurred during build; please see the pending changes window for details."
                            : result.Exception.Message;
                        MessageBox.Show(message, "Build failed", MessageBoxButton.OK, MessageBoxImage.Error);
                        return(false);
                    }

                    // Launch urls in browser
                    var launchUrls = msbuildProject.Items.Where(pii => pii.ItemType == BlinkboxSccOptions.Current.UrlToLaunchPropertyName);
                    foreach (var launchItem in launchUrls)
                    {
                        this.LaunchBrowser(launchItem.EvaluatedInclude);
                    }

                    // Clean up project to prevent caching.
                    projectCollection.UnloadAllProjects();
                    projectCollection.UnregisterAllLoggers();
                }

                return(true);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Build failed", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }