public void TestSeraliseToJson()
        {
            string       json = NewtonsoftHelpers.SerializeObject(ecb.BuildDefault());
            StreamWriter sw   = new StreamWriter("configuration.json");

            sw.WriteLine(json);
            sw.Close();
        }
Beispiel #2
0
        public void TestSeraliseToJson()
        {
            string json = JsonConvert.SerializeObject(ecb.BuildDefault(),
                                                      new FieldMapConfigJsonConverter(),
                                                      new ProcessorConfigJsonConverter(),
                                                      new JsonConverterForEndpointOptions(),
                                                      new JsonConverterForEnricherOptions(),
                                                      new MigrationClientConfigJsonConverter());
            StreamWriter sw = new StreamWriter("configuration.json");

            sw.WriteLine(json);
            sw.Close();
        }
        public void Setup()
        {
            var levelSwitch = new LoggingLevelSwitch();

            Log.Logger = new LoggerConfiguration().MinimumLevel.ControlledBy(levelSwitch).WriteTo.Console().CreateLogger();

            ecb = new EngineConfigurationBuilder(new NullLogger <EngineConfigurationBuilder>());
            var services = new ServiceCollection();

            services.AddSingleton <LoggingLevelSwitch>(levelSwitch);

            // Field Mapps
            services.AddTransient <FieldBlankMap>();
            services.AddTransient <FieldLiteralMap>();
            services.AddTransient <FieldMergeMap>();
            services.AddTransient <FieldValueMap>();
            services.AddTransient <FieldToFieldMap>();
            services.AddTransient <FieldtoFieldMultiMap>();
            services.AddTransient <FieldToTagFieldMap>();
            services.AddTransient <FieldValuetoTagMap>();
            services.AddTransient <MultiValueConditionalMap>();
            services.AddTransient <RegexFieldMap>();
            services.AddTransient <TreeToTagFieldMap>();
            //Services
            services.AddSingleton <IDetectOnlineService, DetectOnlineService>();
            services.AddSingleton <IDetectVersionService, DetectVersionService>();
            //Containers
            services.AddSingleton <FieldMapContainer>();
            services.AddSingleton <ProcessorContainer>();
            services.AddSingleton <TypeDefinitionMapContainer>();
            services.AddSingleton <GitRepoMapContainer>();
            services.AddSingleton <ChangeSetMappingContainer>();

            //
            services.AddSingleton <IEngineConfigurationBuilder, EngineConfigurationBuilder>();
            services.AddSingleton <EngineConfiguration>(ecb.BuildDefault());
            services.AddSingleton <ITelemetryLogger, TelemetryLoggerMock>();
            services.AddApplicationInsightsTelemetryWorkerService();
            services.AddLogging();

            //Clients
            services.AddTransient <IMigrationClient, MigrationClient>();
            services.AddTransient <IWorkItemMigrationClient, WorkItemMigrationClient>();
            services.AddTransient <IWorkItemQueryBuilder, WorkItemQueryBuilder>();

            services.AddSingleton <IMigrationEngine, MigrationEngine>();

            services.AddSingleton <ExecuteOptions>((p) => null);

            _services = services.BuildServiceProvider();
        }
 public void Setup()
 {
     ecb  = new EngineConfigurationBuilder();
     host = new HostBuilder().ConfigureServices((context, services) =>
     {
         services.AddSingleton <IDetectOnlineService, DetectOnlineService>();
         services.AddSingleton <IDetectVersionService, DetectVersionService>();
         services.AddSingleton <IEngineConfigurationBuilder, EngineConfigurationBuilderStub>();
         services.AddSingleton <EngineConfiguration>(ecb.BuildDefault());
         services.AddSingleton <ProcessorContainer>();
         services.AddSingleton <TypeDefinitionMapContainer>();
         services.AddSingleton <GitRepoMapContainer>();
         services.AddSingleton <ChangeSetMappingContainer>();
         services.AddSingleton <ITelemetryLogger, TelemetryClientAdapter>();
         services.AddSingleton <ITeamProjectContext, TeamProjectContextMoc>();
         services.AddSingleton <MigrationEngineCore>();
     }).Build();
 }
