public void Deserialise_From_JSon_Test()
        {
            string expected = "Azure cloudy league";
            string actual   = "Not set";

            QueryRequest <Get_League_Summary_Definition> queryRequest = new QueryRequest <Get_League_Summary_Definition>();

            queryRequest.QueryName             = "Get League Definition";
            queryRequest.QueryUniqueIdentifier = Guid.NewGuid();

            Get_League_Summary_Definition paramData = new Get_League_Summary_Definition();

            paramData.League_Name = expected;

            queryRequest.SetParameters(paramData);

            string asJson = JsonConvert.SerializeObject(queryRequest);

            QueryRequest <Get_League_Summary_Definition> deserialisedQueryRequest = null;

            if (!string.IsNullOrWhiteSpace(asJson))
            {
                deserialisedQueryRequest = JsonConvert.DeserializeObject <QueryRequest <Get_League_Summary_Definition> >(asJson);

                actual = deserialisedQueryRequest.GetParameters().League_Name;
            }

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public static async Task <Guid> GetLeagueSummaryCreateQueryRequestActivity(
            [ActivityTrigger] DurableActivityContext context,
            ILogger log)
        {
            #region Logging
            if (null != log)
            {
                log.LogInformation($"GetLeagueSummaryCreateQueryRequestActivity started - instance {context.InstanceId} ");
            }
            #endregion

            QueryRequest <Get_League_Summary_Definition> queryRequest = context.GetInput <QueryRequest <Get_League_Summary_Definition> >();

            if (queryRequest.QueryUniqueIdentifier.Equals(Guid.Empty))
            {
                queryRequest.QueryUniqueIdentifier = Guid.NewGuid();
            }

            // Create a new Query record to hold the event stream for this query...
            QueryLogRecord <Get_League_Summary_Definition> qryRecord = QueryLogRecord <Get_League_Summary_Definition> .Create(
                queryRequest.QueryName,
                queryRequest.GetParameters(),
                queryRequest.ReturnTarget,
                queryRequest.ReturnPath,
                queryRequest.QueryUniqueIdentifier);


            if (null != qryRecord)
            {
                EventStream queryEvents = new EventStream(Constants.Domain_Query,
                                                          queryRequest.QueryName,
                                                          qryRecord.QueryUniqueIdentifier.ToString());


                if (null != queryEvents)
                {
                    await queryEvents.CreateIfNotExists();

                    // Set the context for the events to be written using
                    queryEvents.SetContext(new WriteContext("GetLeagueSummaryCreateQueryRequestActivity", context.InstanceId));

                    // Log the query creation
                    await queryEvents.AppendEvent(new TheLongRun.Common.Events.Query.QueryCreated(queryRequest.QueryName,
                                                                                                  qryRecord.QueryUniqueIdentifier));
                }

                // Return the ID of the query record we created
                return(qryRecord.QueryUniqueIdentifier);
            }

            // If we got here there was a problem so return an empty GUID
            return(Guid.Empty);
        }
        public static async Task OnGetLeagueSummaryQueryHandler(
            [EventGridTrigger] EventGridEvent eventGridEvent,
            [OrchestrationClient] DurableOrchestrationClient getLeagueSummaryQueryHandlerOrchestrationClient,
            Microsoft.Extensions.Logging.ILogger log
            )
        {
            #region Logging
            if (null != log)
            {
                log.LogDebug("Function triggered in OnGetLeagueSummaryQuery");
            }

            if (null == eventGridEvent)
            {
                // This function should not proceed if there is no event data
                if (null != log)
                {
                    log.LogError("Missing event grid trigger data in OnGetLeagueSummaryQuery");
                }
                return;
            }
            else
            {
                if (null != log)
                {
                    log.LogDebug($"Event grid topic: {eventGridEvent.Topic}");
                    log.LogDebug($"Event grid subject: {eventGridEvent.Subject }");
                    log.LogDebug($"Event grid metadata version: {eventGridEvent.MetadataVersion }");
                    log.LogDebug($"Event grid event type: {eventGridEvent.EventType }");
                    log.LogDebug($"Event Grid Data : {eventGridEvent.Data }");
                }
            }
            #endregion

            try
            {
                #region Logging
                if (null != log)
                {
                    log.LogDebug($"Get the query parameters in OnGetLeagueSummaryQuery");
                    if (null == eventGridEvent.Data)
                    {
                        log.LogError($"The query parameter has no values in OnGetLeagueSummaryQuery");
                        return;
                    }
                }
                #endregion


                // Get the query request details out of the event grid data request
                var jsondata = JsonConvert.SerializeObject(eventGridEvent.Data);
                QueryRequest <Get_League_Summary_Definition> queryRequest = null;
                if (!string.IsNullOrWhiteSpace(jsondata))
                {
                    queryRequest = JsonConvert.DeserializeObject <QueryRequest <Get_League_Summary_Definition> >(jsondata);
                }

                if (null != queryRequest)
                {
                    if (null != log)
                    {
                        log.LogInformation($"Running query handler with durable functions orchestration");
                        log.LogInformation($"{queryRequest.QueryName} with league {queryRequest.GetParameters().League_Name}");
                    }

                    // Using Azure Durable functions to do the query chaining
                    string instanceId = await getLeagueSummaryQueryHandlerOrchestrationClient.StartNewAsync("OnGetLeagueSummaryQueryHandlerOrchestrator", queryRequest);

                    if (null != log)
                    {
                        log.LogInformation($"Started OnGetLeagueSummaryQueryHandlerOrchestrator orchestration with ID = '{instanceId}'.");
                    }

                    var status = await getLeagueSummaryQueryHandlerOrchestrationClient.GetStatusAsync(instanceId);

                    if (null != log)
                    {
                        log.LogInformation($"Orchestration  '{instanceId}' has status {status.RuntimeStatus} : {status.Output}.");
                    }
                }
                else
                {
                    if (null != log)
                    {
                        log.LogError($"Unable to read query request from eventgrid data: {eventGridEvent.Data} Type: {eventGridEvent.Data.GetType()} ");
                    }
                }
            }
            catch (Exception ex)
            {
                if (null != log)
                {
                    log.LogError(ex.ToString(), ex);
                }
                throw;
            }
        }
        public static async Task <ActivityResponse> GetLeagueSummaryLogParametersActivity(
            [ActivityTrigger] DurableActivityContext context,
            ILogger log = null)
        {
            ActivityResponse ret = new ActivityResponse()
            {
                FunctionName = "GetLeagueSummaryLogParametersActivity"
            };

            try
            {
                QueryRequest <Get_League_Summary_Definition> queryRequest = context.GetInput <QueryRequest <Get_League_Summary_Definition> >();

                if (null != queryRequest)
                {
                    if (null != log)
                    {
                        // Unable to get the request details from the orchestration
                        log.LogInformation($"GetLeagueSummaryLogParametersActivity : Logging parameters for query {queryRequest.QueryUniqueIdentifier} ");
                    }

                    EventStream queryEvents = EventStream.Create(Constants.Domain_Query,
                                                                 queryRequest.QueryName,
                                                                 queryRequest.QueryUniqueIdentifier.ToString());

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

                        // set the parameter(s)
                        await queryEvents.AppendEvent(new TheLongRun.Common.Events.Query.QueryParameterValueSet
                                                          (nameof(Get_League_Summary_Definition.League_Name), queryRequest.GetParameters().League_Name));

                        if (null != log)
                        {
                            // Unable to get the request details from the orchestration
                            log.LogInformation($"GetLeagueSummaryLogParametersActivity : Logged parameters - League name : {queryRequest.GetParameters().League_Name } ");
                        }

                        ret.Message = $"Logged parameters - League name : {queryRequest.GetParameters().League_Name } ";
                    }
                    else
                    {
                        ret.Message    = $"Unable to get the event stream for {queryRequest.QueryName} : {queryRequest.QueryUniqueIdentifier }";
                        ret.FatalError = true;
                    }
                }
                else
                {
                    ret.Message    = $"Unable to get the 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($"GetLeagueSummaryLogParametersActivity : error {ex.Message} ");
                }
                ret.Message    = ex.Message;
                ret.FatalError = true;
            }
            return(ret);
        }