Esempio n. 1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: PerFileAccessLog.exe SizeInMegabytes outputfile, e.g. PerFileAccessLog 1000 C:\\myoutputfile.csv");
            }

            int sizeInMb = -1;

            if (!Int32.TryParse(args[0], out sizeInMb) || sizeInMb < 1)
            {
                Console.WriteLine("Unable to parse size argument. Should be positive integer.");
            }

            string outputFile = args[1];

            var  sizeInBytes = sizeInMb * 1024 * 1024;
            var  date        = new DateTime(2015, 1, 1);
            var  random      = new Random();
            long bytes       = 0;

            using (var outfile = System.IO.File.Open(outputFile, FileMode.CreateNew))
            {
                while (bytes < sizeInBytes)
                {
                    var numEntriesForDate = random.Next(0, 500000);
                    for (int i = 0; i < numEntriesForDate; i++)
                    {
                        var logEntry   = new PerFileLogEntry(date);
                        var entryBytes = System.Text.Encoding.UTF8.GetBytes(logEntry.ToString());
                        outfile.Write(entryBytes, 0, entryBytes.Length);

                        bytes += entryBytes.Length;
                        if (bytes >= sizeInBytes)
                        {
                            break;
                        }
                    }
                    date = date.AddDays(1);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                throw new ArgumentException();
            }

            if (!int.TryParse(args[0], out int sizeInMb) || sizeInMb < 1)
            {
                throw new ArgumentNullException(nameof(sizeInMb));
            }

            string outputFile = args[1];

            long bytes       = 0;
            var  random      = new Random();
            var  date        = new DateTime(2018, 1, 1);
            int  sizeInBytes = sizeInMb * 1024 * 1024;

            using (FileStream outfile = File.Open(outputFile, FileMode.CreateNew))
            {
                while (bytes < sizeInBytes)
                {
                    int numEntriesForDate = random.Next(0, 500000);
                    for (int i = 0; i < numEntriesForDate; i++)
                    {
                        date = date.AddHours(1);
                        var    logEntry   = new PerFileLogEntry(date);
                        byte[] entryBytes = Encoding.UTF8.GetBytes(logEntry.ToString());
                        outfile.Write(entryBytes, 0, entryBytes.Length);

                        bytes += entryBytes.Length;
                        if (bytes >= sizeInBytes)
                        {
                            break;
                        }
                    }
                }
            }
        }