Exemplo n.º 1
0
        /// <summary>
        /// Fetches prime numbers from existing result files.
        /// </summary>
        /// <param name="fileHandler">The object handling the result files.</param>
        /// <returns>Container holding information about the loaded prime numbers.</returns>
        public ExistingPrimesLoadingResult FetchExistingPrimes(ResultFileHandler fileHandler)
        {
            //Tell the user the loading has started.
            var startingArgs = new LoadingPrimesFromResultFileStartedArgs();

            OnLoadingPrimesFromResultFileStarted?.Invoke(this, startingArgs);

            //Load the existing primes.
            var result = fetchPrimes(fileHandler.ResultFiles);

            //Store the index of the last result file with room for more prime numbers.
            result.IndexOfLastResultFileToStoreIn = findFirstStorableFileIndex(fileHandler.ResultFiles);

            //Tell the user that the loading finished.
            int numberOfPrimesLoaded      = result.CachedPrimes.Count;
            int numberOfResultFilesLoaded = (int)Math.Ceiling(result.CachedPrimes.Count / (decimal)Configuration.NumberOfPrimesInFile);
            var loadingFinishedArgs       = new LoadingPrimesFromResultFileFinishedArgs(numberOfPrimesLoaded, numberOfResultFilesLoaded);

            OnLoadingPrimesFromResultFileFinished?.Invoke(this, loadingFinishedArgs);

            //Return the result from the loading.
            return(result);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Handles the OnLoadingPrimesFromResultFileFinished event for the object loading existing prime numbers.
 /// </summary>
 /// <param name="loader">The object loading the existing prime numbers.</param>
 /// <param name="args">The information about the event.</param>
 private void Loader_OnLoadingPrimesFromResultFileFinished(object loader, LoadingPrimesFromResultFileFinishedArgs args)
 {
     OnLoadingPrimesFromResultFileFinished?.Invoke(loader, args);
 }