Add() public méthode

Add a decoder.
Adding zero decoders will make the server add the default ones which is MultiPartDecoder and UrlDecoder.
public Add ( IBodyDecoder decoder ) : void
decoder IBodyDecoder decoder to add
Résultat void
        /// <summary>
        /// Initialise a HTTP server
        /// </summary>
        /// <param name="path">The path to the web root of the http server</param>
        public WebServer(string path)
        {
            _httpServer = new HttpServer.Server();

            // Add the controller module and all controllers
            var controllerModule = new RestControllerModule();
            var cType = typeof(RestRequestController);
            AppDomain.CurrentDomain.GetAssemblies().ToList()
                .SelectMany(s => s.GetTypes())
                .Where(p => p.IsSubclassOf(cType) && p != cType && !p.IsAbstract)
                .ToList()
                .ForEach(t => controllerModule.Add((RestRequestController)Activator.CreateInstance(t)));
            _httpServer.Add(controllerModule);

            // Add the basic file module
            int cacheDuration = 2592000;
            Program.Config.TryGetInt("cacheDuration", out cacheDuration);
            var fileModule = new CachedFileModule(Math.Max(0, cacheDuration));
            fileModule.Resources.Add(new HttpServer.Resources.FileResources("/", path));
            _httpServer.Add(fileModule);

            // Set name
            string serverName;
            Program.Config.TryGetString("name", out serverName, "Touchee");
            _httpServer.ServerName = serverName;

            // Go to root
            _httpServer.Add(new SimpleRouter("/", "/index.html"));
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            var filter = new LogFilter();
            filter.AddStandardRules();
            //LogFactory.Assign(new ConsoleLogFactory(filter));

            // create a server.
            var server = new Server();
            
            // same as previous example.
            var module = new FileModule();
            module.Resources.Add(new FileResources("/", Environment.CurrentDirectory + "\\files\\"));
            server.Add(module);
            server.RequestReceived += OnRequest;
            server.Add(new MultiPartDecoder());

            // use one http listener.
            server.Add(HttpListener.Create(IPAddress.Any, 8085));
            server.Add(new SimpleRouter("/", "/index.html"));

            // start server, can have max 5 pending accepts.
            server.Start(5);

            Console.ReadLine();
        }