Beispiel #5
0
        public void Setup()
        {
            ecb = new EngineConfigurationBuilder();
            var serviceColl = new ServiceCollection();

            serviceColl.AddSingleton <IDetectOnlineService, DetectOnlineService>();
            serviceColl.AddSingleton <IDetectVersionService, DetectVersionService>();
            serviceColl.AddSingleton <IEngineConfigurationBuilder, EngineConfigurationBuilder>();
            serviceColl.AddSingleton <EngineConfiguration>(ecb.BuildDefault());
            serviceColl.AddSingleton <TelemetryClient>(new TelemetryClient());
            serviceColl.AddSingleton <ProcessorContainer>();
            serviceColl.AddSingleton <TypeDefinitionMapContainer>();
            serviceColl.AddSingleton <GitRepoMapContainer>();
            serviceColl.AddSingleton <ChangeSetMappingContainer>();
            serviceColl.AddSingleton <ITelemetryLogger, TestTelemetryLogger>();
            serviceColl.AddSingleton <MigrationEngine>();
            services = serviceColl.BuildServiceProvider();
        }
 public EngineConfigurationWrapper(IEngineConfigurationBuilder engineConfigurationBuilder, ExecuteOptions opts, ILogger <EngineConfigurationWrapper> logger)
 {
     if (opts == null) //means that we are in init command and not execute
     {
         _engineConfiguration = engineConfigurationBuilder.BuildDefault();
         return;
     }
     if (opts.ConfigFile == string.Empty)
     {
         opts.ConfigFile = "configuration.json";
     }
     if (!File.Exists(opts.ConfigFile))
     {
         logger.LogInformation("The config file {ConfigFile} does not exist, nor does the default 'configuration.json'. Use '{ExecutableName}.exe init' to create a configuration file first", opts.ConfigFile, Assembly.GetEntryAssembly().GetName().Name);
         throw new ArgumentException("missing configfile");
     }
     logger.LogInformation("Config Found, creating engine host");
     _engineConfiguration = engineConfigurationBuilder.BuildFromFile(opts.ConfigFile);
 }
