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); }
/// <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; }
public RepeatManager(RepeatInfo info, QuranAyah firstAyah, int currentIteration) { if (firstAyah == null) throw new ArgumentNullException("firstAyah"); RepeatInfo = info ?? new RepeatInfo(); Counter = currentIteration; FirstAyah = firstAyah; GenerateLastAyah(); }
public RepeatManager(RepeatInfo info, QuranAyah firstAyah, int currentIteration) { if (firstAyah == null) { throw new ArgumentNullException("firstAyah"); } RepeatInfo = info ?? new RepeatInfo(); Counter = currentIteration; FirstAyah = firstAyah; GenerateLastAyah(); }
/// <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); }
public void EmptyRepeatProducesNoneString() { var repeat = new RepeatInfo(); Assert.Equal("None-0-times", repeat.ToString()); }
public void RepeatToStringMatch(RepeatAmount actAmount, int actCount, string pattern) { var repeat = new RepeatInfo {RepeatAmount = actAmount, RepeatCount = actCount}; Assert.Equal(pattern, repeat.ToString()); }
/// <summary> /// AudioRequest from a formatted string /// </summary> /// <param name="formattedString">[local|streaming]://reciterId?amount=AudioDownloadAmount&currentAyah=1:2&fromAyah=1:2&to=2:1&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"); } }