Example #1
0
        private BookReading GetPsalm(Psalm psalm)
        {
            BookReading resultReading = null;

            if (StartStihos != null || EndStihos != null)
            {
                var reading = psalm.GetElement();

                resultReading = new BookReading();

                int end = (EndStihos != null && EndStihos < reading.Text.Count) ? (int)EndStihos : reading.Text.Count;

                for (int start = StartStihos ?? 1; start <= end; start++)
                {
                    var stihos = reading.Text.FirstOrDefault(c => c.StihosNumber == start);
                    if (stihos != null)
                    {
                        resultReading.Text.Add(stihos);
                    }
                }
            }
            else
            {
                resultReading = psalm.GetElement();
            }

            return(resultReading);
        }
Example #2
0
        /// <summary>
        /// Возвращает либо существующий Псалом из БД либо новый из Reader-a
        /// </summary>
        /// <param name="psalm"></param>
        /// <returns></returns>
        private Psalm GetPsalm(Psalm psalm)
        {
            var response = Service.Get(new GetPsalmRequest()
            {
                Number = psalm.Number
            });
            var result = response.Psalm ?? psalm;

            result.Definition = GetDefinition(result);

            return(result);
        }
Example #3
0
        protected override void Validate(ITypiconSerializer serializer)
        {
            if (StartStihos.HasValue &&
                EndStihos.HasValue &&
                StartStihos > EndStihos)
            {
                AddBrokenConstraint(new BusinessConstraint("Начальный стих не может иметь значения больше, чем конечный стих."), nameof(PsalmLink));
            }

            if (!Psalm.IsValid(serializer))
            {
                AppendAllBrokenConstraints(Psalm, serializer, nameof(PsalmLink));
            }
        }
Example #4
0
        public void MigratePsalms(IPsalterReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("IPsalterReader in MigratePsalms");
            }

            Psalm currentPsalm = null;

            //IPsalterElement currentElement = null;

            while (reader.Read())
            {
                switch (reader.ElementType)
                {
                case PsalterElementKind.Kathisma:
                    //не нужна- ничего не делаем
                    break;

                case PsalterElementKind.Psalm:
                    //если до этого читали Псалом, то добавляем его в базу
                    if (currentPsalm != null)
                    {
                        InsertOrUpdatePsalm(currentPsalm);
                    }
                    currentPsalm = GetPsalm(reader.Element as Psalm);
                    break;

                case PsalterElementKind.PsalmAnnotation:
                    currentPsalm.GetElement(Serializer).Annotation.Merge(reader.Element as BookStihos);
                    break;

                case PsalterElementKind.PsalmText:
                    currentPsalm.GetElement(Serializer).Text.Merge(reader.Element as BookStihos);
                    break;

                case PsalterElementKind.Slava:
                    //не нужна- ничего не делаем
                    if (currentPsalm != null)
                    {
                        InsertOrUpdatePsalm(currentPsalm);
                    }
                    break;
                }
            }
        }
Example #5
0
        /// <summary>
        /// В случае отсутствия Псалма с таким номером в БД добавляет его
        /// </summary>
        /// <param name="currentPsalm"></param>
        private void InsertOrUpdatePsalm(Psalm currentPsalm)
        {
            var response = Service.Get(new GetPsalmRequest()
            {
                Number = currentPsalm.Number
            });

            currentPsalm.Definition = GetDefinition(currentPsalm);

            if (response.Psalm == null)
            {
                Service.Add(new AddPsalmRequest()
                {
                    Psalm = currentPsalm
                });
            }
            else
            {
                Service.Update(new UpdatePsalmRequest()
                {
                    Psalm = currentPsalm
                });
            }
        }
Example #6
0
 private string GetDefinition(Psalm psalm)
 {
     return(Serializer.Serialize(psalm.GetElement(Serializer) ?? new BookReading()));
 }
 private string GetDefinition(Psalm psalm)
 {
     return(new TypiconSerializer().Serialize(psalm.GetElement() ?? new BookReading()));
 }