public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties)
        {
            statusCode    = 0;
            properties    = null;
            statusMessage = string.Empty;
            try
            {
                if (notificationType == NotificationType.Notification && notificationEventArgs is CheckinNotification)
                {
                    var checkinNotification = notificationEventArgs as CheckinNotification;
                    if (ShouldMergeItemsIfNecessary(requestContext, checkinNotification))
                    {
                        var changeset = requestContext.GetChangeset(checkinNotification.Changeset);
                        if (changeset != null)
                        {
                            TfsTeamProjectCollection impersonatedCollection = requestContext.GetImpersonatedCollection(changeset.Committer);
                            MergeWorkItems(impersonatedCollection, changeset.ChangesetId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TeamFoundationApplicationCore.LogException("Inmeta.TFS.MergeWorkItemEventHandler encountered an exception", ex);
            }

            return(EventNotificationStatus.ActionPermitted);
        }
Exemple #2
0
        public EventNotificationStatus ProcessEvent(IVssRequestContext requestContext, NotificationType notificationType,
                                                    object notificationEventArgs, out int statusCode, out string statusMessage,
                                                    out Microsoft.TeamFoundation.Common.ExceptionPropertyCollection properties)
        {
            statusCode    = 0;
            properties    = null;
            statusMessage = String.Empty;
            try
            {
                BuildUpdatedEvent updatedEvent = (BuildUpdatedEvent)notificationEventArgs;
                Build             build        = updatedEvent.Build;
                Log.Info($"ProcessEvent {notificationEventArgs.GetType().Name} for build {updatedEvent.BuildId} (Build Number : {updatedEvent.Build.BuildNumber}, Build Definition: {updatedEvent.Build.Definition.Name})");

                CiEvent ciEvent = CiEventUtils.ToCiEvent(build);
                if (notificationEventArgs is BuildStartedEvent)
                {
                    ciEvent.EventType = CiEventType.Started;
                    _pluginManager.GeneralEventsQueue.Add(ciEvent);
                }
                else if (notificationEventArgs is BuildCompletedEvent)
                {
                    ciEvent.EventType = CiEventType.Finished;
                    _pluginManager.HandleFinishEvent(ciEvent);
                }
            }
            catch (Exception e)
            {
                var msg = $"ProcessEvent {notificationEventArgs.GetType().Name} failed {e.Message}";
                Log.Error(msg, e);
                TeamFoundationApplicationCore.LogException(requestContext, msg, e);
            }
            return(EventNotificationStatus.ActionPermitted);
        }
 public static void LogToFile(string logMessage)
 {
     try
     {
         FileStream   stream     = new FileStream("D:\\TFS_Log.txt", FileMode.OpenOrCreate);
         StreamWriter fileWriter = new StreamWriter(stream);
         fileWriter.WriteLine(logMessage);
         fileWriter.Close();
         stream.Close();
     }
     catch (Exception ex)
     {
         TeamFoundationApplicationCore.LogException("Logging to text file failed", ex);
     }
 }
        internal static void LogException(Exception ex)
        {
            TeamFoundationApplicationCore.LogException(ex.Message, ex);

            EventLog.WriteEntry(EventLogSource, ex.Message, EventLogEntryType.Error, 1001);

            if (PluginConfiguration.Instance.HasLog)
            {
                var lines = new List <string>();

                lines.Add("Exception: " + ex.Message);
                lines.Add(ex.StackTrace);

                File.AppendAllLines(PluginConfiguration.Instance.LogFile, lines);
            }
        }
        public EventNotificationStatus ProcessEvent(IVssRequestContext requestContext,
                                                    NotificationType notificationType, object notificationEventArgs,
                                                    out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties)
        {
            statusCode    = 0;
            statusMessage = string.Empty;
            properties    = null;

            if (notificationType == NotificationType.Notification)
            {
                try
                {
                    if (notificationEventArgs is CheckinNotification)
                    {
                        var           notification = notificationEventArgs as CheckinNotification;
                        StringBuilder logMessage   = new StringBuilder();
                        logMessage.Append("\n***************************************\r\n");
                        logMessage.Append("New Check-in Done, Change set Details:-\r\n");
                        logMessage.AppendFormat("ChangeSet Id:{0}\r\n", notification.Changeset);
                        logMessage.AppendFormat("ChangeSet Description:{0}\r\n", notification.Comment);
                        logMessage.AppendFormat("Checked-in User:{0}\r\n", notification.ChangesetOwner.DistinctDisplayName);
                        logMessage.AppendFormat("Machine Name:{0}\r\n", notification.ComputerName);
                        logMessage.AppendFormat("Associated Work Items:{0}\r\n", notification.NotificationInfo.WorkItemInfo.Length);
                        StringBuilder workitems = new StringBuilder();
                        if (notification.NotificationInfo.WorkItemInfo.Length > 0)
                        {
                            for (int workitemindex = 0; workitemindex < notification.NotificationInfo.WorkItemInfo.Length; workitemindex++)
                            {
                                workitems.AppendFormat("{0},", notification.NotificationInfo.WorkItemInfo[0].Id);
                            }
                        }
                        logMessage.Append("\n***************************************");
                        VersionControlLogger.LogToFile(logMessage.ToString());
                    }
                }
                catch (Exception e)
                {
                    TeamFoundationApplicationCore.LogException("logger failed", e);
                }
            }
            return(EventNotificationStatus.ActionPermitted);
        }
Exemple #6
0
        public EventNotificationStatus ProcessEvent(IVssRequestContext requestContext,
                                                    NotificationType notificationType, object notificationEventArgs,
                                                    out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties)
        {
            statusCode    = 0;
            statusMessage = string.Empty;
            properties    = null;

            if (notificationType == NotificationType.DecisionPoint)
            {
                try
                {
                    if (notificationEventArgs is CheckinNotification)
                    {
                        var  notification   = notificationEventArgs as CheckinNotification;
                        bool IsCheckInValid = true;
                        if (String.IsNullOrEmpty(notification.Comment))
                        {
                            statusMessage  = " Check in Comments Cannot Be empty";
                            IsCheckInValid = IsCheckInValid && false;
                        }
                        if (notification.NotificationInfo.WorkItemInfo.Length <= 0)
                        {
                            statusMessage  = "Associate Change set With a Work Item To Check In";
                            IsCheckInValid = IsCheckInValid && false;
                        }
                        if (!IsCheckInValid)
                        {
                            return(EventNotificationStatus.ActionDenied);
                        }
                    }
                }
                catch (Exception e)
                {
                    TeamFoundationApplicationCore.LogException("Check In Validation failed", e);
                }
            }
            return(EventNotificationStatus.ActionPermitted);
        }