示例#1
0
        /// <summary>
        /// Get file generator and load defaults from config file.
        /// </summary>
        /// <returns></returns>
        static FileGenerator GetFileGenerator()
        {
            FileGenerator fileGenerator = new FileGenerator(
                System.Configuration.ConfigurationManager.AppSettings.Get("LipsumIpsumGenerator.Dictionary").Split(','),
                new Random()
                );

            fileGenerator.MinWords      = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("LipsumIpsumGenerator.MinWords"));
            fileGenerator.MaxWords      = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("LipsumIpsumGenerator.MaxWords"));
            fileGenerator.MinSentences  = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("LipsumIpsumGenerator.MinSentences"));
            fileGenerator.MaxSentences  = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("LipsumIpsumGenerator.MaxSentences"));
            fileGenerator.MinParagraphs = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("LipsumIpsumGenerator.MinParagraphs"));
            fileGenerator.MaxParagraphs = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("LipsumIpsumGenerator.MaxParagraphs"));
            return(fileGenerator);
        }
示例#2
0
        /// <summary>
        /// Run test program.
        /// </summary>
        /// <param name="program"></param>
        static void Run(SchedulerType schedulerType, string deviceFolder, int fileCount, int taskCount)
        {
            // Report program options
            Console.WriteLine("[{0}] pi scheduler type = {1}", DateTime.Now.ToFileTime(), schedulerType);
            Console.WriteLine("[{0}] pi device folder = {1}", DateTime.Now.ToFileTime(), deviceFolder);
            Console.WriteLine("[{0}] pi file count = {1}", DateTime.Now.ToFileTime(), fileCount);
            Console.WriteLine("[{0}] pm {1}kb", DateTime.Now.ToFileTime(), GC.GetTotalMemory(true) / 1024);

            FileGenerator   fileGenerator  = GetFileGenerator();
            IWriteScheduler writeScheduler = CreateWriteScheduler(schedulerType);

            foreach (IDevice device in GetDevices(new DirectoryInfo(deviceFolder)))
            {
                Console.WriteLine("[{0}] pi register device {1}", DateTime.Now.ToFileTime(), device.Id);
                writeScheduler.Register(device);
            }


            // Test using sequential writes.
            Console.WriteLine("[{0}] pm {1}kb", DateTime.Now.ToFileTime(), GC.GetTotalMemory(true) / 1024);
            DisplayScheduler(writeScheduler);
            foreach (Tuple <string, byte[]> current in fileGenerator.GetFiles(fileCount))
            {
                writeScheduler.Write(current.Item1, current.Item2);
                DisplayScheduler(writeScheduler);
            }
            Console.WriteLine("[{0}] pm {1}kb", DateTime.Now.ToFileTime(), GC.GetTotalMemory(true) / 1024);

            // Test using concurrent writes.
            Task[] tasks = new Task[taskCount];
            for (int i = 0; i < tasks.Length; i++)
            {
                tasks[i] = new Task(() =>
                {
                    foreach (Tuple <string, byte[]> current in fileGenerator.GetFiles(fileCount))
                    {
                        writeScheduler.Write(current.Item1, current.Item2);
                        DisplayScheduler(writeScheduler);
                    }
                });
                tasks[i].Start();
            }
            Task.WaitAll(tasks);
        }