Exemplo n.º 1
0
 public ThreadEntity(System.Web.HttpContext webApp, WebSetting.WebSettingItem webSetting, URLManage.URLItem urlItem, Xy.Tools.Web.UrlAnalyzer currentURL)
 {
     _webContext = webApp;
     _webSetting = webSetting;
     _urlItem    = urlItem;
     _url        = currentURL;
     _content    = new HTMLContainer(_webSetting.Encoding);
 }
Exemplo n.º 2
0
 public ThreadEntity(System.Web.HttpContext webApp, WebSetting.WebSettingItem webSetting, URLManage.URLItem urlItem, Xy.Tools.Web.UrlAnalyzer currentURL)
 {
     _webContext = webApp;
     _webSetting = webSetting;
     _urlItem = urlItem;
     _url = currentURL;
     _content = new HTMLContainer(_webSetting.Encoding);
 }
Exemplo n.º 3
0
 public void Write(HTMLContainer content)
 {
     content._memoryStream.WriteTo(_memoryStream);
     _isStringDirty = false;
     _isByteDirty = false;
 }
Exemplo n.º 4
0
        public void Handle()
        {
            if (!string.IsNullOrEmpty(_urlItem.Mime))
            {
                _webContext.Response.ContentType = _urlItem.Mime;
            }
            switch (_urlItem.ContentType)
            {
            case URLManage.URLType.MainContent:
                //_webContext.Response.ContentType += "; charset=" + _webSetting.Encoding.WebName;
                //_webContext.Response.HeaderEncoding = _webSetting.Encoding;
                Xy.Web.Page.PageAbstract _page = Runtime.Web.PageClassLibrary.Get(_urlItem.PageClassName);
#if DEBUG
                Xy.Tools.Debug.Log.WriteEventLog("page created");
#endif
                _page.Init(this, this._webSetting);
#if DEBUG
                Xy.Tools.Debug.Log.WriteEventLog("page inited");
#endif
                try {
                    _page.Handle("@PageDir:" + _urlItem.PagePath, _urlItem.PagePath, _urlItem.EnableScript, false);
#if DEBUG
                    Xy.Tools.Debug.Log.WriteEventLog("page handled");
#endif
                } catch (Page.PageEndException) {
                    _content = _page.HTMLContainer;
                    return;
                } catch (Exception ex) {
                    try {
                        Page.PageErrorState _pes = _page.onError(ex);
                        if ((_pes & Page.PageErrorState.WriteLog) == Page.PageErrorState.WriteLog)
                        {
                            string _errorLogContent = _buildErrorString(_page, ex);
                            Xy.Tools.Debug.Log.WriteErrorLog(ex.Message);
                        }
                        if ((_pes & Page.PageErrorState.ThrowOut) == Page.PageErrorState.ThrowOut)
                        {
                            throw new Exception("A error occur on " + _urlItem.PageClassName, ex);
                        }
                    } catch (Page.PageEndException) {
                        return;
                    }
                }
                _content = _page.HTMLContainer;
                break;

            case URLManage.URLType.ResourceFile:
                DateTime _modifiedTime = System.IO.File.GetLastWriteTime(_url.PhysicalPath);
                if (Xy.Tools.IO.File.IsClientCached(_webContext.Request.Headers["If-Modified-Since"], _modifiedTime) && !_webSetting.DebugMode)
                {
                    WebContext.Response.StatusCode      = 304;
                    WebContext.Response.SuppressContent = true;
                }
                else
                {
                    WebContext.Response.Cache.SetLastModified(DateTime.Now);
                    if (_urlItem.Age.TotalMinutes > 0)
                    {
                        WebContext.Response.Cache.SetMaxAge(_urlItem.Age);
                        WebContext.Response.Cache.SetExpires(DateTime.Now.Add(_urlItem.Age));
                        WebContext.Response.Expires         = Convert.ToInt32(_urlItem.Age.TotalMinutes);
                        WebContext.Response.ExpiresAbsolute = DateTime.Now.Add(_urlItem.Age);
                        WebContext.Response.AddHeader("Cache-Control", "max-age=" + _urlItem.Age.TotalMinutes);
                    }
                    _webContext.Response.TransmitFile(_url.PhysicalPath);
                }
                break;

            case URLManage.URLType.Prohibit:
                throw new Exception("Access denied " + URL.ToString());
            }
        }
