예제 #1
0
        public static JobServer get()
        {
            if (instance == null)
            {
                instance = new JobServer();
            }

            return(instance);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Wel...");

            ServiceHost   host   = null;
            NetTcpBinding tcp    = new NetTcpBinding();
            JobServer     server = JobServer.get();

            tcp.MaxBufferPoolSize      = int.MaxValue;
            tcp.MaxBufferSize          = int.MaxValue;
            tcp.MaxConnections         = 100;
            tcp.MaxReceivedMessageSize = int.MaxValue;

            //Find a free port
            uint port      = 6000;
            bool connected = false;

            while (port <= 7000 && !connected)
            {
                try
                {
                    host = new ServiceHost(server);
                    host.AddServiceEndpoint(typeof(JobServerInterface), tcp, String.Concat("net.tcp://127.0.0.1:", port.ToString(), "/ClientServer"));
                    host.Open();
                    connected = true;
                }
                catch (AddressAlreadyInUseException e)
                {
                    port++;
                }
            }

            //Add this client to Web Server list of clients
            RestClient  webServer = new RestClient("https://localhost:44370/");
            RestRequest req       = new RestRequest("api/clients/add");

            req.AddJsonBody(new ClientData("127.0.0.1", port));
            IRestResponse resp = webServer.Post(req);

            Console.WriteLine(String.Concat("...come! System online on port ", port.ToString()));


            //DEBUGGING: Console control over job posting
            bool exit = false;

            while (exit != true)
            {
                string input = Console.ReadLine();

                if (input.Equals("exit") || input.Equals("close"))
                {
                    exit = true;
                }
                else if (input.Equals("post job"))
                {
                    server.SubmitJob("test");
                }
            }

            //server.SubmitJob("test");
            //server.SubmitJob("test2");

            Console.ReadLine();
            host.Close();
        }