public string Compose(RuleHandlerSettings settings, DateTime date)
        {
            //находим самое последнее правило - добавление
            while (settings.Addition != null)
            {
                settings = settings.Addition;
            }

            if (settings.DayWorships == null || settings.DayWorships.Count() == 0)
            {
                return(string.Empty);
            }

            string result = "";

            DayWorship seniorService = settings.DayWorships[0];

            //собираем все имена текстов, кроме главного
            if (settings.DayWorships.Count > 1)
            {
                for (int i = 1; i < settings.DayWorships.Count; i++)
                {
                    result += settings.DayWorships[i].WorshipName[settings.Language.Name] + " ";
                }
            }

            //а теперь разбираемся с главным

            string s = seniorService.WorshipName[settings.Language.Name];

            if (date.DayOfWeek != DayOfWeek.Sunday ||
                (date.DayOfWeek == DayOfWeek.Sunday &&
                 (seniorService.UseFullName || seniorService.WorshipShortName.IsEmpty)))
            {
                result = $"{s} {result}";
            }

            int priority = (settings.Rule is Sign sign) ? sign.Priority : settings.Rule.Template.Priority;

            if (/*(settings.Rule is MenologyRule)
                 * && */(date.DayOfWeek == DayOfWeek.Sunday) &&
                (priority > 1))
            {
                //Если Триоди нет и воскресенье, находим название Недели из Октоиха
                //и добавляем название Недели в начало Name

                //Если имеется короткое название, то добавляем только его

                result = oktoikhContext.GetSundayName(date, settings.Language.Name,
                                                      GetShortName(settings.DayWorships, settings.Language.Name)) + " " + result;

                //жестко задаем воскресный день
                //handlerRequest.Rule = inputRequest.TypiconEntity.Settings.TemplateSunday;
            }

            return(result);
        }
        public void DayWorshipLoading_ItemTexts()
        {
            string path       = Path.Combine(TestContext.CurrentContext.TestDirectory, @"FileName=Data\SQLiteDB.db");
            var    context    = new SQLiteDBContext(path);
            var    unitOfWork = new UnitOfWork(context, new RepositoryFactory(context));

            //TODO: переделать
            DayWorship entity = null;// unitOfWork.Repository<DayWorship>().Get(c => c.Id == 155);

            Assert.IsFalse(entity.WorshipName.IsEmpty);
            Assert.Pass(entity.WorshipName.StringExpression);
        }
Exemple #3
0
        public void LinkPropertiesTest()
        {
            DayWorship dayWorship = new DayWorship();

            SetNullObject(dayWorship);

            Assert.IsNotNull(dayWorship);

            void SetNullObject(DayWorship w)
            {
                w = null;
            }
        }
Exemple #4
0
        public void MigrationDayServiceFactory_Sample()
        {
            ScheduleHandler sh = new ScheduleHandler("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\data\\ScheduleDB.mdb;");

            ScheduleDBDataSet.MineinikRow row = sh.DataSet.Mineinik.FirstOrDefault();

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

            factory.Initialize(row);

            DayWorship dayService = factory.Create();

            Assert.IsNotEmpty(dayService.Definition);
        }
        public ItemText Compose(DateTime date, int seniorRulePriority, IReadOnlyList <DayWorship> dayWorships)
        {
            var result = new ItemText();

            if (dayWorships == null || dayWorships.Count == 0)
            {
                return(result);
            }

            //собираем все имена текстов, кроме главного
            if (dayWorships.Count > 1)
            {
                for (int i = 1; i < dayWorships.Count; i++)
                {
                    result.Merge(dayWorships[i].WorshipName);
                }
            }

            //а теперь разбираемся с главным
            DayWorship seniorService = dayWorships.First();
            var        s             = seniorService.WorshipName;

            if (date.DayOfWeek != DayOfWeek.Sunday ||
                (date.DayOfWeek == DayOfWeek.Sunday &&
                 (seniorService.UseFullName || seniorService.WorshipShortName.IsEmpty)))
            {
                result = new ItemText(seniorService.WorshipName).Merge(result);
            }

            //Воскресный день

            if ((date.DayOfWeek == DayOfWeek.Sunday) && (seniorRulePriority > 1))
            {
                //Если Триоди нет и воскресенье, находим название Недели из Октоиха
                //и добавляем название Недели в начало Name

                //Если имеется короткое название, то добавляем только его
                var shortName = GetShortName(dayWorships);

                var sundayName = queryProcessor.Process(new SundayNameQuery(date, shortName));

                result = sundayName.Merge(result);
            }

            return(result);
        }
        private void EditParent(DayWorship worship, int daysFromEaster)
        {
            var parent = worship.Parent as TriodionDay;

            if (parent.DaysFromEaster != daysFromEaster)
            {
                //значит ищем TriodionDay и задаем его как Parent для worship
                //или же создаем новый
                var newParent = DbContext.Set <TriodionDay>()
                                .FirstOrDefault(c => c.DaysFromEaster == daysFromEaster)
                                ?? new TriodionDay()
                {
                    DaysFromEaster = daysFromEaster
                };

                worship.Parent = newParent;
            }
        }
        private void EditParent(DayWorship worship, DateTime?leapDate)
        {
            //MenologyDay
            ItemDate date = (leapDate != null)
                ? new ItemDate(leapDate.Value.Month, leapDate.Value.Day)
                : new ItemDate();

            var parent = worship.Parent as MenologyDay;

            if (parent.LeapDate.ToString() != date.ToString())
            {
                //значит ищем MenologyDay и задаем его как Parent для worship
                var newParent = DbContext.Set <MenologyDay>()
                                .FirstOrDefault(c => c.LeapDate.Day == date.Day && c.LeapDate.Month == date.Month);

                worship.Parent = newParent;
            }
        }
