/// <summary> /// Performs the health check. /// </summary> public override void PerformHealthCheck() { // health check on load Configured.Batches .ForEach(batch => { It.IsInRange(batch.Name, BatchProcessName.NotSet) .AsGuard <ArgumentException>("name not set on batch"); It.IsEmpty(batch.Description) .AsGuard <ArgumentException>($"description not set on batch: '{batch.Name}'"); It.IsInRange(batch.OperatingYear, BatchOperatingYear.NotSet) .AsGuard <ArgumentException>($"operating year not set on batch: '{batch.Name}'"); // note: empty script blocks are now acceptable //It.IsEmpty(batch.Scripts) // .AsGuard<ArgumentException>($"no scripts set for batch: '{batch.Name}'"); batch.Scripts .ForEach(script => { It.IsInRange(script.Type, TypeOfBatchScript.NotSet) .AsGuard <ArgumentException>($"script type not set for script on batch: '{batch.Name}'"); It.IsEmpty(script.Description) .AsGuard <ArgumentException>($"description not set for script on batch: '{batch.Name}'"); It.IsEmpty(script.Command) .AsGuard <ArgumentException>($"command not set for script on batch: '{batch.Name}'"); }); }); }
/// <summary> /// Performs the health check. /// </summary> public override void PerformHealthCheck() { // health check on load It.IsEmpty(Configured.Entities) .AsGuard <ArgumentNullException>(nameof(Configured.Entities)); Configured.Entities.ForEach(tableMap => { It.IsEmpty(tableMap.Master) .AsGuard <ArgumentException>($"master not set on tablemap {tableMap.Master}"); It.IsEmpty(tableMap.Target) .AsGuard <ArgumentException>($"target not set on tablemap {tableMap.Target}"); It.IsEmpty(tableMap.Attributes) .AsGuard <ArgumentNullException>($"no column mappings for master table '{tableMap.Master}'"); tableMap.Attributes .ForEach(columnMap => { It.IsEmpty(columnMap.Master) .AsGuard <ArgumentException>($"master not set on column map '{columnMap.Master}'"); It.IsEmpty(columnMap.Target) .AsGuard <ArgumentException>($"target not set on column map '{columnMap.Target}'"); }); }); }
/// <summary> /// process, get (the) area routing detail for... /// </summary> /// <param name="theTouchpointID">the touchpoint id</param> /// <param name="inScope">in logging scope</param> /// <returns>the currently running task containing the response message (success only)</returns> internal async Task <HttpResponseMessage> ProcessGetAreaRoutingDetailFor(string theTouchpointID, IScopeLoggingContext inScope) { await inScope.EnterMethod(); It.IsEmpty(theTouchpointID) .AsGuard <MalformedRequestException>(); await inScope.Information($"seeking the routing details: '{theTouchpointID}'"); var theDetail = await RoutingDetails.Get(theTouchpointID); It.IsNull(theDetail) .AsGuard <MalformedRequestException>(theTouchpointID); await inScope.Information($"candidate search complete: '{theDetail.TouchpointID}'"); await inScope.Information($"preparing response..."); var response = Respond.Ok().SetContent(theDetail); await inScope.Information($"preparation complete..."); await inScope.ExitMethod(); return(response); }
/// <summary> /// process, get (the) area routing detail by... /// </summary> /// <param name="theLocation">the location</param> /// <param name="inScope">in logging scope</param> /// <returns>the currently running task containing the response message (success or fail)</returns> internal async Task <HttpResponseMessage> ProcessGetAreaRoutingDetailBy(string theLocation, IScopeLoggingContext inScope) { await inScope.EnterMethod(); theLocation = theLocation?.Trim(); It.IsEmpty(theLocation) .AsGuard <MalformedRequestException>(); await inScope.Information($"seeking the routing details for: '{theLocation}'"); await inScope.Information($"analysing the expression type..."); var theExpressionType = Analyser.GetTypeOfExpressionFor(theLocation); await inScope.Information($"seeking the action for expression type: '{theExpressionType}'"); var actionDo = Actions.GetActionFor(theExpressionType); await inScope.Information($"action for expression type: '{actionDo.Method.Name}'"); var theTouchpoint = await actionDo(theLocation, inScope); await inScope.Information($"action execution complete..."); await inScope.ExitMethod(); return(await ProcessGetAreaRoutingDetailFor(theTouchpoint, inScope)); }
/// <summary> /// get (the) touchpoint id from (the) Postcode /// </summary> /// <param name="theCandidate">the candidate</param> /// <param name="usingScope">using (the logging) scope</param> /// <returns>the LAD code</returns> public async Task <string> GetTouchpointIDFromPostcode(string theCandidate, IScopeLoggingContext usingScope) { await usingScope.EnterMethod(); await usingScope.Information($"seeking postcode '{theCandidate}'"); var result = await Postcode.LookupAsync(theCandidate); It.IsNull(result) .AsGuard <InvalidPostcodeException>(theCandidate); It.IsEmpty(result.Postcode) .AsGuard <InvalidPostcodeException>(theCandidate); await usingScope.Information($"found postcode for '{result.Postcode}'"); await usingScope.Information($"seeking local authority '{result.Codes.AdminDistrict}'"); var authority = await Authority.Get(result.Codes.AdminDistrict); await usingScope.Information($"found local authority '{authority.LADCode}'"); await usingScope.ExitMethod(); return(authority.TouchpointID); }
/// <summary> /// Validates the specified object. /// </summary> /// <param name="objectToValidate">The object to validate.</param> public void Validate(ILearner objectToValidate) { It.IsNull(objectToValidate) .AsGuard <ArgumentNullException>(nameof(objectToValidate)); var learnRefNumber = objectToValidate.LearnRefNumber; var fromDeliveries = objectToValidate.LearningDeliveries.AsSafeReadOnlyList(); var qualifyingAim = GetQualifyingdAimOn(fromDeliveries); if (It.IsNull(qualifyingAim)) { return; } var eligibilities = GetEligibilityRulesFor(qualifyingAim); if (It.IsEmpty(eligibilities)) { return; } var fromEmployments = objectToValidate.LearnerEmploymentStatuses.AsSafeReadOnlyList(); var employment = _check.GetEmploymentStatusOn(qualifyingAim.LearnStartDate, fromEmployments); if (It.IsNull(employment)) { return; } if (IsNotValid(eligibilities, employment)) { RaiseValidationMessage(learnRefNumber, qualifyingAim, employment); } }
/// <summary> /// Gets the list. /// </summary> /// <typeparam name="TReturn">The type of the return.</typeparam> /// <param name="usingThisCommand">using this command.</param> /// <param name="inThisContext">in this context.</param> /// <returns> /// an list of type <typeparamref name="TReturn" /> /// </returns> public ICollection <TReturn> GetList <TReturn>(string usingThisCommand, IConnectionDetail inThisContext) { It.IsEmpty(usingThisCommand) .AsGuard <ArgumentNullException>(nameof(usingThisCommand)); It.IsNull(inThisContext) .AsGuard <ArgumentNullException>(nameof(inThisContext)); return(UsingConnection(inThisContext, x => { var tempList = Collection.Empty <TReturn>(); using (var cmd = CreateCommand(usingThisCommand, x)) { using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var candidate = reader.GetValue(0); tempList.Add(GetValue <TReturn>(candidate)); } } } return tempList; })); }
/// <summary> /// Cleanses the SQL operations. /// </summary> /// <param name="usingThisContent">using this content</param> /// <returns> /// a list of cleansed SQL operations /// </returns> public IReadOnlyCollection <string> CleanseSQLOperations(string usingThisContent) { It.IsEmpty(usingThisContent) .AsGuard <ArgumentNullException>(nameof(usingThisContent)); var temp = usingThisContent .Split(scriptSplits, StringSplitOptions.RemoveEmptyEntries) .AsSafeReadOnlyList(); var results = new List <string>(); // minify... this started with removing tabs on some statements, not sure why... // don't remove 'new lines' ("\r\n") as some scripts contain comments... temp.ForEach(x => { var candidate = x; while (candidate.StartsWith("\r\n") || candidate.StartsWith("\n") || candidate.StartsWith(" \n")) { var startPoint = candidate.IndexOf("\n") + 1; candidate = candidate.Substring(startPoint); } replacements.ForEach(y => candidate = candidate.Replace(y.Key, y.Value)); candidate = candidate.Trim(); if (It.Has(candidate)) { results.Add(candidate); } }); return(results); }
/// <summary> /// Imports the file... /// </summary> /// <param name="usingInstance">using instance.</param> /// <param name="getFileName">get the name of the file</param> /// <param name="andConfirmAnyChallenge">and confirm any challenge.</param> /// <returns> /// the current task /// </returns> public async Task Import(string usingInstance, string usingDatabase, string dbUser, string dbPassword, Func <string> getFileName, Func <string, bool> andConfirmAnyChallenge) { It.IsNull(getFileName) .AsGuard <ArgumentNullException>(nameof(getFileName)); await Handler.RunAsyncOperation <Localised>(async() => { Emitter.Publish("Selecting file..."); var inputFilePath = getFileName(); It.IsEmpty(inputFilePath) .AsGuard <OperationCanceledException, CommonLocalised>(CommonLocalised.CanceledOperation); //var candidateSourceName = Path.GetFileNameWithoutExtension(inputFilePath); // check for DB overwrite... Emitter.Publish("Checking for risk of overwrite..."); var master = Provider.ConnectionToMaster(usingInstance, usingDatabase, dbUser, dbPassword); //if (Context.DataStoreExists(candidateSourceName, master)) //{ // var format = Locals.GetString(Localised.AboutToOverwriteDBFormat); // var msg = Format.String(format, candidateSourceName); // (!andConfirmAnyChallenge(msg)) // .AsGuard<OperationCanceledException, CommonLocalised>(CommonLocalised.CanceledOperation); //} var source = Provider.ConnectionToSource(usingInstance, usingDatabase, dbUser, dbPassword); await BulkLoader.Load(source, master, inputFilePath); }); }
/// <summary> /// Gets the SQL operations... /// </summary> /// <param name="usingThisFile">using this file.</param> /// <param name="withSupplementaryTokenReplacements">with supplementary token replacements.</param> /// <returns> /// a list of batch operations /// </returns> public IReadOnlyCollection <string> GetSQLOperations(string usingThisFile, Func <string, string> withSupplementaryTokenReplacements) { It.IsEmpty(usingThisFile) .AsGuard <ArgumentNullException>(nameof(usingThisFile)); var file = Asset.GetContent(usingThisFile).Result; var content = Pseudonyms.ReplaceTokensIn(file, withSupplementaryTokenReplacements); return(CleanseSQLOperations(content)); }
/// <summary> /// Performs the health check. /// </summary> public override void PerformHealthCheck() { Configured.Substitutions.ForEach(x => { It.IsEmpty(x.TokenValue) .AsGuard <ArgumentException>($"no substitution can have an empty {nameof(x.TokenValue)}"); It.IsEmpty(x.TokenValue) .AsGuard <ArgumentException>($"no substitution can have an empty {nameof(x.Substitute)}"); }); }
/// <summary> /// Performs the health check. /// </summary> public override void PerformHealthCheck() { // health check on load Configured.Rulebases.ForEach(rulebase => { It.IsEmpty(rulebase.Name) .AsGuard <ArgumentException>("name not set on rulebase"); It.IsEmpty(rulebase.ShortName) .AsGuard <ArgumentException>("shortname not set on rulebase"); It.IsInRange(rulebase.OperatingYear, BatchOperatingYear.NotSet) .AsGuard <ArgumentException>($"operating year not set on: '{rulebase.ShortName}'"); It.IsInRange(rulebase.ExecutionType, TypeOfRulebaseExecution.NotSet) .AsGuard <ArgumentException>($"execution type not set on: '{rulebase.ShortName}'"); It.IsInRange(rulebase.OperationType, TypeOfRulebaseOperation.NotSet) .AsGuard <ArgumentException>($"operation type not set on: '{rulebase.ShortName}'"); // OPA rules only if (It.IsInRange(rulebase.ExecutionType, TypeOfRulebaseExecution.OPA)) { // Insert count script check It.IsNull(rulebase.InsertCount) .AsGuard <ArgumentException>($"'{rulebase.ShortName}' does not contain a count insert cases script"); It.IsEmpty(rulebase.InsertCount.Command) .AsGuard <ArgumentException>($"'{rulebase.ShortName}' contains an empty count insert cases script"); It.IsInRange(rulebase.InsertCount.Type, TypeOfBatchScript.NotSet, TypeOfBatchScript.File) .AsGuard <ArgumentException>($"'{rulebase.ShortName}' count insert cases script type is invalid"); // OPA configuration checks It.IsEmpty(rulebase.OPAConfiguration) .AsGuard <ArgumentException>("opa configuration not set on rulebase"); It.IsEmpty(rulebase.OPATransform) .AsGuard <ArgumentException>("opa configuration not set on rulebase"); } rulebase.PostRunRoutines .ForEach(x => { It.IsEmpty(x.Command) .AsGuard <ArgumentException>($"'{rulebase.ShortName}' contains an empty post execution script"); // we only expect statements here It.IsInRange(x.Type, TypeOfBatchScript.NotSet) .AsGuard <ArgumentException>($"'{rulebase.ShortName}' count post execution script type is invalid"); }); rulebase.PreRunRoutines .ForEach(x => { It.IsEmpty(x.Command) .AsGuard <ArgumentException>($"'{rulebase.ShortName}' contains an empty pre execution script"); // we only expect statements here It.IsInRange(x.Type, TypeOfBatchScript.NotSet) .AsGuard <ArgumentException>($"'{rulebase.ShortName}' pre execution script type is invalid"); }); }); }
/// <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> /// Store table exists. /// </summary> /// <param name="usingThisName">using this name.</param> /// <param name="inThisContext">in this context.</param> /// <returns> /// true if it does /// </returns> public bool StoreTableExists(string usingThisName, IConnectionDetail inThisContext) { It.IsEmpty(usingThisName) .AsGuard <ArgumentNullException>(nameof(usingThisName)); It.IsNull(inThisContext) .AsGuard <ArgumentNullException>(nameof(inThisContext)); var usingCommand = $"if object_id('{usingThisName}','u') is not null select 1 else select 0"; return(GetAtom <bool>(usingCommand, inThisContext)); }
/// <summary> /// Data store exists? /// </summary> /// <param name="usingStoreName">using the name of the store.</param> /// <param name="inThisContext">in this context.</param> /// <returns> /// the running task containing the result /// </returns> public bool DataStoreExists(string usingStoreName, IConnectionDetail inThisContext) { It.IsEmpty(usingStoreName) .AsGuard <ArgumentNullException>(nameof(usingStoreName)); It.IsNull(inThisContext) .AsGuard <ArgumentNullException>(nameof(inThisContext)); var usingCommand = $"if exists (select * from sys.databases where name = '{usingStoreName}') select 1 else select 0"; return(GetAtom <bool>(usingCommand, inThisContext)); }
/// <summary> /// Drop the data store. /// </summary> /// <param name="usingStoreName">using the name of the store.</param> /// <param name="inThisContext">in this context.</param> public void DropDataStore(string usingStoreName, IConnectionDetail inThisContext) { It.IsEmpty(usingStoreName) .AsGuard <ArgumentNullException>(nameof(usingStoreName)); It.IsNull(inThisContext) .AsGuard <ArgumentNullException>(nameof(inThisContext)); var command = $"drop database [{usingStoreName}]"; UsingConnection(inThisContext, x => RunCommand(command, x)); }
/// <summary> /// delete... /// </summary> /// <param name="theTouchpoint">the touchpoint (id)</param> /// <returns>an area routing detail (the touchpoint)</returns> public async Task Delete(string theTouchpoint) { It.IsEmpty(theTouchpoint) .AsGuard <ArgumentNullException>(nameof(theTouchpoint)); var usingPath = StoragePaths.GetRoutingDetailResourcePathFor(theTouchpoint); (!await DocumentStore.DocumentExists <RoutingDetail>(usingPath, _partitionKey)) .AsGuard <NoContentException>(); await DocumentStore.DeleteDocument(usingPath, _partitionKey); }
/// <summary> /// Saves the output to the specified file. /// </summary> /// <param name="getFileName">gets the name of the file.</param> /// <returns>the running task</returns> public async Task Save(Func <string> getFileName) { await Handler.RunAsyncOperation <CommonLocalised>(async() => { var fileName = getFileName(); It.IsEmpty(fileName) .AsGuard <OperationCanceledException, CommonLocalised>(CommonLocalised.CanceledOperation); await File.Save(fileName, Text); }); }
/// <summary> /// Performs the health check. /// </summary> public override void PerformHealthCheck() { It.IsEmpty(Configured.FolderNames.OPAConfig) .AsGuard <ArgumentException>("OPA configuration location cannot be empty"); It.IsEmpty(Configured.FolderNames.OPARules) .AsGuard <ArgumentException>("OPA rules location cannot be empty"); It.IsEmpty(Configured.Locations.Experimental) .AsGuard <ArgumentException>("experimental folder location cannot be empty"); It.IsEmpty(Configured.Locations.Production) .AsGuard <ArgumentException>("production folder location cannot be empty"); Current = Configured.DefaultRunMode; }
/// <summary> /// Creates the command. /// </summary> /// <param name="usingThisCommand">using this command.</param> /// <param name="inThisContext">in this context.</param> /// <param name="withTimeout">with timeout.</param> /// <returns> /// a newly created command execution object /// </returns> public IDbCommand CreateCommand(string usingThisCommand, IConnectionContext inThisContext) { It.IsEmpty(usingThisCommand) .AsGuard <ArgumentNullException>(nameof(usingThisCommand)); It.IsNull(inThisContext) .AsGuard <ArgumentNullException>(nameof(inThisContext)); var command = inThisContext.Connection.CreateCommand(); command.CommandText = usingThisCommand; command.CommandTimeout = Asset.ConnectionTimeout; // <= set a default timeout of 10 minutes return(command); }
/// <summary> /// Gets the provider details. /// </summary> /// <param name="usingDetail">using detail.</param> /// <param name="providerIDs">provider ids.</param> /// <returns> /// returns a list of enriched provider details /// </returns> public IReadOnlyCollection <IProviderDetails> GetProviderDetails(IConnectionDetail usingDetail, IReadOnlyCollection <int> providerIDs) { if (It.IsEmpty(providerIDs)) { return(Collection.EmptyAndReadOnly <IProviderDetails>()); } var script = GetScript(BatchProcessName.GetProviderDetails); script = Substitute.ReplaceTokensIn(script, x => x.Replace("${providerIDs}", string.Join(",", providerIDs))); return(Context.GetItems <ProviderDetails, IProviderDetails>(script, usingDetail, "Name")); }
/// <summary> /// process, add new authority for... /// submission choices... /// {"LADCode": "E00060060", "Name": "Widdicombe Sands" } /// {"TouchpointID":"0000000102", "LADCode": "E00060060", "Name": "Widdicombe Sands" } /// </summary> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="usingContent">using content</param> /// <param name="inScope">in scope</param> /// <returns>the result of the operation</returns> public async Task <HttpResponseMessage> ProcessAddNewAuthorityFor( string theTouchpoint, string usingContent, IScopeLoggingContext inScope) { await inScope.EnterMethod(); It.IsEmpty(theTouchpoint) .AsGuard <ArgumentNullException>(nameof(theTouchpoint)); It.IsEmpty(usingContent) .AsGuard <ArgumentNullException>(nameof(usingContent)); await inScope.Information($"deserialising the submitted content: '{usingContent}'"); var theCandidate = JsonConvert.DeserializeObject <IncomingLocalAuthority>(usingContent); It.IsNull(theCandidate) .AsGuard <MalformedRequestException>(nameof(ILocalAuthority.LADCode)); await inScope.Information("deserialisation complete..."); if (It.IsEmpty(theCandidate.TouchpointID)) { await inScope.Information($"applying missing touchpoint details: '{theTouchpoint}'"); theCandidate.TouchpointID = theTouchpoint; } await inScope.Information($"validating the candidate: '{theCandidate.LADCode}'"); await Authority.Validate(theCandidate); await inScope.Information($"validation complete..."); await inScope.Information($"adding the candidate: '{theCandidate.LADCode}'"); var result = await Authorities.Add(theCandidate); await inScope.Information($"candidate addition complete..."); await inScope.Information($"preparing response..."); var response = Respond.Created().SetContent(result); await inScope.Information($"preparation complete..."); await inScope.ExitMethod(); return(response); }
public T GetSafe <T>(IDataReader reader, string columnName, T defaultValue = default(T)) { It.IsNull(reader) .AsGuard <ArgumentNullException>(nameof(reader)); It.IsEmpty(columnName) .AsGuard <ArgumentNullException>(nameof(columnName)); var ordinal = GetSafeOrdinal(reader, columnName); It.IsInRange <int>(ordinal, -1) .AsGuard <ArgumentException>(columnName); return(GetSafe(reader, ordinal, defaultValue)); }
/// <summary> /// Get atom... /// </summary> /// <typeparam name="TReturn">The type of the return.</typeparam> /// <param name="usingThisCommand">using this command.</param> /// <param name="inThisContext">in this context.</param> /// <returns> /// an atom of type <typeparamref name="TReturn" /> /// </returns> public TReturn GetAtom <TReturn>(string usingThisCommand, IConnectionDetail inThisContext) { It.IsEmpty(usingThisCommand) .AsGuard <ArgumentNullException>(nameof(usingThisCommand)); It.IsNull(inThisContext) .AsGuard <ArgumentNullException>(nameof(inThisContext)); return(UsingConnection(inThisContext, x => { using (var cmd = CreateCommand(usingThisCommand, x)) { var result = cmd.ExecuteScalar(); return GetValue <TReturn>(result); } })); }
/// <summary> /// add... /// </summary> /// <param name="theCandidate">the candidate (touchpoint)</param> /// <returns>the newly stored routing details (touchpoint)</returns> public async Task <IRoutingDetail> Add(IncomingRoutingDetail theCandidate) { It.IsNull(theCandidate) .AsGuard <ArgumentNullException>(nameof(theCandidate)); var theTouchpoint = theCandidate?.TouchpointID; It.IsEmpty(theTouchpoint) .AsGuard <ArgumentNullException>(nameof(theTouchpoint)); var usingPath = StoragePaths.GetRoutingDetailResourcePathFor(theTouchpoint); (await DocumentStore.DocumentExists <RoutingDetail>(usingPath, _partitionKey)) .AsGuard <ConflictingResourceException>(); return(await DocumentStore.AddDocument(theCandidate, StoragePaths.RoutingDetailCollection)); }
/// <summary> /// get (the) touchpoint id using the outward code /// </summary> /// <param name="theCandidate">the candidate</param> /// <param name="usingScope">using (the logging) scope</param> /// <returns>the LAD code</returns> public async Task <string> GetTouchpointIDFromOutwardCode(string theCandidate, IScopeLoggingContext usingScope) { await usingScope.EnterMethod(); It.IsEmpty(theCandidate) .AsGuard <ArgumentNullException>(nameof(theCandidate)); await usingScope.Information($"seeking postcode via outward code: '{theCandidate}'"); var result = await Postcode.LookupOutwardCodeAsync(theCandidate); It.IsEmpty(result) .AsGuard <NoContentException>(); await usingScope.ExitMethod(); return(await GetTouchpointIDFromPostcode(result.FirstOrDefault(), usingScope)); }
/// <summary> /// Performs the health check. /// </summary> public override void PerformHealthCheck() { Configured.Maps.ForEach(map => { It.IsEmpty(map.BulkLoad) .AsGuard <ArgumentException>("bulk load schema not set on schema map"); It.IsEmpty(map.BulkExport) .AsGuard <ArgumentException>("bulk export template not set on schema map"); It.IsInRange(map.Collection, TypeOfCollection.NotSet) .AsGuard <ArgumentException>("collection type not set on schema map"); It.IsEmpty(map.Message) .AsGuard <ArgumentException>("message schema not set on schema map"); It.IsEmpty(map.Namespace) .AsGuard <ArgumentException>("namespace not set on schema map"); It.IsInRange(map.Year, BatchOperatingYear.NotSet) .AsGuard <ArgumentException>("batch operating year not set on schema map"); }); }
/// <summary> /// Determines whether [is adult funded on benefits at start of aim] [the specified candidate]. /// </summary> /// <param name="delivery">The delivery.</param> /// <param name="learnerEmployments">The learner employments.</param> /// <returns> /// <c>true</c> if [is adult funded on benefits at start of aim] [the specified candidate]; otherwise, <c>false</c>. /// </returns> public bool IsAdultFundedOnBenefitsAtStartOfAim(ILearningDelivery delivery, IReadOnlyCollection <ILearnerEmploymentStatus> learnerEmployments) { It.IsNull(delivery) .AsGuard <ArgumentNullException>(nameof(delivery)); It.IsEmpty(learnerEmployments) .AsGuard <ArgumentNullException>(nameof(learnerEmployments)); /* * if * LearningDelivery.FundModel = 35 * and the learner's Employment status on the LearningDelivery.LearnStartDate of the learning aim * is (EmploymentStatusMonitoring.ESMType = BSI and EmploymentStatusMonitoring.ESMCode = 1, 2, 3 or 4) * set to Y, * otherwise set to N */ return(_check.HasQualifyingFunding(delivery, TypeOfFunding.AdultSkills) && InReceiptOfBenefits(learnerEmployments, delivery.LearnStartDate)); }
/// <summary> /// Gets the header name space. /// </summary> /// <param name="content">The content.</param> /// <returns>a 'grepped' and cleansed message namespace</returns> public string GetHeaderNameSpace(string content) { It.IsEmpty(content) .AsGuard<ArgumentNullException>(nameof(content)); // get the header part var msgHeader = content.Substring(content.IndexOf("<Message"), 200); // strip out the namespaces var temp = msgHeader .Substring(9, msgHeader.IndexOf(">")) .Split(new string[] { "xmlns" }, StringSplitOptions.RemoveEmptyEntries); // 'our' namespace doesn't have an alias var candidate = temp.FirstOrDefault(x => x.StartsWith("=")); candidate = candidate.Substring(2, candidate.Length - 2); candidate = candidate.Substring(0, candidate.IndexOf("\"")); return candidate; }
/// <summary> /// Gets the items. /// this is a very simple list hydration class /// </summary> /// <typeparam name="TReturn">The return type.</typeparam> /// <typeparam name="TContract">the returning contract type</typeparam> /// <param name="usingThisCommand">using this command.</param> /// <param name="inThisContext">in this context.</param> /// <param name="mappedProperties">with mapped properties.</param> /// <returns> /// an list of type <typeparamref name="TContract" /> /// </returns> public IReadOnlyCollection <TContract> GetItems <TReturn, TContract>(string usingThisCommand, IConnectionDetail inThisContext, params string[] mappedProperties) where TContract : class where TReturn : class, TContract, new() { It.IsEmpty(usingThisCommand) .AsGuard <ArgumentNullException>(nameof(usingThisCommand)); It.IsNull(inThisContext) .AsGuard <ArgumentNullException>(nameof(inThisContext)); return(UsingConnection(inThisContext, x => { using (var cmd = CreateCommand(usingThisCommand, x)) { using (var reader = cmd.ExecuteReader()) { return CollectionFromDataReader <TReturn, TContract>(reader, mappedProperties); } } })); }