Beispiel #1
0
        public Ymnos(Ymnos source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("Ymnos");
            }

            //ElementName = string.Copy(source.ElementName);
            source.Stihoi.ForEach(c => Stihoi.Add(new ItemText(c)));
            Text       = new ItemText(source.Text.StringExpression);
            Kind       = source.Kind;
            Annotation = (source.Annotation != null) ? new ItemText(source.Annotation) : null;
        }
Beispiel #2
0
        /// <summary>
        /// Возвращает коллекцию богослужебных текстов
        /// </summary>
        /// <param name="count">Количество. Если = 0, то выдаем все без фильтрации</param>
        /// <param name="startFrom">стартовый индекс (1 - ориентированный)</param>
        /// <returns></returns>
        public YmnosStructure GetYmnosStructure(int count, int startFrom)
        {
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            if (startFrom < 1 || startFrom > YmnosStructureCount)
            {
                throw new ArgumentOutOfRangeException("startFrom");
            }

            ThrowExceptionIfInvalid();

            if (count == 0)
            {
                //выдаем все без фильтрации
                YmnosStructure result = new YmnosStructure();
                foreach (YmnosGroup group in Groups)
                {
                    result.Groups.Add(new YmnosGroup(group));
                }
                return(result);
            }

            YmnosStructure ymnis = new YmnosStructure();

            /*если заявленное количество больше того, что есть, выдаем с повторами
             * например: 8 = 3 3 2
             *           10= 4 4 3
             *
             */
            //if (count > YmnosStructureCount)
            //{
            int appendedCount = 0;

            int i = startFrom - 1;

            YmnosGroup lastGroup = null;

            while (appendedCount < count)
            {
                //округляем в большую сторону результат деления count на YmnosStructureCount
                //в результате получаем, сколько раз необходимо повторять песнопение
                int b = (int)Math.Ceiling((double)(count - appendedCount) / (YmnosStructureCount - i));

                YmnosGroup groupToAdd = this[i];

                if (lastGroup == null || !lastGroup.Equals(groupToAdd))
                {
                    ymnis.Groups.Add(groupToAdd);
                    lastGroup = groupToAdd;
                    appendedCount++;
                    b--;
                }

                Ymnos ymnosToAdd = groupToAdd.Ymnis[0];

                while (b > 0)
                {
                    lastGroup.Ymnis.Add(new Ymnos(ymnosToAdd));

                    b--;
                    appendedCount++;
                }

                i++;
            }
            //}

            return(ymnis);
        }