private static int Main(string[] args)
        {
            try
            {
                ConsoleWorkSettingsReader consoleReader = new ConsoleWorkSettingsReader(new WorkSettingsReader(), new WorkSettingsWriter());
                WorkSettings settings = consoleReader.InitializeFromCommandLine(args);
                if (null == settings)
                {
                    return -1;
                }

                Connector connector = new Connector();
                connector.OnEventMessage += connector_OnEventMessage;
                connector.ProcessCallback.OnMessage += ProcessCallback_OnMessage;

                SetupLoggingForConnector(settings, connector);

                SetupIncludedItemsForConnector(settings, connector);

                SetupExcludedItemsForConnector(settings, connector);

                connector.StartTarget(
                    settings.TargetPath,
                    settings.TargetWorkingDir,
                    settings.TargetArgs,
                    true,
                    false);

                try
                {
                    IReportWriter reportWriter = GetReportWriter(settings);
                    if (settings.OutputToFile)
                    {
                        using (StreamWriter writer = File.CreateText(settings.FileNameForReport))
                        {
                            reportWriter.WriteReport(connector.BlockWalker.Report, writer);
                        }
                    }
                    else
                    {
                        reportWriter.WriteReport(connector.BlockWalker.Report, Console.Out);
                    }
                }
                catch (Exception ex)
                {
                    LogError("Can't save report ({0})", ex.Message);
                }

                if (connector.TargetExitCode.HasValue)
                    return connector.TargetExitCode.Value;
            }
            catch (SettingsException ex)
            {
                LogError(ex.Message);
                return -1;
            }
            catch (Exception ex)
            {
                LogError(ex.Message);
                LogError(ex.StackTrace);
                return -1;
            }

            return 0;
        }
 private static void SetupLoggingForConnector(WorkSettings settings, Connector connector)
 {
     connector.UseFileLogging(true);
     connector.UsePipeLogging(false);
     connector.SetLogging((Logging) settings.LogLevel);
 }
 private static void SetupIncludedItemsForConnector(WorkSettings settings, Connector connector)
 {
     foreach (string item in settings.IncludeItems)
     {
         try
         {
             connector.IncludeItem(item);
         }
         catch (ArgumentException)
         {
             LogError("Item '{0}' has wrong format", item);
         }
     }
 }
 public ConnectorActionCallback(Connector connector)
 {
     this.connector = connector;
 }
Exemplo n.º 5
0
        static int Main(string[] args)
        {
            try
            {
                var settings = new WorkSettings();
                if (!settings.InitializeFromCommandLine(args))
                {
                    return -1;
                }

                if (settings.ErrorsToStdout)
                {
                    Console.SetError(Console.Out);
                }

                using (Registration.Create(settings.Register ? System.Reflection.Assembly.GetExecutingAssembly().Location : null))
                {
                    //Console.ReadLine();

                    var connector = new Connector();
                    connector.StatusMessageReceived += connector_StatusMessageReceived;
                    connector.LogEntryReceived += connector_LogEntryReceived;

                    connector.UseFileLogging(true);
                    connector.UsePipeLogging(true);
                    connector.SetLogging((Logging)settings.LogLevel);

                    foreach (var item in settings.IncludeItems)
                    {
                        try
                        {
                            connector.IncludeItem(item);
                        }
                        catch (ArgumentException)
                        {
                            Console.Error.WriteLine("Item '" + item + "' have wrong format");
                        }
                    }

                    foreach (var item in settings.ExcludeItems)
                    {
                        try
                        {
                            connector.ExcludeItem(item);
                        }
                        catch (ArgumentException)
                        {
                            Console.Error.WriteLine("Item '" + item + "' have wrong format");
                        }
                    }

                    var options = new SessionRunOptions
                    {
                        TargetPath = settings.TargetPath,
                        TargetDirectory = settings.TargetWorkingDir,
                        TargetArguments = settings.TargetArgs,
                        RedirectOutput = true,
                        DelayClose = false,
                        FlattenDomains = !settings.DisableFlattenDomains
                    };

                    connector.Options = options;
                    connector.StartTarget();

                    try
                    {
                        var writer = settings.OutputToFile
                            ? new XmlTextWriter(File.CreateText(settings.FileNameForReport))
                            : new XmlTextWriter(Console.Out);
                        using (writer)
                        {
                            writer.Formatting = Formatting.Indented;
                            writer.Indentation = 1;
                            writer.IndentChar = ' ';
                            ReportSerializer.Save(writer, connector.Report);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Can't save report (" + ex.Message + ")");
                    }

#if DEBUG
                    WriteListOfSkippedItems(connector.Report);
#endif

                    if (connector.TargetExitCode.HasValue)
                        return connector.TargetExitCode.Value;
                } // end using
            }
            catch (SettingsException ex)
            {
                Console.Error.WriteLine(ex.Message);
                return -1;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                return -1;
            }

            return 0;
        }
Exemplo n.º 6
0
 public ConnectorActionCallback(Connector connector)
 {
     this.connector = connector;
 }