Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rule">Правило</param>
        /// <param name="text">Текст службы</param>
        /// <returns></returns>
        private RuleHandlerSettings CreateFakeSettings(string rule, string text)
        {
            var menologyRule = new MenologyRule
            {
                RuleDefinition = rule
            };

            var dayWorships = new List <DayWorship>()
            {
                new DayWorship()
                {
                    Definition = text
                }
            };

            var ruleContainer = TestRuleSerializer.Deserialize <RootContainer>(rule);// menologyRule.GetRule<ExecContainer>(TestRuleSerializer.Root);

            return(new RuleHandlerSettings
            {
                Date = DateTime.Today,
                //TypiconRule = menologyRule,
                Menologies = dayWorships,
                RuleContainer = ruleContainer
            });
        }
        public void ExapostilarionRuleTest_FromRealDB()
        {
            var dbContext = TypiconDbContextFactory.Create();

            var typiconEntity = dbContext.Set <TypiconVersion>().First(c => c.Id == 1);

            ServiceSequenceHandler handler = new ServiceSequenceHandler();

            string xml = TestDataXmlReader.GetXmlString("ExapostilarionRuleTest.xml");

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

            MenologyRule rule = typiconEntity.GetMenologyRule(date);

            rule.RuleDefinition = xml;

            handler.Settings.Menologies = rule.DayWorships.ToList();
            handler.Settings.Date       = date;

            OktoikhDay oktoikhDay = DataQueryProcessorFactory.Instance.Process(new OktoikhDayQuery(date));

            handler.Settings.OktoikhDay = oktoikhDay;

            var ruleContainer = TestRuleSerializer.Deserialize <ExapostilarionRule>(xml);

            ruleContainer.Interpret(handler);

            Assert.AreEqual(3, ruleContainer.Structure.Ymnis.Count);
            Assert.IsNotNull(ruleContainer.Structure.Theotokion);
        }
        public void CommonRuleElement_SimplePassing()
        {
            //находим первый попавшийся MenologyRule
            var dbContext = TypiconDbContextFactory.Create();

            var typiconEntity = dbContext.Set <TypiconVersion>().First(c => c.Id == 1);

            MenologyRule           rule    = typiconEntity.MenologyRules[0];
            ServiceSequenceHandler handler = new ServiceSequenceHandler
            {
                Settings = new RuleHandlerSettings()
                {
                    Date = DateTime.Today, TypiconVersionId = 1
                }
            };

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

            var element = TestRuleSerializer.Deserialize <WorshipSequence>(xml);

            element.Interpret(handler);

            var model = handler.ActualWorshipChildElements;

            //WorshipSequenceViewModel model = new WorshipSequenceViewModel(element, handler);

            Assert.AreEqual(30, model.Count);
        }
Exemplo n.º 4
0
        public void CommonRuleElement_SimplePassing()
        {
            //находим первый попавшийся MenologyRule
            EFUnitOfWork _unitOfWork = new EFUnitOfWork();
            //BookStorage.Instance = BookStorageFactory.Create();
            GetTypiconEntityResponse resp          = new TypiconEntityService(_unitOfWork).GetTypiconEntity(1);
            TypiconEntity            typiconEntity = resp.TypiconEntity;
            MenologyRule             rule          = typiconEntity.MenologyRules[0];
            ServiceSequenceHandler   handler       = new ServiceSequenceHandler();

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

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

            var element = TestRuleSerializer.Deserialize <WorshipSequence>(xml);

            element.Interpret(handler);

            var model = handler.GetResult();

            //WorshipSequenceViewModel model = new WorshipSequenceViewModel(element, handler);

            Assert.AreEqual(30, model.FirstOrDefault()?.Count);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void GetEventEntity_Test()
        {
            MenologyRule rule = new MenologyRule();

            rule.RuleDefinition = "new string";

            var evnt = rule.GetDomainEvents().First();

            Assert.IsTrue((evnt as RuleDefinitionChangedEvent).Entity is MenologyRule);
        }
Exemplo n.º 7
0
        public void CheckMenology()
        {
            DayRule rule         = new MenologyRule();
            var     modifiedRule = new ModifiedRule()
            {
                DayRule = rule
            };

            Assert.IsTrue(TypeEqualsOrSubclassOf <MenologyRule> .Is(modifiedRule.DayRule));
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
0
        public void IsCelebrating_Test()
        {
            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = new RuleHandlerSettings()
                {
                    Date = DateTime.Today
                }
            };

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

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


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

            rule.RuleDefinition = xml;

            handler.Settings.Menologies = rule.DayWorships.ToList();

            rule.GetRule <ExecContainer>(Serializer).Interpret(handler);

            var model = handler.ActualWorshipChildElements;

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

            Assert.AreEqual(3, model.Count);

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

            handler.Settings.Menologies = rule.DayWorships.ToList();

            handler.ClearResult();
            rule.GetRule <ExecContainer>(Serializer).Interpret(handler);

            model = handler.ActualWorshipChildElements;

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

            Assert.AreEqual(2, model.Count);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        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());
        }
