Пример #1
0
        private async Task UpdateMessagesCollectionAsync()
        {
            if (!MainActivity.CheckInternetConnection())
            {
                var connectivityErrorPopup = this.GetControl <Grid>(ControlNames.ConnectivityErrorPopup);
                if (!connectivityErrorPopup.IsVisible)
                {
                    connectivityErrorPopup.IsVisible = true;
                    await connectivityErrorPopup.FadeTo(1, 100);
                }
            }

            var allMessages = this.ServiceProvider.MessagesApiProvider.RetreiveSpecificMessages().ToList();

            allMessages.Distinct()
            .ToList()
            .ForEach(_ => this.Messages.Add(new ObservableMessage(_)));

            await Task.CompletedTask;
        }
Пример #2
0
        private IEnumerable <Message> PollServerByMode(PollServerMode mode)
        {
            if (this.ServiceProvider.AuthenticationService.IsAuthenticated)
            {
                if (MainActivity.CheckInternetConnection())
                {
                    var pollingUrl = (mode == PollServerMode.Specific) ? FirebaseConstants.PollingSpecificUrl
                                                                       : FirebaseConstants.PollingAllUrl;
                    using (var webClient = new WebClient())
                    {
                        webClient.Headers.Add("AuthToken", this.ServiceProvider.AuthenticationService.CurrentAuthToken);

                        var responseContent = webClient.DownloadString(pollingUrl);

                        if (!string.IsNullOrEmpty(responseContent))
                        {
                            var filteredMessages = JsonConvert.DeserializeObject <IEnumerable <MonitorApiMessageWrapper> >(responseContent)
                                                   .Select(_ => _.MapToDomainMessage())
                                                   .OrderByDescending(_ => _.CreatedOn)
                                                   .ToList();

                            if (mode == PollServerMode.Specific)
                            {
                                Task.Run(() => this.ServiceProvider.PermanentCacheService.Set(MessagesCacheKey, filteredMessages));
                            }

                            return(filteredMessages);
                        }
                    }
                }
                else if (mode == PollServerMode.Specific)
                {
                    if (this.ServiceProvider.PermanentCacheService.IsSet(MessagesCacheKey))
                    {
                        return(this.ServiceProvider.PermanentCacheService.Get <List <Message> >(MessagesCacheKey));
                    }
                }
            }

            return(new List <Message>());
        }
Пример #3
0
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) => value != null && MainActivity.CheckInternetConnection();