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
            });
        }
Example #2
0
        /// <summary>
        /// Write a line in logs file
        /// </summary>
        /// <param name="category">Error category</param>
        /// <param name="mode">Handling mode</param>
        /// <param name="message">Message to write in logs</param>
        public static void WriteInLogs(ErrorCategory category, HandlingMode mode, string message)
        {
            // Create directory if not exists
            Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), _SettingsPath));

            // Get entire path of logs file
            string LogsFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), _SettingsPath, _LogsName);

            // Write message in logs
            using (StreamWriter logs = new StreamWriter(LogsFile, true))
            {
                string msgDate     = DateTime.Now.ToString();
                string msgCategory = $"[{category.ToString()}]";
                string msgMode     = $"{mode.ToString()}".PadRight(6);

                logs.WriteLine($"{msgDate} - {msgCategory} {msgMode} : {message}");
            }
        }
        /// <summary>
        /// Возвращает копию коллеции параметров с указанным HandlingMode
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public static CustomParamsCollection <IRuleCheckParameter> SetModeParam(this CustomParamsCollection <IRuleCheckParameter> parameters, HandlingMode mode)
        {
            //если существует, копируем элементы, иначе - создаем коллекцию
            var list = (parameters != null) ? new CustomParamsCollection <IRuleCheckParameter>(parameters) : new CustomParamsCollection <IRuleCheckParameter>();

            //находим необходимый элемент

            if (parameters.FirstOrDefault(c => c is WorshipRuleCheckModeParameter) is WorshipRuleCheckModeParameter param)
            {
                list.Remove(param);
            }

            param = new WorshipRuleCheckModeParameter()
            {
                Mode = mode
            };
            list.Add(param);

            return(list);
        }
Example #4
0
        public static List <IRuleCheckParameter> SetModeParam(this List <IRuleCheckParameter> parameters, HandlingMode mode)
        {
            WorshipRuleCheckModeParameter param = null;

            if (parameters == null)
            {
                parameters = new List <IRuleCheckParameter>();
            }
            else
            {
                param = parameters.FirstOrDefault(c => c is WorshipRuleCheckModeParameter) as WorshipRuleCheckModeParameter;
            }

            if (param == null)
            {
                param = new WorshipRuleCheckModeParameter();
                parameters.Add(param);
            }

            param.Mode = mode;

            return(parameters);
        }
Example #5
0
        public Result <FilteredOutputDay> GetDay(int typiconId, DateTime date, string language, HandlingMode handlingMode = HandlingMode.AstronomicDay)
        {
            date = date.Date;

            var scheduleDay = _dbContext.GetScheduleDay(typiconId, date, _serializer);

            //нашли сформированный день
            if (scheduleDay.Success)
            {
                return(Result.Ok(scheduleDay.Value.Localize(language)));
            }

            //добавляем задачу на формирование дня
            var version = _dbContext.GetPublishedVersion(typiconId);

            if (version.Failure)
            {
                return(Result.Fail <LocalizedOutputDay>(version.Error));
            }
            else
            {
                //добавляем задание на формирование выходных форм
                _jobs.Create(new CalculateOutputFormWeekJob(typiconId, version.Value.Id, date));

                return(Result.Fail <LocalizedOutputDay>($"Инициировано формирование расписания. Повторите операцию позже."));
            }
        }