示例#1
0
        public void IsExists_Test()
        {
            EFUnitOfWork _unitOfWork = new EFUnitOfWork();
            //BookStorage.Instance = BookStorageFactory.Create();
            GetTypiconEntityResponse resp          = new TypiconEntityService(_unitOfWork).GetTypiconEntity(1);
            TypiconEntity            typiconEntity = resp.TypiconEntity;

            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = new RuleHandlerSettings()
                {
                    Language = LanguageSettingsFactory.Create("cs-ru")
                }
            };

            string     folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData");
            FileReader reader     = new FileReader(folderPath);
            string     xml        = reader.Read("IsExists.xml");

            //Дата --01-16 exists - false
            DateTime date = new DateTime(2017, 01, 16);

            MenologyRule rule = typiconEntity.GetMenologyRule(date);

            rule.RuleDefinition = xml;

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;
            handler.Settings.Date        = date;

            rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            var model = handler.GetResult();

            //EktenisViewModel model = rule.GetRule<EktenisRule>(TestRuleSerializer.Root).CreateViewModel(handler) as EktenisViewModel;

            Assert.AreEqual(1, model.FirstOrDefault()?.Count);

            //Дата --02-09 exists - true
            date = new DateTime(2017, 02, 09);

            rule = typiconEntity.GetMenologyRule(date);
            rule.RuleDefinition = xml;

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;
            handler.Settings.Date        = date;

            rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            model = handler.GetResult();

            //model = rule.GetRule<EktenisRule>(TestRuleSerializer.Root).CreateViewModel(handler) as EktenisViewModel;

            Assert.AreEqual(2, model.FirstOrDefault()?.Count);
        }
示例#2
0
        public void IsCelebrating_Test()
        {
            //находим первый попавшийся MenologyRule
            EFUnitOfWork _unitOfWork = new EFUnitOfWork();
            //BookStorage.Instance = BookStorageFactory.Create();
            GetTypiconEntityResponse resp          = new TypiconEntityService(_unitOfWork).GetTypiconEntity(1);
            TypiconEntity            typiconEntity = resp.TypiconEntity;

            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = new RuleHandlerSettings()
                {
                    Language = LanguageSettingsFactory.Create("cs-ru"), Date = DateTime.Today
                }
            };

            string     folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData");
            FileReader reader     = new FileReader(folderPath);
            string     xml        = reader.Read("IsCelebrating_Simple.xml");

            //Ektenis element = RuleFactory.CreateElement(xml) as Ektenis;


            //находим Праздничное правило
            MenologyRule rule = typiconEntity.GetMenologyRule(new DateTime(2017, 09, 28));

            rule.RuleDefinition = xml;

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;

            rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            var model = handler.GetResult();

            //var model = rule.GetRule<EktenisRule>(TestRuleSerializer.Root).CreateViewModel(handler) as EktenisViewModel;

            Assert.AreEqual(3, model.FirstOrDefault()?.Count);

            //а теперь находим правило НЕ праздничное
            rule = typiconEntity.GetMenologyRule(new DateTime(2017, 10, 15));
            rule.RuleDefinition = xml;

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;

            handler.ClearResult();
            rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            model = handler.GetResult();

            //model = rule.GetRule<EktenisRule>(TestRuleSerializer.Root).CreateViewModel(handler) as EktenisViewModel;

            Assert.AreEqual(2, model.FirstOrDefault()?.Count);
        }
示例#3
0
        private ScheduleDay GetOrFillScheduleDay(GetRuleSettingsRequest request, TypiconEntity typicon,
                                                 ScheduleHandler handler, ScheduleDay scheduleDay = null)
        {
            //заполняем Правила и день Октоиха
            request.MenologyRule = typicon.GetMenologyRule(request.Date);

            int daysFromEaster = ruleSerializer.BookStorage.Easters.GetDaysFromCurrentEaster(request.Date);

            request.TriodionRule = typicon.GetTriodionRule(daysFromEaster);

            request.ModifiedRule = typicon.GetModifiedRuleHighestPriority(request.Date, ruleSerializer);
            request.OktoikhDay   = ruleSerializer.BookStorage.Oktoikh.Get(request.Date);

            //Формируем данные для обработки
            var settings = settingsFactory.Create(request);

            handler.Settings = settings;

            settings.Rule.GetRule(ruleSerializer).Interpret(handler);

            var container = handler.GetResult();

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

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

                //if (request.Date.DayOfWeek == DayOfWeek.Sunday && sign.Priority > 3)
                //{
                //    //TODO: жесткая привязка к номеру знака воскресного дня
                //    signNumber = 8;// SignMigrator.GetOldId(k => k.Value.Name == "Воскресный день");
                //}

                scheduleDay = new ScheduleDay
                {
                    //задаем имя дню
                    Name       = nameComposer.Compose(settings, request.Date),
                    Date       = request.Date,
                    SignNumber = signNumber,
                    SignName   = sign.SignName[settings.Language.Name],
                };
            }

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

            return(scheduleDay);
        }
