/// <summary>
        /// Perform the validation on the parameters of this "Get League Summary" query and, if all OK, mark it
        /// as allowed to continue
        /// </summary>
        /// <param name="queryId">
        /// Unique identifier of the query event stream for this "Get League Summary" query
        /// </param>
        /// <param name="log">
        /// If set, output progress to this trace writer
        /// </param>
        private static async Task <bool> ValidateGetLeagueSummaryQuery(string queryId,
                                                                       ILogger log)
        {
            const string QUERY_NAME = @"get-league-summary";
            Guid         queryGuid;

            if (Guid.TryParse(queryId, out queryGuid))
            {
                // Get the current state of the query...
                Projection getQueryState = new Projection(@"Query",
                                                          QUERY_NAME,
                                                          queryGuid.ToString(),
                                                          nameof(Query_Summary_Projection));

                if (null != getQueryState)
                {
                    #region Logging
                    if (null != log)
                    {
                        log.LogDebug($"Projection processor created in ValidateGetLeagueSummaryQuery");
                    }
                    #endregion

                    // Run the query summary projection
                    Query_Summary_Projection qryProjection =
                        new Query_Summary_Projection(log);

                    await getQueryState.Process(qryProjection);


                    if ((qryProjection.CurrentSequenceNumber > 0) || (qryProjection.ProjectionValuesChanged()))
                    {
                        // Process the query state as is now...
                        #region Logging
                        if (null != log)
                        {
                            log.LogDebug($"Query { qryProjection.QueryName } projection run for {queryGuid} in ValidateGetLeagueSummaryQuery");
                        }
                        #endregion

                        if (qryProjection.CurrentState == Query_Summary_Projection.QueryState.Completed)
                        {
                            // No need to validate a completed query
                            #region Logging
                            if (null != log)
                            {
                                log.LogWarning($"Query {queryGuid} is complete so no need to validate in ValidateGetLeagueSummaryQuery");
                            }
                            #endregion
                            return(true);
                        }

                        if (qryProjection.CurrentState == Query_Summary_Projection.QueryState.Invalid)
                        {
                            // No need to validate an already invalid query
                            #region Logging
                            if (null != log)
                            {
                                log.LogWarning($"Query {queryGuid} is already marked as invalid so no need to validate in ValidateGetLeagueSummaryQuery");
                            }
                            #endregion
                            return(false);
                        }

                        if (qryProjection.CurrentState == Query_Summary_Projection.QueryState.Validated)
                        {
                            // No need to validate an already validated query
                            #region Logging
                            if (null != log)
                            {
                                log.LogWarning($"Query {queryGuid} is already validated so no need to validate in ValidateGetLeagueSummaryQuery");
                            }
                            #endregion
                            return(true);
                        }

                        // Validations - 1: Check league name is not empty
                        if (qryProjection.ParameterIsSet(nameof(Get_League_Summary_Definition.League_Name)))
                        {
                            string leagueNameParam = qryProjection.GetParameter <string>(nameof(Get_League_Summary_Definition.League_Name));
                            if (string.IsNullOrWhiteSpace(leagueNameParam))
                            {
                                await QueryLogRecord.LogQueryValidationError(queryGuid, QUERY_NAME, true, "League name may not be blank");

                                #region Logging
                                if (null != log)
                                {
                                    log.LogWarning($"Query {QUERY_NAME} :: {queryGuid} has a blank league name in ValidateGetLeagueSummaryQuery");
                                }
                                #endregion
                                return(false);
                            }
                            else
                            {
                                // any additional validation could go here (?)..
                                return(true);
                            }
                        }
                        else
                        {
                            // Parameter is mandatory but may not be set yet so leave the query as is
                            #region Logging
                            if (null != log)
                            {
                                log.LogWarning($"Query { qryProjection.QueryName } has no value specified for the parameter {nameof(Get_League_Summary_Definition.League_Name)} in ValidateGetLeagueSummaryQuery");
                            }
                            #endregion
                            return(false);
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Add projection requests for the projections that need to be run in order to get the data
        /// for this Get League Summary query
        /// </summary>
        /// <param name="queryId">
        /// Unique identifier of the query
        /// </param>
        /// <param name="log">
        /// Optional tracing output
        /// </param>
        private static async Task RequestProjectionsGetLeagueSummaryQuery(
            string queryName,
            string queryId,
            ILogger log)
        {
            Guid queryGuid;

            if (Guid.TryParse(queryId, out queryGuid))
            {
                // Get the current state of the query...
                Projection getQueryState = new Projection(@"Query",
                                                          queryName,
                                                          queryGuid.ToString(),
                                                          nameof(Query_Summary_Projection));

                if (null != getQueryState)
                {
                    #region Logging
                    if (null != log)
                    {
                        log.LogInformation($"Projection processor created to get query state from RequestProjectionsGetLeagueSummaryQuery");
                    }
                    #endregion

                    // Run the query summary projection
                    Query_Summary_Projection qryProjection =
                        new Query_Summary_Projection(log);

                    await getQueryState.Process(qryProjection);

                    if ((qryProjection.CurrentSequenceNumber > 0) || (qryProjection.ProjectionValuesChanged()))
                    {
                        // Process the query state as is now...
                        #region Logging
                        if (null != log)
                        {
                            log.LogDebug($"Query { qryProjection.QueryName } projection run for {queryGuid } in RequestProjectionsGetLeagueSummaryQuery");
                        }
                        #endregion

                        // Ignore queries in an invalid state...
                        if ((qryProjection.CurrentState == Query_Summary_Projection.QueryState.Completed) ||
                            (qryProjection.CurrentState == Query_Summary_Projection.QueryState.Invalid))
                        {
                            // No need to validate a completed query
                            #region Logging
                            if (null != log)
                            {
                                log.LogWarning($"Query {queryGuid} state is {qryProjection.CurrentState} so no projections requested in RequestProjectionsGetLeagueSummaryQuery");
                            }
                            #endregion
                            return;
                        }

                        // Get the league parameter
                        if (qryProjection.ParameterIsSet(nameof(Get_League_Summary_Definition.League_Name)))
                        {
                            string leagueNameParam = qryProjection.GetParameter <string>(nameof(Get_League_Summary_Definition.League_Name));
                            if (string.IsNullOrWhiteSpace(leagueNameParam))
                            {
                                #region Logging
                                if (null != log)
                                {
                                    log.LogError($"Query {queryName } :: {queryGuid} has a blank league name in RequestProjectionsGetLeagueSummaryQuery");
                                }
                                #endregion
                            }
                            else
                            {
                                // Find out what projections have been already requested
                                Query_Projections_Projection qryProjectionsRequested = new Query_Projections_Projection();
                                await getQueryState.Process(qryProjectionsRequested);

                                if ((qryProjectionsRequested.CurrentSequenceNumber > 0) || (qryProjectionsRequested.ProjectionValuesChanged()))
                                {
                                    // Process the query state as is now...
                                    if ((qryProjectionsRequested.UnprocessedRequests.Count == 0) && (qryProjectionsRequested.ProcessedRequests.Count == 0))
                                    {
                                        // No projections have been added to this so add the "get league summary" request
                                        await QueryLogRecord.RequestProjection(queryGuid,
                                                                               qryProjection.QueryName,
                                                                               nameof(Leagues.League.projection.League_Summary_Information),
                                                                               "Leagues",
                                                                               "League",
                                                                               leagueNameParam,
                                                                               null);
                                    }
                                    else
                                    {
                                        if (qryProjectionsRequested.UnprocessedRequests.Count > 0)
                                        {
                                            #region Logging
                                            if (null != log)
                                            {
                                                log.LogWarning($"Query {queryName} projection in progress for {queryGuid } in RequestProjectionsGetLeagueSummaryQuery");
                                            }
                                            #endregion
                                        }
                                        if (qryProjectionsRequested.ProcessedRequests.Count > 0)
                                        {
                                            #region Logging
                                            if (null != log)
                                            {
                                                log.LogWarning($"Query {queryName} projection already processed for {queryGuid } in RequestProjectionsGetLeagueSummaryQuery");
                                            }
                                            #endregion
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }