예제 #1
0
        public override void ModifySchedule(Schedule Schedule)
        {
            ConfStorageLoad();
            EventServerLoad();

            ServiceCapabilities capabilities = Simulator.SystemCapabilities.Instance.ScheduleCapabilities;

            ICalendar standardICalendar        = new ICalendar(Schedule.Standard);
            var       standardICalendarVEvents = standardICalendar.GetVEvents();

            if (standardICalendarVEvents != null && standardICalendarVEvents.Count > capabilities.MaxTimePeriodsPerDay)
            {
                string message = string.Format("There are too many TimePeriods in a day schedule, see MaxTimePeriodsPerDay capability.");
                LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                FaultLib.ReturnFault(message, new string[] { "Sender", "CapabilityViolated", "MaxTimePeriodsPerDay" });
            }

            //Check that schedule exists
            if (!ConfStorage.ScheduleList.ContainsKey(Schedule.token))
            {
                string message = string.Format("Schedule with specified token {0} does not exists.", Schedule.token);
                LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                FaultLib.ReturnFault(message, new string[] { "Sender", "InvalidArgVal", "NotFound" });
            }

            if (Schedule.SpecialDays != null)
            {
                if (Schedule.SpecialDays.Count() >= capabilities.MaxSpecialDaysSchedules)
                {
                    string message = string.Format("There are too many SpecialDaysSchedule entities referred in this schedule, see MaxSpecialDays-Schedules capability.");
                    LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                    FaultLib.ReturnFault(message, new string[] { "Sender", "CapabilityViolated", "MaxSpecialDaysSchedules" });
                }

                foreach (var specialDays in Schedule.SpecialDays)
                {
                    if (specialDays.TimeRange.Count() >= capabilities.MaxTimePeriodsPerDay)
                    {
                        string message = string.Format("There are too many TimePeriods in a day schedule, see MaxTimePeriodsPerDay capability.");
                        LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                        FaultLib.ReturnFault(message, new string[] { "Sender", "CapabilityViolated", "MaxTimePeriodsPerDay" });
                    }
                    if (specialDays.TimeRange != null)
                    {
                        foreach (var timeRange in specialDays.TimeRange)
                        {
                            if (timeRange.Until < timeRange.From)
                            {
                                string message = string.Format("Schedule SpecialDayGroupToken.TimeRange.Until value is less that From value.");
                                LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                                FaultLib.ReturnFault(message, new string[] { "Sender", "InvalidArgVal", "ReferenceNotFound" });
                            }
                        }
                    }
                }

                //Check that all Schedules special days exists
                if (Schedule.SpecialDays.Any(C => !(ConfStorage.SpecialDayGroupList.Keys.Contains(C.GroupToken))))
                {
                    string message = string.Format("Schedule special day group token does not exist.");
                    LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                    FaultLib.ReturnFault(message, new string[] { "Sender", "InvalidArgVal" });
                }
            }

            ConfStorage.ScheduleList.Remove(Schedule.token);
            ConfStorage.ScheduleList.Add(Schedule.token, Schedule);

            EventServer.ConfigurationScheduleChangedEvent(this, Schedule.token);

            EventServerSave();
            ConfStorageSave();
        }
