Пример #1
0
        /// <summary>
        /// Invokes this middleware component allowing it to perform its work against the supplied context.
        /// </summary>
        /// <param name="context">The context containing the request passed through the pipeline.</param>
        /// <param name="next">The delegate pointing to the next piece of middleware to be invoked.</param>
        /// <param name="cancelToken">The cancel token.</param>
        /// <returns>Task.</returns>
        public Task InvokeAsync(GraphQueryExecutionContext context, GraphMiddlewareInvocationDelegate <GraphQueryExecutionContext> next, CancellationToken cancelToken)
        {
            // create and attach the result
            IResponseFieldSet fieldSet = null;

            if (context.FieldResults != null && context.FieldResults.Any())
            {
                fieldSet = this.CreateFinalDictionary(context);
            }

            context.Result = new GraphOperationResult(context.Request, context.Messages, fieldSet, context.Metrics);
            context.Logger?.RequestCompleted(context);
            return(next(context, cancelToken));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphOperationResult" /> class.
        /// </summary>
        /// <param name="originalRequest">The original request.</param>
        /// <param name="messages">The message collection containing any messages that may
        /// have been generated during execution.</param>
        /// <param name="dataItem">The top level field set resolved during the operation.</param>
        /// <param name="metrics">The metrics package that was filled during the operation execution.</param>
        public GraphOperationResult(
            IGraphOperationRequest originalRequest,
            IEnumerable <IGraphMessage> messages = null,
            IResponseFieldSet dataItem           = null,
            IGraphQueryExecutionMetrics metrics  = null)
        {
            this.Request  = originalRequest;
            this.Data     = dataItem;
            this.Messages = new GraphMessageCollection();
            if (messages != null)
            {
                this.Messages.AddRange(messages);
            }

            this.Metrics = metrics;
        }
Пример #3
0
        /// <summary>
        /// Walks the the object collection and writes it to the provided writer.
        /// </summary>
        /// <param name="writer">The json writer to output the reslts to.</param>
        /// <param name="data">The dictionary to output to the writer.</param>
        private void WriteObjectCollection(Utf8JsonWriter writer, IResponseFieldSet data)
        {
            if (data == null)
            {
                writer.WriteNullValue();
            }
            else
            {
                writer.WriteStartObject();
                foreach (var kvp in data.Fields)
                {
                    writer.WritePropertyName(kvp.Key);
                    this.WriteResponseItem(writer, kvp.Value);
                }

                writer.WriteEndObject();
            }
        }
Пример #4
0
 /// <summary>
 /// Sets the completed data response to the result.
 /// </summary>
 /// <param name="data">The data.</param>
 public void SetDataResponse(IResponseFieldSet data)
 {
     this.Data = data;
 }