Beispiel #1
0
        static void RegisterFileHandlers()
        {
            string         pattern       = string.Format("({0})", string.Join("|", fileTypes.Select(x => x.Key).ToArray()));
            RouteAttribute downloadRoute = new RouteAttribute(string.Format(@"^/download/(.*\.{0})$", pattern));
            RouteAttribute fileRoute     = new RouteAttribute(string.Format(@"^/(.*\.{0})$", pattern));

            bool needs_www = fileRoot.Contains("://");

            downloadRoute.m_runOnMainThread = needs_www;
            fileRoute.m_runOnMainThread     = needs_www;

            FileHandlerDelegate callback = FileHandler;

            if (needs_www)
            {
                callback = WWWFileHandler;
            }

            downloadRoute.m_callback = delegate(RequestContext context) {
                callback(context, true);
            };
            fileRoute.m_callback = delegate(RequestContext context) {
                callback(context, false);
            };

            registeredRoutes.Add(downloadRoute);
            registeredRoutes.Add(fileRoute);
        }
Beispiel #2
0
        public void RegisterDefaultHandler(FileHandlerDelegate handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            _defaultHandler = handler;
        }
Beispiel #3
0
        public void RegisterFileType(string extension, FileHandlerDelegate handler)
        {
            if (_fileMethods.ContainsKey(extension))
            {
                throw new ArgumentException("File extension is already registered");
            }

            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            _fileMethods.Add(extension, handler);
        }