/// <summary> /// This method will compare the command type and append unidnetified words to the respective text file /// </summary> /// <param name="commandType">identified command type</param> public static void AddUnidentifiedWordsToCommandText(CommandType commandType) { try { var testFiles = FileManager.GetTestFiles(); var textFile = ""; // get the text file by first removing the file extension, and it's checking whether it's ending // with the provided command type foreach ( var testFile in testFiles.Where( testFile => testFile.Remove(testFile.IndexOf(VbwFileManager.FileExtension(), StringComparison.Ordinal)) .EndsWith(commandType.ToString()))) { // if so, set that particular testFile as the file name textFile = testFile; } // assign the unidentified words to the test file DataManager.AppendToFile(textFile, UnIdentifiedWords); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// this method will add counter to the counter text file /// </summary> /// <param name="commandType"></param> public static void AddToCommandCounter(CommandType commandType) { try { var fileName = VbwFileManager.FilePath() + "count_commandExecutionCounter" + VbwFileManager.FileExtension(); var data = GetFileData(fileName); var valueToBeRemoved = ""; var valueToBeAdded = ""; foreach (var value in from value in data let command = value.Split('|').First() where command == commandType.ToString() select value) { valueToBeRemoved = value; var count = Convert.ToInt32(value.Split('|').Last()); valueToBeAdded = commandType + "|" + ++count; } data.Remove(valueToBeRemoved); data.Add(valueToBeAdded); using (var writer = new StreamWriter(fileName)) { foreach (var content in data) { writer.WriteLine(content); } } } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// This method will append a given list of strings to a text file /// </summary> /// <param name="fileName">Name of the Text File</param> /// <param name="data">List of strings</param> public static void AppendToFile(string fileName, List <string> data) { try { VbwFileManager.AppendToTextFile(fileName, data); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// This method will return the content of a given file name /// </summary> /// <param name="file">name of the file</param> /// <returns>File content as a list of string</returns> public static List <string> GetContentOfAFile(string file) { try { return(DataManager.GetFileData(VbwFileManager.FilePath() + file + VbwFileManager.FileExtension())); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// This method will return explicit file names which starts with the provided value from a given file paths list /// </summary> /// <param name="fileNames">file paths list</param> /// <param name="startsWithValue">starting value</param> /// <returns></returns> public static List <string> GetExplicitFileNamesByPrefix(string[] fileNames, string startsWithValue) { try { return(fileNames.Select(item => item.Replace(VbwFileManager.FilePath(), String.Empty).Replace(VbwFileManager.FileExtension(), String.Empty)).Where(explicitFileName => explicitFileName.StartsWith(startsWithValue)).ToList()); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// this method will acquire test files from the data folder /// </summary> public static string[] GetTestFiles() { try { return(Directory.GetFiles(VbwFileManager.FilePath(), "*" + VbwFileManager.FileExtension())); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// this method is used to acquire and assign test data to relevant test sets by passing the file path /// </summary> /// <param name="filepath">the path of the file</param> private void GetTestSet(string filepath) { try { var explicitFileName = filepath.Replace(VbwFileManager.FilePath(), String.Empty); if (explicitFileName.Substring(0, 3) != "fnc") { return; } var tempList = DataManager.GetFileData(filepath); var prefix = explicitFileName.Substring(4, 5); CheckFunctionalCategory(prefix, tempList); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// this method is used to acquire and assign test data to relevant test sets by passing the file path /// </summary> /// <param name="filepath">the path of the file</param> private void GetTestSet(string filepath) { try { // get the file data of a given file path var tempList = DataManager.GetFileData(filepath); // get the explicit file name by removing the filepath var explicitFileName = filepath.Replace(VbwFileManager.FilePath(), String.Empty); // get the prefix of the file name var prefix = explicitFileName.Substring(0, 3); // invoke the method to store the file data according to the category CheckFunctionalCategory(prefix, tempList); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// This method will populate data available in a give file list to given category Collection /// This method is used for final level data categorization /// </summary> /// <param name="categoryCollections">List of categories</param> /// <param name="fileNames"> list of file names</param> /// <param name="prefix">prefix of the command category</param> public static void PopulateDataToCategories(List <CategoryCollection> categoryCollections, string[] fileNames, string prefix) { try { foreach (var fileName in fileNames) { var explicitFileName = fileName.Replace(VbwFileManager.FilePath(), String.Empty) .Replace(VbwFileManager.FileExtension(), String.Empty); // Get the proper file name, without extensions or the directory if (!explicitFileName.StartsWith(prefix)) { continue; // if the file doesn't belong to the command category meant by the given prefix, continue to the next item of the loop } var fileData = GetFileData(fileName); // else get the file data var fileNameWithoutPrefix = explicitFileName.Replace(prefix + "_", String.Empty); // get the file name without the prefix if (fileNameWithoutPrefix != "websites") // if the file name without prefix not equals to websites { var categoryObject = GetCategoryCollectionObjectFromFileName(categoryCollections, fileNameWithoutPrefix); //get the category object by using the file name without the prefix if (categoryObject != null && fileData != null) // if the category object is not null and the file data is not null { AssignDataToTestSet(categoryObject.List, fileData); // assign file data to the list available in the category object } } else { // this is a special scenario where website names will be taken into account as go command keywords var goCommandCategoryObject = GetCategoryCollectionObjectFromFileName(categoryCollections, "go"); if (goCommandCategoryObject != null) { AssignDataToTestSet(goCommandCategoryObject.List, fileData); } } } } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
public GrammarBuilder GetWebsiteNamesGrammar() { try { Settings.CultureInfo = "en-GB"; var webSiteNames = new List <string>(); using (var fs = File.Open(VbwFileManager.FilePath() + "fnc_brwsr_websites" + VbwFileManager.FileExtension(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var bs = new BufferedStream(fs)) using (var sr = new StreamReader(bs)) { string line; while ((line = sr.ReadLine()) != null) { webSiteNames.Add(line); } } var dictationBuilder = new GrammarBuilder // creating a new grammar builder { Culture = new CultureInfo(Settings.CultureInfo) }; dictationBuilder.AppendDictation(); // append dictation to the created grammar builder var dictaphoneGb = new GrammarBuilder { Culture = new CultureInfo(Settings.CultureInfo) }; dictaphoneGb.Append(dictationBuilder, 0 /* minimum repeat */, 10 /* maximum repeat*/); dictaphoneGb.Append(new Choices(webSiteNames.ToArray())); dictaphoneGb.Append(dictationBuilder, 0 /* minimum repeat */, 10 /* maximum repeat*/); return(dictaphoneGb); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// This method will return data available in a given file as a string array; /// </summary> /// <param name="filePath">file path</param> /// <returns>File data as a list of string</returns> public static List <string> GetFileData(string filePath) { return(VbwFileManager.GetTextFileData(filePath)); }