Exemplo n.º 13
0
        public void IsExists_Test()
        {
            ServiceSequenceHandler handler = new ServiceSequenceHandler();

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

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

            MenologyRule rule = TypiconVersion.GetMenologyRule(date);

            rule.RuleDefinition = xml;

            handler.Settings.Menologies = rule.DayWorships.ToList();
            handler.Settings.Date       = date;

            rule.GetRule <ExecContainer>(Serializer).Interpret(handler);

            var model = handler.ActualWorshipChildElements;

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

            Assert.AreEqual(1, model.Count);

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

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

            handler.Settings.Menologies = rule.DayWorships.ToList();
            handler.Settings.Date       = date;

            rule.GetRule <ExecContainer>(Serializer).Interpret(handler);

            model = handler.ActualWorshipChildElements;

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

            Assert.AreEqual(2, model.Count);
        }
Exemplo n.º 14
0
        public MenologyRule FindMenologyRule(DateTime date)
        {
            //MenologyRule result = (MenologyRule)Rules.AsQueryable().FirstOrDefault(c => ((c is MenologyRule) &&
            //                                    (((MenologyRule)c).Day.GetCurrentDate(date.Year)) == date));

            MenologyRule result = (MenologyRule)ChildElements.FirstOrDefault(c => ((c is MenologyRule) &&
                                                                                   (((MenologyRule)c).Day.GetCurrentDate(date.Year)) == date));

            if (result == null)
            {
                foreach (TypiconFolder folder in Folders)
                {
                    result = folder.FindMenologyRule(date);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 15
0
        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);
        }
        /// <summary>
        /// Из трех правил выбирает главное и составляет коллекцию богослужебных текстов.
        /// Считаем, что ModifiedRule не является ДОПОЛНЕНИЕМ
        /// </summary>
        /// <param name="modifiedRule"></param>
        /// <param name="menologyRule"></param>
        /// <param name="triodionRule"></param>
        /// <returns>Правило для обработки, список текстов богослужений</returns>
        private (DayRule, IEnumerable <DayWorship>) CalculatePriorities(ModifiedRule modifiedRule, MenologyRule menologyRule, TriodionRule triodionRule)
        {
            //Приоритет Минеи
            IDayRule menologyToCompare = SetValues(menologyRule, out int menologyPriority, typeof(MenologyRule));
            //Приоритет Триоди
            IDayRule triodionToCompare = SetValues(triodionRule, out int triodionPriority, typeof(TriodionRule));

            IDayRule SetValues(DayRule dr, out int p, Type t)
            {
                IDayRule r = null;

                p = int.MaxValue;
                if (modifiedRule?.RuleEntity.GetType().Equals(t) == true)
                {
                    r = modifiedRule;
                    p = modifiedRule.Priority;
                }
                else if (dr != null)
                {
                    r = dr;
                    p = dr.Template.Priority;
                }

                return(r);
            };

            var rulesList = new List <IDayRule>();

            int result = menologyPriority - triodionPriority;

            //сравниваем
            switch (result)
            {
            case 1:
            case 0:
                //senior Triodion, junior Menology
                rulesList.Add(triodionToCompare);
                rulesList.Add(menologyToCompare);
                break;

            case -1:
                //senior Menology, junior Triodion
                rulesList.Add(menologyToCompare);
                rulesList.Add(triodionToCompare);
                break;

            default:
                if (result < -1)
                {
                    //только Минея
                    rulesList.Add(menologyToCompare);
                }
                else
                {
                    //только Триодь
                    rulesList.Add(triodionToCompare);
                }
                break;
            }

            //формируем список текстов
            List <DayWorship> dayWorships = new List <DayWorship>();

            rulesList.ForEach(c => dayWorships.AddRange(c.DayWorships));

            //находим главное правило
            var rule = rulesList.First();

            //если это измененное правило, то возвращаем правило, на которое оно указывает
            if (rule is ModifiedRule)
            {
                rule = (rule as ModifiedRule).RuleEntity;
            }

            return(rule as DayRule, dayWorships);
        }
Exemplo n.º 17
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);
                }
            }
        }