Exemple #8
0
        public DayWorship Create()
        {
            if (_row == null)
            {
                throw new ArgumentNullException("ScheduleDBDataSet.MineinikRow");
            }

            DayWorship dayService = new DayWorship()
            {
                //WorshipName = new ItemTextStyled()
            };

            //наполняем содержимое текста службы
            dayService.WorshipName.AddOrUpdate("cs-ru", _row.Name);
            dayService.IsCelebrating = !_row.IsIsCelebratingNull() ? _row.IsCelebrating : false;
            dayService.UseFullName   = !_row.IsUseFullNameNull() ? _row.UseFullName : false;

            if (!_row.IsShortNameNull() && !string.IsNullOrEmpty(_row.ShortName))
            {
                //dayService.WorshipShortName = new ItemTextStyled();
                dayService.WorshipShortName.AddOrUpdate("cs-ru", _row.ShortName);
            }

            string fileName = (!_row.IsDateBNull()) ? new ItemDate(_row.DateB.Month, _row.DateB.Day).Expression + "." + _row.Name : _row.Name;

            //сначала ищем в папке Menology в надежде, что текст определен (как в последствии и должно быть)
            _fileReader.FolderPath = Path.Combine(_folderPath, "Menology");

            string definition = _fileReader.Read(fileName);

            if (string.IsNullOrEmpty(definition))
            {
                //Если его мы не находим, то заменяем текстом по умолчанию, исходя из знака службы
                _fileReader.FolderPath = Path.Combine(_folderPath, "Templates");
                fileName   = SignMigrator.Instance(_row.ServiceSignsRow.Number).MajorTemplateName;
                definition = TransformDefinition(_fileReader.Read(fileName), _row.Name, fileName);
            }

            dayService.Definition = definition;

            return(dayService);
        }
Exemple #9
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());
        }
        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");
        }
