Example #1
0
        public void Apply(string queue, CronExpression expression)
        {
            InboxWorkQueueUri = queue;
            CronExpression = expression;

            SetNextNotification();
        }
Example #2
0
 internal Schedule(string name, string inboxWOrkQueueUri, CronExpression cronExpression, DateTime nextNotification)
 {
     Name = name;
     InboxWorkQueueUri = inboxWOrkQueueUri;
     CronExpression = cronExpression;
     NextNotification = nextNotification;
 }
        public void SaveSchedule()
        {
            var dataStoreName = view.DataStoreValue;

            if (string.IsNullOrEmpty(dataStoreName))
            {
                Log.Warning(ManagementResources.NoDataStoreSelected);

                return;
            }

            var scheduleName = view.ScheduleNameValue;

            if (string.IsNullOrEmpty(scheduleName))
            {
                Log.Warning(string.Format(ManagementResources.ValueMayNotBeEmpty, SchedulingResources.ScheduleName));

                return;
            }

            var inboxWorkQueueUri = view.EndpointInboxWorkQueueUriValue;

            if (string.IsNullOrEmpty(inboxWorkQueueUri))
            {
                Log.Warning(string.Format(ManagementResources.ValueMayNotBeEmpty, ManagementResources.InboxWorkQueueUri));

                return;
            }

            var cronExpressionValue = view.CronExpressionValue;

            if (string.IsNullOrEmpty(cronExpressionValue))
            {
                Log.Warning(string.Format(ManagementResources.ValueMayNotBeEmpty, SchedulingResources.CronExpression));

                return;
            }

            CronExpression cronExpression;

            try
            {
                cronExpression = new CronExpression(cronExpressionValue);
            }
            catch
            {
                Log.Warning(string.Format(SchedulingResources.InvalidCronExpression, cronExpressionValue));

                return;
            }

            QueueTask("AddSchedule",
                      () =>
                      {
                          var connectionName = DataSourceFactory.Create(dataStoreName);

                          using (databaseConnectionFactory.Create(connectionName))
                          {
                              var nextNotification = cronExpression.NextOccurrence(DateTime.Now);

                              databaseGateway.ExecuteUsing(
                                  connectionName,
                                  databaseGateway.GetScalarUsing<int>(connectionName, ScheduleTableAccess.Contains(scheduleName)) == 1
                                      ? ScheduleTableAccess.Save(scheduleName, inboxWorkQueueUri, cronExpressionValue, nextNotification)
                                      : ScheduleTableAccess.Add(scheduleName, inboxWorkQueueUri, cronExpressionValue, nextNotification));
                          }
                      });

            RefreshSchedules();
        }
 private static Schedule Build(string name, string inboxWorkQueueUri, CronExpression cronExpression, DateTime nextNotification)
 {
     return new Schedule(name, inboxWorkQueueUri, cronExpression, nextNotification);
 }
        public Schedule Build(string name, string inboxWorkQueueUri, string cronExpression)
        {
            var expression = new CronExpression(cronExpression);

            return Build(name, inboxWorkQueueUri, expression, expression.NextOccurrence(DateTime.Now));
        }