示例#4
0
        public void DayServiceTest_Working()
        {
            EFUnitOfWork _unitOfWork = new EFUnitOfWork();

            //BookStorage.Instance = BookStorageFactory.Create();

            TypiconEntity typiconEntity = _unitOfWork.Repository <TypiconEntity>().Get(c => c.Name == "Типикон");

            MenologyRule menologyRule = typiconEntity.GetMenologyRule(new DateTime(2017, 09, 28));

            Assert.NotNull(menologyRule.GetRule(TestRuleSerializer.Root));
        }
示例#5
0
        public void KanonasRule_FromDB()
        {
            EFUnitOfWork _unitOfWork = new EFUnitOfWork();
            //BookStorage.Instance = BookStorageFactory.Create();
            GetTypiconEntityResponse resp          = new TypiconEntityService(_unitOfWork).GetTypiconEntity(1);
            TypiconEntity            typiconEntity = resp.TypiconEntity;

            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = new RuleHandlerSettings()
                {
                    Language = LanguageSettingsFactory.Create("cs-ru")
                }
            };

            string     folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData");
            FileReader reader     = new FileReader(folderPath);
            string     xml        = reader.Read("KanonasRuleTest.xml");

            DateTime date = new DateTime(2017, 11, 11);

            MenologyRule rule = typiconEntity.GetMenologyRule(date);

            rule.RuleDefinition = xml;

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;
            handler.Settings.Date        = date;

            var bookStorage = BookStorageFactory.Create();

            OktoikhDay oktoikhDay = bookStorage.Oktoikh.Get(date);

            handler.Settings.OktoikhDay = oktoikhDay;

            //rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            handler.ClearResult();
            KanonasRule kanonasRule = rule.GetRule <KanonasRule>(TestRuleSerializer.Root);

            kanonasRule.Interpret(handler);

            Assert.AreEqual(4, kanonasRule.Kanones.Count());
            //Assert.IsNotNull(kanonasRule.Sedalen);
        }
        public void YmnosStructureRule_FromRealDB()
        {
            EFUnitOfWork _unitOfWork = new EFUnitOfWork();
            //BookStorage.Instance = BookStorageFactory.Create();
            GetTypiconEntityResponse resp          = new TypiconEntityService(_unitOfWork).GetTypiconEntity(1);
            TypiconEntity            typiconEntity = resp.TypiconEntity;

            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = new RuleHandlerSettings()
                {
                    Language = LanguageSettingsFactory.Create("cs-ru")
                }
            };

            string     folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData");
            FileReader reader     = new FileReader(folderPath);
            string     xml        = reader.Read("YmnosStructureRuleTest.xml");

            //Дата --11-09 exists - true
            DateTime date = new DateTime(2017, 11, 09);

            MenologyRule rule = typiconEntity.GetMenologyRule(date);

            rule.RuleDefinition = xml;

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;
            handler.Settings.Date        = date;

            var bookStorage = BookStorageFactory.Create();

            OktoikhDay oktoikhDay = bookStorage.Oktoikh.Get(date);

            handler.Settings.OktoikhDay = oktoikhDay;

            rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            var model = handler.GetResult();

            //SedalenRuleViewModel model = rule.GetRule<SedalenRule>(TestRuleSerializer.Root).CreateViewModel(handler) as SedalenRuleViewModel;

            Assert.AreEqual(3, rule.GetRule <SedalenRule>(TestRuleSerializer.Root).Structure.YmnosStructureCount);
            Assert.Pass(rule.GetRule <SedalenRule>(TestRuleSerializer.Root).Structure.YmnosStructureCount.ToString());
        }
        public void TheotokionRule_FromRealDB()
        {
            EFUnitOfWork _unitOfWork = new EFUnitOfWork();
            //BookStorage.Instance = BookStorageFactory.Create();
            GetTypiconEntityResponse resp          = new TypiconEntityService(_unitOfWork).GetTypiconEntity(1);
            TypiconEntity            typiconEntity = resp.TypiconEntity;

            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = new RuleHandlerSettings()
                {
                    Language = LanguageSettingsFactory.Create("cs-ru")
                }
            };

            string     folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData");
            FileReader reader     = new FileReader(folderPath);
            string     xml        = reader.Read("TheotokionRuleTest.xml");

            //Дата --01-16 exists - false
            DateTime date = new DateTime(2017, 01, 16);

            MenologyRule rule = typiconEntity.GetMenologyRule(date);

            rule.RuleDefinition = xml;

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;
            handler.Settings.Date        = date;

            rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            var model = handler.GetResult();

            //KekragariaRuleViewModel model = rule.GetRule<KekragariaRule>(TestRuleSerializer.Root).CreateViewModel(handler) as KekragariaRuleViewModel;

            Assert.Pass(model.ToString());
            Assert.IsNotNull(model);
        }
