示例#1
0
        /// <summary>
        /// Gets the opa transformation path for.
        /// </summary>
        /// <param name="thisRulebase">this rulebase.</param>
        /// <returns>
        /// the path to the transformation file
        /// </returns>
        public string GetOPATransformationPathFor(IRulebaseConfiguration thisRulebase)
        {
            var operatingYear = thisRulebase.OperatingYear.AsString();
            var workingFolder = thisRulebase.PointerToZip;
            var candidatePath = Path.Combine(workingFolder, Asset.FolderNames.OPARules, thisRulebase.ShortName);
            var files         = GetFileInformationFor(candidatePath, EasyOPAConstant.TransformationFileSearchPattern);

            if (!files.Any())
            {
                workingFolder = Path.Combine(Location.OfAssets, operatingYear, Asset.Locations.Production);
                candidatePath = Path.Combine(workingFolder, Asset.FolderNames.OPARules, thisRulebase.ShortName);
                files         = GetFileInformationFor(candidatePath, EasyOPAConstant.TransformationFileSearchPattern);
            }

            var failedCount = !It.HasCountOf(files, 1);

            failedCount.
            AsGuard <ArgumentException>(Format.String(fileCountFailedMsg, "transformation", thisRulebase.ShortName));

            var candidate = files.First();
            var fileName  = Path.GetFileName(candidate);

            var failedMatch = It.IsDifferent(fileName, thisRulebase.OPATransform);

            failedMatch
            .AsGuard <ArgumentException>(Format.String(matchFailedMsg, "transformation", fileName, thisRulebase.ShortName));

            return(candidate);
        }
示例#2
0
        /// <summary>
        /// Perform supplmental load.
        /// Once the intial load is conducted and a health check
        /// performed, we can do some supplemental stuff...
        /// </summary>
        /// <param name="onConcretion">on concretion.</param>
        public override void PerformSupplmentalLoad(RulesetConfiguration onConcretion)
        {
            // rulebase configuration for experimental loads
            onConcretion.Rulebases
            .Where(x => x.ExecutionType == TypeOfRulebaseExecution.OPA)
            .ForEach(rulebase =>
            {
                var isExperimental = true;
                var operatingYear  = rulebase.OperatingYear.AsString();
                var workingFolder  = Path.Combine(Location.OfAssets, operatingYear, Asset.Locations.Experimental);
                var candidatePath  = Path.Combine(workingFolder, Asset.FolderNames.OPARules, rulebase.ShortName);
                var files          = GetFileInformationFor(candidatePath, EasyOPAConstant.ZipFileSearchPattern);

                if (!UseExperimental || !files.Any())
                {
                    isExperimental = false;
                    workingFolder  = Path.Combine(Location.OfAssets, operatingYear, Asset.Locations.Production);
                    candidatePath  = Path.Combine(workingFolder, Asset.FolderNames.OPARules, rulebase.ShortName);
                    files          = GetFileInformationFor(candidatePath, EasyOPAConstant.ZipFileSearchPattern);
                }

                var failedCount = !It.HasCountOf(files, 1);
                failedCount
                .AsGuard <ArgumentException>(Format.String(fileCountFailedMsg, "zip", rulebase.ShortName));

                rulebase.Set(UseExperimental && isExperimental, workingFolder);
            });

            Mediator.Publish(Message.Create(Configured.Rulebases));
        }
