Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
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);

            fileReader.FolderPath = Path.Combine(FOLDER_PATH, TYPICON_NAME, "Menology");

            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    = fileReader.Read(n);
                    menologyRule.ModRuleDefinition = fileReader.Read(n, "mod");
                }
                else
                {
                    int lastOrder = menologyRule.DayRuleWorships.Max(c => c.Order);
                    menologyRule.DayRuleWorships.Add(new DayRuleWorship()
                    {
                        DayRule = menologyRule, DayWorship = dayWorship, Order = lastOrder + 1
                    });
                }

                _unitOfWork.SaveChanges();
            }

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