示例#8
0
        private void btnTest40mart_Click(object sender, EventArgs e)
        {
            textBoxTesting.Clear();

            var menologyRule = _typiconEntity.GetMenologyRule(dateTimePickerTesting.Value);

            if (menologyRule == null)
            {
                textBoxTesting.AppendText("Правило по заданной дате не найдено.");
                return;
            }

            foreach (EasterItem easterItem in _bookStorage.Easters.GetAll())
            {
                DateTime innerDate = (DateTime.IsLeapYear(easterItem.Date.Year))
                    ? new DateTime(easterItem.Date.Year, menologyRule.DateB.Month, menologyRule.DateB.Day)
                    : new DateTime(easterItem.Date.Year, menologyRule.Date.Month, menologyRule.Date.Day);
                int daysFromEaster = easterItem.Date.Subtract(innerDate).Days;

                textBoxTesting.AppendText(easterItem.Date.Year + " год. " + daysFromEaster + " дней до Пасхи." + Environment.NewLine);
            }
        }
示例#9
0
        private void MigrateMenologyDaysAndRules(TypiconEntity typiconEntity)
        {
            Console.WriteLine("MigrateMenologyDaysAndRules()");

            Timer timer = new Timer();

            timer.Start();

            //TypiconFolderEntity folder = new TypiconFolderEntity() { Name = "Минея" };
            //typiconEntity.RulesFolder.AddFolder(folder);

            //TypiconFolderEntity childFolder = new TypiconFolderEntity() { Name = "Минея 1" };

            //folder.AddFolder(childFolder);

            string folderRulePath = Path.Combine(Properties.Settings.Default.FolderPath, typiconEntity.Name, "Menology");

            FileReader fileRuleReader = new FileReader(folderRulePath);

            MenologyDay  menologyDay  = null;
            MenologyRule menologyRule = null;

            MigrationDayWorshipFactory factory = new MigrationDayWorshipFactory(Properties.Settings.Default.FolderPath);

            foreach (ScheduleDBDataSet.MineinikRow mineinikRow in _sh.DataSet.Mineinik.Rows)
            {
                factory.Initialize(mineinikRow);

                DayWorship dayWorship = factory.Create();

                ItemDate d = (!mineinikRow.IsDateBNull()) ? new ItemDate(mineinikRow.DateB.Month, mineinikRow.DateB.Day) : new ItemDate();

                //menologyDay

                /* Чтобы лишний раз не обращаться к БД,
                 * смотрим, не один и тот же MenologyDay, что и предыдущая строка из Access
                 */
                //if (menologyDay == null || !menologyDay.DateB.Expression.Equals(d.Expression))
                menologyDay = _unitOfWork.Repository <MenologyDay>().Get(c => c.DateB.Expression.Equals(d.Expression));
                if (menologyDay == null)
                {
                    //нет - создаем новый день
                    menologyDay = new MenologyDay()
                    {
                        //Name = mineinikRow.Name,
                        //DayName = XmlHelper.CreateItemTextCollection(
                        //    new CreateItemTextRequest() { Text = mineinikRow.Name, Name = "Name" }),
                        Date  = (mineinikRow.IsDateNull()) ? new ItemDate() : new ItemDate(mineinikRow.Date.Month, mineinikRow.Date.Day),
                        DateB = (mineinikRow.IsDateBNull()) ? new ItemDate() : new ItemDate(mineinikRow.DateB.Month, mineinikRow.DateB.Day),
                    };

                    _unitOfWork.Repository <MenologyDay>().Insert(menologyDay);
                }


                menologyDay.AppendDayService(dayWorship);

                //menologyRule

                /*смотрим, есть ли уже такой объект с заявленной датой
                 * если дата пустая - т.е. праздник переходящий - значит
                 */

                if (!d.IsEmpty)
                {
                    menologyRule = typiconEntity.GetMenologyRule(mineinikRow.DateB);
                }

                if (menologyRule == null || d.IsEmpty)
                {
                    menologyRule = new MenologyRule()
                    {
                        //Name = menologyDay.Name,
                        Date  = menologyDay.Date,
                        DateB = menologyDay.DateB,
                        Owner = typiconEntity,
                        //IsAddition = true,
                        Template = typiconEntity.Signs.First(c => c.SignName["cs-ru"] == mineinikRow.ServiceSignsRow.Name),
                    };

                    menologyRule.DayRuleWorships.Add(new DayRuleWorship()
                    {
                        DayRule = menologyRule, DayWorship = dayWorship
                    });

                    typiconEntity.MenologyRules.Add(menologyRule);

                    //берем xml-правило из файла
                    menologyRule.RuleDefinition = (!mineinikRow.IsDateBNull())
                                                    ? fileRuleReader.Read(menologyDay.DateB.Expression)
                                                    : fileRuleReader.Read(menologyRule.Name);
                }
                else
                {
                    menologyRule.DayRuleWorships.Add(new DayRuleWorship()
                    {
                        DayRule = menologyRule, DayWorship = dayWorship
                    });
                }
            }

            timer.Stop();
            Console.WriteLine(timer.GetStringValue());
        }