Exemple #3
0
        //Control
        public static void Init()
        {
            //See if there is a new version of the web files waiting before we start the server
            if (File.Exists(Core.RootFolder + @"\web.zip"))
            {
                if (Directory.Exists(Core.RootFolder + @"\web\")) Directory.Delete(Core.RootFolder + @"\web\", true);
                Directory.CreateDirectory(YAMS.Core.RootFolder + @"\web\");
                AutoUpdate.ExtractZip(YAMS.Core.RootFolder + @"\web.zip", YAMS.Core.RootFolder + @"\web\");
                File.Delete(Core.RootFolder + @"\web.zip");
            }

            adminServer = new Server();
            publicServer = new Server();

            //Handle the requests for static files
            var adminModule = new FileModule();
            adminModule.Resources.Add(new FileResources("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\"));
            adminServer.Add(adminModule);

            //Add any server specific folders
            var publicModule = new FileModule();
            publicModule.Resources.Add(new FileResources("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\"));
            SqlCeDataReader readerServers = YAMS.Database.GetServers();
            while (readerServers.Read())
            {
                var intServerID = readerServers["ServerID"].ToString();
                if (!Directory.Exists(Core.StoragePath + intServerID + "\\renders\\")) Directory.CreateDirectory(Core.StoragePath + intServerID + "\\renders\\");
                publicModule.Resources.Add(new FileResources("/servers/" + intServerID + "/renders/", Core.StoragePath + intServerID + "\\renders\\"));
                if (!Directory.Exists(Core.StoragePath + intServerID + "\\backups\\")) Directory.CreateDirectory(Core.StoragePath + intServerID + "\\backups\\");
                publicModule.Resources.Add(new FileResources("/servers/" + intServerID + "/backups/", Core.StoragePath + intServerID + "\\backups\\"));
            }
            publicServer.Add(publicModule);

            //Handle requests to API
            adminServer.Add(new Web.AdminAPI());
            publicServer.Add(new Web.PublicAPI());

            adminServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS"))));
            publicServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS"))));

            adminServer.ErrorPageRequested += new EventHandler<ErrorPageEventArgs>(myServer_ErrorPageRequested);
            publicServer.ErrorPageRequested += new EventHandler<ErrorPageEventArgs>(myServer_ErrorPageRequested);

            adminServerThread = new Thread(new ThreadStart(StartAdmin));
            publicServerThread = new Thread(new ThreadStart(StartPublic));
            adminServerThread.Start();
            publicServerThread.Start();

            //Open firewall ports
            Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website");
            Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS")), "Public website");

            Networking.OpenUPnP(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website");
            Networking.OpenUPnP(Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS")), "Public website");
        }
        public static void HttpRestServer()
        {
            var server = new Server();
            var module = new RestModule();

            module.Endpoints.Add(new ReceiveRestEndpoint());
            module.Endpoints.Add(new SyncRestEndpoint());
            module.Endpoints.Add(new StopRestEndpoint());

            server.Add(module);

            // use one http listener.
            server.Add(HttpServer.HttpListener.Create(IPAddress.Loopback, DebugKeys.HttpListenerPort));
            server.Start(5);
        }
Exemple #5
0
 public static void Start()
 {
     if (_webServer != null)
     {
         _webServer.Start(0);
         return;
     }
     _webServer = new Server();
     _webServer.Add(HttpListener.Create(IPAddress.Any, 8080));
     _webServer.PrepareRequest += OnRequest;
     _webServer.Add(new StaticResourceHandler());
     _webServer.Add(new PageHandler());
     _webServer.Add(new SimpleRouter("/", "index.htm"));
     UserSession.Init(_webServer, true);
     _webServer.Start(0);
 }
Exemple #6
0
        private static void StartHTTP()
        {
            try
            {
                HttpServer.Logging.LogFactory.Assign(new HttpServer.Logging.ConsoleLogFactory(new HttpServer.Logging.LogFilter()));
                HTTP = new Server();
                HTTP.Add(HttpListener.Create(System.Net.IPAddress.Any, Settings.Get("HttpPort", 7780)));
                HTTP.Add(new HttpMod());
                HTTP.Start(32);

                LocalFileStorage = Settings.Get("LocalFiles", new Dictionary <string, string>());
            }
            catch (Exception ex)
            {
                Trace.WriteLine("HTTP Startup Error: " + ex.Message);
            }
        }
Exemple #7
0
        //Control
        public static void Init()
        {
            adminServer = new Server();

            //Handle the requests for static files
            var adminModule = new FileModule();
            adminModule.Resources.Add(new FileResources("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\"));
            adminServer.Add(adminModule);
            //Handle requests to API
            adminServer.Add(new Web.AdminAPI());

            adminServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS"))));
            adminServer.ErrorPageRequested += new EventHandler<ErrorPageEventArgs>(myServer_ErrorPageRequested);
            adminServerThread = new Thread(new ThreadStart(StartAdmin));
            adminServerThread.Start();

            //Open firewall ports
            if (Database.GetSetting("EnableOpenFirewall", "YAMS") == "true")
            {
                Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website");
            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            // create a server.
            var server = new Server();

            // same as previous example.
            var module = new FileModule();
            module.Resources.Add(new FileResources("/", Environment.CurrentDirectory + "\\files\\"));
            server.Add(module);

            // use one http listener.
            server.Add(HttpListener.Create(IPAddress.Any, 8085));

            // add our own module.
            server.Add(new Streamer());


            // start server, can have max 5 pending accepts.
            server.Start(5);

            Console.ReadLine();
        }
Exemple #9
0
        public WordLaunch(ServerInfo targetserver)
        {
            InitializeComponent();
            this.targetserver = targetserver;
            plugin = new PluginRpc(targetserver.conn.URL);
            medsize = plugin.GetMediumSize();

            txt_Content.NativeInterface.SetCodePage((int)Constants.SC_CP_UTF8);

            CategoryFullInfo[] cfi = targetserver.conn.GetCategories(0, targetserver.username, targetserver.password);
            foreach (CategoryFullInfo cf in cfi)
            {
                CheckBox cb = new CheckBox();
                cb.Name = "cb_" + cf.categoryName;
                cb.Text = cf.categoryName;
                cb.Tag = cf;
                flow_Categories.Controls.Add(cb);
            }

            postResources = GetNextAvailableDir();
            Directory.CreateDirectory(postResources);

            var module = new FileModule();
            webserv = new Server();
            module.Resources.Add(new FileResources("/",postResources));
            webserv.Add(module);
            webserv.Add(new MultiPartDecoder());
            webserv.RequestReceived+=new EventHandler<RequestEventArgs>(webserv_RequestReceived);

            // use one http listener.
            webserv.Add(HttpListener.Create(System.Net.IPAddress.Any, webservport));
            webserv.Start(5);

            // Find a valid post to use
            url = targetserver.conn.URL.Replace("xmlrpc.php", "?p=2147483646");
        }
        //public WebServer(IPAddress address)
        //{
        //    _ipAddress = address;
        //    // same as previous example.
        //    Setup();
        //}

        public void Setup()
        {
            try
            {
                _server = new HttpServer.Server();
                var module = new FileModule();
                module.Resources.Add(new FileResources("/", ScoreboardConfig.SAVE_SERVER_FILES_FOLDER));

                _server.Add(module);

                _server.RequestReceived += OnRequest;
                _server.Add(new MultiPartDecoder());

                // use one http listener.

                _server.Add(new SimpleRouter("/", "/index.html"));
                _server.Add(new JsonRouter("/GrabOverlayUpdate"));
                _server.Add(new JsonRouter("/GrabMobileUpdate"));
                _server.Add(new JsonRouter("/GetTeam1Members"));
                _server.Add(new JsonRouter("/GetTeam2Members"));
                _server.Add(new JsonRouter("/getJamNumber"));
                _server.Add(new JsonRouter("/addAssist"));
                _server.Add(new JsonRouter("/removeAssist"));
                _server.Add(new JsonRouter("/addBlock"));
                _server.Add(new JsonRouter("/removeBlock"));
                _server.Add(new JsonRouter("/scoringLoaded"));
                _server.Add(new JsonRouter("/addScore"));
                _server.Add(new JsonRouter("/removeScore"));
                _server.Add(new JsonRouter("/setBlocker1"));
                _server.Add(new JsonRouter("/setBlocker2"));
                _server.Add(new JsonRouter("/setBlocker3"));
                _server.Add(new JsonRouter("/setBlocker4"));
                _server.Add(new JsonRouter("/setPivot"));
                _server.Add(new JsonRouter("/setJammer"));
                _server.Add(new JsonRouter("/setPBox"));
                _server.Add(new JsonRouter("/addpenalty"));
                _server.Add(new JsonRouter("/getallpenaltytypes"));
                _server.Add(new JsonRouter("/loadMainScreen"));

                PortNumber = portsToTry[triedIndex];
                _server.Add(HttpListener.Create(IpAddress, PortNumber));
            }
            catch (Exception exception)
            {
                ErrorViewModel.Save(exception, GetType());
            }
        }
        public override void Init(Kernel kernel)
        {
            PluginOptions = new PluginConfiguration<PluginOptions>(kernel, this.GetType().Assembly);
            PluginOptions.Load();
            Logger.ReportInfo("MBWeb (version "+Version+") Plug-in loaded.");

            server = new Server();
            server.Add(HttpServer.HttpListener.Create(IPAddress.Any, 9999));
            var module = new TinyWebModule();
            module.MapPath("/", "/index.html");
            server.Add(module);

            server.Start(5);
        }
Exemple #12
0
        private static void StartWebServer(string uri, string absolutePath, int port)
        {
            // create a server.
            var server = new Server();
            // add module to serve files i.e. act like a web server
            var module = new FileModule();
            
            // Add mime types for Silverlight PivotViewer
            module.ContentTypes.Add("xaml", new ContentTypeHeader("application/xaml+xml"));
            module.ContentTypes.Add("xap", new ContentTypeHeader("application/x-silverlight-2"));
            module.ContentTypes.Add("cxml", new ContentTypeHeader("text/xml"));
            module.ContentTypes.Add("xml", new ContentTypeHeader("text/xml"));
            module.ContentTypes.Add("dzi", new ContentTypeHeader("text/xml"));
            module.ContentTypes.Add("dzc", new ContentTypeHeader("text/xml"));
            
            module.Resources.Add(new FileResources("/", absolutePath));
            server.Add(module);

            // use one http listener.
            server.Add(HttpListener.Create(IPAddress.Any, port));
            // start server, can have max 5 pending accepts.
            server.Start(5);
        }
Exemple #13
0
        public NancyHost(IPAddress address, int port, INancyBootstrapper bootStrapper)
        {
            var filter = new LogFilter();
            filter.AddStandardRules();
            LogFactory.Assign(new ConsoleLogFactory(filter));
            server = new Server();

            bootStrapper.Initialise();
            engine = bootStrapper.GetEngine();

            // same as previous example.
            AppiaModule module = new AppiaModule(engine);
            server.Add(module);
        }