Ejemplo n.º 1
0
        public async Task Ping(DexihActiveAgent activeAgent, string connectionId)
        {
            _logger.LogTrace($"Ping from {Context.UserIdentifier}");

            var operations = (IDexihOperations)_serviceProvider.GetService(typeof(IDexihOperations));
            await operations.BroadcastClientMessageAsync(connectionId, EClientCommand.ActiveAgentUpdate, activeAgent, CancellationToken.None);
        }
Ejemplo n.º 2
0
 public async Task PingServer(DexihActiveAgent activeAgent, string pingKey)
 {
     _logger.LogTrace($"Ping from {Context.UserIdentifier}");
     var json = JsonExtensions.Serialize(activeAgent);
     await _distributedCache.SetStringAsync(pingKey, json, new DistributedCacheEntryOptions()
     {
         SlidingExpiration = TimeSpan.FromMilliseconds(5000)
     });
 }
Ejemplo n.º 3
0
        public async Task Connect(DexihActiveAgent activeAgent, string securityToken)
        {
            try
            {
                _logger.LogDebug($"Connect from {Context.UserIdentifier}");

                Context.Items.Add("InstanceId", activeAgent.InstanceId);
                Context.Items.Add("SecurityToken", securityToken);
                var remoteAgents = (IRemoteAgents)_serviceProvider.GetService(typeof(IRemoteAgents));
                var operations   = (IDexihOperations)_serviceProvider.GetService(typeof(IDexihOperations));
                await remoteAgents.ConnectRemoteAgent(Context.ConnectionId, activeAgent, operations, CancellationToken.None);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"RemoteAgent connect error {e.Message}");
                throw;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Logs into the dexih instance and returns the cookiecontainer which can be used to authenticate future requests.
        /// </summary>
        /// <returns>The login.</returns>
        private async Task Login()
        {
            try
            {
                //Login to the web server, which will allow future connections to be authenticated.
                var content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("User", Username),
                    new KeyValuePair <string, string>("Password", Password),
                    new KeyValuePair <string, string>("HubName", DefaultDatabase)
                });

                HttpResponseMessage response;
                try
                {
                    var result = await HttpPost("Login", content, true);

                    if ((bool)result["success"])
                    {
                        var agents = result["value"];
                        if (agents != null)
                        {
                            _activeAgent = agents.ToObject <DexihActiveAgent>();
                        }

                        _isAuthenticated = true;
                    }
                    else
                    {
                        throw new ConnectionException($"Error {result?["message"]}", new Exception(result["exceptionDetails"].ToString()));
                    }
                }
                catch (HttpRequestException ex)
                {
                    throw new ConnectionException($"Could not connect to server {Server}. {ex.Message}", ex);
                }
            }
            catch (Exception ex)
            {
                throw new ConnectionException($"Login failed.\n{ex.Message}", ex);
            }
        }
Ejemplo n.º 5
0
        private DexihActiveAgent GetActiveAgent()
        {
            var activeAgent = new DexihActiveAgent()
            {
                Name              = _remoteSettings.AppSettings.Name,
                IsRunning         = true,
                DataPrivacyStatus = _remoteSettings.DataPrivacyStatus(),
                DownloadUrls      = _remoteSettings.GetDownloadUrls(),
                IpAddress         = _remoteSettings.Runtime.ExternalIpAddress,
                IsEncrypted       = _remoteSettings.Network.EnforceHttps,
                InstanceId        = _sharedSettings.InstanceId,
                User              = _remoteSettings.AppSettings.User,
                UpgradeAvailable  = _remoteSettings.UpgradeAvailable(),
                AutoUpgrade       = _remoteSettings.AppSettings.AutoUpgrade,
                Version           = _remoteSettings.Runtime.Version,
                LatestVersion     = _remoteSettings.Runtime.LatestVersion,
                LatestDownloadUrl = _remoteSettings.Runtime.LatestDownloadUrl,
                RemoteAgentKey    = _remoteSettings.Runtime.RemoteAgentKey,
                NamingStandards   = _remoteSettings.NamingStandards
            };

            return(activeAgent);
        }