Exemplo n.º 1
0
        public void Stop()
        {
            if (_listenerServiceHost != null)
            {
                _listenerServiceHost.Dispose();
                _listenerServiceHost = null;
            }

            if (_nativeServiceHost != null)
            {
                if (_nativeServiceHost.State != CommunicationState.Faulted)
                {
                    _nativeServiceHost.BeginClose(null, null);
                }
                _nativeServiceHost = null;
            }

            if (_serviceHost != null)
            {
                if (_serviceHost.State != CommunicationState.Faulted)
                {
                    _serviceHost.BeginClose(null, null);
                }
                _serviceHost = null;
            }

            if (_service != null)
            {
                _service.Dispose();
                _service = null;
            }

            if (_remoteServer != null)
            {
                _remoteServer.Dispose();
                _remoteServer = null;
            }

            if (_server != null)
            {
                _server.Stop();
                _server = null;
            }
        }
Exemplo n.º 2
0
        public void Start()
        {
            if (!IsActive)
            {
                try
                {
                    InstanceManager.Load();

                    ServerConfiguration instance = InstanceManager.Instances[_instanceName];
                    if (instance == null)
                    {
                        // Establish a default configuration
                        instance = ServerConfiguration.DefaultInstance(_instanceName);
                        InstanceManager.Instances.Add(instance);
                        InstanceManager.Save();
                    }

                    _server = new Server();
                    instance.ApplyTo(_server);
                    _remoteServer = new RemoteServer(_server);
                    _nativeServer = new NativeServer(_server);
                    _server.Start();
                    try
                    {
                        _server.LogMessage("Creating WCF Service...");
                        _service = new DataphorService(_remoteServer);

                        _server.LogMessage("Creating Native CLI Service...");
                        _nativeService = new NativeCLIService(_nativeServer);

                        _server.LogMessage("Configuring Service Host...");
                        _serviceHost = instance.UseServiceConfiguration ? new CustomServiceHost(_service) : new ServiceHost(_service);

                        if (!instance.UseServiceConfiguration)
                        {
                            _serviceHost.AddServiceEndpoint
                            (
                                typeof(IDataphorService),
                                DataphorServiceUtility.GetBinding(),
                                DataphorServiceUtility.BuildInstanceURI(Environment.MachineName, instance.PortNumber, instance.Name)
                            );
                        }

                        _server.LogMessage("Opening Service Host...");
                        _serviceHost.Open();

                        _server.LogMessage("Configuring Native CLI Service Host...");
                        _nativeServiceHost = instance.UseServiceConfiguration ? new CustomServiceHost(_nativeService) : new ServiceHost(_nativeService);

                        if (!instance.UseServiceConfiguration)
                        {
                            _nativeServiceHost.AddServiceEndpoint
                            (
                                typeof(INativeCLIService),
                                DataphorServiceUtility.GetBinding(),
                                DataphorServiceUtility.BuildNativeInstanceURI(Environment.MachineName, instance.PortNumber, instance.Name)
                            );
                        }

                        _server.LogMessage("Opening Native CLI Service Host...");
                        _nativeServiceHost.Open();

                        // Start the listener
                        if (instance.ShouldListen)
                        {
                            _server.LogMessage("Starting Listener Service...");
                            _listenerServiceHost = new ListenerServiceHost(instance.OverrideListenerPortNumber, instance.RequireSecureListenerConnection, instance.AllowSilverlightClients, instance.UseServiceConfiguration);
                        }
                    }
                    catch (Exception exception)
                    {
                        _server.LogError(exception);
                        throw;
                    }
                }
                catch
                {
                    Stop();
                    throw;
                }
            }
        }