Пример #1
0
        public void Subscribe()
        {
            lock (this._Sync)
            {
                if (this.Status != MonitorStatus.Subscribed)
                {
                    this.UpdateQueue();

                    NotificationReciever.NotifyChangeSetId += new NotifyChangeSetIdDelegate(OnNotifyChangeSetId);

                    Uri ServiceUri = this.GetServiceUri();

                    this.StartListener(ServiceUri);

                    bool CurrentlySubscribed = this.Subscribed();

                    if (!CurrentlySubscribed)
                    {
                        DeliveryPreference SubscriptionInfo = this.GetSubscriptionInfo(ServiceUri.ToString());
                        this.State.AlertId = this.EventService.SubscribeEvent(this.Server.AuthenticatedUserName, "CheckinEvent", String.Empty, SubscriptionInfo);
                    }
                    this._Status = MonitorStatus.Subscribed;
                }
            }
        }
Пример #2
0
        public void IEventService_should_return_the_same_subscription_id_for_duplicate_subscriptions()
        {
            // arrange
            var collection         = new TfsTeamProjectCollection(new Uri("http://localhost:8080/tfs/DefaultCollection"));
            var eventService       = collection.GetService <IEventService>();
            var deliveryPreference = new DeliveryPreference
            {
                Address  = string.Format("http://foo/{0}", GetType().FullName),
                Schedule = DeliverySchedule.Immediate,
                Type     = DeliveryType.Soap
            };

            var firstSubscriptionId  = 0;
            var secondSubscriptionId = 0;

            try
            {
                firstSubscriptionId = eventService.SubscribeEvent("BuildStatusChangeEvent", null, deliveryPreference);

                // act
                secondSubscriptionId = eventService.SubscribeEvent("BuildStatusChangeEvent", null, deliveryPreference);
            }
            finally
            {
                // absterge
                try { eventService.UnsubscribeEvent(firstSubscriptionId); } catch { }
                try { eventService.UnsubscribeEvent(secondSubscriptionId); } catch { }
            }

            // assert
            Assert.AreNotEqual(0, secondSubscriptionId);
            Assert.AreEqual(firstSubscriptionId, secondSubscriptionId);
        }