Exemplo n.º 5
0
 public void Handle()
 {
     if (!string.IsNullOrEmpty(_urlItem.Mime))
         _webContext.Response.ContentType = _urlItem.Mime;
     switch (_urlItem.ContentType) {
         case URLManage.URLType.MainContent:
             //_webContext.Response.ContentType += "; charset=" + _webSetting.Encoding.WebName;
             //_webContext.Response.HeaderEncoding = _webSetting.Encoding;
             Xy.Web.Page.PageAbstract _page = Runtime.Web.PageClassLibrary.Get(_urlItem.PageClassName);
     #if DEBUG
             Xy.Tools.Debug.Log.WriteEventLog("page created");
     #endif
             _page.Init(this, this._webSetting);
     #if DEBUG
             Xy.Tools.Debug.Log.WriteEventLog("page inited");
     #endif
             try {
                 _page.Handle("@PageDir:" + _urlItem.PagePath, _urlItem.PagePath, _urlItem.EnableScript, false);
     #if DEBUG
                 Xy.Tools.Debug.Log.WriteEventLog("page handled");
     #endif
             } catch (Page.PageEndException) {
                 _content = _page.HTMLContainer;
                 return;
             } catch (Exception ex) {
                 try {
                     Page.PageErrorState _pes = _page.onError(ex);
                     if ((_pes & Page.PageErrorState.WriteLog) == Page.PageErrorState.WriteLog) {
                         string _errorLogContent = _buildErrorString(_page, ex);
                         Xy.Tools.Debug.Log.WriteErrorLog(ex.Message);
                     }
                     if ((_pes & Page.PageErrorState.ThrowOut) == Page.PageErrorState.ThrowOut) {
                         throw new Exception("A error occur on " + _urlItem.PageClassName, ex);
                     }
                 } catch (Page.PageEndException) {
                     return;
                 }
             }
             _content = _page.HTMLContainer;
             break;
         case URLManage.URLType.ResourceFile:
             DateTime _modifiedTime = System.IO.File.GetLastWriteTime(_url.PhysicalPath);
             if (Xy.Tools.IO.File.IsClientCached(_webContext.Request.Headers["If-Modified-Since"], _modifiedTime) && !_webSetting.DebugMode) {
                 WebContext.Response.StatusCode = 304;
                 WebContext.Response.SuppressContent = true;
             } else {
                 WebContext.Response.Cache.SetLastModified(DateTime.Now);
                 if (_urlItem.Age.TotalMinutes > 0) {
                     WebContext.Response.Cache.SetMaxAge(_urlItem.Age);
                     WebContext.Response.Cache.SetExpires(DateTime.Now.Add(_urlItem.Age));
                     WebContext.Response.Expires = Convert.ToInt32(_urlItem.Age.TotalMinutes);
                     WebContext.Response.ExpiresAbsolute = DateTime.Now.Add(_urlItem.Age);
                     WebContext.Response.AddHeader("Cache-Control", "max-age=" + _urlItem.Age.TotalMinutes);
                 }
                 _webContext.Response.TransmitFile(_url.PhysicalPath);
             }
             break;
         case URLManage.URLType.Prohibit:
             throw new Exception("Access denied " + URL.ToString());
     }
 }
Exemplo n.º 6
0
 public void Write(HTMLContainer content)
 {
     content._memoryStream.WriteTo(_memoryStream);
     _isStringDirty = false;
     _isByteDirty   = false;
 }