コード例 #1
0
        public GetScheduleDayResponse GetScheduleDay(GetScheduleDayRequest request)
        {
            //находим метод обработки дня
            HandlingMode mode = request.CheckParameters.GetMode();

            //Формируем данные для обработки
            var settingsRequest = new ScheduleDataCalculatorRequest()
            {
                Date             = request.Date,
                TypiconVersionId = request.TypiconId,
                ApplyParameters  = request.ApplyParameters,
                CheckParameters  = request.CheckParameters
                                   .SetModeParam((mode == HandlingMode.AstronomicDay) ? HandlingMode.ThisDay : mode)
            };

            OutputDay scheduleDay = GetOrFillScheduleDay(settingsRequest, request.Handler);

            if (mode == HandlingMode.AstronomicDay)
            {
                //ищем службы следующего дня с маркером IsDayBefore == true
                settingsRequest.Date            = request.Date.AddDays(1);
                settingsRequest.CheckParameters = settingsRequest.CheckParameters.SetModeParam(HandlingMode.DayBefore);

                scheduleDay = GetOrFillScheduleDay(settingsRequest, request.Handler, scheduleDay);
            }

            return(new GetScheduleDayResponse()
            {
                Day = scheduleDay
            });
        }
コード例 #2
0
 public static void AddWorships(this OutputDay day, List <OutputWorshipModel> worshipModels, ITypiconSerializer typiconSerializer)
 {
     foreach (var wm in worshipModels)
     {
         day.AddWorship(wm, typiconSerializer);
     }
 }
コード例 #3
0
        public CreateOutputDayResponse(OutputDay day, IEnumerable <BusinessConstraint> constraints)
        {
            Day = day ?? throw new ArgumentNullException(nameof(day));

            if (constraints != null)
            {
                BrokenConstraints = constraints;
            }
        }
コード例 #4
0
 public static FilteredOutputDay FilterOut(this OutputDay day, OutputFilter filter)
 => new FilteredOutputDay()
 {
     Id       = day.Id,
     Date     = day.Date,
     Header   = day.Header?.FilterOut(filter),
     Worships = day.Worships
                .OrderBy(c => c.Order)
                .ToList()
                .FilterOut(filter),
     ModifiedDate = day.ModifiedDate
 };
コード例 #5
0
        /// <summary>
        /// Вычисляет свойства для заполнения выходной формы
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private OutputDayInfo GetOutputDayInfo(IScheduleDataCalculator dataCalculator, ScheduleDataCalculatorRequest request)
        {
            //Формируем данные для обработки
            var response = dataCalculator.Calculate(request);

            var outputDay = new OutputDay()
            {
                TypiconId = request.TypiconId,
                Date      = request.Date
            };

            if (response.Success)
            {
                //все удачно - собираем информацию

                var settings = response.Value.Settings;

                var brokenConstraints = GetBrokenConstraints(settings);

                _handler.Settings = settings;

                _handler.ClearResult();

                settings.RuleContainer.Interpret(_handler);

                var results = _handler.GetResults();

                var sign = response.Value.Rule.Template.GetPredefinedTemplate();

                outputDay.Header = new OutputDayHeader()
                {
                    //задаем имя дню
                    Name = _nameComposer.Compose(request.Date, response.Value.Rule.Template.Priority, settings.AllWorships),

                    PredefinedSignId = sign.Id,
                    //Если settings.PrintDayTemplate определен в ModifiedRule, то назначаем его
                    PrintDayTemplate = settings.PrintDayTemplate ?? sign.PrintTemplate
                };

                return(new OutputDayInfo(
                           outputDay,
                           settings.AllWorships,
                           results,
                           brokenConstraints));
            }
            else
            {
                //если response возвращается неудачный, то возвращаем "пустую" информацию
                return(new OutputDayInfo(
                           outputDay,
コード例 #6
0
        public static void UpdateOutputDay(this TypiconDBContext dbContext, OutputDay outputDay)
        {
            var outputDays = dbContext.Set <OutputDay>()
                             .Where(c => c.TypiconId == outputDay.TypiconId && c.Date.Date == outputDay.Date.Date);

            if (outputDays.Any())
            {
                dbContext.Set <OutputDay>().RemoveRange(outputDays);
            }

            dbContext.Set <OutputDay>().Add(outputDay);

            dbContext.SaveChanges();
        }
コード例 #7
0
        public OutputDayInfo(OutputDay day, IEnumerable <DayWorship> dayWorships
                             , ScheduleResults scheduleResults, IEnumerable <BusinessConstraint> constraints)
        {
            Day             = day ?? throw new ArgumentNullException(nameof(day));
            ScheduleResults = scheduleResults ?? throw new ArgumentNullException(nameof(scheduleResults));

            if (dayWorships != null)
            {
                _dayWorships = dayWorships.ToList();
            }

            if (constraints != null)
            {
                BrokenConstraints = constraints;
            }
        }
コード例 #8
0
        public static void AddWorship(this OutputDay day, OutputWorshipModel worshipModel, ITypiconSerializer typiconSerializer)
        {
            var w = new OutputWorship()
            {
                OutputDay      = day,
                Order          = day.GetMaxOrder() + 1,
                Time           = worshipModel.Time,
                Name           = new ItemTextStyled(worshipModel.Name),
                AdditionalName = (worshipModel.AdditionalName != null)
                    ? new ItemTextStyled(worshipModel.AdditionalName)
                    : new ItemTextStyled(),
                Definition = (worshipModel.ChildElements.Any())
                    ? typiconSerializer.Serialize(worshipModel.ChildElements)
                    : string.Empty
            };

            day.Worships.Add(w);
        }
コード例 #9
0
        private OutputDay GetOrFillScheduleDay(ScheduleDataCalculatorRequest request, ScheduleHandler handler, OutputDay scheduleDay = null)
        {
            //Формируем данные для обработки
            var response = dataCalculator.Calculate(request);

            var settings = response.Settings;

            handler.Settings = settings;

            settings.RuleContainer.Interpret(handler);

            var container = handler.GetResult();

            if (scheduleDay == null)
            {
                //Sign sign = (settings.Rule is Sign s) ? s : GetTemplateSign(settings.Rule.Template);
                var sign = GetPredefinedTemplate(response.Rule.Template);

                //Если settings.SignNumber определен в ModifiedRule, то назначаем его
                int signNumber = settings.SignNumber ?? sign.Number.Value;

                scheduleDay = new OutputDay
                {
                    //задаем имя дню
                    Name           = nameComposer.Compose(request.Date, response.Rule.Template.Priority, settings.AllWorships),
                    Date           = request.Date,
                    PredefinedSign = sign
                };
            }

            //if (container != null)
            //{
            scheduleDay.Worships.AddRange(container);
            //}

            return(scheduleDay);
        }
コード例 #10
0
        public static async Task UpdateOutputFormAsync(this TypiconDBContext dbContext, OutputDay outputDay)
        {
            var outputDays = dbContext.Set <OutputDay>()
                             .Where(c => c.TypiconId == outputDay.TypiconId && c.Date.Date == outputDay.Date.Date);

            if (outputDays.Any())
            {
                dbContext.Set <OutputDay>().RemoveRange(outputDays);
            }

            dbContext.Set <OutputDay>().Add(outputDay);

            await dbContext.SaveChangesAsync();
        }
コード例 #11
0
 private static int GetMaxOrder(this OutputDay day)
 {
     return((day.Worships.Count != 0) ? day.Worships.Max(c => c.Order) : 0);
 }