Ejemplo n.º 1
0
        private void OnShowSimplePush(string type)
        {
            var notification = new AppNotification {
                Duration = TimeSpan.FromSeconds(10)
            };

            switch (type)
            {
            case "Warning":
                notification.Title   = SIMPLE_PUSH_WARNING_TITLE;
                notification.Content = SIMPLE_PUSH_WARNING_CONTENT;
                notification.Type    = AppNotificationType.Warning;
                break;

            case "Error":
                notification.Title   = SIMPLE_PUSH_ERROR_TITLE;
                notification.Content = SIMPLE_PUSH_ERROR_CONTENT;
                notification.Type    = AppNotificationType.Error;
                break;

            case "Info":
                notification.Title   = SIMPLE_PUSH_INFO_TITLE;
                notification.Content = SIMPLE_PUSH_INFO_CONTENT;
                notification.Type    = AppNotificationType.Info;
                break;

            default:
                notification.Title   = SIMPLE_PUSH_DEFAULT_TITLE;
                notification.Content = SIMPLE_PUSH_DEFAULT_CONTENT;
                break;
            }

            appNotificationsService.SendNotification(notification);
        }
Ejemplo n.º 2
0
        private async void OnJoinGroup()
        {
            var request = new Request <VKOperationIsSuccess>("groups.join",
                                                             new Dictionary <string, string>
            {
                { "group_id", groupID.ToString() }
            });
            var response = await vkService.ExecuteRequestAsync(request);

            if (response.IsSuccess)
            {
                await LoadGroupInfo();

                JoinGroup.RaiseCanExecuteChanged();
                ExitGroup.RaiseCanExecuteChanged();
            }
            else
            {
                var notification = new AppNotification
                {
                    Type    = AppNotificationType.Error,
                    Title   = $"Не удалось вступить в сообщество {Group.Name}",
                    Content = "Повторите попытку позднее"
                };
                appNotificationsService.SendNotification(notification);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Загружает информацию о настройках.
        /// </summary>
        private async Task LoadSettings()
        {
            LoadingText = "Загрузка информации о настройках";
            IsLoading   = true;

            var parameters = new Dictionary <string, string>
            {
                { "group_id", Group.ID.ToString() }
            };
            var request  = new Request <VKGroupSettings>("groups.getSettings", parameters);
            var response = await vkService.ExecuteRequestAsync(request);

            if (response.IsSuccess)
            {
                Settings            = response.Response;
                CurrentSubjectIndex = Settings.AvailableSubjects.FindIndex(s => s.ID == Settings.Subject);
            }
            else if (response.Error == VKErrors.AccessDenied)
            {
                var notification = new AppNotification
                {
                    Type     = AppNotificationType.Error,
                    Title    = "Нет доступа к параметрам сообщества",
                    Content  = "Не удалось получить текущие значения параметров",
                    ImageUrl = Group.Photo100
                };
                appNotificationsService.SendNotification(notification);

                if (navigationService.CanGoBack())
                {
                    navigationService.GoBack();
                }
            }
            else
            {
                var notification = new AppNotification
                {
                    Type     = AppNotificationType.Error,
                    Title    = "Не удалось получить текущие значения параметров",
                    Content  = "Повторите попытку позднее",
                    ImageUrl = Group.Photo100
                };
                appNotificationsService.SendNotification(notification);

                if (navigationService.CanGoBack())
                {
                    navigationService.GoBack();
                }
            }

            IsLoading = false;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Проверяет инициализацию клиента.
 /// </summary>
 private async Task <bool> CheckInitialized()
 {
     try
     {
         if (!isInitialized)
         {
             if (String.IsNullOrEmpty(CLIENT_NAME) || String.IsNullOrEmpty(CLIENT_SECRET))
             {
                 var notification = new AppNotification
                 {
                     Type    = AppNotificationType.Error,
                     Title   = "Невозможно инициализировать GrooveMusicService",
                     Content = "CLIENT_NAME или CLIENT_SECRET не заданы"
                 };
                 appNotificationService.SendNotification(notification);
                 isInitialized = false;
                 return(false);
             }
             await client.InitializeAccessTokenAsync();
         }
         isInitialized = true;
         return(true);
     }
     catch (Exception) { return(false); }
 }
Ejemplo n.º 5
0
        public override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
        {
            if (sessionStateService.SessionState.ContainsKey("NewsfeedNextFrom"))
            {
                nextFrom = (string)sessionStateService.SessionState["NewsfeedNextFrom"];
            }

            if (sessionStateService.SessionState.ContainsKey("Newsfeed"))
            {
                var newsfeed = (PaginatedCollection <VKNewsfeedItem>)sessionStateService.SessionState["Newsfeed"];
                newsfeed.LoadMoreItems = LoadMoreItems;
                Newsfeed = newsfeed;

                if (sessionStateService.SessionState.ContainsKey("NewsfeedSuspended"))
                {
                    sessionStateService.SessionState.Remove("NewsfeedSuspended");
                    var notification = new AppNotification
                    {
                        Type       = AppNotificationType.Warning,
                        Title      = "Новости могли устареть",
                        Content    = "Коснитесь, чтобы обновить",
                        Duration   = TimeSpan.FromSeconds(10),
                        ActionToDo = () =>
                        {
                            FirstVisibleIndex = 0;
                            nextFrom          = null;
                            Newsfeed.Refresh();
                        }
                    };
                    appNotificationsService.SendNotification(notification);
                }

                if (sessionStateService.SessionState.ContainsKey("FirstVisibleNewsfeedIndex"))
                {
                    FirstVisibleIndex = (int)sessionStateService.SessionState["FirstVisibleNewsfeedIndex"];
                }
            }
            else
            {
                Newsfeed = new PaginatedCollection <VKNewsfeedItem>(LoadMoreItems);
            }

            base.OnNavigatedTo(e, viewModelState);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Запустить LongPoll сервис.
        /// </summary>
        public async void Start()
        {
            if (IsWorking)
            {
                return;
            }

            try
            {
                IsWorking = true;
                cts       = new CancellationTokenSource();
                if (ServiceStarted != null)
                {
                    ServiceStarted(this, EventArgs.Empty);
                }

                await ProcessLongPoll();

                var notification = new AppNotification
                {
                    Type     = AppNotificationType.Info,
                    Title    = "Сервис мгновенных сообщений успешно запущен",
                    Content  = "Теперь вы будете в курсе всех новых сообщений",
                    Duration = TimeSpan.FromSeconds(6)
                };
                appNotificationsService.SendNotification(notification);
            }
            catch (OperationCanceledException)
            {
                OnServiceStopped(VKLongPollServiceStopReason.ByUser);
            }
            catch (WebConnectionException)
            {
                OnServiceStopped(VKLongPollServiceStopReason.ConnectionError);
            }
            catch (Exception)
            {
                OnServiceStopped(VKLongPollServiceStopReason.InternalError);
                throw;
            }
        }