public FileSystemRootService(IServiceConnector connector, IServiceAddress address, string path)
            : base(connector, address)
        {
            this.path = path;

            pathInitializationQueue = new List<string>(64);
        }
        /// <inheritdoc cref="IMessageToServiceMapper.AddService(Guid, string, INetworkConnector)"/>
        public void AddService(Guid id, string name, INetworkConnector networkConnector)
        {
            if (!ServiceTypeCache.ContainsKey(name))
            {
                _logger.LogError("Service is not added because it has no message types associated with it. ");
                return;
            }

            Type type = ServiceTypeCache[name][0];

            if (_messageToServiceMap.ContainsKey(type))
            {
                IServiceConnector serviceConnector = _messageToServiceMap[type];
                _serviceMap.TryAdd(id, serviceConnector);
                serviceConnector.AddService(networkConnector, id);
            }
            else
            {
                IServiceConnector serviceConnector = new ServiceConnector(networkConnector, name, id);
                _serviceMap.TryAdd(id, serviceConnector);
                foreach (Type messageType in ServiceTypeCache[name])
                {
                    _messageToServiceMap.TryAdd(messageType, serviceConnector);
                }
                _ = Task.Run(() => serviceConnector.StartPublishingAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ArtifactDeployState{TArtifact,TEntity}"/> class.
 /// </summary>
 /// <param name="art">The artifact.</param>
 /// <param name="entity">The entity.</param>
 /// <param name="connector">The service connector deploying the artifact.</param>
 /// <param name="nextPass">The next pass number.</param>
 public ArtifactDeployState(TArtifact art, TEntity entity, IServiceConnector connector, int nextPass)
 {
     Artifact  = art;
     Entity    = entity;
     Connector = connector;
     NextPass  = nextPass;
 }
Beispiel #4
0
 public FileSystemBlockService(IServiceConnector connector, string path)
     : base(connector)
 {
     this.path = path;
     compressionThread = new Thread(Compress);
     compressionThread.IsBackground = true;
 }
Beispiel #5
0
        public void SetUp()
        {
            SetupEvent.WaitOne();

            adminService = CreateAdminService(storeType);

            IServiceConnector connector = CreateConnector();

            NetworkConfigSource config = new NetworkConfigSource();

            Config(config);
            adminService.Config    = config;
            adminService.Connector = connector;
            adminService.Start();
            networkProfile = new NetworkProfile(connector);

            NetworkConfigSource netConfig = new NetworkConfigSource();

            netConfig.AddNetworkNode(LocalAddress);
            networkProfile.Configuration = netConfig;

            OnSetUp();

            SetupEvent.Set();
        }
 public FileSystemManagerService(IServiceConnector connector, string basePath, 
     string dbPath, IServiceAddress address)
     : base(connector, address)
 {
     this.basePath = basePath;
     this.dbPath = dbPath;
 }
        internal MessageCommunicator(IServiceConnector network, ServiceStatusTracker tracker)
        {
            this.network = network;
            this.tracker = tracker;

            queueMap = new Dictionary<IServiceAddress, RetryMessageQueue>();
        }
Beispiel #8
0
        internal MessageCommunicator(IServiceConnector network, ServiceStatusTracker tracker)
        {
            this.network = network;
            this.tracker = tracker;

            queueMap = new Dictionary <IServiceAddress, RetryMessageQueue>();
        }
        public FileSystemRootService(IServiceConnector connector, IServiceAddress address, string path)
            : base(connector, address)
        {
            this.path = path;

            pathInitializationQueue = new List <string>(64);
        }
Beispiel #10
0
 public static ServiceStatusTracker GetServiceTracker(IServiceAddress[] managers, IServiceConnector connector)
 {
     lock (TrackerCacheMap) {
         ServiceStatusTracker picked = null;
         int pickedCount = 0;
         for (int i = 0; i < managers.Length; ++i) {
             ServiceStatusTracker g;
             if (TrackerCacheMap.TryGetValue(managers[i], out g)) {
                 picked = g;
                 ++pickedCount;
             }
         }
         if (picked == null) {
             picked = new ServiceStatusTracker(connector);
             for (int i = 0; i < managers.Length; ++i) {
                 TrackerCacheMap[managers[i]] = picked;
             }
         } else if (pickedCount != managers.Length) {
             for (int i = 0; i < managers.Length; ++i) {
                 TrackerCacheMap[managers[i]] = picked;
             }
         }
         return picked;
     }
 }
Beispiel #11
0
 public NetworkClient(IServiceAddress[] managerAddresses, IServiceConnector connector, INetworkCache lnc)
 {
     this.connector         = connector;
     this.managerAddresses  = managerAddresses;
     this.localNetworkCache = lnc;
     // Default values,
     MaxTransactionNodeCacheHeapSize = 14 * 1024 * 1024;
 }
Beispiel #12
0
 public NetworkClient(IServiceAddress[] managerAddresses, IServiceConnector connector, INetworkCache lnc)
 {
     this.connector = connector;
     this.managerAddresses = managerAddresses;
     this.localNetworkCache = lnc;
     // Default values,
     MaxTransactionNodeCacheHeapSize = 14*1024*1024;
 }
        /// <summary>
        /// Adds the service connector.
        /// </summary>
        /// <param name="serviceID">The service identifier.</param>
        /// <param name="connector">The connector.</param>
        public void AddServiceConnector(Guid serviceID, IServiceConnector connector)
        {
            if (lstConnectors.ContainsKey(serviceID))
            {
                throw new InvalidOperationException("This service ID is already in use.");
            }

            lstConnectors.Add(serviceID, connector);
        }
Beispiel #14
0
        public static IServiceConnector GetConnector()
        {
            if (_serviceConnector == null)
            {
                _serviceConnector = new QuoridorService();
            }

            return(_serviceConnector);
        }
Beispiel #15
0
        public NetworkClient(IServiceAddress managerAddress, IServiceConnector connector, INetworkCache cache)
        {
            if (!(connector.MessageSerializer is IRpcMessageSerializer) ||
                !((IRpcMessageSerializer)connector.MessageSerializer).SupportsMessageStream)
                throw new ArgumentException("The connector given has an invalid message serializer for this context (must be a IRPC serializer).");

            this.connector = connector;
            this.managerAddress = managerAddress;
            this.cache = cache;
        }
Beispiel #16
0
        public AdminService(IServiceAddress address, IServiceConnector connector, IServiceFactory serviceFactory)
        {
            if (serviceFactory == null)
                throw new ArgumentNullException("serviceFactory");

            this.serviceFactory = serviceFactory;
            this.address = address;
            this.connector = connector;
            analytics = new Analytics();
        }
        public NetworkTreeSystem(IServiceConnector connector, IServiceAddress[] managerAddresses,
		                         INetworkCache networkCache, ServiceStatusTracker serviceTracker)
        {
            this.connector = connector;
            this.managerAddresses = managerAddresses;
            this.networkCache = networkCache;
            this.serviceTracker = serviceTracker;

            failureFloodControl = new Dictionary<IServiceAddress, DateTime>();
            failureFloodControlBidc = new Dictionary<IServiceAddress, DateTime>();
        }
Beispiel #18
0
        protected BlockService(IServiceConnector connector)
        {
            this.connector = connector;

            blockContainerMap        = new Dictionary <BlockId, BlockContainer>();
            blockContainerAccessList = new LinkedList <BlockContainer>();

            maxKnownBlockId = new Dictionary <int, BlockId>();

            blocksPendingSync = new LinkedList <BlockContainer>();
        }
Beispiel #19
0
        public IService CreateService(IServiceAddress serviceAddress, ServiceType serviceType, IServiceConnector connector)
        {
            if (serviceType == ServiceType.Manager)
                return new MemoryManagerService(connector, serviceAddress);
            if (serviceType == ServiceType.Root)
                return new MemoryRootService(connector);
            if (serviceType == ServiceType.Block)
                return new MemoryBlockService(connector);

            throw new ArgumentException("An invalid service type was specified.");
        }
Beispiel #20
0
        public AdminService(IServiceAddress address, IServiceConnector connector, IServiceFactory serviceFactory)
        {
            if (serviceFactory == null)
            {
                throw new ArgumentNullException("serviceFactory");
            }

            this.serviceFactory = serviceFactory;
            this.address        = address;
            this.connector      = connector;
            analytics           = new Analytics();
        }
Beispiel #21
0
        protected RootService(IServiceConnector connector, IServiceAddress address)
        {
            this.connector = connector;
            this.address = address;

            lockDb = new Dictionary<string, PathAccess>(128);
            pathInfoMap = new Dictionary<string, PathInfo>(128);
            loadPathInfoQueue = new List<PathInfo>(64);

            serviceTracker = new ServiceStatusTracker(connector);
            serviceTracker.StatusChange += ServiceTracker_OnStatusChange;
        }
Beispiel #22
0
            public HeartbeatThread(ServiceStatusTracker tracker, IServiceConnector connector,
                                   List <TrackedService> monitoredServers)
            {
                this.tracker          = tracker;
                this.connector        = connector;
                this.monitoredServers = monitoredServers;

                thread = new Thread(Execute);
                thread.IsBackground = true;
                thread.Name         = "StatusTracker::Heatbeat";
                thread.Start();
            }
Beispiel #23
0
        internal NetworkTreeSystem(IServiceConnector connector, IServiceAddress managerAddress, INetworkCache networkCache)
        {
            if (!(connector.MessageSerializer is IRpcMessageSerializer) ||
                !((IRpcMessageSerializer)connector.MessageSerializer).SupportsMessageStream)
                throw new ArgumentException("The message serializer specified by the connector is not valid (must be IRPC).");

            this.connector = connector;
            this.managerAddress = managerAddress;
            this.networkCache = networkCache;
            failures = new Dictionary<IServiceAddress, DateTime>();
            pathToRoot = new Dictionary<string, IServiceAddress>();

            logger = Logger.Network;
        }
Beispiel #24
0
        public void ServiceConnectorSendMessageTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.TrySetUsername("testUser", out var testUser);

            // act
            var result = serviceConnector.SendMessage(_adminUserId, "Hallo test");

            // assert
            Assert.IsNotNull(result);
        }
Beispiel #25
0
        public void ServiceConnectorDeviceGetValueTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            // it must a non exist device
            const long id = 12345678L;
            // act
            var result = serviceConnector.DeviceGetValue(id);

            // assert
            Assert.AreEqual(0, result);
        }
Beispiel #26
0
        public void ServiceConnectorGetAllUsersTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");

            // act
            var result = serviceConnector.GetAllUsers();

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }
Beispiel #27
0
        protected PathClientService(IServiceAddress address, IServiceAddress managerAddress, IServiceConnector connector)
        {
            this.address = address;
            this.managerAddress = managerAddress;
            this.connector = connector;

            NetworkConfigSource netConfig = new NetworkConfigSource();
            netConfig.AddNetworkNode(managerAddress);

            network = new NetworkProfile(connector);
            network.Configuration = netConfig;

            log = Logger.Network;
        }
