Ejemplo n.º 1
0
        static void RunExternalSorting(SorterOptions options, IProgress <string> progress)
        {
            var ram             = BytesStringParser.ParseBytesString(options.AvailableRam);
            var readBufferSize  = BytesStringParser.ParseBytesString(options.ReadBufferSize);
            var writeBufferSize = BytesStringParser.ParseBytesString(options.WriteBufferSize);

            if (readBufferSize > int.MaxValue)
            {
                throw new ArgumentOutOfRangeException($"Read buffer size cannot be greater then {int.MaxValue} bytes.");
            }

            if (writeBufferSize > int.MaxValue)
            {
                throw new ArgumentOutOfRangeException($"Write buffer size cannot be greater then {int.MaxValue} bytes.");
            }

            var stopwatch = Stopwatch.StartNew();

            progress.Report($"Starting external sorting at {DateTime.Now}...");

            string temporaryFolder = "";

            if (string.IsNullOrWhiteSpace(options.TemporaryFolder))
            {
                temporaryFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            }
            else
            {
                temporaryFolder = Path.Combine(options.TemporaryFolder, Guid.NewGuid().ToString());
            }

            Directory.CreateDirectory(temporaryFolder);

            ExternalSorter.Sort(options.InputFile, options.OutputFile, temporaryFolder, ram, (int)readBufferSize, (int)writeBufferSize, progress);

            if (options.CleanTemporaryFolder)
            {
                Directory.Delete(temporaryFolder, true);
            }

            stopwatch.Stop();
            progress.Report($"External sorting completed at {DateTime.Now}. Elapsed time: {stopwatch.Elapsed}");
        }
 public void InvalidBytesValues(string inputValue)
 {
     Assert.Throws <ArgumentException>(() => BytesStringParser.ParseBytesString(inputValue));
 }
        public void ValidBytesValues(string inputValue, long extpectedBytes)
        {
            var actual = BytesStringParser.ParseBytesString(inputValue);

            Assert.AreEqual(extpectedBytes, actual);
        }