public virtual void TryToGetAndSendNewSosOnlineAlerts(SirenOfShameSettings settings, DateTime now, Action <NewAlertEventArgs> invokeNewAlert) { if (!settings.GetSosOnlineContent()) { return; } bool weHaveAlreadyCheckedForAlertsToday = settings.LastCheckedForAlert != null && (now - settings.LastCheckedForAlert.Value).TotalHours < 24; if (weHaveAlreadyCheckedForAlertsToday) { return; } settings.LastCheckedForAlert = DateTime.Now; settings.Save(); var webClient = GetWebClient(); webClient.DownloadStringCompleted += (s, e) => { try { if (e.Error != null) { _log.Error("Error retrieving alert", e.Error); return; } NewAlertEventArgs args = new NewAlertEventArgs(); var successParsing = args.Instantiate(e.Result); if (successParsing) { if (settings.SoftwareInstanceId == null) { settings.SoftwareInstanceId = args.SoftwareInstanceId; settings.Save(); } if (settings.AlertClosed == null || args.AlertDate > settings.AlertClosed) { invokeNewAlert(args); } } } catch (Exception ex) { _log.Error("Error retrieving alert", ex); } }; string url = string.Format(SOS_URL + "/GetAlert?SirenEverConnected={0}&SoftwareInstanceId={1}&ServerType={2}&Version={3}", settings.SirenEverConnected, settings.SoftwareInstanceId, string.Join(",", settings.CiEntryPointSettings.Select(cip => cip.Name)), Application.ProductVersion ); webClient.DownloadStringAsync(new Uri(url)); }
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 }); }
public virtual void StartRealtimeConnection(SirenOfShameSettings settings) { try { if (!settings.GetSosOnlineContent()) { InvokeOnSosOnlineStatusChange("Disabled"); return; } InvokeOnSosOnlineStatusChange("Connecting"); _connection = new HubConnection(SOS_URL); _proxy = _connection.CreateProxy("SosHub"); _proxy.On("addAppNotificationV1", InvokeOnOnNewSosOnlineNotification); _connection.Error += ConnectionOnError; _connection.StateChanged += ConnectionOnStateChanged; _connection.Closed += ConnectionOnClosed; Task result = _connection.Start(); result.ContinueWith(ConnectionOnError, TaskContinuationOptions.OnlyOnFaulted); } catch (Exception ex) { _log.Error("Unable to start realtime connection to SoS Online", ex); } }