Beispiel #28
0
        protected ManagerService(IServiceConnector connector, IServiceAddress address)
        {
            this.connector = connector;
            this.address = address;

            blockServersMap = new Dictionary<long, BlockServiceInfo>();
            blockServersList = new List<BlockServiceInfo>();
            rootServersList = new List<RootServiceInfo>();
            managerServersList = new List<ManagerServiceInfo>();

            rng = new Random();

            serviceTracker = new ServiceStatusTracker(connector);

            blockUpdateTask = new BlockUpdateTask(this);
        }
Beispiel #29
0
        public void ServiceConnectorGetMessagesTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.TrySetUsername("testUser", out var testUser);

            // act
            var result = serviceConnector.GetMessages(_adminUserId);

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
            Assert.AreEqual("Hallo ich bin der Admin Benutzer", result.First().Text);
        }
Beispiel #30
0
        public void ServiceConnectorSetUserAndGetAllUsersTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.TrySetUsername("testUser", out var testUser);

            // act
            var result = serviceConnector.GetAllUsers();

            // assert
            Assert.IsNotNull(result);
            // only admin, well it show only other not self user
            Assert.AreEqual(1, result.Length);
        }
Beispiel #31
0
        protected ManagerService(IServiceConnector connector, IServiceAddress address)
        {
            this.connector = connector;
            this.address = address;

            blockServersMap = new Dictionary<long, BlockServerInfo>(256);
            blockServers = new List<BlockServerInfo>(256);
            rootServers = new List<RootServerInfo>(256);
            random = new Random();

            failureFloodControl = new Dictionary<IServiceAddress, DateTime>();

            heartbeatThread = new Thread(Heartbeat);
            heartbeatThread.IsBackground = true;
            heartbeatThread.Start();
        }
        public GamePage(string launchArguments)
        {
            this.InitializeComponent();
            _messages = new ObservableCollection <PlayerMessage>();
            //_messages.Add(new PlayerMessage() { Message = "Testowa wiadomosc"});
            _players = new ObservableCollection <Player>();
            //_players.Add(new Player() {Id = 1, Name = "Uzytkownik"});
            PlayersListView.ItemsSource  = _players;
            MessagesListView.ItemsSource = _messages;

            // Create the game.

            _game = XamlGame <Game1> .Create(launchArguments, Window.Current.CoreWindow, this);

            _game.GamePage    = this;
            _serviceConnector = SharedModel.GetConnector();
        }
