public QueryResponse Put(Guid id, [FromBody]HolidayCalendar model)
        {
            Logger.DebugFormat("Entered HolidayCalendarsController.Put(). Calendar id = {0}", id);

            var response = new QueryResponse { Valid = true };

            try
            {
                _schedulerCore.AmendHolidayCalendar(id, model.Description, model.DatesExcluded);
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorEditingHolidayCalendar",
                        Type = "Server",
                        Message = string.Format("Error: {0}", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 2
0
        public QueryResponse Delete(Guid id)
        {
            Logger.DebugFormat("Entered CalendarsController.Delete(). id = {0}", id);

            var response = new QueryResponse { Valid = true };

            try
            {
                response.Valid = _schedulerCore.DeleteCalendar(id);
            }
            catch (Exception ex)
            {
                string type = "Server";
                if (ex is ArgumentException)
                {
                    type = "Sender";
                }

                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorDeletingCalendar",
                        Type = type,
                        Message = string.Format("Error deleting calendar {0}.", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 3
0
        public QueryResponse Execute([FromBody]string jobName, [FromBody]string jobGroup = null)
        {
            Logger.InfoFormat("Entered EmailsController.Execute(). jobName = {0}, jobName = {1}", jobName, jobGroup);

            var response = new QueryResponse { Valid = true };

            try
            {
                _schedulerCore.ExecuteJob(jobName, jobGroup);
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorExecutingJob",
                        Type = "Server",
                        Message = string.Format("Error: {0}", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 4
0
        protected QueryResponse CreateJob(BaseJob model, Type jobType, Dictionary<string, object> dataMap, string description = null)
        {
            var response = new QueryResponse { Valid = true };

            try
            {
                var id = _schedulerCore.CreateJob(model.JobName, model.JobGroup, jobType, dataMap, description, model.Id == Guid.Empty ? (Guid?)null : model.Id);
                response.Id = id;
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorCreatingJob",
                        Type = "Server",
                        Message = string.Format("Error: {0}", ex.Message)
                    }
                };
            }

            return response;
        }
        public QueryResponse Post([FromBody]HolidayCalendar model)
        {
            Logger.DebugFormat("Entered HolidayCalendarsController.Post(). Calendar Name = {0}", model.Name);

            var response = new QueryResponse { Valid = true };

            try
            {
                var id = _schedulerCore.AddHolidayCalendar(model.Name, model.Description, model.DatesExcluded);
                response.Id = id;
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorCreatingHolidayCalendar",
                        Type = "Server",
                        Message = string.Format("Error: {0}", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 6
0
        public QueryResponse Post([FromBody]SimpleTrigger model)
        {
            Logger.InfoFormat("Entered TriggersController.Post(). Name = {0}", model.Name);

            var response = new QueryResponse { Valid = true };

            try
            {
                _schedulerCore.ScheduleTrigger(model);
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorSchedulingTrigger",
                        Type = "Server",
                        Message = string.Format("Error scheduling trigger {0}", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 7
0
        public QueryResponse Post([FromBody]CustomJobCronTrigger model)
        {
            Logger.InfoFormat("Entered EmailsController.Post(). Name = {0}", model.TriggerName);

            var response = new QueryResponse { Valid = true };

           try
            {
                _schedulerCore.ScheduleTrigger(new CronTrigger
                {
                    Name = model.TriggerName,
                    Group = model.TriggerGroup,
                    JobName = model.JobName,
                    JobGroup = model.JobGroup,
                    CronExpression = model.CronExpression,
                    StartDateTime = model.StartDateTime,
                });
            }
            catch (Exception ex)
            {
                string type = "Server";

                if (ex is FormatException)
                {
                    type = "Sender";
                }

                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorSchedulingTrigger",
                        Type = type,
                        Message = string.Format("Error scheduling CronTrigger {0}", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 8
0
        public QueryResponse Post([FromBody]CustomJobSimpleTrigger model)
        {
            Logger.InfoFormat("Entered EmailsController.Post(). Name = {0}", model.TriggerName);

            var response = new QueryResponse { Valid = true };

            try
            {
                _schedulerCore.ScheduleTrigger(new SimpleTrigger
                {
                    Name = model.TriggerName,
                    Group = model.TriggerGroup,
                    JobName = model.JobName,
                    JobGroup = model.JobGroup,
                    RepeatCount = model.RepeatCount,
                    RepeatInterval = model.RepeatInterval,
                    StartDateTime = model.StartDateTime,
                });
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorSchedulingTrigger",
                        Type = "Server",
                        Message = string.Format("Error scheduling trigger {0}", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 9
0
        public QueryResponse Post([FromBody]EmailJob model)
        {
            Logger.InfoFormat("Entered EmailsController.Post(). Job Name = {0}", model.JobName);

            var response = new QueryResponse { Valid = true };

            try
            {
                _schedulerCore.CreateJob(model.JobName, model.JobGroup, typeof(SendMailJob));
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorCreatingJob",
                        Type = "Server",
                        Message = string.Format("Error: {0}", ex.Message)
                    }
                };
            }

            return response;
        }
        private QueryResponse CreateJob(DirectoryScanJob model)
        {
            Uri uriResult;
            bool validUri = Uri.TryCreate(model.CallbackUrl, UriKind.Absolute, out uriResult) &&
                            (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

            if (!validUri)
            {
                var response = new QueryResponse {Valid = false};
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorCreatingJob",
                        Type = "Client",
                        Message = string.Format("Invalid CallbackUrl format: {0}", model.CallbackUrl)
                    }
                };

                return response;
            }

            var dataMap = new Dictionary<string, object>
            {
                {"DIRECTORY_NAME", model.DirectoryName},
                {"CALLBACK_URL", model.CallbackUrl},
                {"MINIMUM_UPDATE_AGE", model.MinimumUpdateAge.ToString(CultureInfo.InvariantCulture)},
                {"LAST_MODIFIED_TIME", model.LastModifiedTime.ToString("o")}
            };

            return base.CreateJob(model, typeof (RDirectoryScanJob), dataMap, model.Description);
        }
Ejemplo n.º 11
0
        public QueryResponse Execute(Guid id)
        {
            Logger.DebugFormat("Entered JobsController.Execute(). id = {0}", id);

            var response = new QueryResponse { Valid = true, Id = id };

            try
            {
                _schedulerCore.ExecuteJob(id);
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorExecutingJob",
                        Type = "Server",
                        Message = string.Format("Error: {0}", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 12
0
        public QueryResponse Delete(Guid id)
        {
            Logger.DebugFormat("Entered JobsController.Delete(). id = {0}", id);

            var response = new QueryResponse { Valid = true, Id = id };

            try
            {
                _schedulerCore.RemoveJob(id);
            }
            catch (Exception ex)
            {
                string type = "Server";
                if (ex is ArgumentException)
                {
                    type = "Sender";
                }

                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorRemovingJob",
                        Type = type,
                        Message = string.Format("Error removing job {0}.", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 13
0
        public QueryResponse Post([FromBody] CronTrigger model)
        {
            Logger.DebugFormat("Entered TriggersController.Post(). Name = {0}", model.Name);

            var response = new QueryResponse { Valid = true };

            try
            {
                var id = _schedulerCore.ScheduleTrigger(model);
                response.Id = id;
            }
            catch (Exception ex)
            {
                string type = "Server";

                if (ex is FormatException)
                {
                    type = "Sender";
                }

                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorSchedulingTrigger",
                        Type = type,
                        Message = string.Format("Error scheduling CronTrigger {0}", ex.Message)
                    }
                };
            }

            return response;
        }
        public QueryResponse RemoveExclusionDate(Guid id, [FromBody]RemoveExclusionDatesRequest model)
        {
            Logger.DebugFormat("Entered HolidayCalendarsController.RemoveExclusionDate(). Calendar id = {0}, ExclusionDate = {1}", id, model);

            var response = new QueryResponse { Valid = true, Id = id, Errors = new List<Error>() };

            // Get saved calendar
            Quartz.Impl.Calendar.HolidayCalendar calendar;
            try
            {
                string calendarName;
                calendar = (Quartz.Impl.Calendar.HolidayCalendar)_schedulerCore.GetCalendar(id, out calendarName);
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error getting HolidayCalendar: {0}", ex.Message), ex);

                response.Valid = false;
                response.Errors.Add(new Error
                {
                    Code = "ErrorGettingCalendar",
                    Type = "Server",
                    Message = string.Format("Error: {0}", ex.Message)
                });

                return response;
            }

            // Remove specified exclusion dates
            var newExclusionDates = new List<DateTime>();

            foreach (var excludedDate in calendar.ExcludedDates)
            {
                if (!model.ExclusionDates.Contains(excludedDate))
                {
                    newExclusionDates.Add(excludedDate);
                }
            }

            // Amend calendar
            try
            {
                _schedulerCore.AmendHolidayCalendar(id, calendar.Description, newExclusionDates);
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorAmendingHolidayCalendar",
                        Type = "Server",
                        Message = string.Format("Error: {0}", ex.Message)
                    }
                };
            }

            return response;
        }
        public QueryResponse PostExclusionDate(Guid id, [FromBody]AddExclusionDatesRequest model)
        {
            Logger.DebugFormat("Entered HolidayCalendarsController.PostExclusionDate(). Calendar id = {0}, ExclusionDate = {1}", id, model);

            var response = new QueryResponse {Valid = true, Id = id};

            try
            {
                _schedulerCore.AddHolidayCalendarExclusionDates(id, model.ExclusionDates);
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorAddingExclusionDates",
                        Type = "Server",
                        Message = string.Format("Error: {0}", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 16
0
        public QueryResponse ToggleTriggerState(Guid id, [FromBody] string state)
        {
            Logger.DebugFormat("Entered TriggersController.ToggleTrigger(). id = {0}, state = {1}", id, state);

            var response = new QueryResponse { Valid = true, Id = id};

            try
            {
                if (null == state || (state.ToLower() != "on" && state.ToLower() != "off"))
                {
                    throw new Exception("Invalid state. Provide state value 'ON' or 'OFF'");
                }

                if (state.ToLower() == "off")
                    _schedulerCore.PauseTrigger(id);
                else
                    _schedulerCore.ResumeTrigger(id);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("Error toggling trigger {0}. {1}", id, ex.Message);

                string type = "Server";
                if (ex is ArgumentException)
                {
                    type = "Sender";
                }

                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorTogglingTrigger",
                        Type = type,
                        Message = string.Format("Error toggling trigger state. ({0})", ex.Message)
                    }
                };
            }

            return response;
        }
Ejemplo n.º 17
0
        public QueryResponse Unschedule(Guid jobId)
        {
            Logger.DebugFormat("Entered TriggersController.Unschedule(). jobId = {0}", jobId);

            var response = new QueryResponse { Valid = true };

            try
            {
                _schedulerCore.RemoveJobTriggers(jobId);
            }
            catch (Exception ex)
            {
                response.Valid = false;
                response.Errors = new List<Error>
                {
                    new Error
                    {
                        Code = "ErrorUnschedulingJob",
                        Type = "Server",
                        Message = string.Format("Error: {0}", ex.Message)
                    }
                };
            }

            return response;
        }