Exemplo n.º 18
0
        public void Typicon_TypiconVersion_Creature()
        {
            DayWorship dayService = new DayWorship();

            dayService.WorshipName.AddOrUpdate("cs-ru", "Благовещение");

            MenologyDay menologyday = new MenologyDay()
            {
                Id          = 1,
                DayWorships = new List <DayWorship>()
                {
                    dayService
                },
                Date     = new ItemDate("--04-07"),
                LeapDate = new ItemDate("--04-07")
            };

            TypiconVersion typiconEntity = new TypiconVersion()
            {
                Id = 1,
                //Name = new ItemText()
                //{
                //    Items = new List<ItemTextUnit>() { new ItemTextUnit("cs-ru", "Типикон") }
                //},
                Signs = new List <Sign>()
                {
                    new Sign()
                    {
                        Id = 1
                    }
                }
            };

            //FolderEntity folder = new FolderEntity()
            //{
            //    Name = "Минея",
            //    Folders = new List<FolderEntity>()
            //    {
            //        new FolderEntity()
            //        {
            //            Name = "Благовещение папка",
            //            Rules = new List<RuleEntity>()
            //            {
            //new MenologyRule()
            //{
            //    Id = 1,
            //    //Name = "Благовещение правило",
            //    DayServices = new List<DayService>() { dayService },
            //    Template = typiconEntity.Signs[0]
            //}
            //            }
            //        }
            //    }
            //};

            MenologyRule rule = new MenologyRule()
            {
                Id = 1,
                //Name = "Благовещение правило",
                DayRuleWorships = new List <DayRuleWorship>()
                {
                    new DayRuleWorship()
                    {
                        DayWorship = dayService
                    }
                },
                Template = typiconEntity.Signs[0]
            };

            typiconEntity.MenologyRules.Add(rule);

            Assert.Pass("Your first passing test");
        }
Exemplo n.º 19
0
        private void MigrateMenologyDaysAndRules(TypiconVersion 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(FOLDER_PATH, TYPICON_NAME, "Menology");

            FileReader fileRuleReader = new FileReader(folderRulePath);

            MenologyDay  menologyDay  = null;
            MenologyRule menologyRule = null;

            MigrationDayWorshipFactory factory = new MigrationDayWorshipFactory(FOLDER_PATH);

            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 = _dbContext.Set <MenologyDay>().FirstOrDefault(c => c.LeapDate.Day == d.Day && c.LeapDate.Month == d.Month);
                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),
                        LeapDate = (mineinikRow.IsDateBNull()) ? new ItemDate() : new ItemDate(mineinikRow.DateB.Month, mineinikRow.DateB.Day),
                    };

                    _dbContext.Set <MenologyDay>().Add(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             = new ItemDate(menologyDay.Date),
                        LeapDate         = new ItemDate(menologyDay.LeapDate),
                        TypiconVersionId = typiconEntity.Id,
                        //Owner = typiconEntity,
                        //IsAddition = true,
                        Template = typiconEntity.Signs.First(c => c.SignName.FirstOrDefault(DEFAULT_LANGUAGE).Text == mineinikRow.ServiceSignsRow.Name),
                    };

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

                    typiconEntity.MenologyRules.Add(menologyRule);

                    string n = (!mineinikRow.IsDateBNull())
                                                    ? menologyDay.LeapDate.Expression
                                                    : menologyRule.GetNameByLanguage(DEFAULT_LANGUAGE);

                    //берем xml-правило из файла
                    menologyRule.RuleDefinition    = fileRuleReader.Read(n);
                    menologyRule.ModRuleDefinition = fileRuleReader.Read(n, "mod");
                }
                else
                {
                    int lastOrder = menologyRule.DayRuleWorships.Max(c => c.Order);
                    menologyRule.DayRuleWorships.Add(new DayRuleWorship()
                    {
                        DayRule = menologyRule, DayWorship = dayWorship, Order = lastOrder + 1
                    });
                }
            }

            timer.Stop();
            Console.WriteLine(timer.GetStringValue());
        }
