Пример #1
0
        public void MenologyDayLoading_ItemText_and_Dates()
        {
            string path       = Path.Combine(TestContext.CurrentContext.TestDirectory, @"FileName=Data\SQLiteDB.db");
            var    context    = new SQLiteDBContext(path);
            var    unitOfWork = new UnitOfWork(context, new RepositoryFactory(context));

            MenologyDay entity = unitOfWork.Repository <MenologyDay>().GetAll().FirstOrDefault();

            Assert.IsFalse(entity.Date.IsEmpty);
            Assert.IsFalse(entity.DateB.IsEmpty);
        }
Пример #2
0
        public async Task <Result> ExecuteAsync(CreateMenologyDayCommand command)
        {
            MenologyDay parent = FindParent(command.LeapDate);

            var obj = new DayWorship()
            {
                Parent           = parent,
                WorshipName      = new ItemTextStyled(new ItemTextUnit(CommonConstants.DefaultLanguage, command.Name)),
                WorshipShortName = new ItemText(new ItemTextUnit(CommonConstants.DefaultLanguage, command.ShortName)),
                IsCelebrating    = command.IsCelebrating,
                UseFullName      = command.UseFullName,
                Definition       = command.Definition
            };

            DbContext.Set <DayWorship>().Add(obj);

            await DbContext.SaveChangesAsync();

            return(Result.Ok());
        }
Пример #3
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");
        }
Пример #4
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());
        }
Пример #5
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());
        }