Beispiel #33
0
        public void ServiceConnectorTrySetUsernameTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            const string username = "******";

            // act
            var success = serviceConnector.TrySetUsername(username, out var result);

            // assert
            Assert.IsTrue(success);
            Assert.IsNotNull(result);
            Assert.AreEqual(username, result.Username);
            Assert.AreNotEqual(0, result.ID);
        }
Beispiel #34
0
        public void ServiceConnectorSendMessageAndGetMessageTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.TrySetUsername("testUser", out _);

            // act
            serviceConnector.SendMessage(_adminUserId, "Hallo test");
            var result = serviceConnector.GetMessages(_adminUserId);

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
            Assert.AreEqual("Hallo test", result.Last().Text);
        }
Beispiel #35
0
        public void ServiceConnectorDeviceSendComandValueTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.DeviceGetValue(1L);
            const long value = 234L;

            // act
            var result      = serviceConnector.DeviceSendCommand(1L, 234);
            var resultValue = serviceConnector.DeviceGetValue(1L);

            // assert
            Assert.IsTrue(result);
            Assert.AreEqual(value, resultValue);
        }
Beispiel #36
0
        public void ServiceConnectorDeviceSendComandTextTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.DeviceGetText(1L);
            string sendText = "Hello";

            // act
            var result     = serviceConnector.DeviceSendCommand(1L, sendText);
            var resultText = serviceConnector.DeviceGetText(1L);

            // assert
            Assert.IsTrue(result);
            Assert.AreEqual(sendText, resultText);
        }
        internal ReplicatedValueStore(IServiceAddress address,
		                              IServiceConnector connector,
		                              IDatabase localDb, Object dbWriteLock,
		                              ServiceStatusTracker tracker)
        {
            this.address = address;
            this.connector = connector;
            blockDatabase = localDb;
            blockDbWriteLock = dbWriteLock;
            this.tracker = tracker;
            comm = new MessageCommunicator(connector, tracker);

            cluster = new List<IServiceAddress>(9);
            ClearAllMachines();

            // Add listener for service status updates,
            tracker.StatusChange += TrackerOnStatusChange;
        }
