Ejemplo n.º 1
0
        private static string ProcessEmailRecipients(string inputString, bool addSender)
        {
            string[]         tempRecipients = CollectionUtil.StringToStringArray(inputString, new char[] { ',', ';' });
            StringCollection processedList  = new StringCollection();

            foreach (string recipient in tempRecipients)
            {
                if (recipient == null || recipient.Trim() == "")
                {
                    continue;
                }
                else
                {
                    processedList.Add(recipient.Trim());
                }
            }
            string sender       = Environment.UserName;
            bool   senderInList = false;

            foreach (string recipient in processedList)
            {
                string tempRecipient = recipient;
                int    atIndex       = recipient.IndexOf('@');
                if (atIndex != -1)
                {
                    tempRecipient = recipient.Substring(0, atIndex);
                }
                if (tempRecipient.ToUpper() == sender.ToUpper())
                {
                    senderInList = true;
                    break;
                }
            }
            if (addSender && !senderInList)
            {
                processedList.Add(sender.ToLower());
            }
            return(CollectionUtil.CollectionToString(processedList, ';'));
        }
Ejemplo n.º 2
0
        private void SendEmail(int buildErrorLevel)
        {
            DatabaseInterface dbInterface = new DatabaseInterface();

            string toRecipients;

            string[]         tempRecipients = CollectionUtil.StringToStringArray(pbDataSet.GetBuildProperty("EmailRecipients"), new char[] { ',', ';' });
            StringCollection processedList  = new StringCollection();

            foreach (string recipient in tempRecipients)
            {
                if (recipient == null || recipient.Trim() == "")
                {
                    continue;
                }
                // don't add "@mobius.com" if "@" already specified
                else if (recipient.IndexOf("@") >= 0)
                {
                    processedList.Add(recipient.Trim());
                }
                else
                {
                    string validRecipient = dbInterface.GetUserEmail(recipient).Trim();
                    if (validRecipient.Length > 0)
                    {
                        processedList.Add(validRecipient.Trim() + "@asg.com");
                    }
                }
            }
            toRecipients = CollectionUtil.CollectionToString(processedList, ';');

            SmtpClient client = new SmtpClient("SMTPServerName");
            string     sender = dbInterface.GetUserEmail(Environment.UserName).Trim();

            sender = (sender.Length > 0) ? sender + "@asg.com" : Environment.UserName;
            MailMessage msg     = new MailMessage(new MailAddress(sender), new MailAddress(toRecipients));
            string      subject = "Build Report for " + pbDataSet.GetBuildProperty("ProductName") + " " +
                                  pbDataSet.GetBuildProperty("ProductVersion") + " " +
                                  pbDataSet.GetBuildProperty("ProductPlatform") + " ";
            string branchOrTrunkName = pbDataSet.GetBuildProperty("BranchOrTrunkName");

            if (branchOrTrunkName.ToUpper() != "DEVELOP")
            {
                subject += branchOrTrunkName + " ";
            }
            string releaseOrDebug = pbDataSet.GetBuildProperty("ReleaseOrDebug");

            if (releaseOrDebug != null)
            {
                if ((releaseOrDebug.ToUpper() == "RELEASE" && branchOrTrunkName.ToUpper() == "DEVELOP") ||
                    (releaseOrDebug.ToUpper() == "DEBUG" && branchOrTrunkName.ToUpper() != "DEVELOP"))
                {
                    subject += releaseOrDebug + " ";
                }
            }

            if (buildErrorLevel < 2)
            {
                subject += "(Build Succeeded)";
            }
            else
            {
                subject += "(Build Failed)";
            }

            // message body
            string        body;
            StringBuilder bodyText = new StringBuilder();

            bodyText.Append("\r\n");
            bodyText.Append("Build Machine:            " + Environment.MachineName + "\r\n");
            bodyText.Append("Build User:               "******"\\" + Environment.UserName + "\r\n");
            bodyText.Append("Build Start Time:         " + startTime + "\r\n");
            bodyText.Append("Build Completion Time:    " + completeTime + "\r\n");
            bodyText.Append("Build Status:             " + GetBuildErrorLevelString(buildErrorLevel) + "\r\n");
            bodyText.Append("Library Date:             " + pbDataSet.GetBuildProperty("LibraryDate") + "\r\n");
            bodyText.Append("-------------------------------------------------------------------------\r\n");

            if (isValidationSuccessful)
            {
                bodyText.Append("\r\nBuild Times:\r\n\r\n");
                string           buildTimesFilename = pbDataSet.GetBuildProperty("BuildTimesFileName");
                StringCollection buildTimes         = new StringCollection();
                if (File.Exists(buildTimesFilename))
                {
                    buildTimes = CollectionUtil.ReadValueFile(buildTimesFilename);
                }
                else
                {
                    buildTimes.Add("-- The Build Times Output File, " + buildTimesFilename + ", is Missing --");
                }
                foreach (string line in buildTimes)
                {
                    bodyText.Append(line + "\r\n");
                }
                bodyText.Append("-------------------------------------------------------------------------\r\n");

                bodyText.Append("\r\nBuild Step Results:\r\n\r\n");
                string           buildStepStatusFilename = pbDataSet.GetBuildProperty("BuildStepStatusFileName");
                StringCollection buildStepStatus         = new StringCollection();
                if (File.Exists(buildStepStatusFilename))
                {
                    buildStepStatus = CollectionUtil.ReadValueFile(pbDataSet.GetBuildProperty("BuildStepStatusFileName"));
                }
                else
                {
                    buildStepStatus.Add("-- The Build Step Status Output File, " + buildStepStatusFilename + ", is Missing --");
                }
                if (pbDataSet.GetBuildProperty("Populate") != null && pbDataSet.GetBuildProperty("Populate").ToLower() == "true")
                {
                    buildStepStatus = ChangeLogFilePaths(buildStepStatus, pbDataSet.GetBuildProperty("BuildPath"), pbDataSet.GetBuildProperty("PopulatePath"));
                }
                foreach (string line in buildStepStatus)
                {
                    bodyText.Append(line + "\r\n");
                }
                bodyText.Append("-------------------------------------------------------------------------\r\n");

                bodyText.Append("\r\nCheckBuild Results:\r\n\r\n");
                string           checkBuildResultsFilename = pbDataSet.GetBuildProperty("CheckBuildResultsFileName");
                StringCollection checkBuildResults         = new StringCollection();
                if (File.Exists(checkBuildResultsFilename))
                {
                    checkBuildResults = CollectionUtil.ReadValueFile(checkBuildResultsFilename);
                }
                else
                {
                    checkBuildResults.Add("-- The CheckBuild Output File, " + checkBuildResultsFilename + ", is Missing --");
                }
                foreach (string line in checkBuildResults)
                {
                    bodyText.Append(line + "\r\n");
                }
            }
            else
            {
                // unsuccessful validation
                bodyText.Append("\r\nLibraryBuilder was unable to create the local library on the build machine.");
                bodyText.Append("\r\nThe build could not start.");
                bodyText.Append("\r\nIf you get this error consistently, please contact VMS Administrator.");
                bodyText.Append("\r\n\r\nValidation output file: file://" + GetBuildLogfile());
                bodyText.Append("\r\n\r\n");
            }

            bodyText.Append("-------------------------------------------------------------------------\r\n");

            bodyText.Append("\r\nBuild Properties:\r\n\r\n");
            SortedList buildProperties = pbDataSet.GetBuildProperties();

            foreach (object key in buildProperties.Keys)
            {
                if (((string)key).ToUpper() != "UNIXPASSWORD")
                {
                    string keyString   = (string)key;
                    string valueString = buildProperties[key].ToString();
                    bodyText.Append(keyString + "=" + valueString + "\r\n");
                }
            }
            bodyText.Append("-------------------------------------------------------------------------\r\n");

            body = bodyText.ToString();
            // -- end message body

            MailMessage buildEmail = new MailMessage(new MailAddress(sender), new MailAddress(toRecipients));

            buildEmail.Subject = subject;
            buildEmail.Body    = body;

            client.Send(buildEmail);
        }