public void Handle(ThreadEntity CurrentThreadEntity, Page.PageAbstract CurrentPageClass, HTMLContainer ContentContainer) { _threadEntity = CurrentThreadEntity; _threadEntity.ControlIndex += 1; _dataBuilder.Init(_tagList); _datastring = _dataBuilder.HandleData(CurrentPageClass); HTMLContainer _temp = new HTMLContainer(ContentContainer.Encoding); if (!_xsltLoaded || _threadEntity.WebSetting.DebugMode) { _xsltCache = HandleXSLT(); } _xsltString = _xsltCache; _xsltString = _dataBuilder.InsertParameter(_xsltString); if (!string.IsNullOrEmpty(_xsltParameter)) { _xsltString = InsertParameter(_xsltString, CurrentPageClass); } _temp.Write(HandleHTML(_datastring, _xsltString)); if (_enableScript && _temp.Length > 0) { Control.ControlAnalyze _controls = new ControlAnalyze(CurrentThreadEntity, this.Map, true); _controls.SetContent(_temp.ToArray()); _controls.Analyze(); _temp.Clear(); _controls.Handle(CurrentPageClass, _temp); } ContentContainer.Write(_temp); _threadEntity.ControlIndex -= 1; }
public void Handle(ThreadEntity CurrentThreadEntity, Page.PageAbstract CurrentPageClass, HTMLContainer ContentContainer) { _threadEntity = CurrentThreadEntity; _threadEntity.ControlIndex += 1; _index = Xy.Tools.Control.Tag.TransferValue("PageIndex", _index, CurrentPageClass); _size = Xy.Tools.Control.Tag.TransferValue("PageSize", _size, CurrentPageClass); _max = Xy.Tools.Control.Tag.TransferValue("PageMax", _max, CurrentPageClass); _count = Xy.Tools.Control.Tag.TransferValue("PageCount", _count, CurrentPageClass); if (_innerData == null || (!string.IsNullOrEmpty(_xsltstring) && _threadEntity.WebSetting.DebugMode)) { if (!string.IsNullOrEmpty(_xsltstring)) { using (System.IO.FileStream fs = new System.IO.FileStream(_threadEntity.WebSetting.XsltDir + _xsltstring, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) { using (System.IO.StreamReader sr = new System.IO.StreamReader(fs)) { _innerData.Write(sr.ReadToEnd()); sr.Close(); } fs.Close(); } } } HandleData(); System.Xml.XPath.XPathDocument xpathDoc = new System.Xml.XPath.XPathDocument(new System.IO.StringReader(_datastring)); System.Xml.Xsl.XslCompiledTransform xsl = HandleXSLT(); ContentContainer.Write(Xy.Tools.IO.XML.TransfromXmlStringToHtml(xsl, xpathDoc)); _threadEntity.ControlIndex -= 1; }
public void Handle(ThreadEntity CurrentThreadEntity, Page.PageAbstract CurrentPageClass, HTMLContainer ContentContainer) { _threadEntity = CurrentThreadEntity; _threadEntity.ControlIndex++; if (_webSetting == null) _webSetting = CurrentPageClass.WebSetting; HTMLContainer _container = new HTMLContainer(_webSetting.Encoding); Xy.Web.Page.PageAbstract _page; if (string.IsNullOrEmpty(_type)) _type = "Xy.Web,Xy.Web.Page.EmptyPage"; _page = Runtime.Web.PageClassLibrary.Get(_type); _page.Init(CurrentPageClass, _webSetting, _container); if (_extValues != null) { for (int i = 0; i < _extValues.Count; i++) { if (_page.Request.Values[_extValues.Keys[i]] != null) { _page.Request.Values[_extValues.Keys[i]] = _extValues[i]; } else { _page.Request.Values.Add(_extValues.Keys[i], _extValues[i]); } } } string _staticCacheDir = string.Empty, _staticCacheFile = string.Empty, _staticCachePath = string.Empty; if (_cached) { _staticCacheDir = _webSetting.CacheDir + "IncludeCache\\" + _threadEntity.URL.Dir.Replace('/', '\\'); _staticCacheFile = _file + _valueString; _staticCachePath = _staticCacheDir + _staticCacheFile + ".xycache"; if (!_page.UpdateCache(_staticCachePath, DateTime.Now)) { if (System.IO.File.Exists(_staticCachePath)) { ContentContainer.Write(System.IO.File.ReadAllBytes(_staticCachePath)); return; } } } if (_innerData != null && _innerData.HasContent) { _page.SetContent(_innerData); } _page.Handle(_map, _file, _enableScript, true); if (_cached) { Xy.Tools.IO.File.ifNotExistsThenCreate(_staticCachePath); using (System.IO.FileStream fs = new System.IO.FileStream(_staticCachePath, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read)) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fs)) { try { sw.Write(_container.ToString()); sw.Flush(); } finally { sw.Close(); fs.Close(); } } } } ContentContainer.Write(_container); //ContentContainer.Write(_page.HTMLContainer); _threadEntity.ControlIndex--; }
public void Handle(ThreadEntity CurrentThreadEntity, Page.PageAbstract CurrentPageClass, HTMLContainer ContentContainer) { _threadEntity = CurrentThreadEntity; _threadEntity.ControlIndex += 1; HTMLContainer _innerHTML = new HTMLContainer(ContentContainer.Encoding); if (CurrentPageClass is Page.UserPage) { Page.UserPage up = (Page.UserPage)CurrentPageClass; if (up.CurrentUser != null) { if ((_hasPowerIndex > 0 && up.CurrentUser.HasPower(_hasPowerIndex)) || (!string.IsNullOrEmpty(_hasPowerKey) && up.CurrentUser.HasPower(_hasPowerKey))) { if (_inGroupIndex > 0 || !string.IsNullOrEmpty(_inGroupKey)) { if (up.CurrentUser.InGroup(_inGroupIndex) || up.CurrentUser.InGroup(_inGroupKey)) { _innerHTML.Write(_innerData); } } else { _innerHTML.Write(_innerData); } } else if ((_inGroupIndex > 0 && up.CurrentUser.InGroup(_inGroupIndex)) || (!string.IsNullOrEmpty(_hasPowerKey) && up.CurrentUser.InGroup(_inGroupKey))) { _innerHTML.Write(_innerData); } } } if (_innerHTML.Length == 0 && !string.IsNullOrEmpty(_noPowerMessage)) { ContentContainer.Write(_noPowerMessage); } else { if (_enableScript) { Control.ControlAnalyze _controls = Cache.PageAnalyze.GetInstance(CurrentThreadEntity, CurrentPageClass, this.Map); if (!_controls.IsHandled || CurrentPageClass.WebSetting.DebugMode) { _controls.SetContent(_innerHTML.ToArray()); _controls.Analyze(); } _controls.Handle(CurrentPageClass, ContentContainer); } else { ContentContainer.Write(_innerHTML); } } _threadEntity.ControlIndex -= 1; }
public void Analyze() { if (_content.Length == 0) return; #if DEBUG Xy.Tools.Debug.Log.WriteEventLog(_map + " start control analyze"); #endif int _controlStartPoint = 0; int _controlEndPoint = 0; int _controlDeep = 0; int _lastPoint = _point; int _controlEndPointHold = 0; IControl _controlHold = null; string _controlCreateString; byte[] _tempBytes; HTMLContainer _container; while ((_controlStartPoint = findNextStartTag()) > 0 && _lastPoint < _content.Length) { _controlEndPoint = findNextEndTag(); if (_controlEndPoint == -1) throw new Exception("Unclosed tag"); _tempBytes = new byte[_controlEndPoint - _controlStartPoint]; Buffer.BlockCopy(_content, _controlStartPoint, _tempBytes, 0, _tempBytes.Length); _controlCreateString = _currentThreadEntity.WebSetting.Encoding.GetString(_tempBytes).Trim(); if (_controlDeep > 0) { if (_controlCreateString.IndexOf("@End") == 0) { _controlDeep--; if (_controlDeep == 0) { _tempBytes = new byte[_controlStartPoint - 2 - _controlEndPointHold]; Buffer.BlockCopy(_content, _controlEndPointHold, _tempBytes, 0, _tempBytes.Length); _container = new HTMLContainer(_currentThreadEntity.WebSetting.Encoding); _container.Write(_tempBytes); _controlHold.InnerData = _container; } } else { if (CreateControl(_controlCreateString, true).IsNeedData) _controlDeep++; } } else { _container = new HTMLContainer(_currentThreadEntity.WebSetting.Encoding); _tempBytes = new byte[_controlStartPoint - 2 - _lastPoint]; Buffer.BlockCopy(_content, _lastPoint, _tempBytes, 0, _tempBytes.Length); _container.Write(_tempBytes); _analyzeResultCollection.Add(new AnalyzeResult() { Type = AnalyzeResultType.PureHTML, PureHTML = _container, Map = _map + ".PurlHTML" + _lastPoint + "_" + (_controlStartPoint - 2) }); //_contentList.Add(_container); //_container = new HTMLContainer(_currentThreadEntity.WebSetting.Encoding); //_contentList.Add(_container); _controlHold = CreateControl(_controlCreateString); if (_controlHold.IsNeedData) { _controlDeep++; _controlEndPointHold = _controlEndPoint + 2; } _controlCollection.Add(_controlHold); _analyzeResultCollection.Add(new AnalyzeResult() { Type = AnalyzeResultType.Control, Control = _controlHold, Map = _controlHold.Map }); } _lastPoint = _controlEndPoint + 2; } if (_lastPoint < _content.Length) { _container = new HTMLContainer(_currentThreadEntity.WebSetting.Encoding); _tempBytes = new byte[_content.Length - _lastPoint]; Buffer.BlockCopy(_content, _lastPoint, _tempBytes, 0, _tempBytes.Length); _container.Write(_tempBytes); //_contentList.Add(_container); _analyzeResultCollection.Add(new AnalyzeResult() { Type = AnalyzeResultType.PureHTML, PureHTML = _container, Map = _map + "PurlHTML" + _lastPoint + "_" + _content.Length }); } _isHandled = true; #if DEBUG Xy.Tools.Debug.Log.WriteEventLog(_map + " finish control analyze"); #endif }
public void Handle(Page.PageAbstract currentPageClass, HTMLContainer contentContainer) { if (!_isHandled) { contentContainer.Write(_content); return; } for (int i = 0; i < _analyzeResultCollection.Count; i++) { // if (_isHandled && _controlCollection[i].Cached) { // continue; // } // try { //#if DEBUG // Xy.Tools.Debug.Log.WriteEventLog(_controlCollection[i].Map + " control handle start"); //#endif // _controlCollection[i].Handle(_currentThreadEntity, currentPageClass); //#if DEBUG // Xy.Tools.Debug.Log.WriteEventLog(_controlCollection[i].Map + " control handle end"); //#endif // } catch (Exception ex) { // throw new Exception("meet a error on handle control: " + _controlCollection[i].Map, ex); // } try { #if DEBUG Xy.Tools.Debug.Log.WriteEventLog(_analyzeResultCollection[i].Map + " control handle start"); #endif _analyzeResultCollection[i].Handle(currentPageClass.ThreadEntity, currentPageClass, contentContainer); #if DEBUG Xy.Tools.Debug.Log.WriteEventLog(_analyzeResultCollection[i].Map + " control handle end"); #endif } catch (Exception ex) { throw new Exception("meet an error on handle content: " + _analyzeResultCollection[i].Map, ex); } } }
public void Analyze() { if (_content.Length == 0) { return; } #if DEBUG Xy.Tools.Debug.Log.WriteEventLog(_map + " start control analyze"); #endif int _controlStartPoint = 0; int _controlEndPoint = 0; int _controlDeep = 0; int _lastPoint = _point; int _controlEndPointHold = 0; IControl _controlHold = null; string _controlCreateString; byte[] _tempBytes; HTMLContainer _container; while ((_controlStartPoint = findNextStartTag()) > 0 && _lastPoint < _content.Length) { _controlEndPoint = findNextEndTag(); if (_controlEndPoint == -1) { throw new Exception("Unclosed tag"); } _tempBytes = new byte[_controlEndPoint - _controlStartPoint]; Buffer.BlockCopy(_content, _controlStartPoint, _tempBytes, 0, _tempBytes.Length); _controlCreateString = _currentThreadEntity.WebSetting.Encoding.GetString(_tempBytes).Trim(); if (_controlDeep > 0) { if (_controlCreateString.IndexOf("@End") == 0) { _controlDeep--; if (_controlDeep == 0) { _tempBytes = new byte[_controlStartPoint - 2 - _controlEndPointHold]; Buffer.BlockCopy(_content, _controlEndPointHold, _tempBytes, 0, _tempBytes.Length); _container = new HTMLContainer(_currentThreadEntity.WebSetting.Encoding); _container.Write(_tempBytes); _controlHold.InnerData = _container; } } else { if (CreateControl(_controlCreateString, true).IsNeedData) { _controlDeep++; } } } else { _container = new HTMLContainer(_currentThreadEntity.WebSetting.Encoding); _tempBytes = new byte[_controlStartPoint - 2 - _lastPoint]; Buffer.BlockCopy(_content, _lastPoint, _tempBytes, 0, _tempBytes.Length); _container.Write(_tempBytes); _analyzeResultCollection.Add(new AnalyzeResult() { Type = AnalyzeResultType.PureHTML, PureHTML = _container, Map = _map + ".PurlHTML" + _lastPoint + "_" + (_controlStartPoint - 2) }); //_contentList.Add(_container); //_container = new HTMLContainer(_currentThreadEntity.WebSetting.Encoding); //_contentList.Add(_container); _controlHold = CreateControl(_controlCreateString); if (_controlHold.IsNeedData) { _controlDeep++; _controlEndPointHold = _controlEndPoint + 2; } _controlCollection.Add(_controlHold); _analyzeResultCollection.Add(new AnalyzeResult() { Type = AnalyzeResultType.Control, Control = _controlHold, Map = _controlHold.Map }); } _lastPoint = _controlEndPoint + 2; } if (_lastPoint < _content.Length) { _container = new HTMLContainer(_currentThreadEntity.WebSetting.Encoding); _tempBytes = new byte[_content.Length - _lastPoint]; Buffer.BlockCopy(_content, _lastPoint, _tempBytes, 0, _tempBytes.Length); _container.Write(_tempBytes); //_contentList.Add(_container); _analyzeResultCollection.Add(new AnalyzeResult() { Type = AnalyzeResultType.PureHTML, PureHTML = _container, Map = _map + "PurlHTML" + _lastPoint + "_" + _content.Length }); } _isHandled = true; #if DEBUG Xy.Tools.Debug.Log.WriteEventLog(_map + " finish control analyze"); #endif }
//public static void RemoveOutputCacheItem(string path) { System.Web.HttpResponse.RemoveOutputCacheItem(path); } //public void SetCookie(HttpCookie cookie) { _innerResponse.SetCookie(cookie); } //public void TransmitFile(string filename) { _innerResponse.TransmitFile(filename); } //public void TransmitFile(string filename, long offset, long length) { _innerResponse.TransmitFile(filename, offset, length); } //public void Write(char ch) { _innerResponse.Write(ch); } public void Write(char s) { _content.Write(s.ToString()); }
public virtual void onGetError(Exception ex) { StringBuilder _errorString = new StringBuilder(); Exception exception = ex; PageData.Add("WrongTime", DateTime.Now.ToString()); _errorString.Append("WrongTime:").AppendLine(DateTime.Now.ToString()); PageData.Add("ClientIP", Request.UserHostAddress); _errorString.Append("ClientIP:").AppendLine(Request.UserHostAddress); PageData.Add("ClientBrowser", string.Format("{0} | {1}", Request.Browser.Type, Request.Browser.Browser)); _errorString.Append("ClientBrowser:").AppendLine(string.Format("{0} | {1}", Request.Browser.Type, Request.Browser.Browser)); PageData.Add("UserAgent", Request.UserAgent); _errorString.Append("UserAgent:").AppendLine(Request.UserAgent); PageData.Add("URL", Request.Url.ToString()); _errorString.Append("URL:").AppendLine(Request.Url.ToString()); PageData.Add("Message", exception.Message); _errorString.Append("Message:").AppendLine(exception.Message); Exception inex = exception; System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("Message"); dt.Columns.Add("Source"); dt.Columns.Add("TargetSite"); dt.Columns.Add("Data"); dt.Columns.Add("StackTrace"); int i = 1; while (inex != null) { System.Data.DataRow dr = dt.NewRow(); _errorString.AppendLine("=============================Exception No." + i++ + "============================="); dr["Message"] = string.IsNullOrEmpty(inex.Message) ? "None" : inex.Message.Replace("\r\n", "<br />"); _errorString.AppendLine("Message:" + inex.Message); dr["Source"] = string.IsNullOrEmpty(inex.Source) ? "None" : inex.Source.Replace("\r\n", "<br />"); _errorString.AppendLine("Source:" + inex.Source); dr["TargetSite"] = inex.TargetSite == null ? "None" : inex.TargetSite.ToString(); _errorString.AppendLine("TargetSite:" + inex.TargetSite); StringBuilder _tsb = new StringBuilder(); if (inex.Data != null) { foreach (object _entry in inex.Data.Keys) { _tsb.Append(string.Format("{0}:{1}<br />", _entry.ToString(), inex.Data[_entry])); } _errorString.AppendLine("Data:" + _tsb.ToString()); dr["Data"] = _tsb.Length == 0 ? "None" : _tsb.ToString(); } dr["StackTrace"] = string.IsNullOrEmpty(inex.StackTrace) ? "None" : inex.StackTrace.Replace("\r\n", "<br />"); _errorString.AppendLine("StackTrace:" + inex.StackTrace); dt.Rows.Add(dr); inex = inex.InnerException; } PageData.Add("Error", dt); Xy.Tools.Debug.Log.WriteErrorLog(_errorString.ToString()); Response.StatusCode = 404; if (string.IsNullOrEmpty(ThreadEntity.URLItem.PagePath)) { HTMLContainer _errTemplate = new HTMLContainer(WebSetting.Encoding); _errTemplate.Write(_errorTemplate); SetContent(_errTemplate); } }
public void Handle(ThreadEntity CurrentThreadEntity, Page.PageAbstract CurrentPageClass, HTMLContainer ContentContainer) { _threadEntity = CurrentThreadEntity; _threadEntity.ControlIndex++; if (_webSetting == null) { _webSetting = CurrentPageClass.WebSetting; } HTMLContainer _container = new HTMLContainer(_webSetting.Encoding); Xy.Web.Page.PageAbstract _page; if (string.IsNullOrEmpty(_type)) { _type = "Xy.Web,Xy.Web.Page.EmptyPage"; } _page = Runtime.Web.PageClassLibrary.Get(_type); _page.Init(CurrentPageClass, _webSetting, _container); if (_extValues != null) { for (int i = 0; i < _extValues.Count; i++) { if (_page.Request.Values[_extValues.Keys[i]] != null) { _page.Request.Values[_extValues.Keys[i]] = _extValues[i]; } else { _page.Request.Values.Add(_extValues.Keys[i], _extValues[i]); } } } string _staticCacheDir = string.Empty, _staticCacheFile = string.Empty, _staticCachePath = string.Empty; if (_cached) { _staticCacheDir = _webSetting.CacheDir + "IncludeCache\\" + _threadEntity.URL.Dir.Replace('/', '\\'); _staticCacheFile = _file + _valueString; _staticCachePath = _staticCacheDir + _staticCacheFile + ".xycache"; if (!_page.UpdateCache(_staticCachePath, DateTime.Now)) { if (System.IO.File.Exists(_staticCachePath)) { ContentContainer.Write(System.IO.File.ReadAllBytes(_staticCachePath)); return; } } } if (_innerData != null && _innerData.HasContent) { _page.SetContent(_innerData); } _page.Handle(_map, _file, _enableScript, true); if (_cached) { Xy.Tools.IO.File.ifNotExistsThenCreate(_staticCachePath); using (System.IO.FileStream fs = new System.IO.FileStream(_staticCachePath, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read)) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fs)) { try { sw.Write(_container.ToString()); sw.Flush(); } finally { sw.Close(); fs.Close(); } } } } ContentContainer.Write(_container); //ContentContainer.Write(_page.HTMLContainer); _threadEntity.ControlIndex--; }