Esempio n. 1
0
        private string GetInstanceURI(string hostName, string instanceName, bool useNative)
        {
            try
            {
                if (String.IsNullOrEmpty(instanceName))
                {
                    throw new FaultException <ListenerFault>(new ListenerFault(), "Instance name is empty.  An instance name is required");
                }

                ServerConfiguration server = GetConfiguration().Instances[instanceName];

                if (server == null)
                {
                    throw new FaultException <ListenerFault>(new ListenerFault(), String.Format("Instance Name {0} not found", instanceName));
                }

                if (useNative)
                {
                    return(DataphorServiceUtility.BuildNativeInstanceURI(hostName, server.PortNumber, server.Name));
                }

                return(DataphorServiceUtility.BuildInstanceURI(hostName, server.PortNumber, server.Name));
            }
            catch (Exception exception)
            {
                throw new FaultException <ListenerFault>(ListenerFaultUtility.ExceptionToFault(exception), exception.Message);
            }
        }
Esempio n. 2
0
 public static string GetNativeServerURI(string hostName, string instanceName, int overridePortNumber, int overrideListenerPortNumber)
 {
     if (overridePortNumber > 0)
     {
         return(DataphorServiceUtility.BuildNativeInstanceURI(hostName, overridePortNumber, instanceName));
     }
     else
     {
         return(ListenerFactory.GetInstanceURI(hostName, overrideListenerPortNumber, instanceName, true));
     }
 }
        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;
                }
            }
        }