public EngineConfiguration BuildFromFile(string configFile = "configuration.json")
        {
            EngineConfiguration ec = null;

            try
            {
                string configurationjson = File.ReadAllText(configFile);
                ec = JsonConvert.DeserializeObject <EngineConfiguration>(configurationjson,
                                                                         new FieldMapConfigJsonConverter(),
                                                                         new ProcessorConfigJsonConverter(),
                                                                         new MigrationClientConfigJsonConverter());
            }
            catch (JsonSerializationException ex)
            {
                _logger.LogTrace(ex, "Configuration Error");
                _logger.LogCritical("Your configuration file is malformed and cant be loaded!");
                _logger.LogError(ex.Message);
                _logger.LogError("How to Solve: Malformed Json is usually a result of editing errors. Validate that your {configFile} is valid Json!", configFile);
                Environment.Exit(-1);
                return(null);
            }
            catch (JsonReaderException ex)
            {
                _logger.LogTrace(ex, "Configuration Error");
                _logger.LogCritical("Your configuration file was loaded but was unable to be mapped to ");
                _logger.LogError(ex.Message);
                _logger.LogError("How to Solve: Malformed configurations are usually a result of changes between versions. The best way to understand the change is to run 'migration.exe init' to create a new wel formed config and determin where the problem is!");
                Environment.Exit(-1);
                return(null);
            }

            //var builder = new ConfigurationBuilder();
            //builder.SetBasePath(Directory.GetCurrentDirectory());
            //builder.AddJsonFile(configFile, optional: false, reloadOnChange: true);
            //IConfigurationRoot configuration = builder.Build();
            //var settings = new EngineConfiguration();
            //configuration.Bind(settings);
            //#if !DEBUG
            string appVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(2);

            if (ec?.Version != appVersion)
            {
                _logger.LogError("The config version {Version} does not match the current app version {appVersion}. There may be compatability issues and we recommend that you generate a new default config and then tranfer the settings accross.", ec.Version, appVersion);
                throw new Exception("Version in Config does not match X.X in Application. Please check and revert.");
            }
            //#endif
            return(ec);
        }
        public EngineConfiguration CreateEmptyConfig()
        {
            EngineConfiguration ec = new EngineConfiguration
            {
                LogLevel  = LogEventLevel.Information,
                Version   = Assembly.GetExecutingAssembly().GetName().Version.ToString(2),
                FieldMaps = new List <IFieldMapConfig>(),
                WorkItemTypeDefinition = new Dictionary <string, string> {
                    { "sourceWorkItemTypeName", "targetWorkItemTypeName" }
                },
                Processors = new List <IProcessorConfig>(),
            };

            ec.Source = GetMigrationConfigDefault();
            ec.Target = GetMigrationConfigDefault();
            return(ec);
        }
 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);
 }
        public EngineConfiguration CreateEmptyConfig()
        {
            EngineConfiguration ec = new EngineConfiguration
            {
                LogLevel = LogEventLevel.Information,
                Version  = Assembly.GetExecutingAssembly().GetName().Version.ToString(2),
                Source   = new TeamProjectConfig()
                {
                    Project = "migrationSource1",
                    AllowCrossProjectLinking = false,
                    Collection = new Uri("https://dev.azure.com/nkdagility-preview/"),
                    ReflectedWorkItemIDFieldName = "Custom.ReflectedWorkItemId",
                    PersonalAccessToken          = "",
                    LanguageMaps = new LanguageMaps()
                    {
                        AreaPath = "Area", IterationPath = "Iteration"
                    }
                },
                Target = new TeamProjectConfig()
                {
                    Project = "migrationTarget1",
                    AllowCrossProjectLinking = false,
                    Collection = new Uri("https://dev.azure.com/nkdagility-preview/"),
                    ReflectedWorkItemIDFieldName = "Custom.ReflectedWorkItemId",
                    PersonalAccessToken          = "",
                    LanguageMaps = new LanguageMaps()
                    {
                        AreaPath = "Area", IterationPath = "Iteration"
                    }
                },
                FieldMaps = new List <IFieldMapConfig>(),
                WorkItemTypeDefinition = new Dictionary <string, string> {
                    { "sourceWorkItemTypeName", "targetWorkItemTypeName" }
                },
                Processors = new List <IProcessorConfig>()
            };

            return(ec);
        }
 private void AddExampleFieldMapps(EngineConfiguration ec)
 {
     ec.FieldMaps.Add(new MultiValueConditionalMapConfig()
     {
         WorkItemTypeName      = "*",
         sourceFieldsAndValues = new Dictionary <string, string>
         {
             { "Field1", "Value1" },
             { "Field2", "Value2" }
         },
         targetFieldsAndValues = new Dictionary <string, string>
         {
             { "Field1", "Value1" },
             { "Field2", "Value2" }
         }
     });
     ec.FieldMaps.Add(new FieldBlankMapConfig()
     {
         WorkItemTypeName = "*",
         targetField      = "TfsMigrationTool.ReflectedWorkItemId"
     });
     ec.FieldMaps.Add(new FieldValueMapConfig()
     {
         WorkItemTypeName = "*",
         sourceField      = "System.State",
         targetField      = "System.State",
         defaultValue     = "New",
         valueMapping     = new Dictionary <string, string> {
             { "Approved", "New" },
             { "New", "New" },
             { "Committed", "Active" },
             { "In Progress", "Active" },
             { "To Do", "New" },
             { "Done", "Closed" },
             { "Removed", "Removed" }
         }
     });
     ec.FieldMaps.Add(new FieldtoFieldMapConfig()
     {
         WorkItemTypeName = "*",
         sourceField      = "Microsoft.VSTS.Common.BacklogPriority",
         targetField      = "Microsoft.VSTS.Common.StackRank"
     });
     ec.FieldMaps.Add(new FieldtoFieldMultiMapConfig()
     {
         WorkItemTypeName       = "*",
         SourceToTargetMappings = new Dictionary <string, string>
         {
             { "SourceField1", "TargetField1" },
             { "SourceField2", "TargetField2" }
         }
     });
     ec.FieldMaps.Add(new FieldtoTagMapConfig()
     {
         WorkItemTypeName = "*",
         sourceField      = "System.State",
         formatExpression = "ScrumState:{0}"
     });
     ec.FieldMaps.Add(new FieldMergeMapConfig()
     {
         WorkItemTypeName = "*",
         sourceField1     = "System.Description",
         sourceField2     = "Microsoft.VSTS.Common.AcceptanceCriteria",
         targetField      = "System.Description",
         formatExpression = @"{0} <br/><br/><h3>Acceptance Criteria</h3>{1}"
     });
     ec.FieldMaps.Add(new RegexFieldMapConfig()
     {
         WorkItemTypeName = "*",
         sourceField      = "COMPANY.PRODUCT.Release",
         targetField      = "COMPANY.DEVISION.MinorReleaseVersion",
         pattern          = @"PRODUCT \d{4}.(\d{1})",
         replacement      = "$1"
     });
     ec.FieldMaps.Add(new FieldValuetoTagMapConfig()
     {
         WorkItemTypeName = "*",
         sourceField      = "Microsoft.VSTS.CMMI.Blocked",
         pattern          = @"Yes",
         formatExpression = "{0}"
     });
     ec.FieldMaps.Add(new TreeToTagMapConfig()
     {
         WorkItemTypeName = "*",
         timeTravel       = 1,
         toSkip           = 3
     });
 }
예제 #6
0
 private void AddWorkItemMigrationDefault(EngineConfiguration ec)
 {
     ec.Processors.Add(new WorkItemMigrationConfig());
 }