public static void getScheduledRulesGrid(ICswResources CswResources, CswNbtScheduledRulesReturn Return, string AccessId)
        {
            try
            {
                CswNbtResources NbtResources = (CswNbtResources)CswResources;

                //Here we are using the web reference for the schedule service,
                //overwriting the app.config endpoint uri with the one defined in SetupVbls.
                //The CswSchedSvcAdminEndPointClient::getRules() method will return a collection of objects,
                //each of which represents a scheduled rule for the accessid specified as in CswSchedSvcParams.
                //You can find the server side of this connection in /CswCommon/Csw/MtSched/port
                CswSchedSvcAdminEndPointClient SchedSvcRef = new CswSchedSvcAdminEndPointClient();
                EndpointAddress URI = new EndpointAddress(CswResources.SetupVbls["SchedServiceUri"]);
                SchedSvcRef.Endpoint.Address = URI;
                CswSchedSvcParams CswSchedSvcParams = new CswSchedSvcParams();
                CswSchedSvcParams.CustomerId = AccessId;
                CswSchedSvcReturn svcReturn = SchedSvcRef.getRules(CswSchedSvcParams);

                if (null != svcReturn)
                {
                    _addScheduledRulesGrid(NbtResources, svcReturn.Data, Return);
                }
                Return.Data.CustomerId = AccessId;
            }
            catch (Exception ex)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Could not find the Schedule Service.  Check to make sure the service is running and that the endpoint url is configured correctly.", ex.Message, ex);
            }
        }//getScheduledRulesGrid()
        }//getScheduledRulesGrid()

        public static void updateAllScheduledRules(ICswResources CswResources, CswNbtScheduledRulesReturn Return, CswNbtScheduledRulesReturn.Ret Request)
        {
            CswNbtResources   NbtResources             = (CswNbtResources)CswResources;
            CswSchedSvcReturn svcReturn                = new CswSchedSvcReturn();
            CswSchedSvcAdminEndPointClient SchedSvcRef = new CswSchedSvcAdminEndPointClient();
            //Overwrite the app.config endpoint uri with the one defined in SetupVbls
            EndpointAddress URI = new EndpointAddress(CswResources.SetupVbls["SchedServiceUri"]);

            SchedSvcRef.Endpoint.Address = URI;

            CswSchedSvcParams CswSchedSvcParams = new CswSchedSvcParams();

            CswSchedSvcParams.CustomerId   = Request.CustomerId;
            CswSchedSvcParams.LogicDetails = new Collection <CswScheduleLogicDetail>();
            foreach (CswExtJsGridRow GridRow in Request.Grid.rowData.rows)
            {
                if (CswConvert.ToBoolean(GridRow.data[new CswExtJsGridDataIndex("ScheduledRules", CswEnumScheduleLogicDetailColumnNames.HasChanged)]))
                {
                    CswScheduleLogicDetail Rule = _getLogicDetailFromGridRow(GridRow, "ScheduledRules");
                    CswSchedSvcParams.LogicDetails.Add(Rule);
                }
            }

            svcReturn = SchedSvcRef.updateScheduledRules(CswSchedSvcParams);
            if (null != svcReturn)
            {
                _updateScheduledRulesTable(NbtResources, CswSchedSvcParams.LogicDetails);
                _addScheduledRulesGrid(NbtResources, svcReturn.Data, Return);
            }
        }
        public static void getScheduledRuleStatus(ICswResources _CswResources, CswNbtScheduledRuleStatusReturn Return, object Request)
        {
            CswCommaDelimitedString    RuleStatus = new CswCommaDelimitedString();
            CswNbtWebServiceNbtManager ws         = new CswNbtWebServiceNbtManager((CswNbtResources)_CswResources, CswEnumNbtActionName.View_Scheduled_Rules);
            JObject AccessIds = ws.getActiveAccessIds();

            foreach (String AccessId in AccessIds["customerids"])
            {
                CswNbtScheduledRulesReturn Rules = new CswNbtScheduledRulesReturn();
                getScheduledRulesGrid(_CswResources, Rules, AccessId);
                foreach (CswExtJsGridRow GridRow in Rules.Data.Grid.rowData.rows)
                {
                    CswScheduleLogicDetail Rule = _getLogicDetailFromGridRow(GridRow, "ScheduledRules");
                    if (false == Rule.Disabled)
                    {
                        if (Rule.Reprobate)
                        {
                            DateTime TimeOfReprobate = Rule.LastRun > Rule.LastLoadCheck ? Rule.LastRun : Rule.LastLoadCheck;
                            RuleStatus.Add("REPROBATE on " + AccessId + ": " + Rule.RuleName + " as of " + TimeOfReprobate);
                        }
                        else
                        {
                            TimeSpan LastCheckInterval = DateTime.Now - Rule.LastLoadCheck;
                            TimeSpan RunTimeInterval   = Rule.getRunTimeInterval();
                            RunTimeInterval = RunTimeInterval.Add(new TimeSpan(1, 0, 0));    //1 hour buffer
                            if (LastCheckInterval > RunTimeInterval)
                            {
                                RuleStatus.Add("ERROR on " + AccessId + ": " + Rule.RuleName + " last checked load on " + Rule.LastLoadCheck);
                            }
                        }
                    }
                }
            }
            if (RuleStatus.Count == 0)
            {
                RuleStatus.Add("ALL SCHEDULED SERVICE RULES OK");
            }
            Return.Data.RuleStatus = RuleStatus.ToString();
        }
        private static void _addScheduledRulesGrid(CswNbtResources NbtResources, Collection <CswScheduleLogicDetail> LogicDetails, CswNbtScheduledRulesReturn Ret)
        {
            if (null != LogicDetails && LogicDetails.Count > 0 &&
                null != Ret &&
                null != Ret.Data)
            {
                DataTable GridTable = new DataTable("scheduledrulestable");
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.RuleName, typeof(string));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.Recurrance, typeof(string));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.Interval, typeof(Int32));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.ReprobateThreshold, typeof(Int32));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.MaxRunTimeMs, typeof(Int32));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.Reprobate, typeof(bool));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.RunStartTime, typeof(DateTime));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.RunEndTime, typeof(DateTime));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.TotalRogueCount, typeof(Int32));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.FailedCount, typeof(Int32));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.ThreadId, typeof(Int32));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.StatusMessage, typeof(string));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.Disabled, typeof(bool));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.HasChanged, typeof(bool));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.Priority, typeof(Int32));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.LoadCount, typeof(Int32));
                GridTable.Columns.Add(CswEnumScheduleLogicDetailColumnNames.LastLoadCheck, typeof(DateTime));

                foreach (CswScheduleLogicDetail LogicDetail in LogicDetails)
                {
                    if (null != LogicDetail)
                    {
                        DataRow Row = GridTable.NewRow();
                        Row[CswEnumScheduleLogicDetailColumnNames.RuleName]           = LogicDetail.RuleName;
                        Row[CswEnumScheduleLogicDetailColumnNames.Recurrance]         = LogicDetail.Recurrence;
                        Row[CswEnumScheduleLogicDetailColumnNames.Interval]           = LogicDetail.Interval;
                        Row[CswEnumScheduleLogicDetailColumnNames.ReprobateThreshold] = LogicDetail.ReprobateThreshold;
                        Row[CswEnumScheduleLogicDetailColumnNames.MaxRunTimeMs]       = LogicDetail.MaxRunTimeMs;
                        Row[CswEnumScheduleLogicDetailColumnNames.Reprobate]          = LogicDetail.Reprobate;
                        Row[CswEnumScheduleLogicDetailColumnNames.RunStartTime]       = LogicDetail.RunStartTime;
                        Row[CswEnumScheduleLogicDetailColumnNames.RunEndTime]         = LogicDetail.RunEndTime;
                        Row[CswEnumScheduleLogicDetailColumnNames.TotalRogueCount]    = LogicDetail.TotalRogueCount;
                        Row[CswEnumScheduleLogicDetailColumnNames.FailedCount]        = LogicDetail.FailedCount;
                        Row[CswEnumScheduleLogicDetailColumnNames.ThreadId]           = LogicDetail.ThreadId;
                        Row[CswEnumScheduleLogicDetailColumnNames.StatusMessage]      = LogicDetail.StatusMessage;
                        Row[CswEnumScheduleLogicDetailColumnNames.Priority]           = LogicDetail.Priority;
                        Row[CswEnumScheduleLogicDetailColumnNames.LoadCount]          = LogicDetail.LoadCount;
                        Row[CswEnumScheduleLogicDetailColumnNames.LastLoadCheck]      = LogicDetail.LastLoadCheck;
                        Row[CswEnumScheduleLogicDetailColumnNames.Disabled]           = LogicDetail.Disabled;
                        Row[CswEnumScheduleLogicDetailColumnNames.HasChanged]         = false;

                        GridTable.Rows.Add(Row);
                    }
                }
                CswNbtGrid gd = new CswNbtGrid(NbtResources);
                Ret.Data.Grid = gd.DataTableToGrid(GridTable);
            }
        }