Beispiel #38
0
        public void Disconnect()
        {
            if (connector != null)
            {
                try {
                    connector.Close();
                } finally {
                    try {
                        serviceTracker.Stop();
                    } finally {
                        connector      = null;
                        serviceTracker = null;
                        treeSystem     = null;
                    }

                    connected = false;
                }
            }
        }
        private Service DoCreateService(IServiceAddress serviceAddress, ServiceType serviceType, IServiceConnector connector)
        {
            Service service = null;
            if (serviceType == ServiceType.Manager) {
                if (manager == null) {
                    string npath = Path.Combine(basePath, "manager");
                    if (!Directory.Exists(npath))
                        Directory.CreateDirectory(npath);

                    manager = new FileSystemManagerService(connector, basePath, npath, serviceAddress);
                }

                service = manager;
            } else if (serviceType == ServiceType.Root) {
                if (root == null) {
                    string npath = Path.Combine(basePath, "root");
                    if (!Directory.Exists(npath))
                        Directory.CreateDirectory(npath);

                    root = new FileSystemRootService(connector, serviceAddress, npath);
                }

                service = root;
            } else if (serviceType == ServiceType.Block) {
                if (block == null) {
                    string npath = Path.Combine(basePath, "block");
                    if (!Directory.Exists(npath))
                        Directory.CreateDirectory(npath);

                    block = new FileSystemBlockService(connector, npath);
                }

                service = block;
            }

            if (service != null) {
                service.Started += ServiceStarted;
                service.Stopped += ServiceStopped;
            }

            return service;
        }
