コード例 #1
0
#pragma warning restore SA1306 // Field names must begin with lower-case letter

            internal Mailer(IVssRequestContext requestContext)
            {
                this.Enabled = false;
                try
                {
                    IVssRegistryService service = requestContext.GetService <IVssRegistryService>();
                    Microsoft.TeamFoundation.Framework.Server.RegistryEntryCollection registryEntryCollection = service.ReadEntriesFallThru(requestContext, this.NotificationRootPath + "/*");
                    if (registryEntryCollection["EmailEnabled"].GetValue <bool>(true))
                    {
                        this.SmtpServer  = registryEntryCollection["SmtpServer"].GetValue(string.Empty);
                        this.SmtpPort    = registryEntryCollection["SmtpPort"].GetValue <int>(-1);
                        this.EnableSsl   = registryEntryCollection["SmtpEnableSsl"].GetValue <bool>(false);
                        this.FromAddress = null;

                        string value = registryEntryCollection["EmailNotificationFromAddress"].GetValue(string.Empty);
                        if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(this.SmtpServer))
                        {
                            this.FromAddress = new MailAddress(value);
                            this.Enabled     = true;
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($"SendMail failed: {ex.Message}");
                }
            }
コード例 #2
0
        public TeamFoundationJobExecutionResult Run(
            TeamFoundationRequestContext requestContext,
            TeamFoundationJobDefinition jobDefinition,
            DateTime queueTime,
            out string resultMessage)
        {
            resultMessage = string.Empty;
            try
            {
                this.LogInfo(string.Format("Enter Job"));

                lock (JobLock)
                {
                    XmlNode xmlData = jobDefinition.Data;
                    object  notificationEventArgs = DeserializeXml(xmlData);
                    this.workflowRunner.ProcessEvent(requestContext, NotificationType.Notification, notificationEventArgs, true, true);
                }
            }
            catch (RequestCanceledException e)
            {
                this.LogError(string.Format("Workflow cancel: "), e);
                return(TeamFoundationJobExecutionResult.Stopped);
            }
            catch (Exception e)
            {
                this.LogError(string.Format("Workflow error: "), e);
                resultMessage = e.ToString();
                return(TeamFoundationJobExecutionResult.Failed);
            }

            this.LogInfo(string.Format("Leave Job"));

            return(TeamFoundationJobExecutionResult.Succeeded);
        }
コード例 #3
0
        /// <summary>
        /// When implemented in a derived class, performs the execution of the activity.
        /// </summary>
        /// <param name="context">The execution context under which the activity executes.</param>
        protected override void Execute(CodeActivityContext context)
        {
            TeamFoundationRequestContext requestContext = context.GetValue(this.TeamFoundationRequestContext);

          #if UsingILocationService
            ILocationService tfLocationService = requestContext.GetService <ILocationService>();
            Uri uriRequestContext = new Uri(tfLocationService.GetLocationData(requestContext, Guid.Empty).GetServerAccessMapping(requestContext).AccessPoint + "/" + requestContext.ServiceHost.Name);
#else
            var tfLocationService = requestContext.GetService <TeamFoundationLocationService>();
            var accessMapping     = tfLocationService.GetServerAccessMapping(requestContext);
            Uri uriRequestContext = new Uri(tfLocationService.GetHostLocation(requestContext, accessMapping));
#endif
            string     strHost = System.Environment.MachineName;
            string     strFQDN = System.Net.Dns.GetHostEntry(strHost).HostName;
            UriBuilder uriBuilderRequestContext = new UriBuilder(uriRequestContext.Scheme, strFQDN, uriRequestContext.Port, uriRequestContext.PathAndQuery);
            string     teamProjectCollectionUrl = uriBuilderRequestContext.Uri.AbsoluteUri;
            var        teamProjectCollection    = new TfsTeamProjectCollection(new Uri(teamProjectCollectionUrl));
            string     serverUri = teamProjectCollectionUrl;

            var           workItemEvent = context.GetValue(this.WorkItemChangedEvent);
            int           workItemId    = workItemEvent.CoreFields.IntegerFields.First(k => k.Name == "ID").NewValue;
            WorkItemStore workItemStore = GetWorkitemStore(serverUri);
            var           workItem      = workItemStore.GetWorkItem(workItemId);

            context.SetValue(this.ChangedFields, workItemEvent.ChangedFields);
            context.SetValue(this.WorkItem, workItem);
            context.SetValue(this.TFSCollectionUrl, serverUri);
        }
コード例 #4
0
 public RequestContextWrapper(
     IVssRequestContext context,
     NotificationType notificationType,
     object notificationEventArgs)
 {
     this.context      = context;
     this.Notification = new NotificationWrapper(notificationType, notificationEventArgs as WorkItemChangedEvent);
 }
コード例 #5
0
 public RequestContextWrapper(
     IVssRequestContext context,
     NotificationType notificationType,
     object notificationEventArgs)
 {
     this.context = context;
     this.Notification = new NotificationWrapper(notificationType, notificationEventArgs as WorkItemChangedEvent);
 }
コード例 #6
0
        /// <summary>
        /// This is the one where all the magic starts.  Main() so to speak.  I will load the settings, connect to TFS and apply the aggregation rules.
        /// </summary>
        public EventNotificationStatus ProcessEvent(
            IVssRequestContext requestContext,
            NotificationType notificationType,
            object notificationEventArgs,
            out int statusCode,
            out string statusMessage,
            out ExceptionPropertyCollection properties)
        {
            var logger  = new ServerEventLogger(GetDefaultLoggingLevel());
            var context = new RequestContextWrapper(requestContext, notificationType, notificationEventArgs);
            var runtime = RuntimeContext.GetContext(
                GetServerSettingsFullPath,
                context,
                logger,
                (runtimeContext) => new WorkItemRepository(runtimeContext),
                (runtimeContext) => new ScriptLibrary(runtimeContext));

            if (runtime.HasErrors)
            {
                statusCode    = 99;
                statusMessage = string.Join(". ", runtime.Errors);
                properties    = null;
                return(EventNotificationStatus.ActionPermitted);
            }

            var result = new ProcessingResult();

            try
            {
                // Check if we have a workitem changed event before proceeding
                if (notificationType == NotificationType.Notification && notificationEventArgs is WorkItemChangedEvent)
                {
                    using (EventProcessor eventProcessor = new EventProcessor(runtime))
                    {
                        logger.StartingProcessing(context, context.Notification);
                        result = eventProcessor.ProcessEvent(context, context.Notification);
                        logger.ProcessingCompleted(result);
                    }
                }
            }
            catch (Exception e)
            {
                logger.ProcessEventException(e);

                // notify failure
                result.StatusCode         = -1;
                result.StatusMessage      = "Unexpected error: " + e.Message;
                result.NotificationStatus = EventNotificationStatus.ActionPermitted;
            }

            statusCode    = result.StatusCode;
            statusMessage = result.StatusMessage;
            properties    = result.ExceptionProperties;
            return(result.NotificationStatus);
        }
コード例 #7
0
        /// <summary>
        /// This is the one where all the magic starts.  Main() so to speak.  I will load the settings, connect to TFS and apply the aggregation rules.
        /// </summary>
        public EventNotificationStatus ProcessEvent(
            IVssRequestContext requestContext,
            NotificationType notificationType,
            object notificationEventArgs,
            out int statusCode,
            out string statusMessage,
            out ExceptionPropertyCollection properties)
        {
            var logger = new ServerEventLogger(LogLevel.Normal);
            var context = new RequestContextWrapper(requestContext, notificationType, notificationEventArgs);
            var runtime = RuntimeContext.GetContext(
                GetServerSettingsFullPath,
                context,
                logger,
                (collectionUri, toImpersonate, logEvents) =>
                    new WorkItemRepository(collectionUri, toImpersonate, logEvents));

            if (runtime.HasErrors)
            {
                statusCode = 99;
                statusMessage = string.Join(". ", runtime.Errors);
                properties = null;
                return EventNotificationStatus.ActionPermitted;
            }

            var result = new ProcessingResult();
            try
            {
                // Check if we have a workitem changed event before proceeding
                if (notificationType == NotificationType.Notification && notificationEventArgs is WorkItemChangedEvent)
                {
                    using (EventProcessor eventProcessor = new EventProcessor(runtime))
                    {
                        logger.StartingProcessing(context, context.Notification);
                        result = eventProcessor.ProcessEvent(context, context.Notification);
                        logger.ProcessingCompleted(result);
                    }
                }
            }
            catch (Exception e)
            {
                logger.ProcessEventException(e);

                // notify failure
                result.StatusCode = -1;
                result.StatusMessage = "Unexpected error: " + e.Message;
                result.NotificationStatus = EventNotificationStatus.ActionPermitted;
            }

            statusCode = result.StatusCode;
            statusMessage = result.StatusMessage;
            properties = result.ExceptionProperties;
            return result.NotificationStatus;
        }
コード例 #8
0
        private Uri GetCollectionUriFromContext(IVssRequestContext requestContext)
        {
            ILocationService service = requestContext.GetService <ILocationService>();

            return(service.GetSelfReferenceUri(requestContext, service.GetDefaultAccessMapping(requestContext)));
        }
コード例 #9
0
 private Uri GetCollectionUriFromContext(IVssRequestContext requestContext)
 {
     ILocationService service = requestContext.GetService<ILocationService>();
     return service.GetSelfReferenceUri(requestContext, service.GetDefaultAccessMapping(requestContext));
 }