Ejemplo n.º 1
0
        /// <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>
        /// Store exists, a cleanse routine will be executed
        /// </summary>
        /// <param name="usingContext">using context.</param>
        /// <param name="forProvider">for provider.</param>
        /// <param name="inYear">in year.</param>
        public override void StoreExists(IContainSessionContext usingContext, int forProvider, BatchOperatingYear inYear)
        {
            var batch = Batches.GetBatch(BatchProcessName.CleanseProcessingDataStore, inYear);

            Emitter.Publish(batch.Description);

            Context.Run(batch.Scripts, usingContext.ProcessingLocation, x => Token.DoSecondaryPass(x, forProvider));
        }
        /// <summary>
        /// Loads...
        /// </summary>
        /// <param name="intoSource">into source.</param>
        /// <param name="onMaster">on master.</param>
        /// <param name="fromInputFile">from input file.</param>
        /// <returns>
        /// the currently running task
        /// </returns>
        public async Task Load(IConnectionDetail intoSource, IConnectionDetail onMaster, string fromInputFile)
        {
            await Task.Run(async () =>
            {
                It.IsNull(intoSource)
                    .AsGuard<ArgumentNullException>(nameof(intoSource));
                It.IsNull(onMaster)
                    .AsGuard<ArgumentNullException>(nameof(onMaster));
                It.IsEmpty(fromInputFile)
                    .AsGuard<ArgumentNullException>(nameof(fromInputFile));

                //if (Context.DataStoreExists(intoSource.Name, onMaster))
                //{
                //    Context.DropDataStore(intoSource.Name, onMaster);
                //}

                Emitter.Publish($"Creating data store: {intoSource.DBName}");

                //Context.CreateDataStore(intoSource.Name, onMaster);

                var content = await FileManager.Load(fromInputFile); // <= very lazy and inefficient..
                var messageNamespace = GetHeaderNameSpace(content);

                It.IsEmpty(messageNamespace)
                    .AsGuard<ArgumentException, Localised>(Localised.UnableToRetrieveMessageNamespace);

                var buildSchema = await Schema.Generate(
                    messageNamespace,
                    intoSource,
                    (inContext, loadSchemaPath, createTables) =>
                    {
                        var loader = GetLoader(inContext, createTables);
                        loader.Execute(loadSchemaPath, fromInputFile);
                    });

                Mediator.Publish(ChangeYearMessage.Create(buildSchema.Year, buildSchema.Collection));

                var batchList = Batches.GetBatch(BatchProcessName.BuildSourceDataStore, buildSchema.Year);
                var s = batchList.Scripts.ElementAt(1).Command;
                if (s.Contains("ILR"))
                {
                    s = Regex.Replace(s, @"[A-Z]\w+-[0-9]\w+-[0-9]\w+-[0-9]\w+-[0-9]\w+-[0-9]\w+", Path.GetFileNameWithoutExtension(fromInputFile));
                }
                else
                {
                    s = s.Replace("originalFileName", Path.GetFileNameWithoutExtension(fromInputFile));
                }
                batchList.Scripts.ElementAt(1).Command = s;

                Emitter.Publish(batchList.Description);

                Context.Run(batchList.Scripts, intoSource);
            });
        }
        /// <summary>
        /// Builds the store.
        /// </summary>
        /// <param name="usingContext">using context.</param>
        /// <param name="forProvider">for provider.</param>
        /// <param name="inYear">in year.</param>
        public override void BuildStore(IContainSessionContext usingContext, int forProvider, BatchOperatingYear inYear)
        {
            var batch = Batches.GetBatch(BatchProcessName.BuildProcessingDataStore, inYear);

            Emitter.Publish(batch.Description);

            var forTarget = usingContext.ProcessingLocation;

            CreateSchemaFor(
                forTarget,
                batch.Scripts.AsSafeReadOnlyList(),
                x => Token.DoSecondaryPass(x, inYear, forTarget, usingContext.ReturnPeriod));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the script.
        /// </summary>
        /// <param name="forProcessName">for process name</param>
        /// <param name="withCandidate">with candidate.</param>
        /// <returns>
        /// the 'de' tokenised script
        /// </returns>
        public string GetScript(BatchProcessName forProcessName, string withCandidate = null)
        {
            var batch  = Batches.GetBatch(forProcessName);
            var script = batch.Scripts.First();

            var failedType = !It.IsInRange(script.Type, TypeOfBatchScript.Statement);

            failedType
            .AsGuard <ArgumentException>($"script should be a statement {forProcessName}");

            return(It.Has(withCandidate)
                ? script.Command.Replace(Token.ForSourceDataStore, withCandidate)
                : script.Command);
        }
        /// <summary>
        /// Builds the store.
        /// </summary>
        /// <param name="usingContext">using context.</param>
        /// <param name="forProvider">for provider.</param>
        /// <param name="inYear">in year.</param>
        public override void BuildStore(IContainSessionContext usingContext, int forProvider, BatchOperatingYear inYear)
        {
            var batch = Batches.GetBatch(BatchProcessName.BuildResultsDataStore, inYear);

            Emitter.Publish(batch.Description);

            //CreateDataStoreUsing(usingContext, batch.Scripts.First());

            var    command     = $"select TOP(1) [FileName] from [Valid].[File] WHERE [FileName] like '%{forProvider}%';";
            string ilrFileName = RunSafe.Try(() => Coordinate.GetAtom <string>(command, usingContext.SourceLocation));
            var    forTarget   = usingContext.ResultsDestination;

            CreateSchemaFor(
                forTarget,
                batch.Scripts.AsSafeReadOnlyList(),
                x => Token.DoSecondaryPass(x, inYear, forTarget, usingContext.ReturnPeriod, ilrFileName, forProvider.ToString()));
        }
        /// <summary>
        /// Store exists, a cleanse routine will be executed
        /// </summary>
        /// <param name="usingContext">using context.</param>
        /// <param name="forProvider">for provider.</param>
        /// <param name="inYear">in year.</param>
        public override void StoreExists(IContainSessionContext usingContext, int forProvider, BatchOperatingYear inYear)
        {
            var forTarget = usingContext.ResultsDestination;
            var batch     = Batches.GetBatch(BatchProcessName.BuildResultsDataStore, inYear);

            if (!Context.StoreTableExists("Valid.Learner", forTarget))
            {
                CreateSchemaFor(
                    forTarget,
                    batch.Scripts.Skip(1).AsSafeReadOnlyList(),
                    x => Token.DoSecondaryPass(x, inYear, forTarget, usingContext.ReturnPeriod));
            }

            batch = Batches.GetBatch(BatchProcessName.CleanseResultsDataStore);

            Emitter.Publish(batch.Description);

            Context.Run(batch.Scripts, forTarget, x => Token.DoSecondaryPass(x, forProvider));
        }