public EngineConfiguration BuildWorkItemMigration()
 {
     return(ecb.BuildWorkItemMigration());
 }
        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);
        }
Example #3
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);
        }