示例#10
0
        public void IsTwoSaints_Test()
        {
            EFUnitOfWork _unitOfWork = new EFUnitOfWork();
            //BookStorage.Instance = BookStorageFactory.Create();
            GetTypiconEntityResponse resp          = new TypiconEntityService(_unitOfWork).GetTypiconEntity(1);
            TypiconEntity            typiconEntity = resp.TypiconEntity;

            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = new RuleHandlerSettings()
                {
                    Language = LanguageSettingsFactory.Create("cs-ru"), Date = DateTime.Today
                }
            };

            string     folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData");
            FileReader reader     = new FileReader(folderPath);
            string     xml        = reader.Read("IsTwoSaints_Simple.xml");

            //Ektenis element = RuleFactory.CreateElement(xml) as Ektenis;


            //Минея - попразднество, 1 святой
            MenologyRule rule = typiconEntity.GetMenologyRule(new DateTime(2017, 09, 28));

            rule.RuleDefinition = xml;

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;

            rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            var model = handler.GetResult();

            //EktenisViewModel model = rule.GetRule<EktenisRule>(TestRuleSerializer.Root).CreateViewModel(handler) as EktenisViewModel;

            Assert.AreEqual(1, model.FirstOrDefault()?.Count);

            //Триодь, Минея - 1 святой
            rule = typiconEntity.GetMenologyRule(new DateTime(2017, 3, 16));
            rule.RuleDefinition = xml;

            TriodionRule triodRule = typiconEntity.GetTriodionRule(-20);

            rule.DayWorships.AddRange(triodRule.DayWorships);

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;

            handler.ClearResult();
            rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            model = handler.GetResult();

            //model = rule.GetRule<EktenisRule>(TestRuleSerializer.Root).CreateViewModel(handler) as EktenisViewModel;

            Assert.AreEqual(1, model.FirstOrDefault()?.Count);

            //а теперь находим правило НЕ праздничное, 2 святых
            rule = typiconEntity.GetMenologyRule(new DateTime(2017, 5, 31));
            rule.RuleDefinition = xml;

            handler.Settings.Rule        = rule;
            handler.Settings.DayWorships = rule.DayWorships;

            handler.ClearResult();
            rule.GetRule(TestRuleSerializer.Root).Interpret(handler);

            model = handler.GetResult();

            //model = rule.GetRule<EktenisRule>(TestRuleSerializer.Root).CreateViewModel(handler) as EktenisViewModel;

            Assert.AreEqual(2, model.FirstOrDefault()?.Count);
        }
