Beispiel #1
0
        void workerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            FileInfo fileInfo = e.UserState as FileInfo;

            TotalFilesLabel.Content      = FileCount.ToString();
            CurrentFileLabel.Content     = fileInfo.Name;
            CurrentFileSizeLabel.Content = (fileInfo.Length / 1000).ToString() + " KB";
        }
Beispiel #2
0
 /// <summary>
 /// Initialize the formatter to format the file pattern to get a file name.
 /// </summary>
 private void InitializeFormatter()
 {
     Formatter.SetProperty("Hour", DateTime.Now.Hour.ToString("00"));
     Formatter.SetProperty("hour", (((DateTime.Now.Hour + 11) % 12) + 1).ToString("00"));
     Formatter.SetProperty("meridian", (DateTime.Now.Hour >= 12) ? "PM" : "AM");
     Formatter.SetProperty("minute", DateTime.Now.Minute.ToString("00"));
     Formatter.SetProperty("second", DateTime.Now.Second.ToString("00"));
     Formatter.SetProperty("year", DateTime.Now.Year.ToString("0000"));
     Formatter.SetProperty("month", DateTime.Now.Month.ToString("00"));
     Formatter.SetProperty("day", DateTime.Now.Day.ToString("00"));
     Formatter.SetProperty("dayofweek", DateTime.Now.DayOfWeek.ToString());
     Formatter.SetProperty("dayofyear", DateTime.Now.DayOfYear.ToString("000"));
     Formatter.SetProperty("weekday", DateTime.Now.ToString("dddd"));
     Formatter.SetProperty("filenumber", FileCount.ToString());
 }
Beispiel #3
0
 public override string ToString()
 {
     if (FileCount == -1)
     {
         return("");
     }
     else if (FileCount > 0)
     {
         return(TopFolderName + " (" + FileCount.ToString() + ")");
     }
     else
     {
         return(TopFolderName);
     }
 }
Beispiel #4
0
        void workerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            end = DateTime.Now;
            TotalFilesLabel.Content = FileCount.ToString();
            TotalTimeLabel.Content  = (end - start).TotalSeconds.ToString() + " seconds.";

            DataModel.TimeToScan = (end - start).TotalSeconds.ToString();
            // When we stop the scan in between, we don't drop the table or clean it.
            // We print all the results we have populated so far.
            DataModel.Clear();
            DBQueries.FindDuplicateEntries(this._dbEngine, this.DataModel);

            _scanInProgress         = false;
            DirScanButton.IsEnabled = true;
        }
        async Task OnExecuteAsync()
        {
            OutputPath = Path.GetFullPath(OutputPath);

            if (File.Exists(OutputPath))
            {
                throw new Exception("O caminho onde os arquivos aleatórios serão gravados precisa ser um diretório");
            }

            if (string.IsNullOrWhiteSpace(FileNameTemplate))
            {
                throw new Exception("Você precisa informar um template válido para nome do arquivo");
            }

            FileNameTemplate = FileNameTemplate.Replace("{n}", "{0}");

            if (!Directory.Exists(OutputPath))
            {
                Directory.CreateDirectory(OutputPath);
            }

            if (FileCount < 1)
            {
                throw new Exception("Você precisa informar pelo menos 1 arquivo para gerar");
            }

            if (string.IsNullOrWhiteSpace(MinFileSize))
            {
                throw new Exception("Você precisa informar o parâmetro --min-file-size");
            }

            if (string.IsNullOrWhiteSpace(MaxFileSize))
            {
                throw new Exception("Você precisa informar o parâmetro --max-file-size");
            }

            var minFileSize = ParseHumanSize(MinFileSize);
            var maxFileSize = ParseHumanSize(MaxFileSize);

            if (minFileSize < 1)
            {
                throw new Exception("O tamanho mínimo do arquivo aleatório precisa ser de pelo menos 1 byte");
            }

            if (maxFileSize < minFileSize)
            {
                throw new Exception("O tamanho máximo do arquivo aleatório precisa ser pelo menos o mesmo tamanho mínimo");
            }

            var currentFile             = 1;
            var fileCountCharactersSize = FileCount.ToString().Length;
            var rnd = new Random();

            while (currentFile <= FileCount)
            {
                var fileNumber = (currentFile++).ToString().PadLeft(fileCountCharactersSize, '0');
                var fileName   = string.Format(FileNameTemplate, fileNumber);
                var filePath   = Path.Combine(OutputPath, fileName);
                var fileSize   = rnd.Next(minFileSize, maxFileSize);

                Console.WriteLine("Gerando arquivo {0} com {1}...", fileName, FormatHumanSize(fileSize));

                var fileBytes = new Byte[fileSize];

                rnd.NextBytes(fileBytes);

                using (var stream = new FileStream(filePath, FileMode.Create))
                    await stream.WriteAsync(fileBytes, 0, fileSize);
            }
        }