Пример #1
0
        /// <summary>
        /// Check whether or not the schedule is Ad-Hoc, and return true if it is.
        /// </summary>
        ///
        /// <param name="ScheduleName"> A ScheduleName provided by an external function</param>
        /// <param name="Settings">An IConfiguration provided by an external function</param>
        ///
        /// <returns>
        /// bool
        /// </returns>
        public bool CheckScheduleAdHocStatus(string ScheduleName, IConfiguration Settings)
        {
            SchedulesReader reader        = new SchedulesReader();
            JObject         RootJson      = reader.ReadSchedulesFile(Settings);
            JObject         SchedulesJson = RootJson["Schedules"].ToObject <JObject>();
            JToken          Schedule      = SchedulesJson.GetValue(ScheduleName, StringComparison.CurrentCultureIgnoreCase);
            bool            AdHoc         = new bool();

            try
            {
                AdHoc = bool.Parse(Schedule["ScheduleAdHoc"].ToString());
            }
            catch (NullReferenceException)
            {
                throw new Exceptions.InvalidParameterException("The schedule {0} does not exist for the given client", ScheduleName);
            }

            if (AdHoc)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Check that the Frequency provided is valid, and return a string.
        /// </summary>
        ///
        /// <param name="ScheduleName"> A schedule name provided by an external function</param>
        ///
        /// <returns>
        /// int (-1,2)
        /// </returns>
        public int CheckFrequency(string ScheduleName, IConfiguration Settings)
        {
            SchedulesReader Reader        = new SchedulesReader();
            JObject         SchedulesList = Reader.ReadSchedulesFile(Settings);
            string          Frequency     = "";

            try
            {
                JToken ScheduleToken = SchedulesList.SelectToken("Schedules." + ScheduleName);
                Frequency = ScheduleToken.Value <string>("ScheduleFrequency");
            }
            catch (Newtonsoft.Json.JsonException)
            {
                throw new Exceptions.InvalidIOConfiguration("The schedule {0} could not be found.", ScheduleName);
            }

            if (Frequency == "Weekly")
            {
                return(0);
            }
            else if (Frequency == "Monthly")
            {
                return(1);
            }
            else if (Frequency == "Annually")
            {
                return(2);
            }
            else
            {
                return(-1);
            }
        }
Пример #3
0
        /// <summary>
        /// Read a file containing available schedule names and return an error if the given schedule could not be found
        /// </summary>
        ///
        ///
        /// <param name="ScheduleName">A schedule name provided by an external function</param>
        /// <param name="Settings">Settings configuration used for making a call to EazyCustomerManager</param>
        ///
        /// <example>
        /// CheckScheduleNameIsAvailable("TestSchedule")
        /// </example>
        ///
        /// <returns>
        /// bool
        /// </returns>
        public bool CheckScheduleNameIsAvailable(string ScheduleName, IConfiguration Settings)
        {
            SchedulesReader reader            = new SchedulesReader();
            JObject         RootJson          = reader.ReadSchedulesFile(Settings);
            JObject         SchedulesJson     = RootJson["Schedules"].ToObject <JObject>();
            List <string>   ScheduleNamesList = new List <string>();

            foreach (JProperty property in SchedulesJson.Properties())
            {
                ScheduleNamesList.Add(property.Name.ToLower());
            }

            if (ScheduleNamesList.Contains(ScheduleName, StringComparer.OrdinalIgnoreCase))
            {
                return(true);
            }
            else
            {
                throw new Exceptions.InvalidParameterException(string.Format("{0} is not a valid schedule name. The available schedule names are: {1}", ScheduleName, string.Join(", ", ScheduleNamesList)));
            }
        }