Beispiel #40
0
        public void ServiceConnectorDeviceSendComandGetResponseTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.DeviceGet(1L);
            const long id       = 1L;
            const long value    = 456L;
            string     sendText = "Hello";

            // act
            var result         = serviceConnector.DeviceSendCommand(id, value, sendText);
            var resultResponse = serviceConnector.DeviceGet(id);

            // assert
            Assert.IsTrue(result);
            Assert.AreEqual(sendText, resultResponse.Text);
            Assert.AreEqual(value, resultResponse.Value);
        }
 public MemoryBlockService(IServiceConnector connector)
     : base(connector)
 {
     blockData = new Dictionary<BlockId, Stream>();
 }
Beispiel #42
0
 protected RootService(IServiceConnector connector)
 {
     this.connector = connector;
     pathCache = new Dictionary<string, PathAccess>(128);
 }
Beispiel #43
0
 public PathConnection(RootService service, string pathName, 
     IServiceConnector connector, IServiceAddress manager,
     INetworkCache networkCache)
 {
     this.service = service;
     this.pathName = pathName;
     treeSystem = new NetworkTreeSystem(connector, manager, networkCache);
 }
Beispiel #44
0
 public RestPathClientService(HttpServiceAddress address, IServiceAddress managerAddress, IServiceConnector connector)
     : base(address, managerAddress, connector)
 {
 }
 public MemoryRootService(IServiceConnector connector, IServiceAddress address)
     : base(connector, address)
 {
     pathStreams = new Dictionary<string, Stream>();
 }
Beispiel #46
0
 public FileSystemBlockService(IServiceConnector connector, string path)
     : base(connector)
 {
     this.path = path;
 }
        public static int Main(string[] args)
        {
            m_Server = new HttpServerBase("R.O.B.U.S.T.", args);

            IConfig serverConfig = m_Server.Config.Configs["Startup"];

            if (serverConfig == null)
            {
                System.Console.WriteLine("Startup config section missing in .ini file");
                throw new Exception("Configuration error");
            }

            string connList = serverConfig.GetString("ServiceConnectors", String.Empty);

            string[] conns = connList.Split(new char[] { ',', ' ' });

//            int i = 0;
            foreach (string c in conns)
            {
                if (c == String.Empty)
                {
                    continue;
                }

                string configName = String.Empty;
                string conn       = c;
                uint   port       = 0;

                string[] split1 = conn.Split(new char[] { '/' });
                if (split1.Length > 1)
                {
                    conn = split1[1];

                    string[] split2 = split1[0].Split(new char[] { '@' });
                    if (split2.Length > 1)
                    {
                        configName = split2[0];
                        port       = Convert.ToUInt32(split2[1]);
                    }
                    else
                    {
                        port = Convert.ToUInt32(split1[0]);
                    }
                }
                string[] parts        = conn.Split(new char[] { ':' });
                string   friendlyName = parts[0];
                if (parts.Length > 1)
                {
                    friendlyName = parts[1];
                }

                IHttpServer server = m_Server.HttpServer;
                if (port != 0)
                {
                    server = m_Server.GetHttpServer(port);
                }

                if (port != m_Server.DefaultPort && port != 0)
                {
                    m_log.InfoFormat("[SERVER]: Loading {0} on port {1}", friendlyName, port);
                }
                else
                {
                    m_log.InfoFormat("[SERVER]: Loading {0}", friendlyName);
                }

                IServiceConnector connector = null;

                Object[] modargs = new Object[] { m_Server.Config, server,
                                                  configName };
                connector = ServerUtils.LoadPlugin <IServiceConnector>(conn,
                                                                       modargs);
                if (connector == null)
                {
                    modargs   = new Object[] { m_Server.Config, server };
                    connector =
                        ServerUtils.LoadPlugin <IServiceConnector>(conn,
                                                                   modargs);
                }

                if (connector != null)
                {
                    m_ServiceConnectors.Add(connector);
                    m_log.InfoFormat("[SERVER]: {0} loaded successfully", friendlyName);
                }
                else
                {
                    m_log.InfoFormat("[SERVER]: Failed to load {0}", conn);
                }
            }
            int res = m_Server.Run();

            Environment.Exit(res);

            return(0);
        }
