/// <summary> /// Exports to ILR /// </summary> /// <param name="usingSource">using source.</param> /// <param name="inContext">in context.</param> /// <param name="forProvider">for provider.</param> /// <returns> /// the currently running task /// </returns> public async Task Export(IInputDataSource usingSource, IConnectionDetail inContext, int forProvider) { It.IsNull(usingSource) .AsGuard <ArgumentNullException>(nameof(usingSource)); It.IsNull(inContext) .AsGuard <ArgumentNullException>(nameof(inContext)); await Task.Run(async() => { using (Timing.BeginScope($"Export file for {forProvider}")) { var schema = Schemas.GetSchema(usingSource.OperatingYear); var schemaPath = Path.Combine(Location.OfAssets, schema.Message); var templatePath = Path.Combine(Location.OfAssets, schema.BulkExport); var candidate = await FileManager.Load(templatePath); var batch = Batches.GetBatch(BatchProcessName.ExportSourceDataToILRFile, usingSource.OperatingYear); candidate = candidate.Replace(Token.ForNamespace, schema.Namespace); batch.Scripts .ForEach(script => RunScript(script, inContext, forProvider, ref candidate)); var outputPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "exportILR.xml"); await FileManager.Save(outputPath, candidate); await StripEmptyTags(outputPath); Emitter.Publish(Indentation.FirstLevel, CommonLocalised.Completed); //(!await Validator.IsValid(outputPath, schemaPath)) // .AsGuard<OperationCanceledException, CommonLocalised>(CommonLocalised.SchemaValidationFailed); } }); }
/// <summary> /// Generates the schema. /// </summary> /// <param name="forMessageNamespace">for message namespace.</param> /// <param name="inContext">in context.</param> /// <param name="andExecuteBulkload">and execute (a) bulk load</param> /// <returns> /// the schema map sued to generate the data source /// </returns> public async Task <ISchemaMap> Generate(string forMessageNamespace, IConnectionDetail inContext, Action <IConnectionDetail, string, bool> andExecuteBulkload) { It.IsEmpty(forMessageNamespace) .AsGuard <ArgumentNullException>(nameof(forMessageNamespace)); It.IsNull(andExecuteBulkload) .AsGuard <ArgumentNullException>(nameof(andExecuteBulkload)); return(await Task.Run(() => { var schemaMap = Schemas.GetSchema(forMessageNamespace); It.IsNull(schemaMap) .AsGuard <ArgumentException, Localised>(Localised.FailedToObtainSchemaMap); var loadSchemaPath = Path.Combine(Location.OfAssets, schemaMap.BulkLoad); var messageSchemaPath = Path.Combine(Location.OfAssets, schemaMap.Message); var relationshipsPath = Path.Combine(Location.OfAssets, "relationships.xml"); SQLDatabase.Open(inContext.SQLDetail); var sqlSchema = new SQLSchema(messageSchemaPath); var relations = GetRelations(relationshipsPath, sqlSchema.NameSpace); sqlSchema.SetRelationships(relations); var autoGenerateTables = false; //var newPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "newSchema.xml"); //var buildSchema = sqlSchema.GenerateBulkLoadSchemaWithIdentity(); //buildSchema.Save(newPath); if (!autoGenerateTables) { sqlSchema.CreateTables(); } andExecuteBulkload(inContext, loadSchemaPath, autoGenerateTables); SQLDatabase.Close(); return schemaMap; })); }