Beispiel #1
0
        /// <summary>
        /// Create web item based on runtime handler (without any originating file)
        /// </summary>
        /// <param name="handler">Runtime handler</param>
        /// <returns>Created web item</returns>
        public static WebItem Runtime(ResponseHandler handler)
        {
            var item = new WebItem(null);

            item.Handler = handler;

            return(item);
        }
Beispiel #2
0
        private void addAction(string pattern, WebItem item)
        {
            if (pattern == "/index")
            {
                _actions.Add("/", item);
            }

            _actions.Add(pattern, item);
        }
Beispiel #3
0
        protected void ErrorPage(int errorCode, string relativeFilePath)
        {
            switch (errorCode)
            {
            case 404:
                _404 = getWebItem(relativeFilePath);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Fill item with item.FilePath, is called on every file change
        /// </summary>
        /// <param name="item">Filled item</param>
        /// <param name="action">Action called when item has to be refreshed</param>
        private void fillItem(WebItem item, Action action)
        {
            action();
            if (item.Watcher == null)
            {
                var directory = Path.GetDirectoryName(item.FilePath) + Path.DirectorySeparatorChar;
                var fileName  = Path.GetFileName(item.FilePath);
                item.Watcher = new FileSystemWatcher(directory, fileName);

                item.Watcher.EnableRaisingEvents = true;
                item.Watcher.NotifyFilter        = NotifyFilters.LastWrite | NotifyFilters.FileName;
                item.Watcher.Created            += (s, e) => itemChangeHandler(action);
                item.Watcher.Renamed            += (s, e) => itemChangeHandler(action);
                item.Watcher.Changed            += (s, e) => itemChangeHandler(action);
            }
        }
Beispiel #5
0
        public ResponseManagerBase(WebApplication application, string rootPath, params Type[] controllers)
        {
            RootPath    = rootPath + Path.DirectorySeparatorChar;
            Application = application;
            foreach (var controller in controllers)
            {
                foreach (var action in controller.GetMethods())
                {
                    if (action.DeclaringType.IsSubclassOf(typeof(ResponseController)))
                    {
                        registerAction(action);
                    }
                }
            }

            _304 = WebItem.Runtime(_handler_304);
        }
Beispiel #6
0
        protected WebItem SendRaw(string file, string ext)
        {
            var item = new WebItem(file);

            fillItem(item, () =>
            {
                var bytes = File.ReadAllBytes(file);
                var mime  = getMime(ext);
                item.ETag = DateTime.Now.Ticks.ToString();

                item.Handler = (r) =>
                {
                    r.SetContentType(mime);
                    r.SetLength(bytes.Length);
                    r.Write(bytes);
                };
            });

            return(item);
        }
Beispiel #7
0
 /// <summary>
 /// Publish action item with given uri
 /// </summary>
 /// <param name="uri">Uri to publish</param>
 /// <param name="actionItem">Published action item</param>
 protected void PublishAction(string uri, WebItem actionItem)
 {
     _actions.Add(uri, actionItem);
 }
Beispiel #8
0
 /// <summary>
 /// Publish file item with given uri
 /// </summary>
 /// <param name="fileId">Id of registered file</param>
 /// <param name="fileItem">Published file item</param>
 protected void RegisterFile(string fileId, WebItem fileItem)
 {
     _files.Add(fileId, fileItem);
 }
Beispiel #9
0
 internal ActionInfo(string pattern, WebItem handler)
 {
     Pattern = pattern;
     Item    = handler;
 }