Beispiel #48
0
 public MemoryBlockService(IServiceConnector connector)
     : base(connector)
 {
     blockData = new Dictionary <BlockId, Stream>();
 }
            public HeartbeatThread(ServiceStatusTracker tracker, IServiceConnector connector,
			                       List<TrackedService> monitoredServers)
            {
                this.tracker = tracker;
                this.connector = connector;
                this.monitoredServers = monitoredServers;

                thread = new Thread(Execute);
                thread.IsBackground = true;
                thread.Name = "StatusTracker::Heatbeat";
                thread.Start();
            }
Beispiel #50
0
            public PathConnection(RootService service, PathInfo pathInfo, IServiceConnector connector, IServiceAddress[] managerServers,
			                      INetworkCache cache, ServiceStatusTracker statusTracker)
            {
                this.service = service;
                this.pathInfo = pathInfo;
                treeSystem = new NetworkTreeSystem(connector, managerServers, cache, statusTracker);
            }
Beispiel #51
0
 public IService CreateService(IServiceAddress serviceAddress, ServiceType serviceType, IServiceConnector connector)
 {
     return factory.CreateService(serviceAddress, serviceType, connector);
 }
Beispiel #52
0
 public NetworkClient(IServiceAddress managerAddress, IServiceConnector connector)
     : this(new IServiceAddress[] { managerAddress}, connector)
 {
 }
Beispiel #53
0
 public NetworkClient(IServiceAddress[] managerAddresses, IServiceConnector connector)
     : this(managerAddresses, connector, MachineState.GetCacheForManager(managerAddresses))
 {
 }
Beispiel #54
0
        public void Disconnect()
        {
            if (connector != null) {
                try {
                    connector.Close();
                } finally {
                    try {
                        serviceTracker.Stop();
                    } finally {
                        connector = null;
                        serviceTracker = null;
                        treeSystem = null;
                    }

                    connected = false;
                }
            }
        }
