public static async Task <ActivityResponse> LogQueryProjectionInFlightActivity( [ActivityTrigger] DurableActivityContext context, ILogger log) { // TODO: Pass this as a parameter CQRSAzure.EventSourcing.IWriteContext writeContext = null; ActivityResponse resp = new ActivityResponse() { FunctionName = "LogQueryProjectionInFlightActivity" }; ProjectionRequest projectionRequest = context.GetInput <ProjectionRequest>(); if (null != projectionRequest) { await QueryLogRecord.LogProjectionStarted( projectionRequest.CorrelationIdentifier, projectionRequest.ParentRequestName, projectionRequest.ProjectionName, projectionRequest.DomainName, projectionRequest.AggregateTypeName, projectionRequest.AggregateInstanceUniqueIdentifier, projectionRequest.AsOfDate, projectionRequest.CorrelationIdentifier.ToString(), writeContext ); resp.Message = $"Started running projection query {projectionRequest.CorrelationIdentifier} : {projectionRequest}) "; } else { resp.Message = "Unable to get projection request from context"; resp.FatalError = true; } return(resp); }
public static async Task <ActivityResponse> LogQueryProjectionResultActivity( [ActivityTrigger] DurableActivityContext context, ILogger log ) { CQRSAzure.EventSourcing.IWriteContext writeContext = null; // TODO: Pass this as a parameter ActivityResponse resp = new ActivityResponse() { FunctionName = "LogQueryProjectionResultActivity" }; // get the ProjectionResultsRecord ProjectionResultsRecord <object> data = context.GetInput <ProjectionResultsRecord <object> >(); if (null != data) { await QueryLogRecord.LogProjectionResult(data.CorrelationIdentifier, data.ParentRequestName, data.ProjectionName, data.DomainName, data.AggregateTypeName, data.EntityUniqueIdentifier, data.CurrentAsOfDate, data.Result, data.CurrentSequenceNumber, writeContext); resp.Message = $"Saved projection result to query {data.ParentRequestName} - {data.CorrelationIdentifier} "; } else { resp.Message = "Unable to get projection result from context"; resp.FatalError = true; } return(resp); }
/// <summary> /// Perform the underlying validation on the specified command /// </summary> /// <param name="commandId"> /// The unique identifier of the command to validate /// </param> /// <remarks> /// This is common functionality, whether called by function chaining or by duarble functions /// </remarks> private static async Task <bool> ValidateSetLeagueEmailAddressCommand(string commandName, string commandId, ILogger log, CQRSAzure.EventSourcing.IWriteContext writeContext = null) { Guid commandGuid; if (Guid.TryParse(commandId, out commandGuid)) { #region Logging if (null != log) { log.LogDebug($"Validating command {commandId} in ValidateSetLeagueEmailAddressCommand"); } #endregion // Get the current state of the command... Projection getCommandState = new Projection(Constants.Domain_Command, commandName, commandGuid.ToString(), nameof(Command_Summary_Projection)); if (null != getCommandState) { #region Logging if (null != log) { log.LogDebug($"Projection processor created in ValidateSetLeagueEmailAddressCommand"); } #endregion Command_Summary_Projection cmdProjection = new Command_Summary_Projection(log); await getCommandState.Process(cmdProjection); if ((cmdProjection.CurrentSequenceNumber > 0) || (cmdProjection.ProjectionValuesChanged())) { #region Logging if (null != log) { log.LogDebug($"Command { cmdProjection.CommandName} projection run for {commandGuid} in ValidateSetLeagueEmailAddressCommand"); } #endregion if (cmdProjection.CurrentState == Command_Summary_Projection.CommandState.Completed) { // No need to validate a completed command #region Logging if (null != log) { log.LogWarning($"Command {commandId} is complete so no need to validate in ValidateSetLeagueEmailAddressCommand"); } #endregion return(true); } if (cmdProjection.CurrentState == Command_Summary_Projection.CommandState.Validated) { // No need to process ana lready validated command #region Logging if (null != log) { log.LogWarning($"Command {commandId} is validated so no need to validate again in ValidateSetLeagueEmailAddressCommand"); } #endregion return(true); } if ((cmdProjection.CurrentState == Command_Summary_Projection.CommandState.Created) || (cmdProjection.CurrentState == Command_Summary_Projection.CommandState.Invalid)) { bool leagueNameValid = false; bool emailAddressValid = false; // New or previously invalid command can be validated if (cmdProjection.ParameterIsSet(nameof(Set_Email_Address_Definition.LeagueName))) { // League name may not be blank string leagueName = cmdProjection.GetParameter <string>(nameof(Set_Email_Address_Definition.LeagueName)); if (string.IsNullOrWhiteSpace(leagueName)) { await CommandErrorLogRecord.LogCommandValidationError(commandGuid, COMMAND_NAME, true, "League name may not be blank", writeContext); #region Logging if (null != log) { log.LogWarning($"Command {COMMAND_NAME } :: {commandId} has a blank league name in ValidateSetLeagueEmailAddressCommand"); } #endregion } else { leagueNameValid = true; } } else { await CommandErrorLogRecord.LogCommandValidationError(commandGuid, COMMAND_NAME, true, "League name parameter has not been set", writeContext); } // The email address should not be blank if (cmdProjection.ParameterIsSet(nameof(Set_Email_Address_Definition.New_Email_Address))) { string emailAddress = cmdProjection.GetParameter <string>(nameof(Set_Email_Address_Definition.New_Email_Address)); if (string.IsNullOrEmpty(emailAddress)) { await CommandErrorLogRecord.LogCommandValidationError(commandGuid, COMMAND_NAME, false, "Email address is blank", writeContext); #region Logging if (null != log) { log.LogWarning($"Command {COMMAND_NAME } :: {commandId} has a future dated incorporation date in ValidateSetLeagueEmailAddressCommand"); } #endregion } else { emailAddressValid = true; } } else { await CommandErrorLogRecord.LogCommandValidationError(commandGuid, COMMAND_NAME, false, "Email address parameter has not been set", writeContext); } if (emailAddressValid && leagueNameValid) { await CommandErrorLogRecord.LogCommandValidationSuccess(commandGuid, COMMAND_NAME, writeContext); return(true); } } } else { // No events were read into the projection so do nothing #region Logging if (null != log) { log.LogWarning($"No command events read for {commandId} in ValidateSetLeagueEmailAddressCommand"); } #endregion } } } // If, for any reason, we can't validate the command the default is to return false return(false); }