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);
        }
        private TypiconEntity Migrate(User user)
        {
            var typicon = new TypiconEntity()
            {
                Name = new ItemText()
                {
                    Items = new List <ItemTextUnit>()
                    {
                        new ItemTextUnit("cs-ru", "Типикон")
                    }
                },
                DefaultLanguage = DEFAULT_LANGUAGE,
                OwnerId         = user.Id,
                Status          = TypiconStatus.Draft
            };

            _dbContext.Set <TypiconEntity>().Add(typicon);
            Commit();

            var typiconEntity = new TypiconVersion()
            {
                TypiconId     = typicon.Id,
                VersionNumber = 1,
                IsModified    = true
                                //Делаем сразу опубликованную версию
                                //BDate = DateTime.Now
            };

            typicon.Versions.Add(typiconEntity);
            Commit();

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

            int i = 1;

            foreach (ScheduleDBDataSet.ServiceSignsRow row in _sh.DataSet.ServiceSigns.Rows)
            {
                SignMigrator signMigrator = new SignMigrator(row.Number);

                Sign sign = new Sign()
                {
                    //Id = signMigrator.NewId,
                    Priority         = signMigrator.Priority,
                    TypiconVersionId = typiconEntity.Id,
                    //Owner = typiconEntity,
                    IsTemplate        = row.IsTemplate,
                    RuleDefinition    = fileReader.Read(row.Name),
                    ModRuleDefinition = fileReader.Read(row.Name, "mod")
                };
                sign.SignName.AddOrUpdate(DEFAULT_LANGUAGE, row.Name);

                if (signMigrator.Number != null)
                {
                    sign.Number = (int)signMigrator.Number;
                }

                if (signMigrator.TemplateId != null)
                {
                    sign.Template   = typiconEntity.Signs.First(c => c.Number == signMigrator.TemplateId);
                    sign.IsAddition = true;
                }

                typiconEntity.Signs.Add(sign);

                i++;
            }

            Commit();

            MigrateMenologyDaysAndRules(typiconEntity);
            //Commit();

            MigrateTriodionDaysAndRules(typiconEntity);
            Commit();

            MigrateCommonRules(typiconEntity);
            Commit();

            MigrateExplicitRules(typiconEntity);
            Commit();

            MigratePsalms();
            MigrateKathismas(typiconEntity);

            return(typicon);
        }
Example #3
0
        private void Migrate()
        {
            TypiconEntity typiconEntity = new TypiconEntity()
            {
                Name     = "Типикон",
                Settings = new TypiconSettings()
                {
                    DefaultLanguage = "cs-ru",
                    //IsExceptionThrownWhenInvalid = true
                }
            };

            //typiconEntity.RulesFolder = new TypiconFolderEntity() { Name = "Правила", Owner = typiconEntity };

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

            FileReader fileReader = new FileReader(folderPath);

            int i = 1;

            foreach (ScheduleDBDataSet.ServiceSignsRow row in _sh.DataSet.ServiceSigns.Rows)
            {
                //int priority = _signPriorites.ContainsKey(row.Name) ? _signPriorites[row.Name] : row.ID;

                SignMigrator signMigrator = new SignMigrator(row.Number);

                Sign sign = new Sign()
                {
                    //Id = signMigrator.NewId,
                    Name           = row.Name,
                    Priority       = signMigrator.Priority,
                    Owner          = typiconEntity,
                    IsTemplate     = row.IsTemplate,
                    RuleDefinition = fileReader.Read(row.Name),
                    SignName       = new ItemTextStyled()// { StringExpression = row.Name }
                };

                if (signMigrator.Number != null)
                {
                    sign.Number = (int)signMigrator.Number;
                }

                sign.SignName.AddElement("cs-ru", row.Name);

                if (signMigrator.TemplateId != null)
                {
                    sign.Template   = typiconEntity.Signs.First(c => c.Number == signMigrator.TemplateId);
                    sign.IsAddition = true;
                }

                typiconEntity.Signs.Add(sign);

                i++;
            }

            _unitOfWork.Repository <TypiconEntity>().Insert(typiconEntity);

            Commit();

            MigrateMenologyDaysAndRules(typiconEntity);
            MigrateTriodionDaysAndRules(typiconEntity);
            MigrateCommonRules(typiconEntity);

            Commit();

            MigratePsalms();
            //TODO: раскомментировать и исправить. Не работает с EFSQLite
            //MigrateKathismas(typiconEntity);
            Commit();
        }