Beispiel #55
0
        public static int Main(string[] args)
        {
            Culture.SetCurrentCulture();
            Culture.SetDefaultCurrentCulture();

            ServicePointManager.DefaultConnectionLimit = 64;
            ServicePointManager.Expect100Continue      = false;
            ServicePointManager.UseNagleAlgorithm      = false;
            ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;

            m_Server = new HttpServerBase("R.O.B.U.S.T.", args);

            string registryLocation;

            IConfig serverConfig = m_Server.Config.Configs["Startup"];

            if (serverConfig == null)
            {
                System.Console.WriteLine("Startup config section missing in .ini file");
                throw new Exception("Configuration error");
            }

            int dnsTimeout = serverConfig.GetInt("DnsTimeout", 30000);

            try { ServicePointManager.DnsRefreshTimeout = dnsTimeout; } catch { }

            m_NoVerifyCertChain    = serverConfig.GetBoolean("NoVerifyCertChain", m_NoVerifyCertChain);
            m_NoVerifyCertHostname = serverConfig.GetBoolean("NoVerifyCertHostname", m_NoVerifyCertHostname);


            string connList = serverConfig.GetString("ServiceConnectors", String.Empty);

            registryLocation = serverConfig.GetString("RegistryLocation", ".");

            IConfig servicesConfig = m_Server.Config.Configs["ServiceList"];

            if (servicesConfig != null)
            {
                List <string> servicesList = new List <string>();
                if (connList != String.Empty)
                {
                    servicesList.Add(connList);
                }

                foreach (string k in servicesConfig.GetKeys())
                {
                    string v = servicesConfig.GetString(k);
                    if (v != String.Empty)
                    {
                        servicesList.Add(v);
                    }
                }

                connList = String.Join(",", servicesList.ToArray());
            }

            string[] conns = connList.Split(new char[] { ',', ' ', '\n', '\r', '\t' });

//            int i = 0;
            foreach (string c in conns)
            {
                if (c == String.Empty)
                {
                    continue;
                }

                string configName = String.Empty;
                string conn       = c;
                uint   port       = 0;

                string[] split1 = conn.Split(new char[] { '/' });
                if (split1.Length > 1)
                {
                    conn = split1[1];

                    string[] split2 = split1[0].Split(new char[] { '@' });
                    if (split2.Length > 1)
                    {
                        configName = split2[0];
                        port       = Convert.ToUInt32(split2[1]);
                    }
                    else
                    {
                        port = Convert.ToUInt32(split1[0]);
                    }
                }
                string[] parts        = conn.Split(new char[] { ':' });
                string   friendlyName = parts[0];
                if (parts.Length > 1)
                {
                    friendlyName = parts[1];
                }

                IHttpServer server;

                if (port != 0)
                {
                    server = MainServer.GetHttpServer(port);
                }
                else
                {
                    server = MainServer.Instance;
                }

                m_log.InfoFormat("[SERVER]: Loading {0} on port {1}", friendlyName, server.Port);

                IServiceConnector connector = null;

                Object[] modargs = new Object[] { m_Server.Config, server, configName };
                connector = ServerUtils.LoadPlugin <IServiceConnector>(conn, modargs);

                if (connector == null)
                {
                    modargs   = new Object[] { m_Server.Config, server };
                    connector = ServerUtils.LoadPlugin <IServiceConnector>(conn, modargs);
                }

                if (connector != null)
                {
                    m_ServiceConnectors.Add(connector);
                    m_log.InfoFormat("[SERVER]: {0} loaded successfully", friendlyName);
                }
                else
                {
                    m_log.ErrorFormat("[SERVER]: Failed to load {0}", conn);
                }
            }

            loader = new PluginLoader(m_Server.Config, registryLocation);

            int res = m_Server.Run();

            if (m_Server != null)
            {
                m_Server.Shutdown();
            }

            Util.StopThreadPool();

            Environment.Exit(res);

            return(0);
        }
 public ServiceStatusTracker(IServiceConnector connector)
 {
     monitoredServers = new List<TrackedService>(128);
     heartbeatThread = new HeartbeatThread(this, connector, monitoredServers);
 }
 public IService CreateService(IServiceAddress serviceAddress, ServiceType serviceType, IServiceConnector connector)
 {
     return(DoCreateService(serviceAddress, serviceType, connector));
 }
