public static async Task OnCreateLeagueCommandHandlerOrchestrator
            ([OrchestrationTrigger] DurableOrchestrationContext context,
            Microsoft.Extensions.Logging.ILogger log)
        {
            CommandRequest <Create_New_League_Definition> cmdRequest = context.GetInput <CommandRequest <Create_New_League_Definition> >();

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

                Create_New_League_Definition parameters = cmdRequest.GetParameters();
                IEnumerable <CommandNotificationImpactedEntity> impactedEntities = null;
                if (null != parameters)
                {
                    Tuple <string, string>[] entitiesImpacted = new Tuple <string, string>[] { new Tuple <string, string>(@"League", parameters.LeagueName) };
                    impactedEntities = CommandNotificationImpactedEntity.CreateImpactedEntityList(entitiesImpacted);
                }

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

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

                    if (!valid)
                    {
                        resp.Message    = $"Validation failed for command {cmdRequest.CommandName} id: {cmdRequest.CommandUniqueIdentifier }";
                        resp.FatalError = true;
                    }
                }

                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 (!resp.FatalError)
                {
                    // execute the command
                    resp = await context.CallActivityWithRetryAsync <ActivityResponse>("CreateLeagueCommandHandlerAction",
                                                                                       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);
                    }
                }

                if (!resp.FatalError)
                {
                    // 3) Mark the step as complete
                    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 (!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);
                }

                // Fire the orchestration to do the actual work of sending notifications
                Command_Get_Notifications_Request payload = new Command_Get_Notifications_Request()
                {
                    CommandName             = cmdRequest.CommandName,
                    CommandUniqueIdentifier = cmdRequest.CommandUniqueIdentifier.ToString()
                };

                // call the orchestrator...
                resp = await context.CallSubOrchestratorAsync <ActivityResponse>("CommandNotificationOrchestrator", payload);

                #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)
                {
                    // Unable to get the request details from the orchestration
                    log.LogError("OnCreateLeagueCommandHandlerOrchestrator : Unable to get the command request from the context");

                    string contextAsString = context.GetInput <string>();
                    if (!string.IsNullOrWhiteSpace(contextAsString))
                    {
                        log.LogError($"Context was {contextAsString} ");
                    }
                    else
                    {
                        log.LogError($"Context was blank ");
                    }
                }
                #endregion
                return;
            }
        }
Пример #2
0
        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);

                    CommandStepResponse stepValidateResponse = new CommandStepResponse()
                    {
                        CommandName             = cmdRequest.CommandName,
                        CommandUniqueIdentifier = cmdRequest.CommandUniqueIdentifier,
                        StepName         = "Set League Email Address Command Validation",
                        Message          = resp.Message,
                        ImpactedEntities = impactedEntities
                    };
                    resp = await context.CallActivityAsync <ActivityResponse>("CommandStepCompleteActivity", stepValidateResponse);


                    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 stepCommandResponse = new CommandStepResponse()
                            {
                                CommandName             = cmdRequest.CommandName,
                                CommandUniqueIdentifier = cmdRequest.CommandUniqueIdentifier,
                                StepName         = resp.FunctionName,
                                Message          = resp.Message,
                                ImpactedEntities = impactedEntities
                            };
                            resp = await context.CallActivityAsync <ActivityResponse>("CommandStepCompleteActivity", stepCommandResponse);
                        }


                        // 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);
                        }

                        // Fire the orchestration to do the actual work of sending notifications
                        Command_Get_Notifications_Request payload = new Command_Get_Notifications_Request()
                        {
                            CommandName             = cmdRequest.CommandName,
                            CommandUniqueIdentifier = cmdRequest.CommandUniqueIdentifier.ToString()
                        };

                        // call the orchestrator...
                        resp = await context.CallSubOrchestratorAsync <ActivityResponse>("CommandNotificationOrchestrator", payload);

                        #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);
                        }
                    }
                }
            }
        }