public List <Recipe> SortListBySettings(List <Recipe> recipes, FindSettings settings) { if (recipes == null || settings == null) { throw new ArgumentNullException(); } if (recipes.Count == 0) { throw new ArgumentException("Not found"); } if (recipes.Count == 1) { return(recipes); } if (settings.SortedBy == "name") { return(SortedByName(recipes, settings)); } if (settings.SortedBy == "nutritional value") { return(SorterByNutritionalValue(recipes, settings)); } return(recipes); }
private List <Recipe> SortedByName(List <Recipe> recipes, FindSettings settings) { if (settings.IsAsc) { return(recipes.OrderBy(x => x.Name).ToList()); } return(recipes.OrderByDescending(x => x.Name).ToList()); }
private List <Recipe> SorterByNutritionalValue(List <Recipe> recipes, FindSettings settings) { if (settings.IsAsc) { return(recipes.OrderBy(x => x.NutritionalValue.GetCalories()).ToList()); } return(recipes.OrderByDescending(x => x.NutritionalValue.GetCalories()).ToList()); }
public RecipeMenu() { _recipeService = new RecipeService(); _findSettings = new FindSettings { IsAsc = true, SortedBy = "name" }; }
public List <Recipe> GetObjects(string name, FindSettings settings) { if (name == null) { throw new ArgumentNullException(); } if (name == "") { return(UseFilter(_recipes, settings).ToList()); } return(UseFilter(_recipes.Where(x => x.Name.ToLower().Contains(name.ToLower())).ToList(), settings).ToList()); }
private IEnumerable <Recipe> UseFilter(List <Recipe> recipes, FindSettings settings) { if (settings?.FilterValue != null) { if (settings.IsMore) { return(recipes.Where(x => x.NutritionalValue.CompareTo(settings.FilterValue) == 1)); } return(recipes.Where(x => x.NutritionalValue.CompareTo(settings.FilterValue) == -1)); } return(recipes); }
public void Initialize(AppSettings appSettings) { string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); this.Window = new WindowSettings(); this.View = new ViewSettings(); this.CommonDirectoryPath = folderPath; this.TextDirectoryPath = folderPath; this.KanaDirectoryPath = folderPath; this.WaveDirectoryPath = folderPath; this.TextFormat = new TextFormatSettings(); this.Find = new FindSettings(); this.VoiceSamplePerSec = AppModeUtil.CheckSupport(appSettings.AppMode, AppMode.MicroVoice) ? 0x3e80 : 0x5622; if (appSettings.Function.UseConstVoiceDic) { this._constDbsPath = appSettings.Function.ConstVoiceDicPath; } else { this._constDbsPath = ""; this.DbsPath = Path.Combine(Directory.GetParent(Application.StartupPath).FullName, "voice"); } if (appSettings.Function.UseConstLangDic) { this._constLangPath = appSettings.Function.ConstLangDicPath; } else { this._constLangPath = ""; this.LangPath = Path.Combine(Application.StartupPath, AppModeUtil.CheckSupport(appSettings.AppMode, AppMode.MicroLang) ? @"lang\normal" : "lang"); } this.SoundOutput = new SoundOutputSettings(this.VoiceSamplePerSec); this.KanaMode = KanaFormat.AIKANA; this.IgnoredVoiceNames = new List <string>(); this.SelectedVoiceName = ""; this.UserDic = new UserDicSettings(appSettings); this.MasterVolume = 1f; this.BeginPause = 0; this.TermPause = 0; this.HandleNewLineAsSentenceEnd = true; this.UseCommonVoiceSettings = true; this.CommonVoice = new VoiceSettings(); this.Voice = new List <VoiceSettings>(); this.Jeita = new JeitaSettings(); }
public List <Recipe> GetByIngredient(string searchStr, FindSettings settings) { if (searchStr == null) { throw new ArgumentNullException(); } if (_recipes.Count == 0) { throw new NullReferenceException("Recipes list is empty!"); } if (searchStr == "") { return(UseFilter(_recipes.Where(x => x.Ingredients != null && x.Ingredients.Count != 0).ToList(), settings).ToList()); } return(UseFilter(_recipes?.Where(x => x.Ingredients != null && x.Ingredients.Exists(y => y.Name .ToLower().Contains(searchStr.ToLower()))).ToList(), settings).ToList()); }
/// <summary> /// Finds every occourance of a word and returns a list of FindResults /// </summary> /// <param name="toFind">The string you want to find.</param> /// <param name="heapOfText">The text which will be searched</param> /// <returns></returns> public static List <FindResult> FindTextOccurrences(this string heapOfText, string toFind, FindSettings settings) { if (string.IsNullOrEmpty(heapOfText)) { return(null); } string heap = heapOfText; string tofind = toFind; switch (settings) { case FindSettings.CaseSensitive: heap = heapOfText; tofind = toFind; break; case FindSettings.None: heap = heapOfText.ToLower(); tofind = toFind.ToLower(); break; } List <FindResult> indexes = new List <FindResult>(); try { for (int index = 0; ; index += tofind.Length) { try { index = heap.IndexOf(tofind, index); if (index == -1) { return(indexes); } FindResult fr = new FindResult( index, index + tofind.Length, heap.GetRegionOfText(index - 1, index + tofind.Length, 5, 5)); indexes.Add(fr); } catch { return(indexes); } } } catch { return(indexes); } }
/// <summary> /// Finds every occourance of a word and returns a list of FindResults /// </summary> /// <param name="toFind">The string you want to find.</param> /// <param name="heapOfText">The text which will be searched</param> /// <returns></returns> public static List <FindResult> FindTextOccurrences(this string heapOfText, string toFind, FindSettings settings) { if (heapOfText.IsEmpty()) { return(null); } string heapText = heapOfText; string tofind = toFind; bool matchWholeWord = false; if ((settings & FindSettings.MatchCase) == FindSettings.MatchCase) { heapText = heapOfText; tofind = toFind; } else if ((settings & FindSettings.None) == FindSettings.None) { heapText = heapOfText.ToLower(); tofind = toFind.ToLower(); } if ((settings & FindSettings.MatchWholeWord) == FindSettings.MatchWholeWord) { matchWholeWord = true; } List <FindResult> indexes = new List <FindResult>(); try { for (int index = 0; ; index += tofind.Length) { try { index = heapText.CustomIndexOf(tofind, index, matchWholeWord); if (index == -1) { return(indexes); } FindResult fr = new FindResult( index, index + tofind.Length); indexes.Add(fr); } catch { return(indexes); } } } catch { return(indexes); } }
public bool Validate(AppSettings appSettings) { bool flag = false; string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); if (this.Window == null) { this.Window = new WindowSettings(); flag = true; } if (this.View == null) { this.View = new ViewSettings(); flag = true; } if (this.CommonDirectoryPath == null) { this.CommonDirectoryPath = folderPath; } if (this.TextDirectoryPath == null) { this.TextDirectoryPath = folderPath; } if (this.KanaDirectoryPath == null) { this.KanaDirectoryPath = folderPath; } if (this.WaveDirectoryPath == null) { this.WaveDirectoryPath = folderPath; } if (this.TextFormat == null) { this.TextFormat = new TextFormatSettings(); flag = true; } else { try { new Font(this.TextFormat.FontFamilyName, this.TextFormat.Size, this.TextFormat.Style, this.TextFormat.Unit, this.TextFormat.GdiCharSet, this.TextFormat.GdiVerticalFont); } catch { this.TextFormat = new TextFormatSettings(); flag = true; } } if (this.Find == null) { this.Find = new FindSettings(); flag = true; } else { if ((this.Find.Target != FindSettings.TargetField.Text) && (this.Find.Target != FindSettings.TargetField.Yomi)) { this.Find.Target = FindSettings.TargetField.Text; flag = true; } if ((this.Find.Logic != FindSettings.LogicalCondition.And) && (this.Find.Logic != FindSettings.LogicalCondition.Or)) { this.Find.Logic = FindSettings.LogicalCondition.And; flag = true; } if (((this.Find.Match != FindSettings.MatchingCondition.Forward) && (this.Find.Match != FindSettings.MatchingCondition.Backward)) && (this.Find.Match != FindSettings.MatchingCondition.Partial)) { this.Find.Match = FindSettings.MatchingCondition.Partial; flag = true; } if ((this.Find.PageSize < 1) || (this.Find.PageSize > 0xea60)) { this.Find.PageSize = 100; flag = true; } } if ((this.VoiceSamplePerSec != 0x5622) && (this.VoiceSamplePerSec != 0x3e80)) { this.VoiceSamplePerSec = AppModeUtil.CheckSupport(appSettings.AppMode, AppMode.MicroVoice) ? 0x3e80 : 0x5622; flag = true; } if (appSettings.Function.UseConstVoiceDic) { this._constDbsPath = appSettings.Function.ConstVoiceDicPath; } else { this._constDbsPath = ""; if (this.DbsPath == null) { this.DbsPath = Path.Combine(Directory.GetParent(Application.StartupPath).FullName, "voice"); flag = true; } } if (appSettings.Function.UseConstLangDic) { this._constLangPath = appSettings.Function.ConstLangDicPath; } else { this._constLangPath = ""; if (this.LangPath == null) { this.LangPath = Path.Combine(Application.StartupPath, AppModeUtil.CheckSupport(appSettings.AppMode, AppMode.MicroLang) ? @"lang\normal" : "lang"); flag = true; } } if (this.SoundOutput == null) { this.SoundOutput = new SoundOutputSettings(this.VoiceSamplePerSec); flag = true; } else { if ((this.SoundOutput.SamplePerSec != this.VoiceSamplePerSec) && (this.SoundOutput.SamplePerSec != (this.VoiceSamplePerSec / 2))) { this.SoundOutput.SamplePerSec = this.VoiceSamplePerSec; flag = true; } if (((this.SoundOutput.DataFormat != AIAudioFormatType.AIAUDIOTYPE_PCM_16) && (this.SoundOutput.DataFormat != AIAudioFormatType.AIAUDIOTYPE_MULAW_8)) || ((this.SoundOutput.DataFormat == AIAudioFormatType.AIAUDIOTYPE_MULAW_8) && (this.SoundOutput.SamplePerSec != 0x1f40))) { this.SoundOutput.DataFormat = AIAudioFormatType.AIAUDIOTYPE_PCM_16; flag = true; } } if ((this.KanaMode != KanaFormat.AIKANA) && (this.KanaMode != KanaFormat.JEITA)) { this.KanaMode = KanaFormat.AIKANA; flag = true; } if (this.IgnoredVoiceNames == null) { this.IgnoredVoiceNames = new List <string>(); flag = true; } if (this.SelectedVoiceName == null) { this.SelectedVoiceName = ""; flag = true; } if (this.UserDic == null) { this.UserDic = new UserDicSettings(appSettings); flag = true; } else { if (this.UserDic.WordDicPath == null) { this.UserDic.WordDicPath = appSettings.UserDic.DefaultWordDicFilePath; flag = true; } if (this.UserDic.PhraseDicPath == null) { this.UserDic.PhraseDicPath = appSettings.UserDic.DefaultPhraseDicFilePath; flag = true; } if (this.UserDic.SymbolDicPath == null) { this.UserDic.SymbolDicPath = appSettings.UserDic.DefaultSymbolDicFilePath; flag = true; } } if ((this.MasterVolume < 0.01) || (this.MasterVolume > 5.0)) { this.MasterVolume = 1f; flag = true; } if ((this.BeginPause < 0) || (this.BeginPause > 0x2710)) { this.BeginPause = 0; flag = true; } if ((this.TermPause < 0) || (this.TermPause > 0x2710)) { this.TermPause = 0; flag = true; } this.UseCommonVoiceSettings = true; if (this.CommonVoice == null) { this.CommonVoice = new VoiceSettings(); flag = true; } else { if ((this.CommonVoice.Volume < 0.0) || (this.CommonVoice.Volume > 2.0)) { this.CommonVoice.Volume = 1f; flag = true; } if ((this.CommonVoice.Speed < 0.5) || (this.CommonVoice.Speed > 4.0)) { this.CommonVoice.Speed = 1f; flag = true; } if ((this.CommonVoice.Pitch < 0.5) || (this.CommonVoice.Pitch > 2.0)) { this.CommonVoice.Pitch = 1f; flag = true; } if ((this.CommonVoice.Emphasis < 0.0) || (this.CommonVoice.Emphasis > 2.0)) { this.CommonVoice.Emphasis = 1f; flag = true; } if ((this.CommonVoice.MiddlePause < 80) || (this.CommonVoice.MiddlePause > 500)) { this.CommonVoice.MiddlePause = 150; flag = true; } if ((this.CommonVoice.LongPause < 100) || (this.CommonVoice.LongPause > 0x7d0)) { this.CommonVoice.LongPause = 370; flag = true; } if ((this.CommonVoice.SentencePause < 200) || (this.CommonVoice.SentencePause > 0x2710)) { this.CommonVoice.SentencePause = 800; flag = true; } } if (this.Voice == null) { this.Voice = new List <VoiceSettings>(); flag = true; } else { this.Voice.Clear(); } if (this.Jeita == null) { this.Jeita = new JeitaSettings(); flag = true; } else { if (this.Jeita.FemaleVoiceName == null) { this.Jeita.FemaleVoiceName = ""; flag = true; } if (this.Jeita.MaleVoiceName == null) { this.Jeita.MaleVoiceName = ""; flag = true; } if ((this.Jeita.Sex == null) || ((this.Jeita.Sex != "F") && (this.Jeita.Sex != "M"))) { this.Jeita.Sex = "F"; flag = true; } if ((this.Jeita.Volume < 0) || (this.Jeita.Volume > 9)) { this.Jeita.Volume = 7; flag = true; } if ((this.Jeita.Speed < 1) || (this.Jeita.Speed > 9)) { this.Jeita.Speed = 5; flag = true; } if ((this.Jeita.Pitch < 1) || (this.Jeita.Pitch > 5)) { this.Jeita.Pitch = 3; flag = true; } if ((this.Jeita.Emphasis < 0) || (this.Jeita.Emphasis > 3)) { this.Jeita.Emphasis = 2; flag = true; } if ((this.Jeita.MiddlePause < 80) || (this.Jeita.MiddlePause > 300)) { this.Jeita.MiddlePause = 100; flag = true; } if ((this.Jeita.LongPause < 100) || (this.Jeita.LongPause > 0x7d0)) { this.Jeita.LongPause = 300; flag = true; } if ((this.Jeita.SentencePause < 300) || (this.Jeita.SentencePause > 0x2710)) { this.Jeita.SentencePause = 800; flag = true; } } return(!flag); }