Exemplo n.º 1
0
        private void context_BeginRequest(object sender, EventArgs e)
        {
            global.RequestStart(sender, e);
            HttpApplication _application = sender as HttpApplication;
            #if DEBUG
            Xy.Tools.Debug.Log.StartWorkflowLog();
            Xy.Tools.Debug.Log.WriteEventLog("start " + _application.Context.Request.Url.ToString());
            #endif
            Xy.Tools.Web.UrlAnalyzer _url = new Tools.Web.UrlAnalyzer(_application.Context.Request.Url.ToString());

            URLManage.URLCollection _urlCollection = _urlManager.GetUrlItemCollection(_url);
            if (_urlCollection == null) {
                throw new Exception(string.Format("can not found URL collection: {0}", _url.ToString()));
            } else {
            #if DEBUG
            Xy.Tools.Debug.Log.WriteEventLog("get url collection.");
            #endif
                Xy.WebSetting.WebSettingItem _webSetting = _urlCollection.WebConfig;
                if (!string.IsNullOrEmpty(_webSetting.Root)) {
                    _url.SetRoot(_webSetting.Root);
                }
                if (!string.IsNullOrEmpty(_webSetting.Port)) {
                    _url.SetPort(_webSetting.Port);
                }
            #if DEBUG
            Xy.Tools.Debug.Log.WriteEventLog("get websetting item.");
            #endif
                URLManage.URLItem _urlItem = _urlCollection.GetUrlItem(_url.Path);
                if (_urlItem == null) {
                    if(!_webSetting.Compatible) throw new Exception(string.Format("can not found URL item: {0}", _url.ToString()));
                } else {
            #if DEBUG
            Xy.Tools.Debug.Log.WriteEventLog("get url item.");
            #endif
                    ThreadEntity _entity = new ThreadEntity(_application.Context, _webSetting, _urlItem, _url);
                    global.HandleStart(_entity);
            #if DEBUG
            Xy.Tools.Debug.Log.WriteEventLog("created thread entity");
            #endif
                    _entity.Handle();
            #if DEBUG
            Xy.Tools.Debug.Log.WriteEventLog("thread entity handled");
            #endif
                    if (_entity.Content.HasContent) _application.Response.BinaryWrite(_entity.Content.ToArray());
                    global.HandleEnd(_entity);
            #if DEBUG
            Xy.Tools.Debug.Log.WriteEventLog("content outputed");
            Xy.Tools.Debug.Log.EndWorkflowLog();
            #endif
                    _application.Context.Response.End();
                }
            }
        }
Exemplo n.º 2
0
        private void context_BeginRequest(object sender, EventArgs e)
        {
            global.RequestStart(sender, e);
            HttpApplication _application = sender as HttpApplication;

#if DEBUG
            Xy.Tools.Debug.Log.StartWorkflowLog();
            Xy.Tools.Debug.Log.WriteEventLog("start " + _application.Context.Request.Url.ToString());
#endif
            Xy.Tools.Web.UrlAnalyzer _url = new Tools.Web.UrlAnalyzer(_application.Context.Request.Url.ToString());

            URLManage.URLCollection _urlCollection = _urlManager.GetUrlItemCollection(_url);
            if (_urlCollection == null)
            {
                throw new Exception(string.Format("can not found URL collection: {0}", _url.ToString()));
            }
            else
            {
#if DEBUG
                Xy.Tools.Debug.Log.WriteEventLog("get url collection.");
#endif
                Xy.WebSetting.WebSettingItem _webSetting = _urlCollection.WebConfig;
                if (!string.IsNullOrEmpty(_webSetting.Root))
                {
                    _url.SetRoot(_webSetting.Root);
                }
                if (!string.IsNullOrEmpty(_webSetting.Port))
                {
                    _url.SetPort(_webSetting.Port);
                }
#if DEBUG
                Xy.Tools.Debug.Log.WriteEventLog("get websetting item.");
#endif
                URLManage.URLItem _urlItem = _urlCollection.GetUrlItem(_url.Path);
                if (_urlItem == null)
                {
                    if (!_webSetting.Compatible)
                    {
                        throw new Exception(string.Format("can not found URL item: {0}", _url.ToString()));
                    }
                }
                else
                {
#if DEBUG
                    Xy.Tools.Debug.Log.WriteEventLog("get url item.");
#endif
                    ThreadEntity _entity = new ThreadEntity(_application.Context, _webSetting, _urlItem, _url);
                    global.HandleStart(_entity);
#if DEBUG
                    Xy.Tools.Debug.Log.WriteEventLog("created thread entity");
#endif
                    _entity.Handle();
#if DEBUG
                    Xy.Tools.Debug.Log.WriteEventLog("thread entity handled");
#endif
                    if (_entity.Content.HasContent)
                    {
                        _application.Response.BinaryWrite(_entity.Content.ToArray());
                    }
                    global.HandleEnd(_entity);
#if DEBUG
                    Xy.Tools.Debug.Log.WriteEventLog("content outputed");
                    Xy.Tools.Debug.Log.EndWorkflowLog();
#endif
                    _application.Context.Response.End();
                }
            }
        }