Exemple #1
0
        /// <summary>
        /// Регистрирует устройство на получение Push-уведомлений.
        /// </summary>
        public async Task RegisterDevice()
        {
            if (channel == null)
            {
                channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
            }

            if (!String.IsNullOrEmpty(WNSChannelUri) && channel.Uri != WNSChannelUri)
            {
                await UnregisterDevice();
            }

            var parameters = new Dictionary <string, string>
            {
                ["device_id"] = deviceInformationService.GetHardwareID(),
                ["token"]     = channel.Uri,
                ["settings"]  = "{\"msg\":\"on\",\"chat\":\"on\",\"friend\":\"on\",\"reply\":\"on\",\"mention\":\"on\"}"
            };
            var request = new Request <VKOperationIsSuccess>("account.registerDevice", parameters)
            {
                HttpMethod = HttpMethod.POST
            };
            var response = await vkService.ExecuteRequestAsync(request);

            if (!response.IsSuccess)
            {
                throw new Exception("Не удалось зарегистрировать устройство");
            }
            WNSChannelUri = channel.Uri;
            channel.PushNotificationReceived += Channel_PushNotificationReceived;
        }
Exemple #2
0
        /// <summary>
        /// Загрузить информацию о сообществе.
        /// </summary>
        private async Task LoadGroupInfo()
        {
            GroupName = "Загрузка";

            var parameters = new Dictionary <string, string>
            {
                { "group_id", groupID.ToString() },
                { "fields", "city,country,place,description,members_count,counters,start_date,finish_date,can_post,can_see_all_posts,activity,status,contacts,links,fixed_post,verified,site,ban_info" }
            };
            var request  = new Request <List <VKGroupExtended> >("groups.getById", parameters);
            var response = await vkService.ExecuteRequestAsync(request);

            if (response.IsSuccess)
            {
                Group     = response.Response[0];
                GroupName = Group.Name;

                JoinGroup.RaiseCanExecuteChanged();
                ExitGroup.RaiseCanExecuteChanged();
            }
        }
        /// <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;
        }
        /// <summary>
        /// Возвращает данные для подключения к LongPoll серверу.
        /// </summary>
        private async Task <VKLongPollServerData> GetServerData()
        {
            appNotificationsService.SendNotification(new AppNotification
            {
                Type    = AppNotificationType.Default,
                Content = "Получение данных для подключения к серверу..."
            });

            byte currentRetry = 0;

            while (currentRetry < MAX_RETRIES_NUMBER)
            {
                var request  = new Request <VKLongPollServerData>("messages.getLongPollServer", token: cts.Token);
                var response = await vkService.ExecuteRequestAsync(request);

                if (response.IsSuccess)
                {
                    return(response.Response);
                }
                else if (response.Error == VKErrors.ConnectionError)
                {
                    if (++currentRetry < MAX_RETRIES_NUMBER)
                    {
                        int timeout = currentRetry * 5;
                        SendConnectionErrorPush(timeout);
                        await Task.Delay(timeout * 1000, cts.Token);

                        continue;
                    }
                }
            }

            var notification = new AppNotification
            {
                Type    = AppNotificationType.Error,
                Title   = "Не удалось получить данные для подключения",
                Content = "Сервис мгновенных сообщений будет остановлен"
            };

            appNotificationsService.SendNotification(notification);

            throw new Exception("Exit from GetServerData loop");
        }
Exemple #5
0
        public async Task <IEnumerable <VKNewsfeedItem> > LoadMoreItems(uint page)
        {
            var parameters = new Dictionary <string, string>
            {
                { "filters", "post" },
                { "count", "30" }
            };

            if (!String.IsNullOrEmpty(nextFrom))
            {
                parameters["start_from"] = nextFrom;
            }

            var request  = new Request <VKNewsfeedGetResponse>("newsfeed.get", parameters);
            var response = await vkService.ExecuteRequestAsync(request);

            if (response.IsSuccess)
            {
                foreach (var item in response.Response.Items)
                {
                    if (item.SourceID > 0)
                    {
                        item.Owner = response.Response.Profiles.FirstOrDefault(u => u.ID == item.SourceID);
                    }
                    else
                    {
                        item.Owner = response.Response.Groups.FirstOrDefault(g => g.ID == -item.SourceID);
                    }
                }

                nextFrom = response.Response.NextFrom;
                return(response.Response.Items);
            }
            else
            {
                throw new Exception();
            }
        }