示例#3
0
        public SQLSchema(string xmlSchemaPath)
        {
            //Load the schema
            var schema = LoadSchema(xmlSchemaPath);

            //Get the namespace
            NameSpace      = schema.TargetNamespace;
            Tables         = Collection.Empty <SQLTable>();
            TableHierarchy = new XmlDocument();

            //Loop through the top-level elements - only be one of these too
            var elements = schema.Elements.Values
                           .OfType <XmlSchemaElement>()
                           .AsSafeReadOnlyList();

            var failedCount = !It.HasCountOf(elements, 1);

            failedCount.AsGuard <ArgumentException>("too many root elements");

            elements.ForEach(x => TraverseParticle(x, schema, TableHierarchy, null));
        }
        /// <summary>
        /// Supplmental load.
        /// Once the intial load is conducted and a health check
        /// performed, we can do some supplemental stuff...
        /// </summary>
        /// <param name="onConcretion">on concretion.</param>
        public override void PerformSupplmentalLoad(SQLBatchConfiguration onConcretion)
        {
            if (!UseExperimental)
            {
                return;
            }

            // load the experimental SQL files from the asset folder.
            It.IsNull(onConcretion)
            .AsGuard <ArgumentNullException>(nameof(onConcretion));

            var yearList = GetYearList();

            yearList.ForEach(year =>
            {
                var workingFolder = Path.Combine(Location.OfAssets, year, Asset.Locations.Experimental);
                var files         = GetFileInformationFor(workingFolder, EasyOPAConstant.ScriptFileSearchPattern);

                files.ForEach(file =>
                {
                    var shortCommand = Path.GetFileNameWithoutExtension(file);

                    var existing = onConcretion.Batches
                                   .SelectMany(x => x.Scripts)
                                   .Where(y => y.Command.Contains(year) && y.Command.Contains(shortCommand))
                                   .AsSafeReadOnlyList();

                    // one file per 'year' of operation
                    var notFound = !It.HasCountOf(existing, 1);
                    notFound
                    .AsGuard <ArgumentException>($"unable to supplant original script: not found {shortCommand}");

                    existing.ForEach(x =>
                    {
                        x.Command     = file;
                        x.Description = $"{x.Description} - Experimental script";
                    });
                });
            });
        }
        public char GetWorkPlaceEmpIdChecksum(int workPlaceEmpId)
        {
            /*
             * Calculate the checksum digit based on characters 1 to 8 using the formula
             *  [11 - ((9 * 1st digit + 8 * 2nd digit + 7 * 3rd digit + 6 * 4th digit + 5 * 5th digit + 4 * 6th digit + 3 * 7th digit + 2 * 8th digit) mod 11)]
             * if result = 11 set DD14 to 0,
             * if result = 10
             *      or the LearningDeliveryWorkPlacement.WorkPlaceEmpId is not 9 characters in length
             *      set DD14 to 'X',
             *  otherwise set DD14 to number of the result(1 - 9)
             */

            var list = workPlaceEmpId.AsSafeReadOnlyDigitList();

            if (!It.HasCountOf(list, _requiredIDLength))
            {
                return(InvalidLengthChecksum);
            }

            var result = 11 - (Sum(list) % 11);

            return(_validChecksums[result]);
        }
示例#6
0
        /// <summary>
        /// Gets the opa configuration for.
        /// </summary>
        /// <param name="thisRulebase">this rulebase.</param>
        /// <returns>
        /// the cleansed and detokenised configuration file
        /// </returns>
        public string GetOPAConfigurationFor(IRulebaseConfiguration thisRulebase)
        {
            var operatingYear = thisRulebase.OperatingYear.AsString();
            var workingFolder = thisRulebase.PointerToZip;
            var candidatePath = Path.Combine(workingFolder, Asset.FolderNames.OPAConfig, thisRulebase.ShortName);
            var files         = GetFileInformationFor(candidatePath, EasyOPAConstant.ConfigurationFileSearchPattern);

            if (!files.Any())
            {
                workingFolder = Path.Combine(Location.OfAssets, operatingYear, Asset.Locations.Production);
                candidatePath = Path.Combine(workingFolder, Asset.FolderNames.OPAConfig, thisRulebase.ShortName);
                files         = GetFileInformationFor(candidatePath, EasyOPAConstant.ConfigurationFileSearchPattern);
            }

            var failedCount = !It.HasCountOf(files, 1);

            failedCount.
            AsGuard <ArgumentException>(Format.String(fileCountFailedMsg, "configuration", thisRulebase.ShortName));

            var candidate = files.First();
            var fileName  = Path.GetFileName(candidate);

            var failedMatch = It.IsDifferent(fileName, thisRulebase.OPAConfiguration);

            failedMatch
            .AsGuard <ArgumentException>(Format.String(matchFailedMsg, "configuration", fileName, thisRulebase.ShortName));

            var schema = Schema.GetSchema(thisRulebase.OperatingYear);

            // regardless of where the configuration files are,
            // we always set the location of the zip file to the pointer
            return(File
                   .ReadAllText(candidate)
                   .Replace(Token.ForWorkingFolder, thisRulebase.PointerToZip)
                   .Replace(Token.ForPeriodStartDate, schema.PeriodStartDate));
        }
        /// <summary>
        /// Gets the employer identifier checksum.
        /// </summary>
        /// <param name="thisEmployer">this employer.</param>
        /// <returns>
        /// the checksum character
        /// </returns>
        public char GetEmployerIDChecksum(int thisEmployer)
        {
            /*
             *  Calculate the checksum digit based on characters 1 to 8 using the formula
             *      [11 - ((9*1st digit + 8*2nd digit + 7*3rd digit + 6*4th digit + 5*5th digit + 4*6th digit + 3*7th digit + 2*8th digit) mod 11)]
             *      if result = 11 set DD05 to 0,
             *      if result = 10
             *          or the LearningEmploymentStatus.EmpId is not 9 characters in length
             *          set DD05 to 'X',
             *      otherwise set DD05 to number of the result (1-9).
             */

            var list = thisEmployer.AsSafeReadOnlyDigitList();

            // the employer id has to have a length of 9 digits
            if (!It.HasCountOf(list, _requiredIDLength))
            {
                return(InvalidLengthChecksum);
            }

            var result = 11 - (Sum(list) % 11);

            return(_validChecksums[result]);
        }