public static Configuration CreateApiConfiguration(IConfiguration pledgeConfig) { var apiConfig = new Configuration { Id = pledgeConfig.Id, Name = pledgeConfig.Name, Author = pledgeConfig.Author, Description = pledgeConfig.Description, InputSchema = new Schema { IsDelimited = pledgeConfig.Model.InputType == DocumentType.Delimited, Delimiter = pledgeConfig.Model.InputDelimiter, HasHeaderRow = pledgeConfig.Model.InputHasHeader, Rows = pledgeConfig.Model.InputSchema.Select(item => { return new SchemaRow { InputHeader = item.ColumnName, InputIndex = item.ColumnIndex, InputLength = item.ColumnLength }; }).ToList() }, OutputSchema = new Schema { IsDelimited = pledgeConfig.Model.OutputType == DocumentType.Delimited, Delimiter = pledgeConfig.Model.OutputDelimiter, HasHeaderRow = pledgeConfig.Model.OutputHasHeader, Rows = pledgeConfig.Model.OutputSchema.Select(item => { return new SchemaRow { InputHeader = item.InputColumnName, InputIndex = item.InputColumnIndex, OutputHeader = item.ColumnName, OutputIndex = item.ColumnIndex, OutputLength = item.ColumnLength }; }).ToList() }, Rules = DeconstructRules(pledgeConfig) }; return apiConfig; }
/// <summary> /// Creates a pledge configuration from the specified api configuration. /// </summary> /// <param name="apiConfig">The API configuration.</param> /// <returns></returns> public static IConfiguration CreatePledgeConfiguration(Configuration apiConfig) { var pledgeConfig = new BaseConfiguration { Id = apiConfig.Id, Name = apiConfig.Name, Author = apiConfig.Author, Description = apiConfig.Description, Rules = ReconstructRules(apiConfig.InputSchema, apiConfig.Rules), Model = new BaseDocument { InputType = apiConfig.InputSchema.IsDelimited ? DocumentType.Delimited : DocumentType.FixedLength, OutputType = apiConfig.OutputSchema.IsDelimited ? DocumentType.Delimited : DocumentType.FixedLength, InputDelimiter = apiConfig.OutputSchema.Delimiter, OutputDelimiter = apiConfig.InputSchema.Delimiter, InputHasHeader = apiConfig.InputSchema.HasHeaderRow, OutputHasHeader = apiConfig.OutputSchema.HasHeaderRow, InputSchema = RebuildSchema(apiConfig.InputSchema.Rows), OutputSchema = RebuildSchema(apiConfig.InputSchema.Rows, apiConfig.OutputSchema.Rows, apiConfig.Rules) } }; return pledgeConfig; }
public void SaveConfiguration(Configuration configuration) { var pledgeManager = new PledgeManager(); var coreConfiguration = ModelTransformer.CreatePledgeConfiguration(configuration); pledgeManager.SaveConfiguration(coreConfiguration); }