예제 #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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
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();
        }
예제 #4
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);
            }
        }
예제 #5
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;
                }
            }
        }
예제 #6
0
 public InstancerClient(string hostName) : base(DataphorServiceUtility.BuildInstanceURI(hostName, Constants.InstancerPortNumber, Constants.InstancerName))
 {
     _hostName = hostName;
 }