Exemple #1
0
        // GetNextPort
        // per node, a hash of used port numbers with a next port number
        // record starting port number
        // while the port number is used
        // get next port number from the configured range for the instance, with rollover
        // if the port number is equal to the starting port number
        // raise all ports used
        // else
        // return the port number

        // Request an instance url
        public string RequestInstance(string instanceName)
        {
            lock (_syncHandle)
            {
                var entry = _instances[instanceName];
                if (entry != null)
                {
                    // TODO: More sophisticated handling of server state?
                    // The assumption here is that if it is in the list of instances, it's a valid instance
                    entry.LastRequested = DateTime.Now;
                    return(entry.InstanceUri);
                }

                var hostName   = GetNextHost();
                var portNumber = GetNextPort(hostName);

                entry = new InstanceEntry {
                    InstanceName = instanceName, HostName = hostName, PortNumber = portNumber
                };
                entry.InstanceUri = DataphorServiceUtility.BuildInstanceURI(hostName, portNumber, instanceName);
                entry.ProcessId   = DeployInstance(entry);
                _instances.Add(instanceName, entry);

                return(entry.InstanceUri);
            }
        }
Exemple #2
0
        public ListenerServiceHost(int overridePortNumber, bool requireSecureConnection, bool useCrossDomainService, bool useServiceConfiguration)
        {
            int listenerPort = overridePortNumber == 0 ? DataphorServiceUtility.DefaultListenerPortNumber : overridePortNumber;

            _listenerHost = useServiceConfiguration ? new CustomServiceHost(typeof(ListenerService)) : new ServiceHost(typeof(ListenerService));

            if (!useServiceConfiguration)
            {
                _listenerHost.AddServiceEndpoint
                (
                    typeof(IListenerService),
                    DataphorServiceUtility.GetBinding(),
                    DataphorServiceUtility.BuildListenerURI(Environment.MachineName, listenerPort)
                );
            }

            try
            {
                _listenerHost.Open();
            }
            catch
            {
                // An error indicates the service could not be started because there is already a listener running in another process.
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
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));
     }
 }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the ChannelFactoryEntry class.
        /// </summary>
        /// <param name="descriptor">The endpoint descriptor for the cached channel entry.</param>
        public ChannelFactoryEntry(EndpointDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

            _descriptor = descriptor;

            _channelFactory = new ChannelFactory <TChannel>(descriptor.Binding, descriptor.EndpointAddress);

            DataphorServiceUtility.ServiceEndpointHook(_channelFactory.Endpoint);

            _channelFactory.Open();
        }
Exemple #6
0
        protected override void OnStart(string[] args)
        {
            var service = new InstancerService();

            service.BinDirectory      = ServiceSettings.Default.BinDirectory;
            service.InstanceDirectory = ServiceSettings.Default.InstanceDirectory;
            _host = new ServiceHost(service);
            _host.AddServiceEndpoint
            (
                typeof(IInstancerService),
                DataphorServiceUtility.GetBinding(),
                DataphorServiceUtility.BuildInstanceURI(Environment.MachineName, Constants.InstancerPortNumber, Constants.InstancerName)
            );

            _host.Open();
        }
Exemple #7
0
        public void Open()
        {
            if (!IsActive)
            {
                if (!String.IsNullOrEmpty(_clientConfigurationName))
                {
                    _channelFactory = new ChannelFactory <IClientDataphorService>(_clientConfigurationName);
                }
                else
                {
                    if (_overridePortNumber == 0)
                    {
                        Uri uri = new Uri(ListenerFactory.GetInstanceURI(_hostName, _overrideListenerPortNumber, _instanceName));
                        _channelFactory =
                            new ChannelFactory <IClientDataphorService>
                            (
                                DataphorServiceUtility.GetBinding(),
                                new EndpointAddress(uri, DataphorServiceUtility.BuildEndpointIdentityCall())
                            );
                    }
                    else
                    {
                        _channelFactory =
                            new ChannelFactory <IClientDataphorService>
                            (
                                DataphorServiceUtility.GetBinding(),
                                new EndpointAddress
                                (
                                    new Uri(DataphorServiceUtility.BuildInstanceURI(_hostName, _overridePortNumber, _instanceName)),
                                    DataphorServiceUtility.BuildEndpointIdentityCall()
                                )
                            );
                    }
                }

                DataphorServiceUtility.ServiceEndpointHook(_channelFactory.Endpoint);
            }
        }
        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;
                }
            }
        }
 public InstancerClient(string hostName) : base(DataphorServiceUtility.BuildInstanceURI(hostName, Constants.InstancerPortNumber, Constants.InstancerName))
 {
     _hostName = hostName;
 }
Exemple #10
0
 public ListenerClient(string hostName, int overridePortNumber) : base(new Uri(DataphorServiceUtility.BuildListenerURI(hostName, overridePortNumber)))
 {
     _hostName = hostName;
 }