Example #1
0
        private async Task <DevicesResponse> DismissAlerts(IEnumerable <string> alertIds, Action onReconnect = null, bool silentMode = false, bool global = false, string deviceId = null)
        {
            try
            {
                //prepare request
                var request = new DismissAlertRequest(alertIds);

                //get response
                var response = await this.DoRequest <DismissAlertRequest, DevicesResponse>(request, withCaching : false, onReconnect : onReconnect, silentMode : silentMode);

                //after-response tasks
                if (response != null && response.Body != null)
                {
                    if (global)
                    {
                        if (response.Body.ActiveAlertsCount != null)
                        {
                            DataCache.SetActiveAlertsCount(response.Body.ActiveAlertsCount);
                        }

                        if (response.Body.Alerts != null)
                        {
                            DataCache.CacheAlerts(response.Body.Alerts.Values, deleteNonexisting: true);
                        }
                    }
                    else
                    {
                        if (response.Body.Alerts != null)
                        {
                            DataCache.CacheAlertsForDevice(deviceId, response.Body.Alerts.Values, deleteNonexisting: true);
                        }
                    }
                }

                return(response);
            }

            catch (Exception e)
            {
                LogUtility.LogException(e);
            }

            return(null);
        }