示例#1
0
 static void StartServer()
 {
     Console.WriteLine("Initializing server");
     _Server = new Webserver(_Hostname, _Port, DefaultRoute);
     _Server.Settings.Headers.Host = "https://" + _Hostname + ":" + _Port;
     _Server.Start();
 }
示例#2
0
        public static void Main(string[] args)
        {
            ApiService apiService = new ApiService();
            Webserver  server     = new Webserver(apiService);

            server.Start();
        }
示例#3
0
 static void Main(string[] args)
 {
     _Server = new Webserver(_Hostname, _Port, false, null, null, DefaultRoute);
     _Server.Start();
     Console.WriteLine("HttpServerLite listening on http://" + _Hostname + ":" + _Port);
     Console.WriteLine("ENTER to exit");
     Console.ReadLine();
 }
示例#4
0
 public void Run(IBackgroundTaskInstance taskInstance)
 {
     taskInstance.GetDeferral();
     Webserver server = new Webserver();
     ThreadPool.RunAsync(workItem =>
     {
         server.Start();
     });
 }
示例#5
0
        static void Main(string[] args)
        {
            StartServer();

            Console.WriteLine("Started on https://" + _Hostname + ":" + _Port);

            while (_RunForever)
            {
                Console.Write("Command [? for help]: ");
                string userInput = Console.ReadLine();
                if (String.IsNullOrEmpty(userInput))
                {
                    continue;
                }

                switch (userInput)
                {
                case "?":
                    Menu();
                    break;

                case "q":
                    _RunForever = false;
                    break;

                case "c":
                case "cls":
                    Console.Clear();
                    break;

                case "state":
                    Console.WriteLine(_Server.IsListening);
                    break;

                case "start":
                    _Server.Start();
                    break;

                case "stop":
                    _Server.Stop();
                    break;

                case "dispose":
                    _Server.Dispose();
                    break;

                case "conn":
                    ListConnections();
                    break;
                }
            }
        }
示例#6
0
 private static void Main(string[] args)
 {
     Console.WindowWidth  = 100;
     Console.WindowHeight = 40;
     try
     {
         if (!File.Exists("server.jar"))
         {
             WebClient cl = new WebClient();
             cl.DownloadProgressChanged += cl_DownloadProgressChanged;
             cl.DownloadFileCompleted   += cl_DownloadFileCompleted;
             cl.DownloadFileAsync(new Uri("https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar"), "server.jar");
             while (!fileDownloaded)
             {
                 Thread.Sleep(100);
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         Console.ReadKey();
         return;
     }
     try
     {
         // The following commands are needed to redirect the standard output.
         // This means that it will be redirected to the Process.StandardOutput StreamReader.
         procStartInfo.RedirectStandardOutput = true;
         procStartInfo.UseShellExecute        = false;
         // Do not create the black window.
         procStartInfo.CreateNoWindow = false;
         proc.StartInfo           = procStartInfo;
         proc.ErrorDataReceived  += proc_DataReceived;
         proc.OutputDataReceived += proc_DataReceived;
         proc.Start();
         Webserver.Start();
         new Thread(HandleCommand).Start();
         while (!proc.HasExited)
         {
             ;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     Console.WriteLine("Press any key to exit.");
     Console.ReadKey();
 }
示例#7
0
 static void StartServer()
 {
     if (_Server != null && _Server.IsListening)
     {
         Console.WriteLine("Already initialized");
         return;
     }
     else
     {
         Console.WriteLine("Initializing server");
         _Server = new Webserver(_Hostname, _Port, true, "cavemantcp.pfx", "simpletcp", DefaultRoute);
         _Server.Settings.Headers.Host    = "https://" + _Hostname + ":" + _Port;
         _Server.Events.ServerStarted    += ServerStarted;
         _Server.Events.ServerStopped    += ServerStopped;
         _Server.Events.ServerDisposing  += ServerDisposing;
         _Server.Events.Logger            = Console.WriteLine;
         _Server.Settings.Debug.Responses = true;
         _Server.Settings.Debug.Routing   = true;
         _Server.Start();
     }
 }
示例#8
0
        public void ResolveWebserviceTest()
        {
            Webserver server = new Webserver();

            server.Bind("http://+:80/Temporary_Listen_Addresses/FortAwesomeUtil.test/base/");
            var dummy1 = new DummyWebservice();

            server.RegisterWebservice("foo1/", dummy1);
            var dummy2 = new DummyWebservice();

            server.RegisterWebservice("foo2/a/", dummy2);
            server.RegisterWebservice("foo2/b/", dummy2);
            server.Start();

            string     url      = "http://127.0.0.1:80/Temporary_Listen_Addresses/FortAwesomeUtil.test/base/foo2/a/basic/";
            Webservice expected = dummy1; // TODO: Initialize to an appropriate value
            Webservice actual;

            actual = server.ResolveWebservice(url);
            Assert.AreEqual(expected, actual);
        }
示例#9
0
        static void Main(string[] args)
        {
            Webserver server = new Webserver();

            ConsoleWrite.Green("MyWebServer starts now!");
            try
            {
                Thread serverThread = new Thread(() => server.Start());
                serverThread.Start();
                ConsoleWrite.Green("Server is running.");

                ////Manual Loading of Plugins (not working as intended, because .dll files could not be created right)

                //ConsoleWrite.Green("Server is running...");
                //ConsoleWrite.White("Hit the F1-key to stop the server.");
                //ConsoleWrite.White("Press F2 to add a plugin to the plugin-manager.");
                //while (true)
                //{
                //    var key = Console.ReadKey().Key;
                //    if (key == ConsoleKey.F1)
                //    {
                //        serverThread.Abort();

                //        ConsoleWrite.White("\nServer stopped.");
                //    }

                //    if (key == ConsoleKey.F2)
                //    {
                //        ConsoleWrite.White("DLL-Name:");
                //        string dllName = Console.ReadLine();

                //        string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                //        string path = Path.Combine(directory, @"static-files", dllName);

                //        try
                //        {
                //            var DLL = Assembly.LoadFile(path);

                //            foreach (Type type in DLL.GetExportedTypes())
                //            {
                //                if (type.GetInterface("IPlugin") != null)
                //                {
                //                    server.AddPlugin((IPlugin)Activator.CreateInstance(type));
                //                    ConsoleWrite.Green("Plugin added successfully!");
                //                }
                //            }
                //        }
                //        catch (Exception e)
                //        {
                //            ConsoleWrite.Red("Error adding plugin: " + e.Message);
                //        }
                //    }
                //}
            }
            catch (Exception e)
            {
                ConsoleWrite.Red("Server could not be started! ERROR: " + e.Message);
            }

            while (true) //Console should not close, even if there is no clients
            {
            }
        }