コード例 #1
0
        public void CreateWriter_CreatesWriter(INdjsonWriterFactory ndjsonWriterFactory)
        {
            ActionContext actionContext = PrepareActionContext();

            INdjsonWriter <ValueType> ndjsonWriter = ndjsonWriterFactory.CreateWriter <ValueType>(actionContext, OK_RESULT);

            Assert.NotNull(ndjsonWriter);
        }
コード例 #2
0
        public override async Task ExecuteResultAsync(ActionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            INdjsonWriterFactory ndjsonTextWriterFactory = context.HttpContext.RequestServices.GetRequiredService <INdjsonWriterFactory>();

            using (_ndjsonTextWriter = ndjsonTextWriterFactory.CreateWriter(context, this))
            {
                _readyTaskCompletionSource.SetResult(true);

                await _completeTaskCompletionSource.Task;
            }
        }
コード例 #3
0
        /// <summary>
        /// Executes the result operation of the action method asynchronously. This method is called by MVC to process the result of an action method.
        /// </summary>
        /// <param name="context">The <see cref="ActionContext"/> in which the result is executed. The context information includes information about the action that was executed and request information.</param>
        /// <returns>A <see cref="Task"/> that represents the asynchronous execute operation.</returns>
        public override async Task ExecuteResultAsync(ActionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            INdjsonWriterFactory ndjsonTextWriterFactory = context.HttpContext.RequestServices.GetRequiredService <INdjsonWriterFactory>();

            using (INdjsonWriter ndjsonTextWriter = ndjsonTextWriterFactory.CreateWriter(context, this))
            {
                await foreach (object value in _values)
                {
                    await ndjsonTextWriter.WriteAsync(value);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Executes the result operation of the action method asynchronously. This method is called by MVC to process the result of an action method.
        /// </summary>
        /// <param name="context">The <see cref="ActionContext"/> in which the result is executed. The context information includes information about the action that was executed and request information.</param>
        /// <returns>A <see cref="Task"/> that represents the asynchronous execute operation.</returns>
        public override async Task ExecuteResultAsync(ActionContext context)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            INdjsonWriterFactory ndjsonTextWriterFactory = context.HttpContext.RequestServices.GetRequiredService <INdjsonWriterFactory>();

            using INdjsonWriter <T> ndjsonTextWriter = ndjsonTextWriterFactory.CreateWriter <T>(context, this);

            try
            {
                await foreach (T value in _values.WithCancellation(context.HttpContext.RequestAborted))
                {
                    await ndjsonTextWriter.WriteAsync(value, context.HttpContext.RequestAborted);
                }
            }
            catch (OperationCanceledException) when(context.HttpContext.RequestAborted.IsCancellationRequested)
            {
            }
        }