示例#1
0
        public AudioRequest(int reciterId, QuranAyah verse, RepeatInfo repeat, int currentRepeatIteration, AudioDownloadAmount audioDownloadAmount)
        {
            if (verse == null)
                throw new ArgumentNullException("verse");

            if (verse == null || verse.Surah < 1 || verse.Surah > 114)
                throw new ArgumentException("verse");

            this.Reciter = AudioUtils.GetReciterById(reciterId);
            this.AudioDownloadAmount = audioDownloadAmount;
            this.FromAyah = verse;
            this.CurrentAyah = verse;
            this.ToAyah = AudioUtils.GetLastAyahToPlay(verse, audioDownloadAmount);

            if (repeat != null)
            {
                this.RepeatInfo = repeat;
            }
            else
            {
                this.RepeatInfo = new RepeatInfo();
            }

            this.repeatManager = new RepeatManager(this.RepeatInfo, verse, currentRepeatIteration);
        }
示例#2
0
        /// <summary>
        /// Parses repeat string in the format:
        /// [RepeatAmount]-[num]-times
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns></returns>
        public static RepeatInfo FromString(string pattern)
        {
            var repeatInfo = new RepeatInfo {RepeatAmount = RepeatAmount.None, RepeatCount = 0};
            if (!string.IsNullOrWhiteSpace(pattern))
            {
                var splitPattern = pattern.Split('-');
                if (splitPattern.Length == 3)
                {
                    try
                    {
                        repeatInfo.RepeatAmount = (RepeatAmount) Enum.Parse(typeof (RepeatAmount), splitPattern[0]);
                        if (splitPattern[1] == "infinite")
                        {
                            repeatInfo.RepeatCount = int.MaxValue;
                        }
                        else
                        {
                            repeatInfo.RepeatCount = int.Parse(splitPattern[1]);
                        }
                        
                        if (repeatInfo.RepeatAmount == RepeatAmount.None)
                        {
                            repeatInfo.RepeatCount = 0;
                        }
                    }
                    catch
                    {
                        // Ignore
                    }
                }
            }

            return repeatInfo;
        }
示例#3
0
        public RepeatManager(RepeatInfo info, QuranAyah firstAyah, int currentIteration)
        {
            if (firstAyah == null)
                throw new ArgumentNullException("firstAyah");

            RepeatInfo = info ?? new RepeatInfo();

            Counter = currentIteration;

            FirstAyah = firstAyah;
            GenerateLastAyah();
        }
示例#4
0
        public RepeatManager(RepeatInfo info, QuranAyah firstAyah, int currentIteration)
        {
            if (firstAyah == null)
            {
                throw new ArgumentNullException("firstAyah");
            }

            RepeatInfo = info ?? new RepeatInfo();

            Counter = currentIteration;

            FirstAyah = firstAyah;
            GenerateLastAyah();
        }
示例#5
0
        /// <summary>
        /// Parses repeat string in the format:
        /// [RepeatAmount]-[num]-times
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns></returns>
        public static RepeatInfo FromString(string pattern)
        {
            var repeatInfo = new RepeatInfo {
                RepeatAmount = RepeatAmount.None, RepeatCount = 0
            };

            if (!string.IsNullOrWhiteSpace(pattern))
            {
                var splitPattern = pattern.Split('-');
                if (splitPattern.Length == 3)
                {
                    try
                    {
                        repeatInfo.RepeatAmount = (RepeatAmount)Enum.Parse(typeof(RepeatAmount), splitPattern[0]);
                        if (splitPattern[1] == "infinite")
                        {
                            repeatInfo.RepeatCount = int.MaxValue;
                        }
                        else
                        {
                            repeatInfo.RepeatCount = int.Parse(splitPattern[1]);
                        }

                        if (repeatInfo.RepeatAmount == RepeatAmount.None)
                        {
                            repeatInfo.RepeatCount = 0;
                        }
                    }
                    catch
                    {
                        // Ignore
                    }
                }
            }

            return(repeatInfo);
        }
示例#6
0
 public void EmptyRepeatProducesNoneString()
 {
     var repeat = new RepeatInfo();
     Assert.Equal("None-0-times", repeat.ToString());
 }
示例#7
0
 public void RepeatToStringMatch(RepeatAmount actAmount, int actCount, string pattern)
 {
     var repeat = new RepeatInfo {RepeatAmount = actAmount, RepeatCount = actCount};
     Assert.Equal(pattern, repeat.ToString());
 }
示例#8
0
        /// <summary>
        /// AudioRequest from a formatted string
        /// </summary>
        /// <param name="formattedString">[local|streaming]://reciterId?amount=AudioDownloadAmount&amp;currentAyah=1:2&amp;fromAyah=1:2&amp;to=2:1&amp;repeat=xxx;currentRepeat=2</param>
        public AudioRequest(string formattedString)
        {
            if (string.IsNullOrEmpty(formattedString))
                throw new ArgumentNullException("formattedString");

            try
            {
                Uri patternAsUri = new Uri(formattedString);
                if (patternAsUri.Scheme.Equals("local", StringComparison.OrdinalIgnoreCase))
                    IsStreaming = false;
                else if (patternAsUri.Scheme.Equals("streaming", StringComparison.OrdinalIgnoreCase))
                    IsStreaming = true;
                else
                    throw new ArgumentException("scheme");

                this.Reciter = AudioUtils.GetReciterById(int.Parse(patternAsUri.Host));

                var splitQueryString = patternAsUri.Query.Split(new char[] { '?', '&' });

                int currentRepeatIteration = 0;

                foreach (var part in splitQueryString)
                {
                    var splitPart = part.Split('=');
                    if (splitPart[0].Equals("amount", StringComparison.OrdinalIgnoreCase))
                    {
                        this.AudioDownloadAmount =
                            (AudioDownloadAmount) Enum.Parse(typeof (AudioDownloadAmount), splitPart[1]);
                    }
                    else if (splitPart[0].Equals("currentAyah", StringComparison.OrdinalIgnoreCase))
                    {
                        this.CurrentAyah = QuranAyah.FromString(splitPart[1]);
                    }
                    else if (splitPart[0].Equals("fromAyah", StringComparison.OrdinalIgnoreCase))
                    {
                        this.FromAyah = QuranAyah.FromString(splitPart[1]);
                    }
                    else if (splitPart[0].Equals("toAyah", StringComparison.OrdinalIgnoreCase))
                    {
                        this.ToAyah = QuranAyah.FromString(splitPart[1]);
                    }
                    else if (splitPart[0].Equals("repeat", StringComparison.OrdinalIgnoreCase))
                    {
                        this.RepeatInfo = RepeatInfo.FromString(splitPart[1]);
                    }
                    else if (splitPart[0].Equals("currentRepeat", StringComparison.OrdinalIgnoreCase))
                    {
                        int.TryParse(splitPart[1], out currentRepeatIteration);
                    }
                }

                if (this.CurrentAyah == null)
                    this.CurrentAyah = this.FromAyah;

                this.repeatManager = new RepeatManager(this.RepeatInfo, this.FromAyah, currentRepeatIteration);
            }
            catch
            {
                throw new ArgumentException("formattedString");
            }
        }