Ejemplo n.º 1
0
        private static void Run(Options options)
        {
            // reconfigure loggers to use a file in the current directory
            // or the file specified by the "Log" commandline parameter
            if (LogManager.Configuration != null)
            {
                var target = (FileTarget)LogManager.Configuration.FindTargetByName("logfile");
                if (target != null)
                {
                    var pathToLog = options.LogFile;
                    if (pathToLog == null)
                    {
                        pathToLog = Path.Combine(Environment.CurrentDirectory, "ConvertWorkload.log");
                    }
                    if (!Path.IsPathRooted(pathToLog))
                    {
                        pathToLog = Path.Combine(Environment.CurrentDirectory, pathToLog);
                    }
                    target.FileName = pathToLog;
                    LogManager.ReconfigExistingLoggers();
                }
            }

            EventReader reader = null;

            if (options.InputFile.EndsWith(".trc"))
            {
                reader = new SqlTraceEventReader(options.InputFile);
            }
            else if (options.InputFile.EndsWith(".evt"))
            {
                // TODO: implement extended events reader
            }
            EventWriter       writer    = new WorkloadFileEventWriter(options.OutputFile);
            WorkloadConverter converter = new WorkloadConverter(reader, writer);

            converter.ApplicationFilter = new string[1] {
                options.ApplicationFilter
            };
            converter.DatabaseFilter = new string[1] {
                options.DatabaseFilter
            };
            converter.HostFilter = new string[1] {
                options.HostFilter
            };
            converter.LoginFilter = new string[1] {
                options.LoginFilter
            };

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                logger.Info("Received shutdown signal...");
                source.CancelAfter(TimeSpan.FromSeconds(10)); // give a 10 seconds cancellation grace period
                converter.Stop();
            };

            Task t = processConverter(converter);

            t.Wait();
            logger.Info("Converter stopped.");
        }
Ejemplo n.º 2
0
 public WorkloadConverter(EventReader reader, EventWriter writer)
 {
     this.reader = reader;
     this.writer = writer;
 }
Ejemplo n.º 3
0
        private static void Run(Options options)
        {
            // reconfigure loggers to use a file in the current directory
            // or the file specified by the "Log" commandline parameter
            if (LogManager.Configuration != null)
            {
                var target = (FileTarget)LogManager.Configuration.FindTargetByName("logfile");
                if (target != null)
                {
                    var pathToLog = options.LogFile;
                    if (pathToLog == null)
                    {
                        pathToLog = Path.Combine(Environment.CurrentDirectory, "ConvertWorkload.log");
                    }
                    if (!Path.IsPathRooted(pathToLog))
                    {
                        pathToLog = Path.Combine(Environment.CurrentDirectory, pathToLog);
                    }
                    target.FileName = pathToLog;
                    LogManager.ReconfigExistingLoggers();
                }
            }

            // check whether localdb is installed
            logger.Info("Checking LocalDB...");
            LocalDBManager manager = new LocalDBManager();

            if (!manager.CanConnectToLocalDB())
            {
                logger.Info("Installing LocalDB...");
                try
                {
                    manager.InstallLocalDB();
                }
                catch (InvalidOperationException)
                {
                    logger.Error("This operation requires elevation. Restart the application as an administrator.");
                    return;
                }
            }

            EventReader reader = null;

            if (options.InputFile.EndsWith(".trc"))
            {
                reader = new SqlTraceEventReader(options.InputFile);
            }
            else
            {
                reader = new ExtendedEventsEventReader(options.InputFile);
            }
            EventWriter       writer    = new WorkloadFileEventWriter(options.OutputFile);
            WorkloadConverter converter = new WorkloadConverter(reader, writer);

            if (options.ApplicationFilter != null)
            {
                converter.ApplicationFilter = new string[1] {
                    options.ApplicationFilter
                }
            }
            ;
            if (options.DatabaseFilter != null)
            {
                converter.DatabaseFilter = new string[1] {
                    options.DatabaseFilter
                }
            }
            ;
            if (options.HostFilter != null)
            {
                converter.HostFilter = new string[1] {
                    options.HostFilter
                }
            }
            ;
            if (options.LoginFilter != null)
            {
                converter.LoginFilter = new string[1] {
                    options.LoginFilter
                }
            }
            ;

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                logger.Info("Received shutdown signal...");
                source.CancelAfter(TimeSpan.FromSeconds(10)); // give a 10 seconds cancellation grace period
                converter.Stop();
            };

            Task t = processConverter(converter);

            t.Wait();
            logger.Info("Converter stopped.");
        }