/*=========================*/
        #endregion

        #region Date Methods
        /*=========================*/

        // TODO: maybe move some of the day code Methods to core\Utilities\DayCode
        protected bool CheckRangeDate(ref ArrayList dates)
        {
            if ((Instance.ParentInstance != null) &&
                (Instance.ParentInstance.ActiveSchedulingRule != null) &&
                (!String.IsNullOrEmpty(Instance.ParentInstance.ActiveSchedulingRule.FromDate)) &&
                (!String.IsNullOrEmpty(Instance.ParentInstance.ActiveSchedulingRule.ToDate)))
            {
                string excatUnits = Instance.ParentInstance.ActiveSchedulingRule.ExcatUnits != null ? Instance.ParentInstance.ActiveSchedulingRule.ExcatUnits : string.Empty;
                dates = ScheduleConvertor.GetRangeDate(Instance.ParentInstance.ActiveSchedulingRule.FromDate.ToString(), Instance.ParentInstance.ActiveSchedulingRule.ToDate.ToString(), excatUnits);
                return(true);
            }
            else if ((Instance.ParentInstance.ParentInstance != null) &&
                     (Instance.ParentInstance.ParentInstance.ActiveSchedulingRule != null) &&
                     (!String.IsNullOrEmpty(Instance.ParentInstance.ParentInstance.ActiveSchedulingRule.FromDate)) &&
                     (!String.IsNullOrEmpty(Instance.ParentInstance.ParentInstance.ActiveSchedulingRule.ToDate)))
            {
                string excatUnits = Instance.ParentInstance.ParentInstance.ActiveSchedulingRule.ExcatUnits != null ? Instance.ParentInstance.ParentInstance.ActiveSchedulingRule.ExcatUnits : string.Empty;
                dates = ScheduleConvertor.GetRangeDate(Instance.ParentInstance.ParentInstance.ActiveSchedulingRule.FromDate.ToString(), Instance.ParentInstance.ParentInstance.ActiveSchedulingRule.ToDate.ToString(), excatUnits);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public ScheduleObjectCollection GetAll()
        {
            ScheduleObjectCollection parameters = new ScheduleObjectCollection();
            QueryBuilder             builder;

            try
            {
                builder = new QueryBuilder();
                builder.Append(this.BaseQuery(false, 0));
                parameters = ScheduleConvertor.DataTableToCollection(this.ExecuteDataSet(builder.Query, false).Tables[0]);
            }
            catch (System.Exception exception1)
            {
                throw new Exception(MethodBase.GetCurrentMethod().Name, exception1);
            }
            return(parameters);
        }
Beispiel #3
0
        public static TaskScheduleObject TaskScheduleRowToObject(DataRow taskSchedule)
        {
            TaskScheduleObject obj = new TaskScheduleObject();

            try
            {
                if (taskSchedule != null)
                {
                    obj.TschedID = RowFunctions.GetValueFromRowToGuid(taskSchedule, TaskScheduleObject.TSCHED_ID, true, DataRowVersion.Current);
                    obj.Schedule = ScheduleConvertor.ScheduleRowToObject(taskSchedule);
                    obj.Task     = TaskConvertor.TaskRowToObject(taskSchedule);
                    return(obj);
                }
                obj = null;
            }
            catch (System.Exception exception1)
            {
                Exception innerException = exception1;
                throw new Exception(MethodBase.GetCurrentMethod().Name, innerException);
            }
            return(obj);
        }
        /// <summary>
        /// Create a service According to the service rule.
        /// </summary>
        /// <param name="accountServiceElement"></param>
        /// <param name="accountID"></param>
        /// <param name="childService"></param>
        /// <param name="rule"></parammmmm>
        private void HandleRule(AccountServiceElement accountServiceElement, int accountID, ServiceInstance childService, SchedulingRuleElement rule)
        {
            switch (rule.CalendarUnit)
            {
            case CalendarUnit.ReRun:
                if (ScheduleConvertor.CheckFullSchedule(rule.FullSchedule))
                {
                    AddServiceRule(accountServiceElement, rule, childService, accountID);
                }

                break;

            // Month
            case CalendarUnit.Month:
                // Loop on all the days values in the rule.
                foreach (int day in rule.SubUnits)
                {
                    if (day == DateTime.Now.Day)
                    {
                        AddServiceRule(accountServiceElement, rule, childService, accountID);
                    }
                }
                break;

            // Week
            case CalendarUnit.Week:
                // Loop on all the days values in the rule.
                foreach (int day in rule.SubUnits)
                {
                    // DayOfWeek return values of 0-6 and because of it we -1 on left side.
                    if (day == (int)DateTime.Now.DayOfWeek + 1)
                    {
                        AddServiceRule(accountServiceElement, rule, childService, accountID);
                    }
                }
                break;

            // Day
            case CalendarUnit.Day:
                AddServiceRule(accountServiceElement, rule, childService, accountID);
                break;

            // AlwaysOn
            case CalendarUnit.AlwaysOn:

                ServiceInstance service;
                if (childService == null && _firstRun)
                {
                    try
                    {
                        service = CreateNewService(accountServiceElement, DateTime.Now, rule, accountID);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(string.Format("Can't add the always on service {0} for accoutID {1}", accountServiceElement.ToString(), accountID.ToString()), ex, LogMessageType.Error);
                        return;
                    }
                }
                else
                {
                    service = childService;
                }

                // Add the service to the scheduleTable.
                if (service != null)
                {
                    _scheduleTable.AddService(service);
                }
                break;

            // Never should be here
            default:
                Log.Write(String.Format("The service {0}  don't have calendar unit, can't schedule the service."
                                        , accountServiceElement != null ? accountServiceElement.Uses.Element.Name : childService.Configuration.Name), LogMessageType.Warning);
                break;
            }
        }