Beispiel #58
0
        public static int Main(string[] args)
        {
            // Make sure we don't get outbound connections queueing
            ServicePointManager.DefaultConnectionLimit = 50;
            ServicePointManager.UseNagleAlgorithm      = false;

            m_Server = new HttpServerBase("R.O.B.U.S.T.", args);

            string registryLocation;

            IConfig serverConfig = m_Server.Config.Configs["Startup"];

            if (serverConfig == null)
            {
                System.Console.WriteLine("Startup config section missing in .ini file");
                throw new Exception("Configuration error");
            }

            string connList = serverConfig.GetString("ServiceConnectors", String.Empty);

            registryLocation = serverConfig.GetString("RegistryLocation", ".");

            IConfig servicesConfig = m_Server.Config.Configs["ServiceList"];

            if (servicesConfig != null)
            {
                List <string> servicesList = new List <string>();
                if (connList != String.Empty)
                {
                    servicesList.Add(connList);
                }

                foreach (string k in servicesConfig.GetKeys())
                {
                    string v = servicesConfig.GetString(k);
                    if (v != String.Empty)
                    {
                        servicesList.Add(v);
                    }
                }

                connList = String.Join(",", servicesList.ToArray());
            }

            string[] conns = connList.Split(new char[] { ',', ' ', '\n', '\r', '\t' });

//            int i = 0;
            foreach (string c in conns)
            {
                if (c == String.Empty)
                {
                    continue;
                }

                string configName = String.Empty;
                string conn       = c;
                uint   port       = 0;

                string[] split1 = conn.Split(new char[] { '/' });
                if (split1.Length > 1)
                {
                    conn = split1[1];

                    string[] split2 = split1[0].Split(new char[] { '@' });
                    if (split2.Length > 1)
                    {
                        configName = split2[0];
                        port       = Convert.ToUInt32(split2[1]);
                    }
                    else
                    {
                        port = Convert.ToUInt32(split1[0]);
                    }
                }
                string[] parts        = conn.Split(new char[] { ':' });
                string   friendlyName = parts[0];
                if (parts.Length > 1)
                {
                    friendlyName = parts[1];
                }

                IHttpServer server;

                if (port != 0)
                {
                    server = MainServer.GetHttpServer(port);
                }
                else
                {
                    server = MainServer.Instance;
                }

                m_log.InfoFormat("[SERVER]: Loading {0} on port {1}", friendlyName, server.Port);

                IServiceConnector connector = null;

                Object[] modargs = new Object[] { m_Server.Config, server, configName };
                connector = ServerUtils.LoadPlugin <IServiceConnector>(conn, modargs);

                if (connector == null)
                {
                    modargs   = new Object[] { m_Server.Config, server };
                    connector = ServerUtils.LoadPlugin <IServiceConnector>(conn, modargs);
                }

                if (connector != null)
                {
                    m_ServiceConnectors.Add(connector);
                    m_log.InfoFormat("[SERVER]: {0} loaded successfully", friendlyName);
                }
                else
                {
                    m_log.ErrorFormat("[SERVER]: Failed to load {0}", conn);
                }
            }

            loader = new PluginLoader(m_Server.Config, registryLocation);

            int res = m_Server.Run();

            Environment.Exit(res);

            return(0);
        }
 public FileSystemBlockService(IServiceConnector connector, string path)
     : base(connector)
 {
     this.path = path;
 }
        private Service DoCreateService(IServiceAddress serviceAddress, ServiceType serviceType, IServiceConnector connector)
        {
            Service service = null;

            if (serviceType == ServiceType.Manager)
            {
                if (manager == null)
                {
                    string npath = Path.Combine(basePath, "manager");
                    if (!Directory.Exists(npath))
                    {
                        Directory.CreateDirectory(npath);
                    }

                    manager = new FileSystemManagerService(connector, basePath, npath, serviceAddress);
                }

                service = manager;
            }
            else if (serviceType == ServiceType.Root)
            {
                if (root == null)
                {
                    string npath = Path.Combine(basePath, "root");
                    if (!Directory.Exists(npath))
                    {
                        Directory.CreateDirectory(npath);
                    }

                    root = new FileSystemRootService(connector, serviceAddress, npath);
                }

                service = root;
            }
            else if (serviceType == ServiceType.Block)
            {
                if (block == null)
                {
                    string npath = Path.Combine(basePath, "block");
                    if (!Directory.Exists(npath))
                    {
                        Directory.CreateDirectory(npath);
                    }

                    block = new FileSystemBlockService(connector, npath);
                }

                service = block;
            }

            if (service != null)
            {
                service.Started += ServiceStarted;
                service.Stopped += ServiceStopped;
            }

            return(service);
        }