Exemplo n.º 20
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());
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        public void IsTwoSaints_Test()
        {
            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = new RuleHandlerSettings()
                {
                    Date = DateTime.Today
                }
            };

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

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


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

            rule.RuleDefinition = xml;

            handler.Settings.Menologies = rule.DayWorships.ToList();

            rule.GetRule <ExecContainer>(Serializer).Interpret(handler);

            var model = handler.ActualWorshipChildElements;

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

            Assert.AreEqual(1, model.Count);

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

            TriodionRule triodRule = TypiconVersion.GetTriodionRule(-20);

            handler.Settings.Menologies = rule.DayWorships.ToList();
            handler.Settings.Triodions  = triodRule.DayWorships.ToList();

            handler.ClearResult();
            rule.GetRule <ExecContainer>(Serializer).Interpret(handler);

            model = handler.ActualWorshipChildElements;

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

            Assert.AreEqual(1, model.Count);

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

            handler.Settings.Menologies = rule.DayWorships.ToList();

            handler.ClearResult();
            rule.GetRule <ExecContainer>(Serializer).Interpret(handler);

            model = handler.ActualWorshipChildElements;

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

            Assert.AreEqual(2, model.Count);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Из трех правил выбирает главное и составляет коллекцию богослужебных текстов.
        /// Считаем, что ModifiedRule не является ДОПОЛНЕНИЕМ
        /// </summary>
        /// <param name="modifiedRule"></param>
        /// <param name="menologyRule"></param>
        /// <param name="triodionRule"></param>
        /// <returns>Правило для обработки, список текстов богослужений</returns>
        private (DayRule MajorRule, IEnumerable <DayWorship> Menologies, IEnumerable <DayWorship> Triodions, bool ModifiedIsUsed) CalculatePriorities(ModifiedRule modifiedRule, MenologyRule menologyRule, TriodionRule triodionRule)
        {
            //Приоритет Минеи
            IDayRule menologyToCompare = SetValues(menologyRule
                                                   , out int menologyPriority
                                                   , TypeEqualsOrSubclassOf <MenologyRule> .Is(modifiedRule?.DayRule));

            //Приоритет Триоди
            IDayRule triodionToCompare = SetValues(triodionRule
                                                   , out int triodionPriority
                                                   , TypeEqualsOrSubclassOf <TriodionRule> .Is(modifiedRule?.DayRule));

            IDayRule SetValues(DayRule dr, out int p, bool typeEqualsOrSubclassOf)
            {
                IDayRule r = null;

                p = int.MaxValue;

                if (typeEqualsOrSubclassOf)
                {
                    r = modifiedRule;//.DayRule;
                    p = modifiedRule.Priority;
                }
                else if (dr != null)
                {
                    r = dr;
                    p = dr.Template.Priority;
                }

                return(r);
            };

            IDayRule majorRule  = null;
            var      menologies = new List <DayWorship>();
            var      triodions  = new List <DayWorship>();

            int result = menologyPriority - triodionPriority;

            //сравниваем
            switch (result)
            {
            case 1:
            case 0:
                //senior Triodion, junior Menology
                majorRule = triodionToCompare;

                menologies.AddRange(menologyToCompare.DayWorships);
                triodions.AddRange(triodionToCompare.DayWorships);
                break;

            case -1:
                //senior Menology, junior Triodion
                majorRule = menologyToCompare;

                menologies.AddRange(menologyToCompare.DayWorships);
                triodions.AddRange(triodionToCompare.DayWorships);
                break;

            default:
                if (result < -1)
                {
                    //только Минея
                    majorRule = menologyToCompare;

                    menologies.AddRange(menologyToCompare.DayWorships);
                }
                else
                {
                    //только Триодь
                    majorRule = triodionToCompare;

                    triodions.AddRange(triodionToCompare.DayWorships);
                }
                break;
            }

            //Вводим переменную для того, чтобы затем обнулить ссылку на ModifiedRule
            bool modifiedRuleIsUsed = false;

            //если это измененное правило, то возвращаем правило, на которое оно указывает
            if (majorRule is ModifiedRule mr)
            {
                majorRule = mr.DayRule;

                modifiedRuleIsUsed = true;
            }

            return(majorRule as DayRule, menologies, triodions, modifiedRuleIsUsed);
        }
Exemplo n.º 24
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);
                }
            }
        }