Пример #1
0
        public static async Task <ActivityResponse> SetLeagueEmailAddressCommandLogParametersActivity(
            [ActivityTrigger] DurableActivityContext context,
            ILogger log)
        {
            ActivityResponse ret = new ActivityResponse()
            {
                FunctionName = "SetLeagueEmailAddressCommandHandlerActivity"
            };

            try
            {
                CommandRequest <Set_Email_Address_Definition> cmdRequest = context.GetInput <CommandRequest <Set_Email_Address_Definition> >();

                if (null != cmdRequest)
                {
                    if (null != log)
                    {
                        // Unable to get the request details from the orchestration
                        log.LogInformation($"CreateLeagueCommandLogParametersActivity : Logging parameters for command {cmdRequest.CommandUniqueIdentifier} ");
                    }

                    EventStream commandEvents = new EventStream(@"Command",
                                                                cmdRequest.CommandName,
                                                                cmdRequest.CommandUniqueIdentifier.ToString());

                    if (null != commandEvents)
                    {
                        // Set the context for events written
                        commandEvents.SetContext(new WriteContext(ret.FunctionName, context.InstanceId));

                        Set_Email_Address_Definition parameters = cmdRequest.GetParameters();

                        if (null != parameters)
                        {
                            // Set the parameters
                            await commandEvents.AppendEvent(new TheLongRun.Common.Events.Command.ParameterValueSet(nameof(parameters.LeagueName),
                                                                                                                   parameters.LeagueName));

                            await commandEvents.AppendEvent(new TheLongRun.Common.Events.Command.ParameterValueSet(nameof(parameters.New_Email_Address),
                                                                                                                   parameters.New_Email_Address));

                            await commandEvents.AppendEvent(new TheLongRun.Common.Events.Command.ParameterValueSet(nameof(parameters.Notes),
                                                                                                                   parameters.Notes));

                            await commandEvents.AppendEvent(new TheLongRun.Common.Events.Command.ParameterValueSet(nameof(parameters.InstanceIdentifier),
                                                                                                                   parameters.InstanceIdentifier));

                            ret.Message = $"All parameters to set for {cmdRequest.CommandName} : {cmdRequest.CommandUniqueIdentifier}";
                        }
                        else
                        {
                            ret.Message = $"No parameters to set for {cmdRequest.CommandName} : {cmdRequest.CommandUniqueIdentifier}";
                        }
                    }
                    else
                    {
                        ret.Message    = $"Unable to get the event stream for {cmdRequest.CommandName} : {cmdRequest.CommandUniqueIdentifier}";
                        ret.FatalError = true;
                    }
                }
                else
                {
                    ret.FatalError = true;
                    ret.Message    = $"Unable to read command request from {context.InstanceId }";
                }
            }
            catch (Exception ex)
            {
                ret.FatalError = true;
                ret.Message    = ex.Message;
            }

            return(ret);
        }
        public static async Task SetLeagueEmailAddressCommandHandlerOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContext context,
            ILogger log)
        {
            CommandRequest <Set_Email_Address_Definition> cmdRequest = context.GetInput <CommandRequest <Set_Email_Address_Definition> >();


            if (null != cmdRequest)
            {
                ActivityResponse resp = await context.CallActivityWithRetryAsync <ActivityResponse>("SetLeagueEmailAddressCommandLogParametersActivity",
                                                                                                    DomainSettings.CommandRetryOptions(),
                                                                                                    cmdRequest);

                #region Logging
                if (null != log)
                {
                    if (null != resp)
                    {
                        log.LogInformation($"{resp.FunctionName} complete: {resp.Message } ");
                    }
                }
                #endregion
                if (null != resp)
                {
                    context.SetCustomStatus(resp);
                }

                // Get the impacted entities from the command request - in this command they are passed as parameters
                IEnumerable <CommandNotificationImpactedEntity> impactedEntities = null;
                Set_Email_Address_Definition parameters = cmdRequest.GetParameters();
                if (null != parameters)
                {
                    Tuple <string, string>[] entitiesImpacted = new Tuple <string, string>[] { new Tuple <string, string>(@"League", parameters.LeagueName) };
                    impactedEntities = CommandNotificationImpactedEntity.CreateImpactedEntityList(entitiesImpacted);
                }

                if (!resp.FatalError)
                {
                    // 1) Validate the command
                    bool valid = await context.CallActivityWithRetryAsync <bool>("SetLeagueEmailAddressCommandValidationActivity",
                                                                                 DomainSettings.CommandRetryOptions(),
                                                                                 cmdRequest);

                    if (!resp.FatalError)
                    {
                        CommandStepResponse stepResponse = new CommandStepResponse()
                        {
                            CommandName             = cmdRequest.CommandName,
                            CommandUniqueIdentifier = cmdRequest.CommandUniqueIdentifier,
                            StepName         = resp.FunctionName,
                            Message          = resp.Message,
                            ImpactedEntities = impactedEntities
                        };
                        resp = await context.CallActivityAsync <ActivityResponse>("CommandStepCompleteActivity", stepResponse);
                    }

                    if (valid)
                    {
                        // 2) Perform the operation of the command
                        resp = await context.CallActivityWithRetryAsync <ActivityResponse>("SetLeagueEmailAddressCommandHandlerActivity",
                                                                                           DomainSettings.CommandRetryOptions(),
                                                                                           cmdRequest);

                        #region Logging
                        if (null != log)
                        {
                            if (null != resp)
                            {
                                log.LogInformation($"{resp.FunctionName} complete: {resp.Message } ");
                            }
                        }
                        #endregion
                        if (null != resp)
                        {
                            context.SetCustomStatus(resp);
                        }

                        //  Mark the step as complete
                        if (!resp.FatalError)
                        {
                            CommandStepResponse stepResponse = new CommandStepResponse()
                            {
                                CommandName             = cmdRequest.CommandName,
                                CommandUniqueIdentifier = cmdRequest.CommandUniqueIdentifier,
                                StepName         = resp.FunctionName,
                                Message          = resp.Message,
                                ImpactedEntities = impactedEntities
                            };
                            resp = await context.CallActivityAsync <ActivityResponse>("CommandStepCompleteActivity", stepResponse);
                        }


                        // Mark the command as complete
                        if (!resp.FatalError)
                        {
                            resp = await context.CallActivityAsync <ActivityResponse>("CommandCompleteActivity", cmdRequest);
                        }

                        #region Logging
                        if (null != log)
                        {
                            if (null != resp)
                            {
                                log.LogInformation($"{resp.FunctionName} complete: {resp.Message } ");
                            }
                        }
                        #endregion
                        if (null != resp)
                        {
                            context.SetCustomStatus(resp);
                        }
                    }
                    else
                    {
                        #region Logging
                        if (null != log)
                        {
                            log.LogWarning($"Command parameters not valid {cmdRequest.CommandName} : {cmdRequest.CommandUniqueIdentifier } ");
                        }
                        #endregion
                        if (null != resp)
                        {
                            resp.Message = $"Command parameters not valid {cmdRequest.CommandName} : {cmdRequest.CommandUniqueIdentifier } ";
                            context.SetCustomStatus(resp);
                        }
                    }
                }
            }
            else
            {
            }
        }