public static async Task <ActivityResponse> CreateLeagueCommandLogParametersActivity(
            [ActivityTrigger] DurableActivityContext context,
            ILogger log)
        {
            ActivityResponse ret = new ActivityResponse()
            {
                FunctionName = "CreateLeagueCommandLogParametersActivity"
            };

            try
            {
                CommandRequest <Create_New_League_Definition> cmdRequest = context.GetInput <CommandRequest <Create_New_League_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 = EventStream.Create(@"Command",
                                                                   cmdRequest.CommandName,
                                                                   cmdRequest.CommandUniqueIdentifier.ToString());

                    if (null != commandEvents)
                    {
                        // Set the event context to indicate who wrote them
                        commandEvents.SetContext(new WriteContext(ret.FunctionName, context.InstanceId));

                        Create_New_League_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.Email_Address),
                                                                                                                   parameters.Email_Address));

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

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

                            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.Message    = $"Unable to get the command request details from {context.ToString()} ";
                    ret.FatalError = true;
                }
            }
            catch (Exception ex)
            {
                if (null != log)
                {
                    // Unable to get the request details from the orchestration
                    log.LogError($"CreateLeagueCommandLogParametersActivity : error {ex.Message} ");
                }
                ret.Message    = ex.Message;
                ret.FatalError = true;
            }
            return(ret);
        }
        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;
            }
        }