Exemple #11
0
        private void MigrateTriodionDaysAndRules(TypiconVersion typiconEntity)
        {
            Console.WriteLine("MigrateTriodionDaysAndRules()");

            Timer timer = new Timer();

            timer.Start();

            //TypiconFolderEntity folder = new TypiconFolderEntity() { Name = "Триодь" };

            //typiconEntity.RulesFolder.AddFolder(folder);

            foreach (ScheduleDBDataSet.TriodionRow row in _sh.DataSet.Triodion.Rows)
            {
                //CreateItemTextRequest req = new CreateItemTextRequest();
                //req.Text = row.Name;
                //req.Name = "Name1";
                //req.Style.IsBold = row.IsNameBold;
                //ItemTextCollection itemTextCol = XmlHelper.CreateItemTextCollection(req);

                DayWorship dayWorship = new DayWorship()
                {
                    WorshipName = new ItemTextStyled()
                };
                dayWorship.WorshipName.IsBold = row.IsNameBold;
                dayWorship.WorshipName.AddOrUpdate(DEFAULT_LANGUAGE, row.Name);

                //DayWorship dayWorship = new DayWorship()
                //{
                //    WorshipName = new ItemFakeText() { StringExpression = row.Name }
                //};

                TriodionDay day = new TriodionDay()
                {
                    //Name = row.Name,
                    //DayName = itemTextCol,
                    DaysFromEaster = (int)row.DayFromEaster,
                };

                day.AppendDayService(dayWorship);
                //day.Sign = _dbContext.Set<Sign>().Get(c => c.Id == row.SignID);

                _dbContext.Set <TriodionDay>().Add(day);

                string folderPath = Path.Combine(FOLDER_PATH, TYPICON_NAME, "Triodion");

                FileReader fileReader = new FileReader(folderPath);

                TriodionRule rule = new TriodionRule()
                {
                    //Name = day.Name,
                    DaysFromEaster   = day.DaysFromEaster,
                    TypiconVersionId = typiconEntity.Id,
                    //Owner = typiconEntity,
                    //IsAddition = true,
                    Template          = typiconEntity.Signs.First(c => c.SignName.FirstOrDefault(DEFAULT_LANGUAGE).Text == row.ServiceSignsRow.Name),
                    RuleDefinition    = fileReader.Read(row.DayFromEaster.ToString()),
                    ModRuleDefinition = fileReader.Read(row.DayFromEaster.ToString(), "mod")
                };
                rule.DayRuleWorships = new List <DayRuleWorship>()
                {
                    new DayRuleWorship()
                    {
                        DayRule = rule, DayWorship = dayWorship, Order = 1
                    }
                };

                //folder.AddRule(rule);
                typiconEntity.TriodionRules.Add(rule);
            }

            timer.Stop();
            Console.WriteLine(timer.GetStringValue());

            //_unitOfWork.Commit();
        }
Exemple #12
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());
        }
Exemple #13
0
        private void MigrateTriodionDaysAndRules(TypiconEntity typiconEntity)
        {
            Console.WriteLine("MigrateTriodionDaysAndRules()");

            Timer timer = new Timer();

            timer.Start();

            //TypiconFolderEntity folder = new TypiconFolderEntity() { Name = "Триодь" };

            //typiconEntity.RulesFolder.AddFolder(folder);

            foreach (ScheduleDBDataSet.TriodionRow row in _sh.DataSet.Triodion.Rows)
            {
                //CreateItemTextRequest req = new CreateItemTextRequest();
                //req.Text = row.Name;
                //req.Name = "Name1";
                //req.Style.IsBold = row.IsNameBold;
                //ItemTextCollection itemTextCol = XmlHelper.CreateItemTextCollection(req);

                DayWorship dayWorship = new DayWorship()
                {
                    WorshipName = new ItemTextStyled()
                };
                dayWorship.WorshipName.Style.IsBold = row.IsNameBold;
                dayWorship.WorshipName.AddElement("cs-ru", row.Name);

                //DayWorship dayWorship = new DayWorship()
                //{
                //    WorshipName = new ItemFakeText() { StringExpression = row.Name }
                //};

                TriodionDay day = new TriodionDay()
                {
                    //Name = row.Name,
                    //DayName = itemTextCol,
                    DaysFromEaster = (int)row.DayFromEaster,
                };

                day.AppendDayService(dayWorship);
                //day.Sign = _unitOfWork.Repository<Sign>().Get(c => c.Id == row.SignID);

                _unitOfWork.Repository <TriodionDay>().Insert(day);

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

                FileReader fileReader = new FileReader(folderPath);

                TriodionRule rule = new TriodionRule()
                {
                    //Name = day.Name,
                    DaysFromEaster = day.DaysFromEaster,
                    Owner          = typiconEntity,
                    //IsAddition = true,
                    Template       = typiconEntity.Signs.First(c => c.SignName["cs-ru"] == row.ServiceSignsRow.Name),
                    RuleDefinition = fileReader.Read(row.DayFromEaster.ToString()),
                };
                rule.DayRuleWorships = new List <DayRuleWorship>()
                {
                    new DayRuleWorship()
                    {
                        DayRule = rule, DayWorship = dayWorship
                    }
                };

                //folder.AddRule(rule);
                typiconEntity.TriodionRules.Add(rule);
            }

            timer.Stop();
            Console.WriteLine(timer.GetStringValue());

            //_unitOfWork.Commit();
        }
Exemple #14
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());
        }