示例#1
0
        static void Main()
        {
            Program._Administration = new Administration();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ip = "localhost:8000";

            if (!File.Exists("bind.txt"))
            {
                File.Create("bind.txt");
            }
            if (File.Exists("bind.txt"))
            {
                try
                {
                    string temp = File.ReadAllText("bind.txt");
                    if (!string.IsNullOrEmpty(temp) && !string.IsNullOrWhiteSpace(temp) && temp.Length > 2)
                    {
                        ip = temp;
                    }
                }
                catch(Exception)
                {

                }
            }

            ServerGUI gui = new ServerGUI();

            ControlWriter consoleWriter = new ControlWriter(gui.infoText);
            Console.SetOut(consoleWriter);

            // creeer een host proces voor de TrafficMessageService
            ServiceHost host = new ServiceHost(typeof(CTrafficMessage));

            // creeer een zgn. end-point voor de service
            Type contract = typeof(ITrafficMessage);
            BasicHttpBinding binding = new BasicHttpBinding();
            string baseAddress = "http://" + ip + "/MEX";
            Uri address = new Uri(baseAddress + "/MessageService");
            host.AddServiceEndpoint(contract, binding, address);

            // creeer een zgn. mex endpoint om de wsdl van de service te hosten
            host.Description.Behaviors.Add(new ServiceMetadataBehavior());
            EndpointAddress endPointAddress = new EndpointAddress(baseAddress + "/MEX");
            ServiceEndpoint mexEndpoint = new ServiceMetadataEndpoint(endPointAddress);
            host.AddServiceEndpoint(mexEndpoint);

            ServiceDebugBehavior debug = host.Description.Behaviors.Find<ServiceDebugBehavior>();

            // if not found - add behavior with setting turned on
            if (debug == null)
            {
                host.Description.Behaviors.Add(
                     new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
            }
            else
            {
                // make sure setting is turned ON
                if (!debug.IncludeExceptionDetailInFaults)
                {
                    debug.IncludeExceptionDetailInFaults = true;
                }
            }

            // start de service
            host.Open();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            _ITTF_SERVER_CONTROL_FORM = new ITTF_SERVER_CONTROL_FORM();
            _ITTF_SERVER_CONTROL_FORM.Show();

            _rawinput = new CRawInput(gui.Handle, CaptureOnlyInForeground);

            _rawinput.AddMessageFilter();   // Adding a message filter will cause keypresses to be handled

            _rawinput.KeyPressed += OnKeyPressed;

            new AdministrationForm().Show();
            Application.Run(gui);

            _CTrafficMessage.Bye();
        }
示例#2
0
文件: Program.cs 项目: herisant/t22-4
        static void Main()
        {
            Program._Administration = new Administration();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ip = "localhost:8000";

            if (!File.Exists("bind.txt"))
            {
                File.Create("bind.txt");
            }
            if (File.Exists("bind.txt"))
            {
                try
                {
                    string temp = File.ReadAllText("bind.txt");
                    if (!string.IsNullOrEmpty(temp) && !string.IsNullOrWhiteSpace(temp) && temp.Length > 2)
                    {
                        ip = temp;
                    }
                }
                catch (Exception)
                {
                }
            }

            ServerGUI gui = new ServerGUI();

            ControlWriter consoleWriter = new ControlWriter(gui.infoText);

            Console.SetOut(consoleWriter);

            // creeer een host proces voor de TrafficMessageService
            ServiceHost host = new ServiceHost(typeof(CTrafficMessage));

            // creeer een zgn. end-point voor de service
            Type             contract    = typeof(ITrafficMessage);
            BasicHttpBinding binding     = new BasicHttpBinding();
            string           baseAddress = "http://" + ip + "/MEX";
            Uri address = new Uri(baseAddress + "/MessageService");

            host.AddServiceEndpoint(contract, binding, address);

            // creeer een zgn. mex endpoint om de wsdl van de service te hosten
            host.Description.Behaviors.Add(new ServiceMetadataBehavior());
            EndpointAddress endPointAddress = new EndpointAddress(baseAddress + "/MEX");
            ServiceEndpoint mexEndpoint     = new ServiceMetadataEndpoint(endPointAddress);

            host.AddServiceEndpoint(mexEndpoint);

            ServiceDebugBehavior debug = host.Description.Behaviors.Find <ServiceDebugBehavior>();

            // if not found - add behavior with setting turned on
            if (debug == null)
            {
                host.Description.Behaviors.Add(
                    new ServiceDebugBehavior()
                {
                    IncludeExceptionDetailInFaults = true
                });
            }
            else
            {
                // make sure setting is turned ON
                if (!debug.IncludeExceptionDetailInFaults)
                {
                    debug.IncludeExceptionDetailInFaults = true;
                }
            }

            // start de service
            host.Open();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            _ITTF_SERVER_CONTROL_FORM = new ITTF_SERVER_CONTROL_FORM();
            _ITTF_SERVER_CONTROL_FORM.Show();

            _rawinput = new CRawInput(gui.Handle, CaptureOnlyInForeground);

            _rawinput.AddMessageFilter();   // Adding a message filter will cause keypresses to be handled

            _rawinput.KeyPressed += OnKeyPressed;

            new AdministrationForm().Show();
            Application.Run(gui);

            _CTrafficMessage.Bye();
        }