Exemplo n.º 1
0
 static void CurrentDomaind_ProcessExit(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(urlServerDir))
     {
         OnStopCalculadoraServer.RemoveServerDoServerDir(urlServerDir, url);
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += CurrentDomaind_ProcessExit;
            Console.WriteLine(@"******* SERVIDOR CALCULADORA *********");
            IPAddress[] localIps = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (var ipAddress in localIps)
            {
                if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
                {
                    url = ipAddress.ToString();
                }
            }

            var port = default(string);

            urlServerDir = default(string);
            var operacoes = default(string);

            Console.WriteLine(@"Informe porta do servidor:");
            port = Console.ReadLine();
            url  = PreparaUrl(url) + ":" + port;

            Console.WriteLine(@"Informe url Diretorio Servidores: ");
            urlServerDir = Console.ReadLine();
            urlServerDir = PreparaUrl(urlServerDir);

            Console.WriteLine(@"Informe as Operações possiveis separadas por | e sem acentos:");
            Console.WriteLine(@"Ex: Soma|Subtracao|Multiplicacao");
            operacoes = Console.ReadLine();


            var config = new HttpSelfHostConfiguration(url);

            config.Routes.MapHttpRoute("API", "api/{controller}/{action}/{id}",
                                       new { id = RouteParameter.Optional });

            using (var server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();
                OnStartCalculadoraServer.RegistraNoServerDir(urlServerDir, url, operacoes);
                Console.WriteLine(@"Online:");
                Console.WriteLine(url);
                Console.WriteLine(@"Press any key to stop");
                Console.ReadKey();
                server.CloseAsync();
            }
            Console.ReadKey();
            OnStopCalculadoraServer.RemoveServerDoServerDir(urlServerDir, url);
        }