Пример #3
0
        private void SubscribeButton_Click(object sender, EventArgs e)
        {
            if (textBoxSendTo.Text.Trim().Length == 0)
            {
                MessageBox.Show("There are no email/SOAP addresses in the Send To box.");
                return;
            }

            if (textBoxExpression.Text.Trim().Length == 0)
            {
                MessageBox.Show("No XPath expression has been entered.");
                return;
            }

            if (tfsCollection == null)
            {
                MainForm.DisplayException("No Team Foundation Server selected");
                return;
            }

            if (comboBoxEventType.SelectedItem == null)
            {
                MessageBox.Show("No Event selected");
                return;
            }

            if (comboBoxFormat.SelectedItem == null)
            {
                MessageBox.Show("No Format selected");
                return;
            }

            if (comboBoxSchedule.SelectedItem == null)
            {
                MessageBox.Show("No Schedule selected");
                return;
            }

            DeliveryPreference preference = new DeliveryPreference();

            preference.Type     = (DeliveryType)Enum.Parse(typeof(DeliveryType), comboBoxFormat.Text);
            preference.Schedule = (DeliverySchedule)Enum.Parse(typeof(DeliverySchedule), comboBoxSchedule.Text);
            preference.Address  = textBoxSendTo.Text;

            try
            {
                string eventType = comboBoxEventType.Text;
                string filter    = textBoxExpression.Text;
                string name      = textBoxName.Text;

                eventService.SubscribeEvent(userName, eventType, filter, preference, name);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error subscribing to event", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            ShowSubscriptions();
        }
Пример #4
0
        public void TestDeliveryPreference()
        {
            DeliveryPreference Info = this.GetSubscriptionInfo(@"http://*****:*****@"http://me:1234/here");
            Assert(Info.Schedule.ToString(), DeliverySchedule.Immediate.ToString());
            Assert(Info.Type.ToString(), DeliveryType.Soap.ToString());
        }
Пример #5
0
        private DeliveryPreference GetSubscriptionInfo(string address)
        {
            DeliveryPreference SubscriptionInfo = new DeliveryPreference();

            SubscriptionInfo.Address  = address;
            SubscriptionInfo.Type     = DeliveryType.Soap;
            SubscriptionInfo.Schedule = DeliverySchedule.Immediate;
            return(SubscriptionInfo);
        }
Пример #6
0
        /// <summary>
        /// Subn
        /// </summary>
        protected virtual void Subscribe()
        {
            string address = this.Description.Endpoints[0].Address.Uri.AbsoluteUri;

            Trace.WriteLineIf(Constants.CommonSwitch.Level == TraceLevel.Verbose, string.Format("Subscrbing to Notification event at address {0}", address), Constants.NotificationServiceHost);
            DeliveryPreference preference = CreateDeliveryPrefrence(address);

            _subscriptionId = ServiceHelper.Subscribe(UserName, typeof(EventTypeT).Name.ToString(), null, preference);
        }
Пример #7
0
        private DeliveryPreference CreateDeliveryPrefrence(string endPointAddress)
        {
            DeliveryPreference preference = new DeliveryPreference();

            preference.Address  = endPointAddress;
            preference.Type     = DeliveryType.Soap;
            preference.Schedule = DeliverySchedule.Immediate;
            return(preference);
        }
Пример #8
0
        private static DeliveryPreference CreateDeliveryPreference(string endPointAddress)
        {
            var preference = new DeliveryPreference
            {
                Address  = endPointAddress,
                Type     = DeliveryType.Soap,
                Schedule = DeliverySchedule.Immediate
            };

            return(preference);
        }
Пример #9
0
        internal void Subscribe(TfsUser u, string tag, string eventType, string delType, string filter)
        {
            IEventService es = tpCollection.GetService(typeof(IEventService)) as IEventService;

            DeliveryPreference del = new DeliveryPreference();

            del.Schedule = DeliverySchedule.Immediate;
            del.Type     = (DeliveryType)Enum.Parse(typeof(DeliveryType), delType);
            del.Address  = u.Email;

            es.SubscribeEvent(u.SID, eventType, filter, del, tag);
        }
Пример #10
0
        private static bool MigrateAlerts(TeamFoundationIdentity sourceUser, TeamFoundationIdentity targetUser)
        {
            WriteLog(LogLevel.Ok, "Copying subscriptions");

            Subscription[] userSubscriptions = null;

            try
            {
                userSubscriptions = _es.GetEventSubscriptions(sourceUser.Descriptor);
            }
            catch (Exception e)
            {
                WriteLog(LogLevel.Warning, "Could not get subscriptions for user " + sourceUser.Descriptor + ": " + e.Message + ".");
                WriteLog(LogLevel.Warning, "Skipping subscriptions.");
                return(true);
            }

            if (userSubscriptions == null || !userSubscriptions.Any())
            {
                WriteLog(LogLevel.Warning, "No subscriptions found.");
                return(true);
            }

            foreach (Subscription subs in userSubscriptions)
            {
                string teamProjectName = GetTeamProjectNameById(subs.ProjectId);
                if (subs.Tag.Contains("CodeReviewChangedEvent"))
                {
                    WriteLog(string.Format("Skipping CodeReviewChangedEvent for user '{0}' in Team Project '{1}'", sourceUser.UniqueName, teamProjectName));
                    continue;
                }
                WriteLog(string.Format("Migrating subscription '{0}' in Team Project '{1}' from user '{2}' to user '{3}'", ConvertSubscriptionTagToName(subs.Tag), teamProjectName, sourceUser.UniqueName, targetUser.UniqueName));
                DeliveryPreference deliverPreference = new DeliveryPreference();
                deliverPreference.Address  = targetUser.UniqueName;
                deliverPreference.Schedule = subs.DeliveryPreference.Schedule;
                deliverPreference.Type     = subs.DeliveryPreference.Type;

                try
                {
                    _es.SubscribeEvent(targetUser.Descriptor.Identifier, subs.EventType, subs.ConditionString, deliverPreference, subs.Tag, teamProjectName);
                    WriteLog(LogLevel.Ok, "Migration succeeded");
                }
                catch (Exception ex)
                {
                    WriteLog(LogLevel.Error, string.Format("Migration failed: {0}, continuing to next subscription", ex.ToString()));
                }
            }
            WriteLog(LogLevel.Ok, "Finished copying subscriptions");

            return(true);
        }
Пример #11
0
        public void Subscribe()
        {
            foreach (var server in servers)
            {
                var eventService = GetEventService(server);

                var deliveryPreference = new DeliveryPreference
                {
                    Schedule = DeliverySchedule.Immediate,
                    Type = DeliveryType.Soap,
                    Address = notificationServiceConfig.Uri.ToString()
                };

                var subscriptionId = eventService.SubscribeEvent(EventName, string.Empty, deliveryPreference, Classification);

                if (this.log.IsInfoEnabled) this.log.InfoFormat("Subscribed to server {0} event {1} subscription id {2}", server.Name, EventName, subscriptionId);
            }
        }
        public bool CreateSubscription(string userId, string tfsUrl)
        {
            if (DoesSubscriptionExist(userId, tfsUrl))
            {
                return false;
            }

            var projectCollection = new TfsTeamProjectCollection(new Uri(tfsUrl));
            var eventService = projectCollection.GetService<IEventService>();

            var delPrev = new DeliveryPreference();
            delPrev.Type = DeliveryType.Soap;
            delPrev.Schedule = DeliverySchedule.Immediate;
            delPrev.Address = _deliveryAddress;

            eventService.SubscribeEvent(userId, "BuildCompletionEvent", string.Empty, delPrev);

            return true;
        }
Пример #13
0
        public List <TfsSubscriptionsItem> ListSubscriptions(ref List <TfsUser> lstUser, string tpName = null)
        {
            IEventService es = tpCollection.GetService(typeof(IEventService)) as IEventService;

            string filter = string.Format("\"PortfolioProject\" = '{0}'", teamProjectName);

            DeliveryPreference del = new DeliveryPreference();

            del.Schedule = DeliverySchedule.Immediate;
            del.Type     = DeliveryType.EmailHtml;

            List <TfsSubscriptionsItem> lst = new List <TfsSubscriptionsItem>();

            string sTEAMPROJECTNAME = string.Empty;

            if (tpName != null)
            {
                sTEAMPROJECTNAME = teamProjectName.ToUpper();
            }

            foreach (Subscription s in es.GetAllEventSubscriptions())
            {
                if (sTEAMPROJECTNAME == string.Empty || s.ConditionString.ToUpper().Contains("'" + sTEAMPROJECTNAME + "'"))
                {
                    lst.Add(new TfsSubscriptionsItem()
                    {
                        ID = s.ID,
                        Conditionstring = s.ConditionString,
                        Tag             = ParseTag(s.Tag),
                        Subscriber      = s.Subscriber,
                        EmailType       = s.DeliveryPreference.Type.ToString(),
                        EventTypeName   = s.EventType,
                        User            = GetTfsUserFromList(s.Subscriber, ref lstUser),
                        Email           = s.DeliveryPreference.Address
                    });
                }
            }

            return(lst);
        }
Пример #14
0
        private void TFSUpdateB_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                var url = ListenerURLTB.Text;
                RegistryProcessor.SetString(RegistryProcessor.ListenerUrlParameter, url);

                // Get Eventing Service
                var eventService = (IEventService)TfsServer.GetService(typeof(IEventService));

                // Set delivery preferences
                var dPref = new DeliveryPreference {
                    Schedule = DeliverySchedule.Immediate, Address = url, Type = DeliveryType.Soap
                };

                const string tag = "VersionOneTFSServer";

                // Unsubscribe to all events
                foreach (var s in eventService.GetEventSubscriptions(TfsServer.AuthorizedIdentity.Descriptor, tag))
                {
                    eventService.UnsubscribeEvent(s.ID);
                }

                // Subscribe to checked events
                var filter = string.Empty;
                eventService.SubscribeEvent("CheckinEvent", filter, dPref, tag);
                eventService.SubscribeEvent("BuildCompletionEvent2", filter, dPref, tag);

                UpdateStatus();
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #15
0
        private void TFSUpdateB_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                var url = ListenerURLTB.Text;
                RegistryProcessor.SetString(RegistryProcessor.ListenerUrlParameter, url);

                // Get Eventing Service
                var eventService = (IEventService)TfsServer.GetService(typeof(IEventService));

                // Set delivery preferences
                var dPref = new DeliveryPreference { Schedule = DeliverySchedule.Immediate, Address = url, Type = DeliveryType.Soap };

                const string tag = "VersionOneTFSServer";

                // Unsubscribe to all events
                foreach (var s in eventService.GetEventSubscriptions(TfsServer.AuthorizedIdentity.Descriptor, tag))
                {
                    eventService.UnsubscribeEvent(s.ID);
                }

                // Subscribe to checked events
                var filter = string.Empty;
                eventService.SubscribeEvent("CheckinEvent", filter, dPref, tag);
                eventService.SubscribeEvent("BuildCompletionEvent2", filter, dPref, tag);

                UpdateStatus();
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #16
0
        private DeliveryPreference GetSubscriptionInfo(string address)
        {
            DeliveryPreference SubscriptionInfo = new DeliveryPreference();

            SubscriptionInfo.Address = address;
            SubscriptionInfo.Type = DeliveryType.Soap;
            SubscriptionInfo.Schedule = DeliverySchedule.Immediate;
            return SubscriptionInfo;
        }
Пример #17
0
        public static int Subscribe(string userName, string eventToSubscribeTo, string filterExpression, DeliveryPreference preference)
        {
            TraceHelper.TraceVerbose(Constants.CommonSwitch, "Subscribing to {0} using UserName:{1} FilterExpression:{2}", eventToSubscribeTo, userName, filterExpression);
            IEventService service = GetService <IEventService>();

            return(service.SubscribeEvent(userName, eventToSubscribeTo, filterExpression, preference));
        }
Пример #18
0
 public static int Subscribe(string userName, TeamFoundationServerEvents eventToSubscribeTo, string filterExpression, DeliveryPreference preference)
 {
     return(Subscribe(userName, eventToSubscribeTo.ToString(), filterExpression, preference));
 }