Beispiel #1
0
        public HostForm()
        {
            InitializeComponent();

            Current = this;

            host = new ServiceHost<CounterService>();
            host.Opening += new EventHandler(host_StateChanged);
            host.Opened += new EventHandler(host_StateChanged);
            host.Closing += new EventHandler(host_StateChanged);
            host.Closed += new EventHandler(host_StateChanged);
            host.Faulted += new EventHandler(host_StateChanged);
            host.BeginOpen(null, null);
        }
 public static void Start()
 {
     if (crs == null && customResolver == null)
     {
         crs = new CustomPeerResolverService();
         crs.ControlShape = false;
         customResolver = new ServiceHost(crs);
         crs.Open();
         customResolver.BeginOpen((AsyncCallback)((t) =>
         {
             App.Log.Info("Служба разрешения имен запущена успешно!");
             App.ViewModel.AddLogMessage("Служба разрешения имен запущена успешно!");
         }), null);//.Open();
     }
 }
Beispiel #3
0
        public HostForm(string baseAddress)
        {
            InitializeComponent();

            this.Text = baseAddress;

            Current = this;

            host = new ServiceHost<CounterService>(new Uri(baseAddress));
            host.Opening += new EventHandler(host_StateChanged);
            host.Opened += new EventHandler(host_StateChanged);
            host.Closing += new EventHandler(host_StateChanged);
            host.Closed += new EventHandler(host_StateChanged);
            host.Faulted += new EventHandler(host_StateChanged);
            host.BeginOpen(null, null);
        }
Beispiel #4
0
        private Program()
        {
            GraphInit();
            _connection = TcpConnection.Instance;

            Console.WriteLine("Airline Server");

            var soapHost = new ServiceHost(typeof(SOAPService));
            soapHost.BeginOpen(null, soapHost);

            var listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 7000);
            listener.Start();
            EndPoint remote = null;

            _discountWorker = new Thread(() => ApplyDiscounts());
            _discountWorker.Name = "Discount Worker";
            _discountWorker.Start();

            _removeWorker = new Thread(() => ApplyDiscounts());
            _removeWorker.Name = "Remove Worker";
            _removeWorker.Start();

            while (true)
            {
                try
                {
                    var current = listener.AcceptSocket();
                    remote = current.RemoteEndPoint;

                    Console.WriteLine("200 OK - Connection accepted from {0}",
                        remote);

                    var clientThread = new Thread(() => _connection.ManageClient(current));
                    clientThread.Start();
                }
                catch (SocketException se)
                {
                    if (remote == null)
                        Console.WriteLine("410 GONE - Connection not established");
                    else
                        Console.WriteLine("410 GONE - Connection with {0} was interrupted",
                            remote);
                    Debug.WriteLine(se.Message);
                }
            }
        }
Beispiel #5
0
        private void OpenServices()
        {
            // Create a singleton instance for the host
            ChatService chatService = new ChatService(this);
            chatServiceHost = new ServiceHost(chatService, this.localAddress);

            // Create a discovery behavior
            EndpointDiscoveryBehavior endpointDiscoveryBehavior = new EndpointDiscoveryBehavior();

            // Add an extension element with the username
            endpointDiscoveryBehavior.Extensions.Add(
                new XElement(
                    "root",
                    new XElement("Name", this.userName)));

            // Find the endpoint
            ServiceEndpoint simpleEndpoint =
                this.chatServiceHost.Description.Endpoints.Find(typeof(ISimpleChatService));

            // Add our behavior to the endpoint before opening it
            simpleEndpoint.Behaviors.Add(endpointDiscoveryBehavior);

            ShowStatus("Opening chat service...");
            chatServiceHost.BeginOpen(
                (result) =>
                {
                    chatServiceHost.EndOpen(result);
                    ShowStatus("Chat service ready");
                },
                null);
            OpenAnnouncementService();
        }
