Exemple #1
0
        public void AddHost(string hostname, bool saveAccessCode)
        {
            if (this.config.Hosts.FirstOrDefault(h => h.Hostname == hostname) == null)
            {
                Mogger.LogError(LogMessages.HostExists);
                return;
            }
            var host = new Host {
                Hostname = hostname, SaveAccessCode = saveAccessCode
            };

            this.config.Hosts.Add(host);
            MogmogConnection connection;

            try
            {
                connection = new MogmogConnection(hostname, this.config.Hosts.IndexOf(host), saveAccessCode);
            }
            catch (RpcException e)
            {
                this.config.Hosts.Remove(host);
                if (e.Status.Detail == "Error starting gRPC call: No connection could be made because the target machine actively refused it.")
                {
                    Mogger.LogError(LogMessages.HostOffline); // A more user-friendly error
                }
                else
                {
                    Mogger.LogError(e.Message);
                }
                return;
            }
            connection.MessageReceivedEvent += MessageReceived;
            this.connections.Add(connection);
        }
Exemple #2
0
        public MogmogConnectionManager(MogmogConfiguration config)
        {
            this.config      = config ?? throw new ArgumentNullException(nameof(config));
            this.connections = new DisposableStrongIndexedList <MogmogConnection>();

            foreach (var host in config.Hosts)
            {
                if (string.IsNullOrEmpty(host.Hostname))
                {
                    this.connections.Append(null);
                }
                else
                {
                    var connection = new MogmogConnection(host.Hostname, this.connections.Count, host.SaveAccessCode);
                    connection.MessageReceivedEvent += MessageReceived;
                    this.connections.Append(connection);
                }
            }
        }