Exemplo n.º 1
0
        public virtual async Task <DesktopAppConnectionResult> StartRealtimeConnection(SirenOfShameSettings settings)
        {
            try
            {
                if (!settings.GetSosOnlineContent())
                {
                    InvokeOnSosOnlineStatusChange("Disabled");
                    return(new DesktopAppConnectionResult {
                        Success = false
                    });
                }
                InvokeOnSosOnlineStatusChange("Connecting");
                _connection = new HubConnection(SOS_URL);
                _proxy      = _connection.CreateHubProxy("SosHub");
                _proxy.On("addChatMessageToDesktopClients", InvokeOnOnNewSosOnlineNotification);
                _connection.Error        += ConnectionOnError;
                _connection.StateChanged += ConnectionOnStateChanged;
                _connection.Closed       += ConnectionOnClosed;
                await _connection.Start();

                var credentialApiModel = new CredentialApiModel
                {
                    UserName = settings.SosOnlineUsername,
                    Password = settings.SosOnlinePassword,
                };
                var result = await _proxy.Invoke <DesktopAppConnectionResult>("connectDesktopApp", credentialApiModel);

                if (!result.Success)
                {
                    _connection.Stop();
                }
                return(result);
            }
            catch (Exception ex)
            {
                _log.Error("Unable to start realtime connection to SoS Online", ex);
            }
            return(new DesktopAppConnectionResult {
                Success = false
            });
        }
Exemplo n.º 2
0
 public virtual async Task<DesktopAppConnectionResult> StartRealtimeConnection(SirenOfShameSettings settings)
 {
     try
     {
         if (!settings.GetSosOnlineContent())
         {
             InvokeOnSosOnlineStatusChange("Disabled");
             return new DesktopAppConnectionResult { Success = false };
         }
         InvokeOnSosOnlineStatusChange("Connecting");
         _connection = new HubConnection(SOS_URL);
         _proxy = _connection.CreateHubProxy("SosHub");
         _proxy.On("addChatMessageToDesktopClients", InvokeOnOnNewSosOnlineNotification);
         _connection.Error += ConnectionOnError;
         _connection.StateChanged += ConnectionOnStateChanged;
         _connection.Closed += ConnectionOnClosed;
         await _connection.Start();
         var credentialApiModel = new CredentialApiModel
         {
             UserName = settings.SosOnlineUsername,
             Password = settings.SosOnlinePassword,
         };
         var result = await _proxy.Invoke<DesktopAppConnectionResult>("connectDesktopApp", credentialApiModel);
         if (!result.Success)
         {
             _connection.Stop();
         }
         return result;
     } 
     catch (Exception ex)
     {
         _log.Error("Unable to start realtime connection to SoS Online", ex);
     }
     return new DesktopAppConnectionResult { Success = false };
 }