Beispiel #6
0
        /// <summary>
        /// 系统打开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_OpenSystem_Click(object sender, RoutedEventArgs e)
        {
            if (IsOpenSystem)
            {
                MessageBox.Show("系统已启动!");
                return;
            }
            try
            {
                //交通管制串口
                if (SPComControl == null)
                {
                    ControlCOMInit();
                }
                if (!SPComControl.IsOpen)
                {
                    SPComControl.portname = GlobalPara.Gcontrolcomname;
                    SPComControl.Open();
                    SPComControl.DiscardInBuffer();
                    SPComControl.Write(buf_trafficctl, 0, buf_trafficctl.Length);
                }

                //叫料系统串口
                if (GlobalPara.IsCallFun)
                {
                    if (SPComCall == null)
                    {
                        CallCOMInit();
                    }
                    if (!SPComCall.IsOpen)
                    {
                        SPComCall.portname = GlobalPara.Gcallcomname;
                        SPComCall.Open();
                        SPComCall.DiscardInBuffer();
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (SPComControl != null)
                {
                    SPComControl.Close();
                }
                if (SPComCall != null)
                {
                    SPComCall.Close();
                }
                MessageBox.Show(ex.Message);
                return;
            }

            Array.Clear(buf_virtualtrafficctl, 0, buf_virtualtrafficctl.Length);
            if (!pageShift.IsEnabled && cbautoshift.IsChecked.Value)
            {
                pageShift.Start();//开始计时,开始循环
            }
            if (!DataTimer.IsEnabled)
            {
                SPComControl.DiscardInBuffer();
                DataTimer.Start();//数据发送Timers
            }
            if (SPComControl.IsOpen)
            {
                imgCOM.Source = new BitmapImage(new Uri("pack://application:,,,/Image/Light_Open_24.png"));
                lblcomstate.Content = "打开";
                lblcomstate.Foreground = Brushes.Green;
            }
            else
            {
                return;
            }
            IsOpenSystem = true;
            imgSystem.Source = new BitmapImage(new Uri("pack://application:,,,/Image/Light_Open_24.png"));
            lblsystemstate.Content = "打开";
            lblsystemstate.Foreground = Brushes.Green;
            btnControl.IsEnabled = true;
            btn_OpenSystem.IsEnabled = false;
            btn_CloseSystem.IsEnabled = true;
            try
            {
                if (GlobalPara.IsClientFun)
                {
                    if (_host == null)
                    {
                        _host = new ServiceHost(typeof(WcfDuplexMessageService.MessageService));
                        IAsyncResult result = _host.BeginOpen(new AsyncCallback(HostOpenAsync), _host);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " and "+ex.InnerException);
            }
        }
Beispiel #7
0
        public static unsafe int OnLoad(IntPtr vmPtr, IntPtr optionsPtr, IntPtr reserved)
        {
            _loaded = true;

            JavaVM vm = JavaVM.GetOrCreateInstance(new JavaVMHandle(vmPtr));

            string optionsString = null;
            if (optionsPtr != IntPtr.Zero)
                optionsString = ModifiedUTF8Encoding.GetString((byte*)optionsPtr);

            string[] options = new string[0];
            if (optionsString != null)
            {
                options = optionsString.Split(',', ';');
            }

#if false
            // quick test
            GetEnvironmentVersion(vm);

            Action<JavaVM> action = GetEnvironmentVersion;
            IAsyncResult result = action.BeginInvoke(vm, null, null);
            result.AsyncWaitHandle.WaitOne();
#endif

            AppDomain.CurrentDomain.AssemblyResolve += HandleAssemblyResolve;

            if (options.Contains("ShowAgentExceptions", StringComparer.OrdinalIgnoreCase))
            {
                AppDomain.CurrentDomain.FirstChanceException += HandleFirstChanceException;
                AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
                //AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
            }

            if (options.Contains("DisableStatementStepping", StringComparer.OrdinalIgnoreCase))
            {
                JavaVM.DisableStatementStepping = true;
            }

            List<WaitHandle> waitHandles = new List<WaitHandle>();
            Binding binding;

            /*
             * start the wcf services and wait for the client to connect
             */

#if false
            /* IJvmEventsService
             */
            _jvmEventsPublisherHost = new ServiceHost(typeof(JvmEventsPublisher));
            Binding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _jvmEventsPublisherHost.AddServiceEndpoint(typeof(IJvmEventsService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmEventsService/");
            IAsyncResult jvmEventsPublisherStartResult = _jvmEventsPublisherHost.BeginOpen(null, null);
            waitHandles.Add(jvmEventsPublisherStartResult.AsyncWaitHandle);

            /* IJvmToolsInterfaceService
             */
            _jvmToolsInterfaceHost = new ServiceHost(typeof(JvmToolsInterfaceService));
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _jvmToolsInterfaceHost.AddServiceEndpoint(typeof(IJvmToolsInterfaceService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmToolsInterfaceService/");
            IAsyncResult toolsInterfaceStartResult = _jvmToolsInterfaceHost.BeginOpen(null, null);
            waitHandles.Add(toolsInterfaceStartResult.AsyncWaitHandle);

            /* IJvmDebugSessionService
             */
            _jvmDebugSessionHost = new ServiceHost(typeof(JvmDebugSessionService));
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _jvmDebugSessionHost.AddServiceEndpoint(typeof(IJvmDebugSessionService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmDebugSessionService/");
            IAsyncResult debugSessionStartResult = _jvmDebugSessionHost.BeginOpen(null, null);
            waitHandles.Add(debugSessionStartResult.AsyncWaitHandle);
#endif

            /* IDebugProtocolService
             */
            var debugProtocolService = new DebugProtocolService(vm);
            _debugProtocolHost = new ServiceHost(debugProtocolService);
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                MaxReceivedMessageSize = 10 * 1024 * 1024,
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _debugProtocolHost.AddServiceEndpoint(typeof(IDebugProtocolService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/DebugProtocolService/");
            IAsyncResult debugProtocolStartResult = _debugProtocolHost.BeginOpen(null, null);
            waitHandles.Add(debugProtocolStartResult.AsyncWaitHandle);

            /* Wait for the services to finish opening
             */
            WaitHandle.WaitAll(waitHandles.ToArray());

            EventWaitHandle eventWaitHandle = null;
            try
            {
                eventWaitHandle = EventWaitHandle.OpenExisting(string.Format("JavaDebuggerInitHandle{0}", Process.GetCurrentProcess().Id));
            }
            catch (WaitHandleCannotBeOpenedException)
            {
                // must have been launched without the debugger
            }

            if (eventWaitHandle != null)
            {
                eventWaitHandle.Set();
                Action waitAction = _debuggerAttachComplete.Wait;
                IAsyncResult waitResult = waitAction.BeginInvoke(vm.HandleAsyncOperationComplete, null);
                DispatcherFrame frame = new DispatcherFrame(true);
                JvmtiEnvironment environment = debugProtocolService.Environment;
                vm.PushDispatcherFrame(frame, environment, waitResult);
            }

            return 0;
        }