ViewPage.cs :  » 2.6.4-mono-.net-core » System.Web » System » Web » Mvc » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » 2.6.4 mono .net core » System.Web 
System.Web » System » Web » Mvc » ViewPage.cs
/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. All rights reserved.
 *
 * This software is subject to the Microsoft Public License (Ms-PL). 
 * A copy of the license can be found in the license.htm file included 
 * in this distribution.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * ***************************************************************************/

namespace System.Web.Mvc{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.IO;
    using System.Text;
    using System.Web;
    using System.Web.UI;

    [FileLevelControlBuilder(typeof(ViewPageControlBuilder))]
    public class ViewPage : Page, IViewDataContainer {

        private string _masterLocation;
        [ThreadStatic]
        private static int _nextId;
        private ViewDataDictionary _viewData;

        public AjaxHelper<object> Ajax {
            get;
            set;
        }

        public HtmlHelper<object> Html {
            get;
            set;
        }

        public string MasterLocation {
            get {
                return _masterLocation ?? String.Empty;
            }
            set {
                _masterLocation = value;
            }
        }

        public object Model {
            get {
                return ViewData.Model;
            }
        }

        public TempDataDictionary TempData {
            get {
                return ViewContext.TempData;
            }
        }

        public UrlHelper Url {
            get;
            set;
        }

        public ViewContext ViewContext {
            get;
            set;
        }

        [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
            Justification = "This is the mechanism by which the ViewPage gets its ViewDataDictionary object.")]
        public ViewDataDictionary ViewData {
            get {
                if (_viewData == null) {
                    SetViewData(new ViewDataDictionary());
                }
                return _viewData;
            }
            set {
                SetViewData(value);
            }
        }

        public HtmlTextWriter Writer {
            get;
            private set;
        }

        public virtual void InitHelpers() {
            Ajax = new AjaxHelper<object>(ViewContext, this);
            Html = new HtmlHelper<object>(ViewContext, this);
            Url = new UrlHelper(ViewContext.RequestContext);
        }

        internal static string NextId() {
            return (++_nextId).ToString(CultureInfo.InvariantCulture);
        }

