Esempio n. 1
0
        public static async Task RenderToStreamAsync(this PageResult pageResult, Stream stream)
        {
            try
            {
                if (pageResult.ResultOutput != null)
                {
                    if (pageResult.LastFilterError != null)
                    {
                        throw new ScriptException(pageResult);
                    }

                    await stream.WriteAsync(MemoryProvider.Instance.ToUtf8Bytes(pageResult.ResultOutput.AsSpan()));

                    return;
                }

                await pageResult.Init();

                await pageResult.WriteToAsync(stream);

                if (pageResult.LastFilterError != null)
                {
                    throw new ScriptException(pageResult);
                }
            }
            catch (Exception e)
            {
                if (ShouldRethrow(e))
                {
                    throw;
                }
                throw HandleException(e, pageResult);
            }
        }
Esempio n. 2
0
        public static async Task RenderAsync(this PageResult pageResult, Stream stream, CancellationToken token = default)
        {
            if (pageResult.ResultOutput != null)
            {
                await stream.WriteAsync(MemoryProvider.Instance.ToUtf8Bytes(pageResult.ResultOutput.AsSpan()), token : token);

                return;
            }

            await pageResult.Init();

            await pageResult.WriteToAsync(stream, token);

            if (pageResult.LastFilterError != null)
            {
                throw new ScriptException(pageResult);
            }
        }
Esempio n. 3
0
        public static void RenderToStream(this PageResult pageResult, Stream stream)
        {
            try
            {
                try
                {
                    if (pageResult.ResultOutput != null)
                    {
                        if (pageResult.LastFilterError != null)
                        {
                            throw new ScriptException(pageResult);
                        }

                        stream.WriteAsync(MemoryProvider.Instance.ToUtf8Bytes(pageResult.ResultOutput.AsSpan())).Wait();
                        return;
                    }

                    pageResult.Init().Wait();
                    pageResult.WriteToAsync(stream).Wait();
                    if (pageResult.LastFilterError != null)
                    {
                        throw new ScriptException(pageResult);
                    }
                }
                catch (AggregateException e)
                {
                    var ex = e.UnwrapIfSingleException();
                    throw ex;
                }
            }
            catch (Exception e)
            {
                if (ShouldRethrow(e))
                {
                    throw;
                }
                throw HandleException(e, pageResult);
            }
        }