/// <summary> /// Starts file search (main functionality). /// </summary> /// <param name="directoryPath">Path to directory.</param> /// <param name="fileNamePattern">Valid file name pattern.</param> /// <param name="allowedCharacters">Allowed characters in file.</param> private async void StartSearch(string directoryPath, string fileNamePattern, string allowedCharacters) { //Initial setup. searchOperationRunning = true; counter = 0; view.SearchResultsTreeView.Nodes.Clear(); view.FilesProccessed = counter.ToString(); configurationSaver.Save(new ConfigurationModel(directoryPath, fileNamePattern, allowedCharacters)); fileSearcher.AllowedCharacters = new HashSet <char>(allowedCharacters.ToCharArray()); fileSearcher.NamePattern = fileNamePattern; //Main operation Progress <FileSearchProgressModel> searchProgress = new Progress <FileSearchProgressModel>(); searchProgress.ProgressChanged += ReportSearchProgress; try { searchOperationToken = new PauseOrCancelTokenSource(); await Task.Run(() => fileSearcher.Search(directoryPath, searchProgress, searchOperationToken.Token)); view.CurrentFile = "None"; } catch (OperationCanceledException) { } catch (ArgumentException) { view.CurrentFile = "Directory not found."; } //Cleanup view.StartButtonText = "Start"; searchOperationRunning = false; timer.Stop(); }
/// <summary> /// Calculates gcd of two number and time of execution of calculations. /// </summary> /// <param name="first">First number.</param> /// <param name="second">Second number.</param> /// <returns>Calculated gcd.</returns> public int Calculate(int first, int second) { timeCalculator.Start(); int gcd = this.algorithm.Calculate(first, second); timeCalculator.Stop(); this.Milliseconds = this.timeCalculator.TimeInMilliseconds; return(gcd); }
/// <summary> /// Calculates gcd and time of algorithm's execution. /// </summary> /// <param name="gcdAlgorithm">Gcd algorithm.</param> /// <param name="first">First number.</param> /// <param name="second">Second number.</param> /// <param name="timeCalculator">Util for time calculation.</param> /// <param name="timeForCalculations">Result time of algorithm's execution.</param> /// <returns></returns> public static int CalculateGcdWithTime(this IGcdAlgorithm gcdAlgorithm, int first, int second, ITimeCalculator timeCalculator, out long timeForCalculations) { gcdAlgorithm.CheckOnNull(); timeCalculator.CheckOnNull(); timeCalculator.Start(); int gcd = gcdAlgorithm.Calculate(first, second); timeCalculator.Stop(); timeForCalculations = timeCalculator.TimeInMilliseconds; return(gcd); }