        [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
        protected override void OnPreInit(EventArgs e) {
            base.OnPreInit(e);

            if (!String.IsNullOrEmpty(MasterLocation)) {
                MasterPageFile = MasterLocation;
            }
        }

        public override void ProcessRequest(HttpContext context) {
            // Tracing requires IDs to be unique.
            ID = NextId();

            base.ProcessRequest(context);
        }

        protected override void Render(HtmlTextWriter writer) {
            Writer = writer;
            try {
                base.Render(writer);
            }
            finally {
                Writer = null;
            }
        }

        public virtual void RenderView(ViewContext viewContext) {
            ViewContext = viewContext;
            InitHelpers();

            bool needServerExecute = false;

            SwitchWriter switchWriter = viewContext.HttpContext.Response.Output as SwitchWriter;
            if (switchWriter == null) {
                switchWriter = new SwitchWriter();
                needServerExecute = true;
            }

            using (switchWriter.Scope(viewContext.Writer)) {
                if (needServerExecute) {
                    // It's safe to reset the _nextId within a Server.Execute() since it pushes a new TraceContext onto
                    // the stack, so there won't be an ID conflict.
                    int originalNextId = _nextId;
                    try {
                        _nextId = 0;
                        viewContext.HttpContext.Server.Execute(HttpHandlerUtil.WrapForServerExecute(this), switchWriter, true /* preserveForm */);
                    }
                    finally {
                        // Restore the original _nextId in case this isn't actually the outermost view, since resetting
                        // the _nextId may now cause trace ID conflicts in the outer view.
                        _nextId = originalNextId;
                    }
                }
                else {
                    ProcessRequest(HttpContext.Current);
                }
            }
        }

        [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "textWriter",
            Justification = "This method existed in MVC 1.0 and has been deprecated.")]
        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
            Justification = "This method existed in MVC 1.0 and has been deprecated.")]
        [Obsolete("The TextWriter is now provided by the ViewContext object passed to the RenderView method.", true /* error */)]
        public void SetTextWriter(TextWriter textWriter) {
            // this is now a no-op
        }

        protected virtual void SetViewData(ViewDataDictionary viewData) {
            _viewData = viewData;
        }

        internal class SwitchWriter : TextWriter {
            public SwitchWriter()
                : base(CultureInfo.CurrentCulture) {
            }

            public override Encoding Encoding {
                get {
                    return InnerWriter.Encoding;
                }
            }

            public override IFormatProvider FormatProvider {
                get {
                    return InnerWriter.FormatProvider;
                }
            }

            internal TextWriter InnerWriter {
                get;
                set;
            }

            public override string NewLine {
                get {
                    return InnerWriter.NewLine;
                }
                set {
                    InnerWriter.NewLine = value;
                }
            }

            public override void Close() {
                InnerWriter.Close();
            }

            public override void Flush() {
                InnerWriter.Flush();
            }

            public IDisposable Scope(TextWriter writer) {
                WriterScope scope = new WriterScope(this, InnerWriter);

                if (writer != this) {
                    InnerWriter = writer;
                }

                return scope;
            }

            public override void Write(bool value) {
                InnerWriter.Write(value);
            }

            public override void Write(char value) {
                InnerWriter.Write(value);
            }

            public override void Write(char[] buffer) {
                InnerWriter.Write(buffer);
            }

            public override void Write(char[] buffer, int index, int count) {
                InnerWriter.Write(buffer, index, count);
            }

            public override void Write(decimal value) {
                InnerWriter.Write(value);
            }

            public override void Write(double value) {
                InnerWriter.Write(value);
            }

            public override void Write(float value) {
                InnerWriter.Write(value);
            }

            public override void Write(int value) {
                InnerWriter.Write(value);
            }

            public override void Write(long value) {
                InnerWriter.Write(value);
            }

            public override void Write(object value) {
                InnerWriter.Write(value);
            }

            public override void Write(string format, object arg0) {
                InnerWriter.Write(format, arg0);
            }

            public override void Write(string format, object arg0, object arg1) {
                InnerWriter.Write(format, arg0, arg1);
            }

            public override void Write(string format, object arg0, object arg1, object arg2) {
                InnerWriter.Write(format, arg0, arg1, arg2);
            }

            public override void Write(string format, params object[] arg) {
                InnerWriter.Write(format, arg);
            }

            public override void Write(string value) {
                InnerWriter.Write(value);
            }

            public override void Write(uint value) {
                InnerWriter.Write(value);
            }

            public override void Write(ulong value) {
                InnerWriter.Write(value);
            }

            public override void WriteLine() {
                InnerWriter.WriteLine();
            }

            public override void WriteLine(bool value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(char value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(char[] buffer) {
                InnerWriter.WriteLine(buffer);
            }

            public override void WriteLine(char[] buffer, int index, int count) {
                InnerWriter.WriteLine(buffer, index, count);
            }

            public override void WriteLine(decimal value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(double value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(float value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(int value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(long value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(object value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(string format, object arg0) {
                InnerWriter.WriteLine(format, arg0);
            }

            public override void WriteLine(string format, object arg0, object arg1) {
                InnerWriter.WriteLine(format, arg0, arg1);
            }

            public override void WriteLine(string format, object arg0, object arg1, object arg2) {
                InnerWriter.WriteLine(format, arg0, arg1, arg2);
            }

            public override void WriteLine(string format, params object[] arg) {
                InnerWriter.WriteLine(format, arg);
            }

            public override void WriteLine(string value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(uint value) {
                InnerWriter.WriteLine(value);
            }

            public override void WriteLine(ulong value) {
                InnerWriter.WriteLine(value);
            }

            private sealed class WriterScope : IDisposable {
                private SwitchWriter _switchWriter;
                private TextWriter _writerToRestore;

                public WriterScope(SwitchWriter switchWriter, TextWriter writerToRestore) {
                    _switchWriter = switchWriter;
                    _writerToRestore = writerToRestore;
                }

                public void Dispose() {
                    _switchWriter.InnerWriter = _writerToRestore;
                }
            }

        }

    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.