/// <summary> /// Setting up QueryParamsWorker for finding and updating UI for query params. /// </summary> /// <param name="speed">Single, Quick, Full</param> /// <param name="logFile">Log File Path</param> public void FindAndSetQueryParamFields(FindQueryParamsSpeed speed, string logFile) { queryParamsWorker = new BackgroundWorker(); queryParamsWorker.DoWork += (obj, e) => QueryParamsWorkerDoWork(speed, logFile); queryParamsWorker.RunWorkerCompleted += QueryParamsWorkerCompleted; StartWaiting(true); queryParamsWorker.RunWorkerAsync(); }
/// <summary> /// Look through the log file and find query parameters available for selection. /// </summary> /// <param name="method">Single, Quick or Full.</param> /// <param name="logFile">Log file path. Kept as param so unit testing is easier.</param> /// <returns></returns> public List <string> FindQueryParams(FindQueryParamsSpeed method, string logFile) { var result = new List <string>(); // We continuously build up this hashset of query parameters, only adding new values to it. var queryParamsHash = new HashSet <string>(); switch (method) { // Reads second line only. First line is the headers. case FindQueryParamsSpeed.Single: File.ReadLines(logFile).Take(2).ToList().ForEach(x => queryParamsHash.UnionWith(ParseLineForQueryParamKeys(x))); break; // Reads top 5% lines. Does this on single thread. case FindQueryParamsSpeed.Quick: int totalRows = int.Parse(lbl_TotalRowsValue.Text); int fivePercent = totalRows / 20; int linesToParse = (fivePercent > 0) ? fivePercent : 2; File.ReadLines(logFile).Take(linesToParse).ToList().ForEach(x => queryParamsHash.UnionWith(ParseLineForQueryParamKeys(x))); break; // Reads all lines. Uses Parralel to make this super fast and proper sick yo. case FindQueryParamsSpeed.Full: Parallel.ForEach(File.ReadLines(logFile), (line, _, lineNumber) => { queryParamsHash.UnionWith(ParseLineForQueryParamKeys(line)); }); break; } // Clean up found query params and sort. result = queryParamsHash.Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); result.Sort(); return(result); }
/// <summary> /// QueryParamsWorker Work task. Finds the Query Params and adds to global params object. /// </summary> /// <param name="speed">Single, Quick, Full</param> /// <param name="logFile">Log file path</param> private void QueryParamsWorkerDoWork(FindQueryParamsSpeed speed, string logFile) { AddToGlobalQueryParams(FindQueryParams(speed, logFile)); }