public int AddScheduler(byte weekDays, TimeSpan time, string name, int idHomeDeviceDestination, string operation, object[] args = null)
        {
            UnitOfWork repository = UnitOfWork.GetInstance();

            HomeDevice homeDevice = repository.HomeDeviceRespository.GetById(idHomeDeviceDestination);

            if (homeDevice == null)
                throw new ArgumentException("HomeDevice id doesn't exist");

            Operation operationInternal = new Operation
            {
                Args = args,
                Name = name,
                OperationName = operation,
                DestionationHomeDevice = homeDevice
            };

            TimeOperation timeOperation = new TimeOperation
            {
                MaskWeekDays = weekDays,
                Time = time,
                Operation = operationInternal
            };
            int idRes = repository.TimeOperationRepository.Insert(timeOperation).Id;

            if (homeDevice.InUse)
            {
                //UPDATE CHECKSUM
                homeDevice.Connector.Node.UpdateChecksum(null);
            }

            repository.Commit();

            return idRes;
        }
 public TimeOperationNode(string content)
 {
     ParentNode         = null;
     Operation          = null;
     Content            = content;
     Operation          = new TimeOperation();
     TimeOperation.Name = content;
 }
示例#3
0
 /// <summary>
 /// 将cron时间表达式初步解析
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 public static ShowCronTimeModel GetCronTimeModel(string expression)
 {
     try
     {
         return(TimeOperation.ExplainScheduleCron(expression));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#4
0
        public void RemoveTimeOperation(int idTimeOperation)
        {
            UnitOfWork repository = UnitOfWork.GetInstance();

            TimeOperation timeOperation = repository.TimeOperationRepository.GetById(idTimeOperation);

            if (timeOperation == null)
            {
                throw new ArgumentException("TimeOperation id doesn't exist");
            }

            if (timeOperation.Operation.DestionationHomeDevice.InUse)
            {
                //UPDATE CHECKSUM
                timeOperation.Operation.DestionationHomeDevice.Connector.Node.UpdateChecksum(null);
            }

            repository.TimeOperationRepository.Delete(timeOperation);
            repository.Commit();
        }
示例#5
0
        /// <summary>
        /// 验证当前调整课程-佟良远
        /// </summary>
        /// <param name="localID">本地方案ID</param>
        /// <param name="classID">班级ID</param>
        /// <param name="item">调整的项</param>
        /// <returns></returns>
        public static Tuple <List <DayPeriodModel>, List <PostionWithWarningInfo> > CheckCanAdjustPosition(string localID, string classID, List <ResultDetailModel> item, ResultModel resultModel)
        {
            var positions = GetMovablePositons(localID, classID, item, resultModel);
            //单向检查结果
            List <DayPeriodModel> oneWayPositions = positions.Item1;
            //双向校验
            List <DayPeriodModel> twoWayPositions = new List <DayPeriodModel>();

            oneWayPositions?.ForEach(x =>
            {
                List <ResultDetailModel> targetItem = resultModel.ResultClasses.Where(rc => rc.ClassID == classID)?
                                                      .SelectMany(rc => rc.ResultDetails)?.ToList()?
                                                      .Where(rd => rd.DayPeriod.Day == x.Day && rd.DayPeriod.PeriodName == x.PeriodName)?.ToList();

                if ((targetItem?.Count() ?? 0) == 0)
                {
                    twoWayPositions.Add(x);
                }
                else
                {
                    Tuple <bool, string> checkresult = CanReplacePosition(localID, classID, item, targetItem, resultModel);
                    if (checkresult.Item1)
                    {
                        twoWayPositions.Add(x);
                    }
                }
            });

            #region 在返回结果中增加当前课位
            DayPeriodModel currentPosition = item?.FirstOrDefault()?.DayPeriod;
            if (currentPosition != null)
            {
                twoWayPositions = TimeOperation.TimeSlotUnion(twoWayPositions, new List <DayPeriodModel>()
                {
                    currentPosition
                });
            }
            #endregion

            return(Tuple.Create(twoWayPositions, positions.Item2));
        }
示例#6
0
        public int AddScheduler(byte weekDays, TimeSpan time, string name, int idHomeDeviceDestination, string operation, object[] args = null)
        {
            UnitOfWork repository = UnitOfWork.GetInstance();

            HomeDevice homeDevice = repository.HomeDeviceRespository.GetById(idHomeDeviceDestination);

            if (homeDevice == null)
            {
                throw new ArgumentException("HomeDevice id doesn't exist");
            }

            Operation operationInternal = new Operation
            {
                Args                   = args,
                Name                   = name,
                OperationName          = operation,
                DestionationHomeDevice = homeDevice
            };

            TimeOperation timeOperation = new TimeOperation
            {
                MaskWeekDays = weekDays,
                Time         = time,
                Operation    = operationInternal
            };
            int idRes = repository.TimeOperationRepository.Insert(timeOperation).Id;

            if (homeDevice.InUse)
            {
                //UPDATE CHECKSUM
                homeDevice.Connector.Node.UpdateChecksum(null);
            }

            repository.Commit();

            return(idRes);
        }
示例#7
0
        public void Retry()
        {
            if (savedEndpointOperation != null)
            {
                switch (Operation)
                {
                case PNOperationType.PNAccessManagerAudit:
                    if (savedEndpointOperation is AuditOperation)
                    {
                        AuditOperation endpoint = savedEndpointOperation as AuditOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNAccessManagerGrant:
                    if (savedEndpointOperation is GrantOperation)
                    {
                        GrantOperation endpoint = savedEndpointOperation as GrantOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNAddChannelsToGroupOperation:
                    if (savedEndpointOperation is AddChannelsToChannelGroupOperation)
                    {
                        AddChannelsToChannelGroupOperation endpoint = savedEndpointOperation as AddChannelsToChannelGroupOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNRemoveGroupOperation:
                    if (savedEndpointOperation is DeleteChannelGroupOperation)
                    {
                        DeleteChannelGroupOperation endpoint = savedEndpointOperation as DeleteChannelGroupOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.ChannelGroupAllGet:
                    if (savedEndpointOperation is ListAllChannelGroupOperation)
                    {
                        ListAllChannelGroupOperation endpoint = savedEndpointOperation as ListAllChannelGroupOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.ChannelGroupGet:
                    if (savedEndpointOperation is ListChannelsForChannelGroupOperation)
                    {
                        ListChannelsForChannelGroupOperation endpoint = savedEndpointOperation as ListChannelsForChannelGroupOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNRemoveChannelsFromGroupOperation:
                    if (savedEndpointOperation is RemoveChannelsFromChannelGroupOperation)
                    {
                        RemoveChannelsFromChannelGroupOperation endpoint = savedEndpointOperation as RemoveChannelsFromChannelGroupOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNGetStateOperation:
                    if (savedEndpointOperation is GetStateOperation)
                    {
                        GetStateOperation endpoint = savedEndpointOperation as GetStateOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNHereNowOperation:
                    if (savedEndpointOperation is HereNowOperation)
                    {
                        HereNowOperation endpoint = savedEndpointOperation as HereNowOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNSetStateOperation:
                    if (savedEndpointOperation is SetStateOperation)
                    {
                        SetStateOperation endpoint = savedEndpointOperation as SetStateOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNWhereNowOperation:
                    if (savedEndpointOperation is WhereNowOperation)
                    {
                        WhereNowOperation endpoint = savedEndpointOperation as WhereNowOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNFireOperation:
                    if (savedEndpointOperation is FireOperation)
                    {
                        FireOperation endpoint = savedEndpointOperation as FireOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNPublishOperation:
                    if (savedEndpointOperation is PublishOperation)
                    {
                        PublishOperation endpoint = savedEndpointOperation as PublishOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PushRegister:
                    if (savedEndpointOperation is AddPushChannelOperation)
                    {
                        AddPushChannelOperation endpoint = savedEndpointOperation as AddPushChannelOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PushGet:
                    if (savedEndpointOperation is AuditPushChannelOperation)
                    {
                        AuditPushChannelOperation endpoint = savedEndpointOperation as AuditPushChannelOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PushUnregister:
                    if (savedEndpointOperation is RemovePushChannelOperation)
                    {
                        RemovePushChannelOperation endpoint = savedEndpointOperation as RemovePushChannelOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNHistoryOperation:
                    if (savedEndpointOperation is HistoryOperation)
                    {
                        HistoryOperation endpoint = savedEndpointOperation as HistoryOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNFetchHistoryOperation:
                    if (savedEndpointOperation is FetchHistoryOperation)
                    {
                        FetchHistoryOperation endpoint = savedEndpointOperation as FetchHistoryOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNMessageCountsOperation:
                    if (savedEndpointOperation is MessageCountsOperation)
                    {
                        MessageCountsOperation endpoint = savedEndpointOperation as MessageCountsOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNTimeOperation:
                    if (savedEndpointOperation is TimeOperation)
                    {
                        TimeOperation endpoint = savedEndpointOperation as TimeOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNSetUuidMetadataOperation:
                    if (savedEndpointOperation is SetUuidMetadataOperation)
                    {
                        SetUuidMetadataOperation endpoint = savedEndpointOperation as SetUuidMetadataOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNSetChannelMetadataOperation:
                    if (savedEndpointOperation is SetChannelMetadataOperation)
                    {
                        SetChannelMetadataOperation endpoint = savedEndpointOperation as SetChannelMetadataOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNDeleteUuidMetadataOperation:
                    if (savedEndpointOperation is RemoveUuidMetadataOperation)
                    {
                        RemoveUuidMetadataOperation endpoint = savedEndpointOperation as RemoveUuidMetadataOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNDeleteChannelMetadataOperation:
                    if (savedEndpointOperation is RemoveChannelMetadataOperation)
                    {
                        RemoveChannelMetadataOperation endpoint = savedEndpointOperation as RemoveChannelMetadataOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNGetUuidMetadataOperation:
                    if (savedEndpointOperation is GetUuidMetadataOperation)
                    {
                        GetUuidMetadataOperation endpoint = savedEndpointOperation as GetUuidMetadataOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNGetChannelMetadataOperation:
                    if (savedEndpointOperation is GetChannelMetadataOperation)
                    {
                        GetChannelMetadataOperation endpoint = savedEndpointOperation as GetChannelMetadataOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNGetAllUuidMetadataOperation:
                    if (savedEndpointOperation is GetAllUuidMetadataOperation)
                    {
                        GetAllUuidMetadataOperation endpoint = savedEndpointOperation as GetAllUuidMetadataOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNGetAllChannelMetadataOperation:
                    if (savedEndpointOperation is GetAllChannelMetadataOperation)
                    {
                        GetAllChannelMetadataOperation endpoint = savedEndpointOperation as GetAllChannelMetadataOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNManageMembershipsOperation:
                    if (savedEndpointOperation is ManageMembershipsOperation)
                    {
                        ManageMembershipsOperation endpoint = savedEndpointOperation as ManageMembershipsOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNSetMembershipsOperation:
                    if (savedEndpointOperation is SetMembershipsOperation)
                    {
                        SetMembershipsOperation endpoint = savedEndpointOperation as SetMembershipsOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNRemoveMembershipsOperation:
                    if (savedEndpointOperation is RemoveMembershipsOperation)
                    {
                        RemoveMembershipsOperation endpoint = savedEndpointOperation as RemoveMembershipsOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNManageChannelMembersOperation:
                    if (savedEndpointOperation is ManageChannelMembersOperation)
                    {
                        ManageChannelMembersOperation endpoint = savedEndpointOperation as ManageChannelMembersOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNSetChannelMembersOperation:
                    if (savedEndpointOperation is SetChannelMembersOperation)
                    {
                        SetChannelMembersOperation endpoint = savedEndpointOperation as SetChannelMembersOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNRemoveChannelMembersOperation:
                    if (savedEndpointOperation is RemoveChannelMembersOperation)
                    {
                        RemoveChannelMembersOperation endpoint = savedEndpointOperation as RemoveChannelMembersOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNGetMembershipsOperation:
                    if (savedEndpointOperation is GetMembershipsOperation)
                    {
                        GetMembershipsOperation endpoint = savedEndpointOperation as GetMembershipsOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNGetChannelMembersOperation:
                    if (savedEndpointOperation is GetChannelMembersOperation)
                    {
                        GetChannelMembersOperation endpoint = savedEndpointOperation as GetChannelMembersOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNAddMessageActionOperation:
                    if (savedEndpointOperation is AddMessageActionOperation)
                    {
                        AddMessageActionOperation endpoint = savedEndpointOperation as AddMessageActionOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                case PNOperationType.PNRemoveMessageActionOperation:
                    if (savedEndpointOperation is RemoveMessageActionOperation)
                    {
                        RemoveMessageActionOperation endpoint = savedEndpointOperation as RemoveMessageActionOperation;
                        if (endpoint != null)
                        {
                            endpoint.Retry();
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
示例#8
0
        private static Tuple <List <DayPeriodModel>, List <PostionWithWarningInfo> > GetMovablePositons(string localID, string classID, List <ResultDetailModel> item, ResultModel resultModel)
        {
            //可用课位,最后取反返回不可用课位
            var dayPeriods   = new List <DayPeriodModel>();
            var notReachable = new List <PostionWithWarningInfo>();

            ICommonDataManager commonDataManager = CacheManager.Instance.UnityContainer.Resolve <ICommonDataManager>();
            var cp   = commonDataManager.GetCPCase(localID);
            var rule = commonDataManager.GetAminRule(localID);
            var algo = commonDataManager.GetAminAlgoRule(localID);

            //获取方案可用时间
            dayPeriods = cp?.Positions?.Where(p => p.IsSelected &&
                                              p.Position != XYKernel.OS.Common.Enums.Position.AB &&
                                              p.Position != XYKernel.OS.Common.Enums.Position.Noon &&
                                              p.Position != XYKernel.OS.Common.Enums.Position.PB)
                         ?.Select(d => d.DayPeriod)?.ToList() ?? new List <DayPeriodModel>();

            cp?.Positions?.Where(p => !p.IsSelected &&
                                 p.Position != XYKernel.OS.Common.Enums.Position.AB &&
                                 p.Position != XYKernel.OS.Common.Enums.Position.Noon &&
                                 p.Position != XYKernel.OS.Common.Enums.Position.PB)
            ?.Select(d => d.DayPeriod)?.ToList()?.ForEach(p => {
                notReachable.Add(new PostionWithWarningInfo()
                {
                    DayPeriod = p, WaringMessage = $"方案不可用时间!"
                });
            });

            //TODO: 是否基于现有模型更新结果模型中的教师信息?
            item?.ForEach(it =>
            {
                List <string> teachers = new List <string>();
                teachers = it?.Teachers == null ? new List <string>() : it.Teachers.ToList();

                //1.0 移除教师在其他班级的课位
                if (teachers.Count > 0)
                {
                    resultModel.ResultClasses?.Where(c => c.ClassID != classID)?.ToList()?.ForEach(c =>
                    {
                        c.ResultDetails?.Where(rd => rd.Teachers != null && rd.Teachers.Intersect(teachers).Count() > 0)?.ToList()?.ForEach(t =>
                        {
                            notReachable.Add(new PostionWithWarningInfo()
                            {
                                DayPeriod = t.DayPeriod, WaringMessage = $"教师在课位({TimeOperation.GetDateInfo(t.DayPeriod)})安排有其他班级课程!"
                            });
                            dayPeriods.RemoveAll(p => p.Day == t.DayPeriod.Day && p.PeriodName == t.DayPeriod.PeriodName);
                        });
                    });
                }

                //2.0 检查批量规则 - 仅查权重为高级的规则
                rule?.TeacherTimes?.Where(t => t.Weight == 1 && teachers.Contains(t.TeacherID))?.ToList()?.ForEach(x =>
                {
                    if (x.ForbidTimes != null)
                    {
                        dayPeriods = TimeOperation.TimeSlotDiff(dayPeriods, x.ForbidTimes);

                        x.ForbidTimes.ForEach(fb =>
                        {
                            notReachable.Add(new PostionWithWarningInfo()
                            {
                                DayPeriod = fb, WaringMessage = $"教师在课位({TimeOperation.GetDateInfo(fb)})有禁止规则!"
                            });
                        });
                    }

                    if (x.MustTimes != null)
                    {
                        //必须时间暂不必查
                    }
                });

                rule?.CourseTimes?.Where(c => c.Weight == 1 && c.ClassID == classID && c.CourseID == it.CourseID)?.ToList()?.ForEach(x =>
                {
                    if (x.ForbidTimes != null)
                    {
                        dayPeriods = TimeOperation.TimeSlotDiff(dayPeriods, x.ForbidTimes);

                        x.ForbidTimes.ForEach(fb =>
                        {
                            notReachable.Add(new PostionWithWarningInfo()
                            {
                                DayPeriod = fb, WaringMessage = $"课程在课位({TimeOperation.GetDateInfo(fb)})有禁止规则!"
                            });
                        });
                    }

                    if (x.MustTimes != null)
                    {
                        int classHourNumber = cp.ClassHours.Where(ch => ch.ClassID == classID && ch.CourseID == it.CourseID).Count();

                        if (x.MustTimes.Count >= classHourNumber)
                        {
                            dayPeriods.ForEach(dp =>
                            {
                                if (!x.MustTimes.Exists(mt => mt.Day == dp.Day && mt.PeriodName == dp.PeriodName))
                                {
                                    notReachable.Add(new PostionWithWarningInfo()
                                    {
                                        DayPeriod = dp, WaringMessage = "课程应先满足排到必须规则指定课位内!"
                                    });
                                }
                            });

                            dayPeriods = TimeOperation.TimeSlotInterSect(dayPeriods, x.MustTimes);
                        }
                        else
                        {
                            List <DayPeriodModel> classHourTimes = resultModel.ResultClasses.Where(c => c.ClassID == classID)
                                                                   ?.SelectMany(c => c.ResultDetails)
                                                                   ?.Where(c => c.CourseID == it.CourseID)
                                                                   ?.Select(c => c.DayPeriod).ToList() ?? new List <DayPeriodModel>()
                            {
                            };

                            List <DayPeriodModel> classHoursInMust = TimeOperation.TimeSlotInterSect(x.MustTimes, classHourTimes);
                            if (classHoursInMust.Count < x.MustTimes.Count)
                            {
                                dayPeriods.ForEach(dp =>
                                {
                                    if (!x.MustTimes.Exists(mt => mt.Day == dp.Day && mt.PeriodName == dp.PeriodName))
                                    {
                                        notReachable.Add(new PostionWithWarningInfo()
                                        {
                                            DayPeriod = dp, WaringMessage = "课程应先满足排到必须规则指定课位内!"
                                        });
                                    }
                                });

                                dayPeriods = TimeOperation.TimeSlotInterSect(dayPeriods, x.MustTimes);
                            }
                            else
                            {
                                //如果课位在必须时间内,则只能和本班课时互换以保障课时优先在必须时间内
                                List <DayPeriodModel> mustTempTimes = TimeOperation.TimeSlotInterSect(x.MustTimes, new List <DayPeriodModel>()
                                {
                                    it.DayPeriod
                                });
                                if (mustTempTimes.Count == 1)
                                {
                                    dayPeriods.ForEach(dp =>
                                    {
                                        if (!classHourTimes.Exists(mt => mt.Day == dp.Day && mt.PeriodName == dp.PeriodName))
                                        {
                                            notReachable.Add(new PostionWithWarningInfo()
                                            {
                                                DayPeriod = dp, WaringMessage = "课程应先满足排到必须规则指定课位内!"
                                            });
                                        }
                                    });

                                    dayPeriods = TimeOperation.TimeSlotInterSect(dayPeriods, classHourTimes);
                                }
                            }
                        }
                    }
                });

                rule?.AmPmClassHours?.Where(a => a.Weight == 1 && a.ClassID == classID && a.CourseID == it.CourseID)?.ToList()?.ForEach(x =>
                {
                    int pmNumber     = 0;
                    int amNumber     = 0;
                    var timePosition = cp.Positions.Where(p => p.DayPeriod.Day == it.DayPeriod.Day && p.DayPeriod.PeriodName == it.DayPeriod.PeriodName).FirstOrDefault();
                    var classHours   = resultModel.ResultClasses?.Where(c => c.ClassID == classID)
                                       ?.SelectMany(c => c.ResultDetails)?.Where(c => c.CourseID == it.CourseID)?.ToList();

                    classHours?.ForEach(c =>
                    {
                        var tPosition = cp.Positions.Where(p => p.DayPeriod.Day == c.DayPeriod.Day && p.DayPeriod.PeriodName == c.DayPeriod.PeriodName).FirstOrDefault();
                        if (tPosition != null)
                        {
                            if (tPosition.Position == XYKernel.OS.Common.Enums.Position.AM)
                            {
                                amNumber = amNumber + 1;
                            }

                            if (tPosition.Position == XYKernel.OS.Common.Enums.Position.PM)
                            {
                                pmNumber = pmNumber + 1;
                            }
                        }
                    });

                    //If current time slot is AM, And PMMax is full, Disable PM
                    if (timePosition.Position == XYKernel.OS.Common.Enums.Position.AM)
                    {
                        if (x.PmMax > 0 && pmNumber >= x.PmMax)
                        {
                            //Disable PM
                            var pmTimes = cp.Positions.Where(p => p.IsSelected && p.Position == XYKernel.OS.Common.Enums.Position.PM).Select(p => p.DayPeriod).ToList();
                            dayPeriods  = TimeOperation.TimeSlotDiff(dayPeriods, pmTimes);

                            pmTimes.ForEach(pt =>
                            {
                                notReachable.Add(new PostionWithWarningInfo()
                                {
                                    DayPeriod = pt, WaringMessage = "违反班级课程的下午最大课时规则!"
                                });
                            });
                        }

                        if (x.AmMax > 0 && amNumber > x.AmMax)
                        {
                            //Disable AM
                            var amTimes = cp.Positions.Where(p => p.IsSelected && p.Position == XYKernel.OS.Common.Enums.Position.AM).Select(p => p.DayPeriod).ToList();
                            dayPeriods  = TimeOperation.TimeSlotDiff(dayPeriods, amTimes);

                            amTimes.ForEach(pt =>
                            {
                                notReachable.Add(new PostionWithWarningInfo()
                                {
                                    DayPeriod = pt, WaringMessage = "违反班级课程的上午最大课时规则!"
                                });
                            });
                        }
                    }

                    //If current time slot is PM, And AMMax is full, Disable AM
                    if (timePosition.Position == XYKernel.OS.Common.Enums.Position.PM)
                    {
                        if (x.AmMax > 0 && amNumber >= x.AmMax)
                        {
                            //Disable AM
                            var amTimes = cp.Positions.Where(p => p.IsSelected && p.Position == XYKernel.OS.Common.Enums.Position.AM).Select(p => p.DayPeriod).ToList();
                            dayPeriods  = TimeOperation.TimeSlotDiff(dayPeriods, amTimes);

                            amTimes.ForEach(at =>
                            {
                                notReachable.Add(new PostionWithWarningInfo()
                                {
                                    DayPeriod = at, WaringMessage = "违反班级课程的上午最大课时规则!"
                                });
                            });
                        }

                        if (x.PmMax > 0 && pmNumber > x.PmMax)
                        {
                            //Disable PM
                            var pmTimes = cp.Positions.Where(p => p.IsSelected && p.Position == XYKernel.OS.Common.Enums.Position.PM).Select(p => p.DayPeriod).ToList();
                            dayPeriods  = TimeOperation.TimeSlotDiff(dayPeriods, pmTimes);

                            pmTimes.ForEach(at =>
                            {
                                notReachable.Add(new PostionWithWarningInfo()
                                {
                                    DayPeriod = at, WaringMessage = "违反班级课程的下午最大课时规则!"
                                });
                            });
                        }
                    }
                });

                rule?.AmPmNoContinues.Where(a => a.Weight == 1 && teachers.Contains(a.TeacherID)).ToList()?.ForEach(x =>
                {
                    List <DayPeriodModel> currentTimeSlots = resultModel.ResultClasses?.SelectMany(c => c.ResultDetails)?.Where(c => c.Teachers != null && c.Teachers.Contains(x.TeacherID))?.ToList()?.Select(c => c.DayPeriod)?.ToList() ?? new List <DayPeriodModel>()
                    {
                    };
                    var amLast  = cp.Positions.Where(p => p.Position == XYKernel.OS.Common.Enums.Position.AM && p.DayPeriod.Day == DayOfWeek.Monday).OrderBy(p => p.PositionOrder).LastOrDefault();
                    var pmFirst = cp.Positions.Where(p => p.Position == XYKernel.OS.Common.Enums.Position.PM && p.DayPeriod.Day == DayOfWeek.Monday).OrderBy(p => p.PositionOrder).FirstOrDefault();
                    List <DayPeriodModel> amLasts  = new List <DayPeriodModel>();
                    List <DayPeriodModel> pmFirsts = new List <DayPeriodModel>();

                    if (amLast != null)
                    {
                        amLasts = cp.Positions.Where(p => p.Position == XYKernel.OS.Common.Enums.Position.AM && p.DayPeriod.PeriodName == amLast.DayPeriod.PeriodName).Select(p => p.DayPeriod).ToList();
                    }

                    if (pmFirst != null)
                    {
                        pmFirsts = cp.Positions.Where(p => p.Position == XYKernel.OS.Common.Enums.Position.PM && p.DayPeriod.PeriodName == pmFirst.DayPeriod.PeriodName).Select(p => p.DayPeriod).ToList();
                    }

                    //合并上午最后一节和下午第一节课位
                    List <DayPeriodModel> availableNoonTimes = TimeOperation.TimeSlotUnion(amLasts, pmFirsts);
                    //教师在中午的上课信息
                    List <DayPeriodModel> teacherNoonTimes             = TimeOperation.TimeSlotInterSect(currentTimeSlots, availableNoonTimes);
                    List <DayPeriodModel> teacherNotAvailableNoonTimes = new List <DayPeriodModel>()
                    {
                    };

                    availableNoonTimes.Select(lnt => lnt.Day).Distinct().ToList().ForEach(lnt => {
                        var teacherCurrentDayNoonTimes = teacherNoonTimes.Where(tnt => tnt.Day == lnt);
                        if (teacherCurrentDayNoonTimes.Count() == 2)
                        {
                            var intersectResult = TimeOperation.TimeSlotInterSect(teacherCurrentDayNoonTimes.ToList(), new List <DayPeriodModel>()
                            {
                                it.DayPeriod
                            });
                            if (intersectResult.Count > 0)
                            {
                                var leftTimeSlot = availableNoonTimes.Where(ant => ant.Day == lnt && ant.Period != it.DayPeriod.Period).FirstOrDefault();
                                if (leftTimeSlot != null)
                                {
                                    teacherNotAvailableNoonTimes.Add(leftTimeSlot);
                                }
                            }
                            else
                            {
                                teacherNotAvailableNoonTimes.AddRange(teacherCurrentDayNoonTimes);
                            }
                        }

                        if (teacherCurrentDayNoonTimes.Count() == 1)
                        {
                            var teacherTimeSlot = teacherCurrentDayNoonTimes.First();
                            if (!(teacherTimeSlot.Day == it.DayPeriod.Day && teacherTimeSlot.Period == it.DayPeriod.Period))
                            {
                                var conflitTimeSlot = availableNoonTimes.Where(ant => ant.Day == teacherTimeSlot.Day && ant.Period != teacherTimeSlot.Period).FirstOrDefault();
                                if (conflitTimeSlot != null)
                                {
                                    teacherNotAvailableNoonTimes.Add(conflitTimeSlot);
                                }
                            }
                        }
                    });

                    dayPeriods = TimeOperation.TimeSlotDiff(dayPeriods, teacherNotAvailableNoonTimes);

                    teacherNotAvailableNoonTimes.ForEach(tn =>
                    {
                        notReachable.Add(new PostionWithWarningInfo()
                        {
                            DayPeriod = tn, WaringMessage = "违反教师中午课时不连排规则!"
                        });
                    });
                });

                rule?.MasterApprenttices.Where(m => m.Weight == 1 && m.CourseID == it.CourseID && (teachers.Contains(m.MasterID) || teachers.Intersect(m.ApprenticeIDs).Count() > 0))?.ToList()?.ForEach(x =>
                {
                    //默认处理逻辑为徒弟之间也不允许同时排课, 不然无法保证互听课
                    List <string> tempTeachers = new List <string>();
                    tempTeachers.AddRange(x.ApprenticeIDs);
                    tempTeachers.Add(x.MasterID);
                    tempTeachers = tempTeachers.Distinct().ToList();

                    var classHoursTimes = resultModel.ResultClasses?.SelectMany(c => c.ResultDetails)?.Where(c => c.CourseID == it.CourseID && c.Teachers.Except(it.Teachers).Count() > 0 && c.Teachers.Intersect(tempTeachers).Count() > 0)?.ToList()?.Select(c => c.DayPeriod);

                    classHoursTimes?.ToList()?.ForEach(c =>
                    {
                        dayPeriods.RemoveAll(d => d.Day == c.Day && d.PeriodName == c.PeriodName);
                        notReachable.Add(new PostionWithWarningInfo()
                        {
                            DayPeriod = c, WaringMessage = "违反师徒跟随规则!"
                        });
                    });
                });

                rule?.Mutexes?.Where(m => m.Weight == 1 && m.CourseIDs != null && m.CourseIDs.Contains(it.CourseID))?.ToList()?.ForEach(x =>
                {
                    List <string> tempCourseIds = x.CourseIDs?.Select(xc => xc)?.ToList();
                    tempCourseIds.RemoveAll(t => t == it.CourseID);

                    var classHoursTimes = resultModel.ResultClasses
                                          ?.Where(r => r.ClassID == classID)?.SelectMany(c => c.ResultDetails)
                                          ?.Where(c => tempCourseIds.Contains(c.CourseID))
                                          ?.ToList()?.Select(c => c.DayPeriod.Day);

                    classHoursTimes?.ToList()?.ForEach(c =>
                    {
                        dayPeriods.Where(d => d.Day == c)?.ToList()?.ForEach(dp =>
                        {
                            notReachable.Add(new PostionWithWarningInfo()
                            {
                                DayPeriod = dp, WaringMessage = "违反课程互斥规则!"
                            });
                        });

                        dayPeriods.RemoveAll(d => d.Day == c);
                    });
                });

                #region 合班规则
                List <string> unionClassIDs = new List <string>();
                rule?.ClassUnions?.Where(cu => cu.ClassIDs != null && cu.ClassIDs.Contains(classID) && cu.CourseID == it.CourseID)?.ToList()?.ForEach(x => {
                    //Get All Union ClassID
                    x.ClassIDs.ForEach(cl => {
                        if (!unionClassIDs.Contains(cl))
                        {
                            unionClassIDs.Add(cl);
                        }
                    });
                });

                if (unionClassIDs.Count > 1)
                {
                    bool flag = true;
                    List <DayPeriodModel> timeslots = new List <DayPeriodModel>();

                    foreach (string classId in unionClassIDs)
                    {
                        var courseTimes = resultModel.ResultClasses?
                                          .Where(rc => rc.ClassID == classId)?
                                          .SelectMany(c => c.ResultDetails)?
                                          .Where(c => c.CourseID == it.CourseID)?
                                          .ToList()?.Select(c => c.DayPeriod)?.ToList() ?? new List <DayPeriodModel>();

                        if (timeslots.Count == 0)
                        {
                            timeslots = courseTimes;
                        }
                        else
                        {
                            List <DayPeriodModel> timesUnion = TimeOperation.TimeSlotUnion(timeslots.ToList(), courseTimes);
                            List <DayPeriodModel> timesDiff  = TimeOperation.TimeSlotDiff(timeslots.ToList(), courseTimes);
                            if (timesUnion.Count != timeslots.Count || timesDiff.Count != 0)
                            {
                                flag = false;
                            }
                        }
                    }

                    if (flag)
                    {
                        List <DayPeriodModel> timesInterSect = TimeOperation.TimeSlotInterSect(timeslots.ToList(), dayPeriods.ToList());
                        List <DayPeriodModel> timesDiff      = TimeOperation.TimeSlotDiff(dayPeriods.ToList(), timesInterSect.ToList());

                        timesDiff?.ForEach(c =>
                        {
                            dayPeriods.RemoveAll(d => d.Day == c.Day && d.PeriodName == c.PeriodName);
                            notReachable.Add(new PostionWithWarningInfo()
                            {
                                DayPeriod = c, WaringMessage = "违反合班规则!"
                            });
                        });
                    }
                }
                #endregion
            });

            return(Tuple.Create(dayPeriods, notReachable));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        var result = new List<ForLoopResourcesResult>();

        var theData = new List<string>();
        for (int i = 0; i < 9999999; i++)
            theData.Add("Item" + i);

        int MaxLoop = 5;

        var S1 = new ForLoopResourcesResult() { Description = "Storing the count in a variable", Duration = 0, MemoryUsage=0 };
        result.Add(S1);
        for (int Loop = 0; Loop < MaxLoop; Loop++)
        {
            using (var tOp = new TimeOperation())
            {
                long MemoryStart = System.GC.GetTotalMemory(false);
                var Count = theData.Count;
                for (int i = 0; i < Count; i++)
                {
                    string s = theData[i];
                }
                S1.Duration += tOp.Stop();
                long MemoryEnd = System.GC.GetTotalMemory(false);
                S1.MemoryUsage += MemoryEnd - MemoryStart;
            }
        }
        System.Threading.Thread.Sleep(5000);
        System.GC.Collect();
        System.Threading.Thread.Sleep(5000);

        var S2 = new ForLoopResourcesResult() { Description = "Normal For Loop", Duration = 0, MemoryUsage=0 };
        result.Add(S2);
        for (int Loop = 0; Loop < MaxLoop; Loop++)
        {
            using (var tOp = new TimeOperation())
            {
                long MemoryStart = System.GC.GetTotalMemory(false);
                for (int i = 0; i < theData.Count; i++)
                {
                    string s = theData[i];
                }
                S2.Duration += tOp.Stop();
                long MemoryEnd = System.GC.GetTotalMemory(false);
                S1.MemoryUsage += MemoryEnd - MemoryStart;

            }
        }
        System.Threading.Thread.Sleep(5000);
        System.GC.Collect();
        System.Threading.Thread.Sleep(5000);

        var S3 = new ForLoopResourcesResult() { Description = "Using List.ForEach", Duration = 0, MemoryUsage=0 };
        result.Add(S3);
        for (int Loop = 0; Loop < MaxLoop; Loop++)
        {
            using (var tOp = new TimeOperation())
            {
                long MemoryStart = System.GC.GetTotalMemory(false);
                theData.ForEach(delegate(string str) { string s = str; });
                long MemoryEnd = System.GC.GetTotalMemory(false);
                S1.MemoryUsage += MemoryEnd - MemoryStart;

                S3.Duration += tOp.Stop();
            }
        }
        System.Threading.Thread.Sleep(5000);
        System.GC.Collect();
        result.ForEach(delegate(ForLoopResourcesResult obj) { obj.Duration = obj.Duration / MaxLoop; });
        GV.DataSource = result;
        GV.DataBind();
    }
示例#10
0
        /// <summary>
        /// 校验天是否在表达式范围内
        /// </summary>
        /// <param name="needCheckDay"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static bool CheckDay(DateTime currentTime, DateTime startTime, string expDay, string expWeek)
        {
            try
            {
                //校验expDay表达式

                //校验expWeek表达式


                //如果周包含'?',则去分析天
                if (expWeek == "?")
                {
                    if (expDay.Contains('*'))
                    {
                        return(true);
                    }
                    else if (expDay.Contains(','))
                    {
                        bool     retBl       = false;
                        string[] superDayArr = expDay.Split(',');//一级日期数组表达式
                        for (int i = 0; i < superDayArr.Length; i++)
                        {
                            if (string.IsNullOrEmpty(superDayArr[i]))
                            {
                                throw new Exception("时间字符串非法!");
                            }
                            else
                            {
                                if (superDayArr[i].Contains('#'))
                                {
                                    if (TimeOperation.DayPoundOperation(superDayArr[i].Split('#')[0], superDayArr[i].Split('#')[1], currentTime))
                                    {
                                        return(true);
                                    }
                                }
                                else if (superDayArr[i].Contains('/'))
                                {
                                    if (TimeOperation.DaysSlashOperation(currentTime, startTime, superDayArr[i].Split('/')[0], superDayArr[i].Split('/')[1]))
                                    {
                                        return(true);
                                    }
                                }
                                else if (superDayArr[i].Contains('-'))
                                {
                                    if (TimeOperation.DayHyphenOperation(superDayArr[i].Split('-')[0], superDayArr[i].Split('-')[1], currentTime.Day))
                                    {
                                        return(true);
                                    }
                                }
                                else if (superDayArr[i] == currentTime.Day.ToString())
                                {
                                    return(true);
                                }
                            }
                        }
                        return(retBl);
                    }
                    else if (expDay.Contains('#'))
                    {
                        return(TimeOperation.DayPoundOperation(expDay.Split('#')[0], expDay.Split('#')[1], currentTime));
                    }
                    else if (expDay.Contains('/'))
                    {
                        return(TimeOperation.DaysSlashOperation(currentTime, startTime, expDay.Split('/')[0], expDay.Split('/')[1]));
                    }
                    else if (expDay.Contains('-'))
                    {
                        return(TimeOperation.DayHyphenOperation(expDay.Split('-')[0], expDay.Split('-')[1], currentTime.Day));
                    }
                    else if (expDay == "W")//工作日
                    {
                        return((int)currentTime.DayOfWeek >= 1 && (int)currentTime.DayOfWeek <= 5 ? true : false);
                    }
                    else if (expDay == "H")//周末
                    {
                        return((int)currentTime.DayOfWeek == 0 || (int)currentTime.DayOfWeek == 6 ? true : false);
                    }
                    else if (expDay == currentTime.Day.ToString())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                //如果天包含'?',则去分析周(周日:0,周一到周六:1->6)
                else if (expDay == "?")
                {
                    int dayOfWeek = (int)currentTime.DayOfWeek;  //获取当天是周几
                    if (expWeek.Contains('*'))
                    {
                        return(true);
                    }
                    else if (expWeek.Contains(','))
                    {
                        bool     bl         = false;
                        string[] expWeekArr = expWeek.Split(',');
                        for (int i = 0; i < expWeekArr.Length; i++)
                        {
                            if (expWeekArr[i].Contains('@'))
                            {
                                if (TimeOperation.AtWeekOperation(currentTime, startTime, expWeekArr[i].Split('@')[0], expWeekArr[i].Split('@')[1]))
                                {
                                    return(true);
                                }
                            }
                            else if (expWeekArr[i].Contains('#'))
                            {
                                if (TimeOperation.WeekPoundOperation(expWeekArr[i].Split('#')[0], expWeekArr[i].Split('#')[1], currentTime))
                                {
                                    return(true);
                                }
                            }
                            else if (expWeekArr[i].Contains('/'))
                            {
                                if (TimeOperation.WeekSlashOperation(startTime, currentTime, expWeekArr[i]))
                                {
                                    return(true);
                                }
                            }
                            else if (expWeekArr[i].Contains('-'))
                            {
                                if (TimeOperation.SingleWeekHyphenOperation(expWeekArr[i].Split('-')[0], expWeekArr[i].Split('-')[1], currentTime))
                                {
                                    return(true);
                                }
                            }
                            else if (expWeek == "W")//工作日
                            {
                                if (dayOfWeek >= 1 && dayOfWeek <= 5)
                                {
                                    return(true);
                                }
                            }
                            else if (expWeek == "H")//周末
                            {
                                if (dayOfWeek == 0 || dayOfWeek == 6)
                                {
                                    return(true);
                                }
                            }
                            else if (expWeek == "F")
                            {
                                if (TimeOperation.GetWeekOfMonth(currentTime) == 1)
                                {
                                    return(true);
                                }
                            }
                            else if (expWeek == "S")
                            {
                                if (TimeOperation.GetWeekOfMonth(currentTime) == 2)
                                {
                                    return(true);
                                }
                            }
                            else if (expWeek == "T")
                            {
                                if (TimeOperation.GetWeekOfMonth(currentTime) == 3)
                                {
                                    return(true);
                                }
                            }
                            else if (expWeek == "R")
                            {
                                if (TimeOperation.GetWeekOfMonth(currentTime) == 4)
                                {
                                    return(true);
                                }
                            }
                            else if (expWeek == "L")
                            {
                                if (TimeOperation.JudgeMonthLastWeek(currentTime))
                                {
                                    return(true);
                                }
                            }
                        }
                        return(bl);
                    }
                    else if (expWeek.Contains('@'))
                    {
                        return(TimeOperation.AtWeekOperation(currentTime, startTime, expWeek.Split('@')[0], expWeek.Split('@')[1]));
                    }
                    else if (expWeek.Contains('#'))
                    {
                        return(TimeOperation.WeekPoundOperation(expWeek.Split('#')[0], expWeek.Split('#')[1], currentTime));
                    }
                    else if (expWeek.Contains('/'))  //间隔几周,此时月份应为*
                    {
                        return(TimeOperation.WeekSlashOperation(startTime, currentTime, expWeek));
                    }
                    else if (expWeek.Contains('-'))  //从周几到周几
                    {
                        return(TimeOperation.SingleWeekHyphenOperation(expWeek.Split('-')[0], expWeek.Split('-')[1], currentTime));
                    }
                    else if (expWeek == "W")//工作日
                    {
                        return(dayOfWeek >= 1 && dayOfWeek <= 5 ? true : false);
                    }
                    else if (expWeek == "H")//周末
                    {
                        return(dayOfWeek == 0 || dayOfWeek == 6 ? true : false);
                    }
                    else if (expWeek == "F")
                    {
                        return(TimeOperation.GetWeekOfMonth(currentTime) == 1 ? true : false);
                    }
                    else if (expWeek == "S")
                    {
                        return(TimeOperation.GetWeekOfMonth(currentTime) == 2 ? true : false);
                    }
                    else if (expWeek == "T")
                    {
                        return(TimeOperation.GetWeekOfMonth(currentTime) == 3 ? true : false);
                    }
                    else if (expWeek == "R")
                    {
                        return(TimeOperation.GetWeekOfMonth(currentTime) == 4 ? true : false);
                    }
                    else if (expWeek == "L")
                    {
                        return(TimeOperation.JudgeMonthLastWeek(currentTime));
                    }
                    else   //单个周几
                    {
                        int weekInt = -1;
                        if (int.TryParse(expWeek, out weekInt))
                        {
                            return(weekInt == dayOfWeek ? true : false);
                        }
                        else
                        {
                            throw new Exception("时间字符串非法!");
                        }
                    }
                }
                //如果天,周都未包含‘?’,表示错误
                else
                {
                    throw new Exception("时间字符串非法!");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#11
0
        private static Tuple <List <DayPeriodModel>, List <PostionWithWarningInfo> > GetMovablePositons(string localID, List <ResultDetailModel> item, ResultModel resultModel)
        {
            //可用课位,最后取反返回不可用课位
            var dayPeriods   = new List <DayPeriodModel>();
            var notReachable = new List <PostionWithWarningInfo>();

            ICommonDataManager commonDataManager = CacheManager.Instance.UnityContainer.Resolve <ICommonDataManager>();
            var cl   = commonDataManager.GetCLCase(localID);
            var rule = commonDataManager.GetMixedRule(localID);
            var algo = commonDataManager.GetMixedAlgoRule(localID);

            //获取方案可用时间
            dayPeriods = cl?.Positions?.Where(p => p.IsSelected &&
                                              p.Position != XYKernel.OS.Common.Enums.Position.AB &&
                                              p.Position != XYKernel.OS.Common.Enums.Position.Noon &&
                                              p.Position != XYKernel.OS.Common.Enums.Position.PB)
                         ?.Select(d => d.DayPeriod)?.ToList() ?? new List <DayPeriodModel>();

            //TODO: 是否基于现有模型更新结果模型中的教师信息?
            item?.ForEach(it =>
            {
                var classHourInfo = cl.ClassHours.FirstOrDefault(c => c.ID == it.ClassHourId);
                string classID    = classHourInfo?.ClassID ?? string.Empty;
                string courseID   = classHourInfo?.CourseID ?? string.Empty;

                List <string> teachers = new List <string>();
                teachers = it?.Teachers == null ? new List <string>() : it.Teachers.ToList();

                //2.0 检查批量规则 - 仅查权重为高级的规则
                rule?.TeacherTimes?.Where(t => t.Weight == 1 && teachers.Contains(t.TeacherID))?.ToList()?.ForEach(x =>
                {
                    if (x.ForbidTimes != null)
                    {
                        dayPeriods = TimeOperation.TimeSlotDiff(dayPeriods, x.ForbidTimes);

                        x.ForbidTimes.ForEach(fb =>
                        {
                            notReachable.Add(new PostionWithWarningInfo()
                            {
                                DayPeriod = fb, WaringMessage = $"教师在课位({TimeOperation.GetDateInfo(fb)})有禁止规则!"
                            });
                        });
                    }

                    if (x.MustTimes != null)
                    {
                        //必须时间暂不必查
                    }
                });

                rule?.CourseTimes?.Where(c => c.Weight == 1 && c.ClassID == classID)?.ToList()?.ForEach(x =>
                {
                    if (x.ForbidTimes != null)
                    {
                        dayPeriods = TimeOperation.TimeSlotDiff(dayPeriods, x.ForbidTimes);

                        x.ForbidTimes.ForEach(fb =>
                        {
                            notReachable.Add(new PostionWithWarningInfo()
                            {
                                DayPeriod = fb, WaringMessage = $"课程在课位({TimeOperation.GetDateInfo(fb)})有禁止规则!"
                            });
                        });
                    }

                    if (x.MustTimes != null)
                    {
                        int classHourNumber = cl.ClassHours.Where(ch => ch.ClassID == classID && ch.CourseID == courseID).Count();

                        if (x.MustTimes.Count >= classHourNumber)
                        {
                            dayPeriods.ForEach(dp =>
                            {
                                if (!x.MustTimes.Exists(mt => mt.Day == dp.Day && mt.PeriodName == dp.PeriodName))
                                {
                                    notReachable.Add(new PostionWithWarningInfo()
                                    {
                                        DayPeriod = dp, WaringMessage = "课程应先满足排到必须规则指定课位内!"
                                    });
                                }
                            });

                            dayPeriods = TimeOperation.TimeSlotInterSect(dayPeriods, x.MustTimes);
                        }
                        else
                        {
                            List <DayPeriodModel> classHourTimes = resultModel.ResultClasses.Where(c => c.ClassID == classID)
                                                                   ?.SelectMany(c => c.ResultDetails)
                                                                   ?.Select(c => c.DayPeriod).ToList() ?? new List <DayPeriodModel>()
                            {
                            };

                            List <DayPeriodModel> classHoursInMust = TimeOperation.TimeSlotInterSect(x.MustTimes, classHourTimes);
                            if (classHoursInMust.Count < x.MustTimes.Count)
                            {
                                dayPeriods.ForEach(dp =>
                                {
                                    if (!x.MustTimes.Exists(mt => mt.Day == dp.Day && mt.PeriodName == dp.PeriodName))
                                    {
                                        notReachable.Add(new PostionWithWarningInfo()
                                        {
                                            DayPeriod = dp, WaringMessage = "课程应先满足排到必须规则指定课位内!"
                                        });
                                    }
                                });

                                dayPeriods = TimeOperation.TimeSlotInterSect(dayPeriods, x.MustTimes);
                            }
                            else
                            {
                                //如果课位在必须时间内,则只能和本班课时互换以保障课时优先在必须时间内
                                List <DayPeriodModel> mustTempTimes = TimeOperation.TimeSlotInterSect(x.MustTimes, new List <DayPeriodModel>()
                                {
                                    it.DayPeriod
                                });
                                if (mustTempTimes.Count == 1)
                                {
                                    dayPeriods.ForEach(dp =>
                                    {
                                        if (!classHourTimes.Exists(mt => mt.Day == dp.Day && mt.PeriodName == dp.PeriodName))
                                        {
                                            notReachable.Add(new PostionWithWarningInfo()
                                            {
                                                DayPeriod = dp, WaringMessage = "课程应先满足排到必须规则指定课位内!"
                                            });
                                        }
                                    });

                                    dayPeriods = TimeOperation.TimeSlotInterSect(dayPeriods, classHourTimes);
                                }
                            }
                        }
                    }
                });

                rule?.AmPmClassHours?.Where(a => a.Weight == 1 && a.ClassID == classID && a.CourseID == courseID)?.ToList()?.ForEach(x =>
                {
                    int pmNumber     = 0;
                    int amNumber     = 0;
                    var timePosition = cl.Positions.Where(p => p.DayPeriod.Day == it.DayPeriod.Day && p.DayPeriod.PeriodName == it.DayPeriod.PeriodName).FirstOrDefault();
                    var classHours   = resultModel.ResultClasses?.Where(c => c.ClassID == classID)
                                       ?.SelectMany(c => c.ResultDetails)?.ToList();

                    classHours?.ForEach(c =>
                    {
                        var tPosition = cl.Positions.Where(p => p.DayPeriod.Day == c.DayPeriod.Day && p.DayPeriod.PeriodName == c.DayPeriod.PeriodName).FirstOrDefault();
                        if (tPosition != null)
                        {
                            if (tPosition.Position == XYKernel.OS.Common.Enums.Position.AM)
                            {
                                amNumber = amNumber + 1;
                            }

                            if (tPosition.Position == XYKernel.OS.Common.Enums.Position.PM)
                            {
                                pmNumber = pmNumber + 1;
                            }
                        }
                    });

                    //If current time slot is AM, And PMMax is full, Disable PM
                    if (timePosition.Position == XYKernel.OS.Common.Enums.Position.AM)
                    {
                        if (x.PmMax > 0 && pmNumber >= x.PmMax)
                        {
                            //Disable PM
                            var pmTimes = cl.Positions.Where(p => p.IsSelected && p.Position == XYKernel.OS.Common.Enums.Position.PM).Select(p => p.DayPeriod).ToList();
                            dayPeriods  = TimeOperation.TimeSlotDiff(dayPeriods, pmTimes);

                            pmTimes.ForEach(pt =>
                            {
                                notReachable.Add(new PostionWithWarningInfo()
                                {
                                    DayPeriod = pt, WaringMessage = "违反班级课程的下午最大课时规则!"
                                });
                            });
                        }

                        if (x.AmMax > 0 && amNumber > x.AmMax)
                        {
                            //Disable AM
                            var amTimes = cl.Positions.Where(p => p.IsSelected && p.Position == XYKernel.OS.Common.Enums.Position.AM).Select(p => p.DayPeriod).ToList();
                            dayPeriods  = TimeOperation.TimeSlotDiff(dayPeriods, amTimes);

                            amTimes.ForEach(pt =>
                            {
                                notReachable.Add(new PostionWithWarningInfo()
                                {
                                    DayPeriod = pt, WaringMessage = "违反班级课程的上午最大课时规则!"
                                });
                            });
                        }
                    }

                    //If current time slot is PM, And AMMax is full, Disable AM
                    if (timePosition.Position == XYKernel.OS.Common.Enums.Position.PM)
                    {
                        if (x.AmMax > 0 && amNumber >= x.AmMax)
                        {
                            //Disable AM
                            var amTimes = cl.Positions.Where(p => p.IsSelected && p.Position == XYKernel.OS.Common.Enums.Position.AM).Select(p => p.DayPeriod).ToList();
                            dayPeriods  = TimeOperation.TimeSlotDiff(dayPeriods, amTimes);

                            amTimes.ForEach(at =>
                            {
                                notReachable.Add(new PostionWithWarningInfo()
                                {
                                    DayPeriod = at, WaringMessage = "违反班级课程的上午最大课时规则!"
                                });
                            });
                        }

                        if (x.PmMax > 0 && pmNumber > x.PmMax)
                        {
                            //Disable PM
                            var pmTimes = cl.Positions.Where(p => p.IsSelected && p.Position == XYKernel.OS.Common.Enums.Position.PM).Select(p => p.DayPeriod).ToList();
                            dayPeriods  = TimeOperation.TimeSlotDiff(dayPeriods, pmTimes);

                            pmTimes.ForEach(at =>
                            {
                                notReachable.Add(new PostionWithWarningInfo()
                                {
                                    DayPeriod = at, WaringMessage = "违反班级课程的下午最大课时规则!"
                                });
                            });
                        }
                    }
                });
            });

            return(Tuple.Create(dayPeriods, notReachable));
        }
 public TimeOperationNode(TimeOperation timeOperation)
 {
     Operation  = timeOperation;
     ParentNode = null;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        var results = new List<StringBuilderResults>();
        int MaxLoops = 5;
        int MaxIterations = 10000;

        var r1 = new StringBuilderResults() { Description = "StringBuilder", MemoryUsage = 0, Duration = 0, TotalExceptions = 0 };
        results.Add(r1);
        for (int Loop = 0; Loop < MaxLoops; Loop++)
        {
            long memoryStart = System.GC.GetTotalMemory(false);
            using (var tOp = new TimeOperation())
            {
                try
                {
                    var sb = new StringBuilder();
                    for (int i = 0; i < MaxIterations; i++)
                    {
                        sb.Append(i.ToString());
                    }
                }
                catch (Exception ex)
                {
                    r1.TotalExceptions++;
                    r1.AddException(ex);
                }
                r1.Duration += tOp.Stop();

            }
            long memoryEnd = System.GC.GetTotalMemory(false);
            r1.MemoryUsage += memoryEnd - memoryStart;
        }
        System.Threading.Thread.Sleep(5000);
        System.GC.Collect();
        System.Threading.Thread.Sleep(5000);

        var r2 = new StringBuilderResults() { Description = "String Concat", MemoryUsage = 0, Duration = 0, TotalExceptions = 0 };
        results.Add(r2);
        for (int Loop = 0; Loop < MaxLoops; Loop++)
        {
            long memoryStart = System.GC.GetTotalMemory(false);
            using (var tOp = new TimeOperation())
            {
                try
                {
                    var sb = "";
                    for (int i = 0; i < MaxIterations; i++)
                    {
                        sb = sb + i.ToString();
                    }
                }
                catch (Exception ex)
                {
                    r2.TotalExceptions++;
                    r2.AddException(ex);
                }
                r2.Duration += tOp.Stop();

            }
            long memoryEnd = System.GC.GetTotalMemory(false);
            r2.MemoryUsage += memoryEnd - memoryStart;
        }
        System.Threading.Thread.Sleep(5000);
        System.GC.Collect();

        results.ForEach(delegate(StringBuilderResults r) { r.Duration = r.Duration / MaxLoops; r.MemoryUsage = r.MemoryUsage / MaxLoops; });

        GV.DataSource = results;
        GV.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var oArrayList = new ArrayList();
        var oList = new List<int>();
        var oHashTable = new Hashtable();
        var oDictionary = new Dictionary<int, int>();

        var results = new List<ComparisonObj>();

        /*
         * Create a new Comparison Object
         * a Comparison object stores the various parameters which we want to monitor
         */

        var coArrayList = new ComparisonObj() { Description = "ArrayList"};
        results.Add(coArrayList);

        //ArrayList
        for (int Loop = 0; Loop < MaxLoops; Loop++)
        {
            oArrayList = new ArrayList();

            //Insert items to the array List
            using (var tOps = new TimeOperation())
            {
                for (int i = 0; i < MaxElements; i++)
                    oArrayList.Add(i);
                coArrayList.Duration_Insert += tOps.Stop();
            }

            //Iterate thru all items in the array list
            using (var tOps = new TimeOperation())
            {
                foreach (object o in oArrayList)
                {
                    int i = (int)o;
                }
                coArrayList.Duration_Iterate += tOps.Stop();
            }

            //Seek the middle number in the arraylist
            using (var tOps = new TimeOperation())
            {
                oArrayList.Contains(MaxElements / 2);
                coArrayList.Duration_Search += tOps.Stop();
            }

            oArrayList.Clear();
        }

        System.Threading.Thread.Sleep(5000);
        var coList = new ComparisonObj() { Description = "List"};
        results.Add(coList);
        for (int Loop = 0; Loop < MaxLoops; Loop++)
        {
            oList = new List<int>();

            using (var tOps = new TimeOperation())
            {
                for (int i = 0; i < MaxElements; i++)
                    oList.Add(i);
                coList.Duration_Insert += tOps.Stop();
            }

            using (var tOps = new TimeOperation())
            {
                foreach (var o in oList)
                {
                    int i = o;
                }
                coList.Duration_Iterate += tOps.Stop();
            }

            using (var tOps = new TimeOperation())
            {
                oList.Contains(MaxElements / 2);
                coList.Duration_Search += tOps.Stop();
            }

            oList.Clear();
        }
        System.Threading.Thread.Sleep(5000);
        var coHashTable = new ComparisonObj() { Description = "HashTable" };
        results.Add(coHashTable);
        for (int Loop = 0; Loop < MaxLoops; Loop++)
        {
            oHashTable = new Hashtable();

            using (var tOps = new TimeOperation())
            {
                for (int i = 0; i < MaxElements; i++)
                    oHashTable.Add(i, i);
                coHashTable.Duration_Insert += tOps.Stop();
            }

            using (var tOps = new TimeOperation())
            {
                foreach (object o in oHashTable.Keys)
                {
                    int i = (int)oHashTable[o];
                }
                coHashTable.Duration_Iterate += tOps.Stop();
            }

            using (var tOps = new TimeOperation())
            {
                oHashTable.ContainsKey(MaxElements / 2);
                coHashTable.Duration_Search += tOps.Stop();
            }

            oHashTable.Clear();
        }

        System.Threading.Thread.Sleep(5000);
        var coDictionary = new ComparisonObj() { Description = "Dictionary" };
        results.Add(coDictionary);
        for (int Loop = 0; Loop < MaxLoops; Loop++)
        {
            oDictionary = new Dictionary<int, int>();

            using (var tOps = new TimeOperation())
            {
                for (int i = 0; i < MaxElements; i++)
                    oDictionary.Add(i, i);
                coDictionary.Duration_Insert += tOps.Stop();
            }

            using (var tOps = new TimeOperation())
            {
                foreach (var o in oDictionary.Keys)
                {
                    int i = (int)oDictionary[o];
                }
                coDictionary.Duration_Iterate += tOps.Stop();
            }

            using (var tOps = new TimeOperation())
            {
                oDictionary.ContainsKey(MaxElements / 2);
                coDictionary.Duration_Search += tOps.Stop();
            }

            oHashTable.Clear();
        }

        System.Threading.Thread.Sleep(5000);
        foreach (var o in results)
        {
            o.Duration_Insert = o.Duration_Insert / MaxLoops;
            o.Duration_Iterate = o.Duration_Iterate / MaxLoops;
            o.Duration_Search = o.Duration_Search / MaxLoops;
        }

        GV.DataSource = results;
        GV.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var results = new List<DisposingResourcesResult>();
        var yDispose = new DisposingResourcesResult() { Description = "Disposing objects", MemoryUsage=0, Duration=0, TotalExceptions=0 };
        results.Add(yDispose);

        var cmd = new SqlCommand();
        cmd.CommandText = "select * from Address";
        int MaxLoops = 5;
        int MaxIterations = 100;
        for (int Loop = 0; Loop < MaxLoops; Loop++)
        {
            long memoryStart = System.GC.GetTotalMemory(false);
            using (var tOp = new TimeOperation())
            {
                try
                {
                    for (int i = 0; i < MaxIterations; i++)
                    {
                        using (var db = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["AdventureWorksConnectionString"].ConnectionString))
                        {
                            db.Open();
                            cmd.Connection = db;
                            using (var r = cmd.ExecuteReader())
                            {
                                while (r.Read())
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    yDispose.TotalExceptions++;
                    yDispose.AddException(ex);
                }
                    yDispose.Duration += tOp.Stop();

            }
            long memoryEnd = System.GC.GetTotalMemory(false);
            yDispose.MemoryUsage += memoryEnd - memoryStart;
        }
        System.GC.Collect();

        var nDispose = new DisposingResourcesResult() { Description = "NOT Disposing objects", MemoryUsage = 0, Duration = 0, TotalExceptions = 0 };
        results.Add(nDispose);
        for (int Loop = 0; Loop < MaxLoops; Loop++)
        {
            long memoryStart = System.GC.GetTotalMemory(false);
            using (var tOp = new TimeOperation())
            {
                for (int i = 0; i < MaxIterations; i++)
                {
                    try
                    {
                        var db = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["AdventureWorksConnectionString"].ConnectionString);
                        db.Open();
                        cmd.Connection = db;
                        using (var r = cmd.ExecuteReader())
                        {
                            while (r.Read())
                            {
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        nDispose.TotalExceptions++;
                        nDispose.AddException(ex);
                    }
                }
                nDispose.Duration += tOp.Stop();
            }
            long memoryEnd = System.GC.GetTotalMemory(false);
            nDispose.MemoryUsage += memoryEnd - memoryStart;
        }
        System.GC.Collect();

        results.ForEach(delegate(DisposingResourcesResult r) { r.Duration = r.Duration / MaxLoops; r.MemoryUsage = r.MemoryUsage / MaxLoops; });

        GV.DataSource = results;
        GV.DataBind();
    }
示例#16
0
        private void acrossTime(ulong startTime, ulong timeLen, BlockValidator validator, TimeOperation op)
        {
            for (ulong dt = 0; dt < timeLen; )
            {
                int begin;
                EventToken[,] block;
                ulong time = startTime + dt;
                getBaseTime(time, out block, out begin);
                time -= (ulong)begin;

                if (!validator(ref block) || block == null)
                {
                    dt = _history.Keys.Where(t => (t > time))
                        .DefaultIfEmpty(startTime + timeLen)
                        .Min() - startTime;
                    continue;
                }

                _history[time] = block;

                for (int blockIndex = begin; blockIndex < block.GetLength(1) && dt < timeLen; blockIndex++, dt++)
                {
                    op(ref block, dt, blockIndex);
                }
            }
        }