Esempio n. 1
0
 // As of now, at least the second field must be filled with a single value, to avoid executing the subscription too frequently.
 private void EnsureScheduleIsValid(SubscriptionSchedule schedule)
 {
     if (string.IsNullOrEmpty(schedule.Seconds) || schedule.Seconds.Contains("["))
     {
         throw new Exception("Subscription schedule must specify at least the 'second' field.");
     }
 }
Esempio n. 2
0
        public virtual void Subscribe(string subscriptionId, string queryName, IEnumerable <QueryParam> parameters, Uri destination, SubscriptionControls controls, SubscriptionSchedule schedule)
        {
            var currentUser = _userProvider.GetCurrentUser();

            EnsureSubscriptionDoesNotExistForUser(subscriptionId, currentUser);
            EnsureQueryExistsAndAllowSubscription(queryName);
            EnsureDestinationIsValid(destination);

            var subscriptionParams = parameters.Select(SubscriptionParameter.Parse);

            var subscription = new Subscription
            {
                Name           = subscriptionId,
                DestinationUrl = destination?.ToString(),
                User           = currentUser,
                LastRunOn      = SystemContext.Clock.Now,
                QueryName      = queryName,
                Controls       = controls,
                Schedule       = schedule
            };

            foreach (var parameter in subscriptionParams)
            {
                subscription.AddParameter(parameter);
            }

            _subscriptionRepository.Save(subscription);
        }