internal static void InformUserOfFailure(string email
            , TeamFoundationRequestContext requestContext, PushNotification pushNotification
            , List<Validation> validationResults)
        {
            var buf = new StringBuilder();
            buf.AppendFormat("{0}'s {1} request was refused for the following reasons:"
                , requestContext.GetNameToDisplay()
                , requestContext.ServiceName
                );
            buf.AppendLine();
            buf.AppendLine();
            foreach (var res in validationResults.Where(res => res.Fails))
            {
                buf.Append(" - ");
                buf.AppendLine(res.ReasonMessage);
            }
            buf.AppendLine();

            buf.AppendLine("Additional information:");
            buf.Append(requestContext.GetSummary());
            buf.AppendLine();

            var message = new MailMessage();
            message.From = new MailAddress(PluginConfiguration.Instance.EmailSender);
            message.To.Add(new MailAddress(email));
            message.Subject = "Push refused";
            message.Body = buf.ToString();
            var smtp = new SmtpClient(PluginConfiguration.Instance.EmailSmtpServer);
            smtp.Send(message);
        }
        internal static void InformUserOfFailure(string email
                                                 , TeamFoundationRequestContext requestContext, PushNotification pushNotification
                                                 , List <Validation> validationResults)
        {
            var buf = new StringBuilder();

            buf.AppendFormat("{0}'s {1} request was refused for the following reasons:"
                             , requestContext.GetNameToDisplay()
                             , requestContext.ServiceName
                             );
            buf.AppendLine();
            buf.AppendLine();
            foreach (var res in validationResults.Where(res => res.Fails))
            {
                buf.Append(" - ");
                buf.AppendLine(res.ReasonMessage);
            }
            buf.AppendLine();

            buf.AppendLine("Additional information:");
            buf.Append(requestContext.GetSummary());
            buf.AppendLine();

            var message = new MailMessage();

            message.From = new MailAddress(PluginConfiguration.Instance.EmailSender);
            message.To.Add(new MailAddress(email));
            message.Subject = "Push refused";
            message.Body    = buf.ToString();
            var smtp = new SmtpClient(PluginConfiguration.Instance.EmailSmtpServer);

            smtp.Send(message);
        }
示例#3
0
        internal static void LogRequest(TeamFoundationRequestContext requestContext, PushNotification pushNotification, TfsGitRepository repository)
        {
            if (!PluginConfiguration.Instance.HasLog)
                return;

            var lines = new List<string>();

            lines.Add(string.Format("Request from {0} for {1}"
                , requestContext.GetNameToDisplay()
                , requestContext.ServiceName
                ));
            lines.Add("Summary for " + requestContext.GetSummary());

            lines.Add(string.Format("{6} #{0} on {1} repo {2} at {3} by {5} ({4})"
                , pushNotification.PushId
                , pushNotification.TeamProjectUri
                , pushNotification.RepositoryName
                , pushNotification.PushTime
                , pushNotification.AuthenticatedUserName
                , pushNotification.Pusher
                , requestContext.Method.Name
                ));

            lines.Add("- Included Commits:");
            foreach (var commitHash in pushNotification.IncludedCommits)
            {
                var commit = repository.TryLookupObject(requestContext, commitHash) as TfsGitCommit;
                lines.Add(string.Format("   Commit {0}: {1} '{2}'"
                    , commit.ObjectId.DisplayHash()
                    , commit.GetCommitterName(requestContext)
                    , commit.GetComment(requestContext)
                    ));

                foreach (var parentCommit in commit.GetParents(requestContext))
                {
                    lines.Add(string.Format("      Parent {0}: {1} '{2}'"
                        , parentCommit.ObjectId.DisplayHash()
                        , parentCommit.GetCommitterName(requestContext)
                        , parentCommit.GetComment(requestContext)
                        ));
                }
            }

            lines.Add("- Ref Update Results:");
            foreach (var refUpdate in pushNotification.RefUpdateResults)
            {
                lines.Add(string.Format("   on {0} {1}..{2} is {3} (succeeded: {4}) rejecter '{5}' message '{6}'"
                    , refUpdate.Name
                    , refUpdate.NewObjectId.DisplayHash()
                    , refUpdate.OldObjectId.DisplayHash()
                    , refUpdate.Status
                    , refUpdate.Succeeded
                    , refUpdate.RejectedBy
                    , refUpdate.CustomMessage
                    ));
            }//for

            File.AppendAllLines(PluginConfiguration.Instance.LogFile, lines);
        }
示例#4
0
        internal static void LogRequest(TeamFoundationRequestContext requestContext, PushNotification pushNotification, TfsGitRepository repository)
        {
            if (!PluginConfiguration.Instance.HasLog)
            {
                return;
            }

            var lines = new List <string>();

            lines.Add(string.Format("Request from {0} for {1}"
                                    , requestContext.GetNameToDisplay()
                                    , requestContext.ServiceName
                                    ));
            lines.Add("Summary for " + requestContext.GetSummary());

            lines.Add(string.Format("{6} #{0} on {1} repo {2} at {3} by {5} ({4})"
                                    , pushNotification.PushId
                                    , pushNotification.TeamProjectUri
                                    , pushNotification.RepositoryName
                                    , pushNotification.PushTime
                                    , pushNotification.AuthenticatedUserName
                                    , pushNotification.Pusher
                                    , requestContext.Method.Name
                                    ));

            lines.Add("- Included Commits:");
            foreach (var commitHash in pushNotification.IncludedCommits)
            {
                var commit = repository.TryLookupObject(requestContext, commitHash) as TfsGitCommit;
                lines.Add(string.Format("   Commit {0}: {1} '{2}'"
                                        , commit.ObjectId.DisplayHash()
                                        , commit.GetCommitterName(requestContext)
                                        , commit.GetComment(requestContext)
                                        ));

                foreach (var parentCommit in commit.GetParents(requestContext))
                {
                    lines.Add(string.Format("      Parent {0}: {1} '{2}'"
                                            , parentCommit.ObjectId.DisplayHash()
                                            , parentCommit.GetCommitterName(requestContext)
                                            , parentCommit.GetComment(requestContext)
                                            ));
                }
            }

            lines.Add("- Ref Update Results:");
            foreach (var refUpdate in pushNotification.RefUpdateResults)
            {
                lines.Add(string.Format("   on {0} {1}..{2} is {3} (succeeded: {4}) rejecter '{5}' message '{6}'"
                                        , refUpdate.Name
                                        , refUpdate.NewObjectId.DisplayHash()
                                        , refUpdate.OldObjectId.DisplayHash()
                                        , refUpdate.Status
                                        , refUpdate.Succeeded
                                        , refUpdate.RejectedBy
                                        , refUpdate.CustomMessage
                                        ));
            }//for

            File.AppendAllLines(PluginConfiguration.Instance.LogFile, lines);
        }