Example #4
0
        private TypiconEntity Migrate(User user)
        {
            var typicon = new TypiconEntity()
            {
                SystemName      = "Типикон",
                DefaultLanguage = DEFAULT_LANGUAGE,
                OwnerId         = user.Id,
                Status          = TypiconStatus.Draft
            };

            _dbContext.Set <TypiconEntity>().Add(typicon);
            Commit();

            var typiconEntity = new TypiconVersion()
            {
                TypiconId = typicon.Id,
                Name      = new ItemText()
                {
                    Items = new List <ItemTextUnit>()
                    {
                        new ItemTextUnit("cs-ru", "Типикон")
                    }
                },
                Description = new ItemText()
                {
                    Items = new List <ItemTextUnit>()
                    {
                        new ItemTextUnit("cs-ru", "Описание Устава Типикон")
                    }
                },
                VersionNumber    = 1,
                IsModified       = true,
                ScheduleSettings = new ScheduleSettings()
                {
                    IsMonday    = true,
                    IsTuesday   = true,
                    IsWednesday = true,
                    IsThursday  = true,
                    IsFriday    = true,
                    IsSaturday  = true,
                    IsSunday    = true
                }
                //Делаем сразу опубликованную версию
                //BDate = DateTime.Now
            };

            typicon.Versions.Add(typiconEntity);
            Commit();

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

            int i = 1;

            var printImporter = new PrintTemplateImporter(Path.Combine(FOLDER_PATH, TYPICON_NAME, "PrintTemplate"));

            typiconEntity.PrintWeekTemplate = printImporter.GetWeek(typiconEntity);

            foreach (ScheduleDBDataSet.ServiceSignsRow row in _sh.DataSet.ServiceSigns.Rows)
            {
                SignMigrator signMigrator = new SignMigrator(row.Number);

                Sign sign = new Sign()
                {
                    //Id = signMigrator.NewId,
                    Priority         = signMigrator.Priority,
                    TypiconVersionId = typiconEntity.Id,
                    //Owner = typiconEntity,
                    //IsTemplate = row.IsTemplate,
                    RuleDefinition    = fileReader.Read(row.Name),
                    ModRuleDefinition = fileReader.Read(row.Name, "mod")
                };
                sign.SignName.AddOrUpdate(DEFAULT_LANGUAGE, row.Name);

                if (signMigrator.Number != null &&
                    !typiconEntity.PrintDayTemplates
                    .Any(c => c.Number == signMigrator.Number.Value))
                {
                    var day = printImporter.GetDay(signMigrator.Number.Value, signMigrator.Icon, signMigrator.IsRed, signMigrator.Name, typiconEntity);

                    //задаем первому шаблону значение шаблона по умолчанию
                    if (typiconEntity.PrintDayDefaultTemplate == null)
                    {
                        typiconEntity.PrintDayDefaultTemplate = day;
                    }

                    typiconEntity.PrintDayTemplates.Add(day);

                    sign.PrintTemplate = day;
                }

                if (signMigrator.TemplateId != null)
                {
                    sign.Template   = typiconEntity.Signs.First(c => c.PrintTemplate?.Number == signMigrator.TemplateId);
                    sign.IsAddition = true;
                }

                typiconEntity.Signs.Add(sign);

                i++;
            }

            Commit();

            MigrateMenologyDaysAndRules(typiconEntity);
            //Commit();

            MigrateTriodionDaysAndRules(typiconEntity);
            Commit();

            MigrateCommonRules(typiconEntity);
            Commit();

            MigrateExplicitRules(typiconEntity);
            Commit();

            MigratePsalms();
            MigrateKathismas(typiconEntity);

            return(typicon);
        }