예제 #1
0
        public static async Task processConverter(WorkloadConverter converter)
        {
            source = new CancellationTokenSource();
            source.Token.Register(CancelNotification);
            var completionSource = new TaskCompletionSource <object>();

            source.Token.Register(() => completionSource.TrySetCanceled());
            var task = Task.Factory.StartNew(() => converter.Convert(), source.Token);
            await Task.WhenAny(task, completionSource.Task);
        }
예제 #2
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 = options.ApplicationFilter;
            converter.DatabaseFilter    = options.DatabaseFilter;
            converter.HostFilter        = options.HostFilter;
            converter.LoginFilter       = 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.");
        }
예제 #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.");
        }