Exemple #1
0
        public Application(TupleList<string, CreateRequestHandler, Dictionary<string, object>> handlers_ = null, string default_host_ = "", List<Func<HTTPRequest, OutputTransform>> transforms_ = null,
                 bool wsgi=false, Dictionary<string, object> settings_=null)
        {
            if (settings_ == null) 
                settings_ = new Dictionary<string, object>();

            if (transforms_ == null)
            {
                transforms = new List<Func<HTTPRequest, OutputTransform>>();
                if (settings_.get("gzip") != null)
                    transforms.Add(r => new GZipContentEncoding(r));
                transforms.Add(r => new ChunkedTransferEncoding(r));
            }
            else
                transforms = transforms_;
            handlers = new TupleList<Regex,List<URLSpec>>();
            named_handlers = new Dictionary<string, object>();
            default_host = default_host_;
            settings = settings_;
            //todo implement
            /*self.ui_modules = {'linkify': _linkify,
                               'xsrf_form_html': _xsrf_form_html,
                               'Template': TemplateModule,
                               }
            self.ui_methods = {}*/
            _wsgi = wsgi;
            /*self._load_ui_modules(settings.get("ui_modules", {}))
            self._load_ui_methods(settings.get("ui_methods", {}))*/
            if (settings.get("static_path") != null)
            {
                var path = settings["static_path"] as string;
                handlers_ = handlers_ ?? new TupleList<string, CreateRequestHandler, Dictionary<string, object>>();
                var static_url_prefix = settings.get("static_url_prefix", "/static/");
                var static_handler_class = settings.get<CreateRequestHandler>("static_handler_class", (app, rq, args) => new StaticFileHandler(app, rq, args));
                var static_handler_args = settings.get("static_handler_args", new Dictionary<string, object>());
                static_handler_args["path"] = path;

                foreach (var pattern in new string[] {Regex.Escape(static_url_prefix) + @"(.*)", 
                                                     @"/(favicon\.ico)", @"/(robots\.txt)"}) 
                {
                    handlers_.Insert(0, Tuple.Create(pattern, static_handler_class, static_handler_args));
                }
            }
            if (handlers_ != null)
                add_handlers(".*$", handlers_);

      
            // Automatically reload modified modules
            if (settings.get("debug") != null && !wsgi)
            {
                //todo implement
                //from tornado import autoreload
                //autoreload.start()
            }
        }