示例#11
0
        private ModifiedYear CreateModifiedYear(TypiconEntity typicon, DateTime date)
        {
            //По умолчанию добавляем год, пусть он и останется пустым
            ModifiedYear modifiedYear = new ModifiedYear()
            {
                Year = date.Year
            };

            DateTime indexDate = new DateTime(date.Year, 1, 1);

            //формируем список дней для изменения до 1 января будущего года
            DateTime endDate = new DateTime(date.Year + 1, 1, 1);

            while (indexDate != endDate)
            {
                //Menology

                //находим правило для конкретного дня Минеи
                MenologyRule menologyRule = typicon.GetMenologyRule(indexDate);

                if (menologyRule == null)
                {
                    throw new ArgumentNullException("MenologyRule");
                }

                InterpretMenologyRule(menologyRule, indexDate, date.Year);

                indexDate = indexDate.AddDays(1);
            }

            //теперь обрабатываем переходящие минейные праздники
            //у них не должны быть определены даты. так их и найдем

            typicon.MenologyRules.FindAll(c => (c.Date.IsEmpty && c.DateB.IsEmpty)).
            ForEach(a =>
            {
                InterpretMenologyRule(a, date, date.Year);

                //не нашел другого способа, как только два раза вычислять изменяемые дни
                InterpretMenologyRule(a, date.AddYears(1), date.Year);
            });

            //Triodion

            //найти текущую Пасху
            //Для каждого правила выполнять interpret(), где date = текущая Пасха. AddDays(Day.DaysFromEaster)
            DateTime easter = Serializer.BookStorage.Easters.GetCurrentEaster(date.Year);

            typicon.TriodionRules.
            ForEach(a =>
            {
                RuleElement rule = a.GetRule(Serializer);
                if (rule != null)
                {
                    ModificationsRuleHandler handler = new ModificationsRuleHandler(
                        new RuleHandlerSettings(a), date.Year);

                    int i = a.DaysFromEaster;
                    rule.Interpret(easter.AddDays(i), handler);
                }
            });

            return(modifiedYear);

            void InterpretMenologyRule(MenologyRule menologyRule, DateTime dateToInterpret, int year)
            {
                if (menologyRule != null)
                {
                    ModificationsRuleHandler handler = new ModificationsRuleHandler(
                        new RuleHandlerSettings(menologyRule), year);
                    //выполняем его
                    menologyRule.GetRule(Serializer).Interpret(dateToInterpret, handler);
                }
            }
        }
示例#12
0
        private static ModifiedYear CreateModifiedYear(TypiconEntity typicon, DateTime date, IRuleSerializerRoot serializer)
        {
            ModificationsRuleHandler handler = new ModificationsRuleHandler(date.Year);

            DateTime indexDate = new DateTime(date.Year, 1, 1);

            //формируем список дней для изменения до 1 января будущего года
            DateTime endDate = new DateTime(date.Year + 1, 1, 1);

            while (indexDate != endDate)
            {
                //Menology

                //находим правило для конкретного дня Минеи
                MenologyRule menologyRule = typicon.GetMenologyRule(indexDate);

                if (menologyRule == null)
                {
                    throw new ArgumentNullException("MenologyRule");
                }

                InterpretMenologyRule(menologyRule, indexDate, handler);

                indexDate = indexDate.AddDays(1);
            }

            //теперь обрабатываем переходящие минейные праздники
            //у них не должны быть определены даты. так их и найдем

            typicon.MenologyRules.FindAll(c => (c.Date.IsEmpty && c.DateB.IsEmpty)).
            ForEach(a =>
            {
                InterpretMenologyRule(a, date, handler);

                //не нашел другого способа, как только два раза вычислять изменяемые дни
                InterpretMenologyRule(a, date.AddYears(1), handler);
            });

            //Triodion

            //найти текущую Пасху
            //Для каждого правила выполнять interpret(), где date = текущая Пасха. AddDays(Day.DaysFromEaster)
            DateTime easter = serializer.BookStorage.Easters.GetCurrentEaster(date.Year);

            typicon.TriodionRules.
            ForEach(a =>
            {
                handler.Settings.Rule = a;
                handler.Settings.Date = easter.AddDays(a.DaysFromEaster);

                a.GetRule(serializer)?.Interpret(handler);
                //RuleElement rule = a.GetRule(serializer);
                //if (rule != null)
                //{
                //    ModificationsRuleHandler handler = new ModificationsRuleHandler(
                //        new RuleHandlerSettings(a, easter.AddDays(a.DaysFromEaster)), date.Year);

                //    rule.Interpret(handler);
                //}
            });

            return(typicon.ModifiedYears.FirstOrDefault(m => m.Year == date.Year));;

            void InterpretMenologyRule(MenologyRule menologyRule, DateTime dateToInterpret, /*int year, */ ModificationsRuleHandler h)
            {
                if (menologyRule != null)
                {
                    h.Settings.Rule = menologyRule;
                    h.Settings.Date = dateToInterpret;

                    //ModificationsRuleHandler handler = new ModificationsRuleHandler(
                    //    new RuleHandlerSettings(, dateToInterpret), year);
                    //выполняем его
                    menologyRule.GetRule(serializer)?.Interpret(h);
                }
            }
        }