Beispiel #7
0
        public void Setup()
        {
            ecb = new EngineConfigurationBuilder(new NullLogger <EngineConfigurationBuilder>());
            var services = new ServiceCollection();

            // Field Mapps
            services.AddTransient <FieldBlankMap>();
            services.AddTransient <FieldLiteralMap>();
            services.AddTransient <FieldMergeMap>();
            services.AddTransient <FieldValueMap>();
            services.AddTransient <FieldToFieldMap>();
            services.AddTransient <FieldtoFieldMultiMap>();
            services.AddTransient <FieldToTagFieldMap>();
            services.AddTransient <FieldValuetoTagMap>();
            services.AddTransient <MultiValueConditionalMap>();
            services.AddTransient <RegexFieldMap>();
            services.AddTransient <TreeToTagFieldMap>();

            //Services
            services.AddSingleton <IDetectOnlineService, DetectOnlineService>();
            services.AddSingleton <IDetectVersionService, DetectVersionService>();



            //Containers
            services.AddSingleton <FieldMapContainer>();
            services.AddSingleton <ProcessorContainer>();
            services.AddSingleton <TypeDefinitionMapContainer>();
            services.AddSingleton <GitRepoMapContainer>();
            services.AddSingleton <ChangeSetMappingContainer>();

            //
            services.AddSingleton <IEngineConfigurationBuilder, EngineConfigurationBuilder>();
            services.AddSingleton <EngineConfiguration>(ecb.BuildDefault());
            services.AddSingleton <TelemetryClient>(new TelemetryClient());
            services.AddSingleton <ITelemetryLogger, TestTelemetryLogger>();
            services.AddSingleton <MigrationEngine>();

            services.AddSingleton <ExecuteOptions>((p) => null);

            _services = services.BuildServiceProvider();
        }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogDebug($"Starting with arguments: {string.Join(" ", Environment.GetCommandLineArgs())}");
            if (_initOptions == null)
            {
                return(Task.CompletedTask);
            }
            _appLifetime.ApplicationStarted.Register(() =>
            {
                Task.Run(() =>
                {
                    try
                    {
                        _telemetryLogger.TrackEvent(new EventTelemetry("InitCommand"));
                        string configFile = _initOptions.ConfigFile;
                        if (string.IsNullOrEmpty(configFile))
                        {
                            configFile = "configuration.json";
                        }
                        _logger.LogInformation("ConfigFile: {configFile}", configFile);
                        if (File.Exists(configFile))
                        {
                            _logger.LogInformation("Deleting old configuration.json reference file");
                            File.Delete(configFile);
                        }
                        if (!File.Exists(configFile))
                        {
                            _logger.LogInformation("Populating config with {Options}", _initOptions.Options.ToString());
                            EngineConfiguration config;
                            switch (_initOptions.Options)
                            {
                            case OptionsMode.Full:
                                config = _configurationBuilder.BuildDefault();
                                break;

                            case OptionsMode.WorkItemTracking:
                                config = _configurationBuilder.BuildWorkItemMigration();
                                break;

                            case OptionsMode.Fullv2:
                                config = _configurationBuilder.BuildDefault2();
                                break;

                            case OptionsMode.WorkItemTrackingv2:
                                config = _configurationBuilder.BuildWorkItemMigration2();
                                break;

                            default:
                                config = _configurationBuilder.BuildDefault();
                                break;
                            }

                            string json     = NewtonsoftHelpers.SerializeObject(config);
                            StreamWriter sw = new StreamWriter(configFile);
                            sw.WriteLine(json);
                            sw.Close();
                            _logger.LogInformation("New configuration.json file has been created");
                        }
                        _exitCode = 0;
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, "Unhandled exception!");
                        _exitCode = 1;
                    }
                    finally
                    {
                        // Stop the application once the work is done
                        _appLifetime.StopApplication();
                    }
                });
            });
            return(Task.CompletedTask);
        }
 public void TestEngineCreation()
 {
     EngineConfiguration ec = ecb.BuildDefault();
     MigrationEngine     me = new MigrationEngine(host, ec);
 }
 public EngineConfiguration BuildDefault()
 {
     return(ecb.BuildDefault());
 }
Beispiel #11
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _appLifetime.ApplicationStarted.Register(() =>
            {
                Task.Run(() =>
                {
                    try
                    {
                        _telemetryLogger.TrackEvent(new EventTelemetry("InitCommand"));
                        string configFile = _initOptions.ConfigFile;
                        if (string.IsNullOrEmpty(configFile))
                        {
                            configFile = "configuration.json";
                        }
                        _logger.LogInformation("ConfigFile: {configFile}", configFile);
                        if (File.Exists(configFile))
                        {
                            _logger.LogInformation("Deleting old configuration.json reference file");
                            File.Delete(configFile);
                        }
                        if (!File.Exists(configFile))
                        {
                            _logger.LogInformation("Populating config with {Options}", _initOptions.Options.ToString());
                            EngineConfiguration config;
                            switch (_initOptions.Options)
                            {
                            case OptionsMode.Full:
                                config = _configurationBuilder.BuildDefault();
                                break;

                            case OptionsMode.WorkItemTracking:
                                config = _configurationBuilder.BuildWorkItemMigration();
                                break;

                            case OptionsMode.Fullv2:
                                config = _configurationBuilder.BuildDefault2();
                                break;

                            case OptionsMode.WorkItemTrackingv2:
                                config = _configurationBuilder.BuildWorkItemMigration2();
                                break;

                            default:
                                config = _configurationBuilder.BuildDefault();
                                break;
                            }
                            _settingWriter.WriteSettings(config, configFile);
                            _logger.LogInformation($"New {configFile} file has been created");
                        }
                        _exitCode = 0;
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, "Unhandled exception!");
                        _exitCode = 1;
                    }
                    finally
                    {
                        // Stop the application once the work is done
                        _appLifetime.StopApplication();
                    }
                });
            });
            return(Task.CompletedTask);
        }