예제 #2
0
        public override string CreateSchedule(Schedule Schedule)
        {
            ConfStorageLoad();

            EventServerLoad();

            if (Schedule.token == "")
            {
                int i = 1;

                Schedule.token = "schedule" + i.ToString();

                while (ConfStorage.ScheduleList.Keys.Contains(Schedule.token))
                {
                    Schedule.token = "schedule" + i.ToString();
                    i++;
                }
            }
            else
            {
                string message = string.Format("Not empty token.");
                LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                FaultLib.ReturnFault(message, new string[] { "Sender", "InvalidArgs" });
            }

            ServiceCapabilities capabilities = Simulator.SystemCapabilities.Instance.ScheduleCapabilities;
            string res = Schedule.token;

            ICalendar standardICalendar        = new ICalendar(Schedule.Standard);
            var       standardICalendarVEvents = standardICalendar.GetVEvents();

            if (standardICalendarVEvents != null && standardICalendarVEvents.Count > capabilities.MaxTimePeriodsPerDay)
            {
                string message = string.Format("There are too many TimePeriods in a day schedule, see MaxTimePeriodsPerDay capability.");
                LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                FaultLib.ReturnFault(message, new string[] { "Sender", "CapabilityViolated", "MaxTimePeriodsPerDay" });
            }

            //Check that there is no schedule with the same token exists
            if (ConfStorage.ScheduleList.ContainsKey(Schedule.token))
            {
                string message = string.Format("Schedule with token {0} aleady exist.", Schedule.token);
                LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                FaultLib.ReturnFault(message, new string[] { "Sender", "InvalidArgVal" });
            }


            //Check MaxSchedules capability
            if (ConfStorage.ScheduleList.Count() >= capabilities.MaxSchedules)
            {
                string message = string.Format("There is not enough space to create new schedule, see the MaxSchedules capability.");
                LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                FaultLib.ReturnFault(message, new string[] { "Receiver", "CapabilityViolated", "MaxSchedules" });
            }


            if (Schedule.SpecialDays != null)
            {
                if (Schedule.SpecialDays.Count() >= capabilities.MaxSpecialDaysSchedules)
                {
                    string message = string.Format("There are too many SpecialDaysSchedule entities referred in this schedule, see MaxSpecialDays-Schedules capability.");
                    LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                    FaultLib.ReturnFault(message, new string[] { "Sender", "CapabilityViolated", "MaxSpecialDaysSchedules" });
                }

                foreach (var specialDays in Schedule.SpecialDays)
                {
                    if (specialDays.TimeRange.Count() > capabilities.MaxTimePeriodsPerDay)
                    {
                        string message = string.Format("There are too many TimePeriods in a day schedule, see MaxTimePeriodsPerDay capability.");
                        LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                        FaultLib.ReturnFault(message, new string[] { "Sender", "CapabilityViolated", "MaxTimePeriodsPerDay" });
                    }
                    if (specialDays.TimeRange != null)
                    {
                        foreach (var timeRange in specialDays.TimeRange)
                        {
                            if (timeRange.Until < timeRange.From)
                            {
                                string message = string.Format("Schedule SpecialDayGroupToken.TimeRange.Until value is less that From value.");
                                LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                                FaultLib.ReturnFault(message, new string[] { "Sender", "InvalidArgVal", "ReferenceNotFound" });
                            }
                        }
                    }
                }

                //Check that all Schedules exists
                if (Schedule.SpecialDays.Any(C => !(ConfStorage.SpecialDayGroupList.Keys.Contains(C.GroupToken))))
                {
                    string message = string.Format("Schedule special day group token does not exist.");
                    LoggingService.LogMessage(message, DUT.PACS.Simulator.ExternalLogging.MessageType.Error);
                    FaultLib.ReturnFault(message, new string[] { "Sender", "InvalidArgVal" });
                }
            }

            ConfStorage.ScheduleList.Add(Schedule.token, Schedule);
            ScheduleState scheduleState = new ScheduleState();

            DateTime dateStart = standardICalendarVEvents.First().DateStart;
            DateTime dateEnd   = standardICalendarVEvents.First().DateEnd;

            if (dateStart.ToFileTime() < DateTime.Now.ToFileTime() && dateEnd.ToFileTime() > DateTime.Now.ToFileTime())
            {
                scheduleState.Active = true;
            }
            else
            {
                scheduleState.Active = false;
            }

            scheduleState.SpecialDaySpecified = capabilities.SpecialDaysSupported;
            scheduleState.SpecialDay          = IsSpecialDay(Schedule);

            ConfStorage.ScheduleStateList.Add(Schedule.token, scheduleState);

            EventServer.ConfigurationScheduleChangedEvent(this, Schedule.token);
            EventServer.ScheduleStateActiveEvent(this, "Initialized", Schedule.token, Schedule.Name, scheduleState.Active, scheduleState.SpecialDay);



            if (dateStart.ToFileTime() > DateTime.Now.ToFileTime() && standardICalendarVEvents.First().Rrule.Contains("DAILY"))
            {
                ScheduleTask(dateStart, dateEnd, Schedule, capabilities);
            }
            else if (dateEnd.ToFileTime() > DateTime.Now.ToFileTime())
            {
                ScheduleTask(DateTime.Now, dateEnd, Schedule, capabilities);
            }

            var specialDayGroupToken = string.Empty;

            if (Schedule.SpecialDays != null)
            {
                specialDayGroupToken = Schedule.SpecialDays.First().GroupToken;
            }

            if (!string.IsNullOrEmpty(specialDayGroupToken))
            {
                if (ConfStorage.SpecialDayGroupList.ContainsKey(specialDayGroupToken))
                {
                    var specialDayGroup = ConfStorage.SpecialDayGroupList[specialDayGroupToken];

                    ICalendar specialDayGroupICalendar        = new ICalendar(specialDayGroup.Days);
                    var       specialDayGroupICalendarVEvents = specialDayGroupICalendar.GetVEvents();

                    DateTime dateSpecialDayStart = specialDayGroupICalendarVEvents.First().DateStart;
                    DateTime dateSpecialDayEnd   = specialDayGroupICalendarVEvents.First().DateEnd;

                    if (string.IsNullOrEmpty(specialDayGroupICalendarVEvents.First().Rrule) || specialDayGroupICalendarVEvents.First().Rrule.Contains("DAILY"))
                    {
                        if (dateSpecialDayStart.ToFileTime() > DateTime.Now.ToFileTime())
                        {
                            ScheduleTask(dateSpecialDayStart, dateSpecialDayEnd, Schedule, capabilities);
                        }
                        else if (dateSpecialDayEnd.ToFileTime() > DateTime.Now.ToFileTime())
                        {
                            ScheduleTask(DateTime.Now, dateSpecialDayEnd, Schedule, capabilities);
                        }
                    }
                }
            }

            EventServerSave();
            ConfStorageSave();

            return(res);
        }