public void Write(IContent content, Stream outputStream)
        {
            var razorViews = new RazorViews();
            var handlerType = content.Handler != null ? content.Handler.GetType() : null;
            var modelType = content.Model != null ? content.Model.GetType() : null;
            var viewType = razorViews.GetViewType(handlerType, modelType);

            if (viewType == null)
            {
                throw new ViewNotFoundException();
            }

            using (var streamWriter = new StreamWriter(outputStream))
            {
                RenderView(content, streamWriter, viewType);
            }
        }
        public Task Write(IContent content, Stream outputStream)
        {
            var razorViews = new RazorViews();
            var handlerType = content.Handler != null ? content.Handler.GetType() : null;
            var modelType = content.Model != null ? content.Model.GetType() : null;
            var viewType = razorViews.GetViewType(handlerType, modelType);

            if (viewType == null)
            {
                throw new ViewNotFoundException();
            }

            byte[] buffer;
            using (var writer = new StringWriter())
            {
                RenderView(content, writer, viewType);
                buffer = Encoding.Default.GetBytes(writer.ToString());
            }

            return outputStream.WriteAsync(buffer, 0, buffer.Length);
        }
Exemplo n.º 3
0
        public Task Write(IContent content, Stream outputStream)
        {
            var razorViews  = new RazorViews();
            var handlerType = content.Handler != null?content.Handler.GetType() : null;

            var modelType = content.Model != null?content.Model.GetType() : null;

            var viewType = razorViews.GetViewType(handlerType, modelType);

            if (viewType == null)
            {
                throw new ViewNotFoundException();
            }

            byte[] buffer;
            using (var writer = new StringWriter())
            {
                RenderView(content, writer, viewType);
                buffer = Encoding.Default.GetBytes(writer.ToString());
            }

            return(outputStream.WriteAsync(buffer, 0, buffer.Length));
        }