Esempio n. 1
0
        public static VkGroup FromJson(JToken json)
        {
            if (json == null)
                throw new ArgumentException("Json can not be null.");

            var result = new VkGroup();

            result.Id = Math.Abs(json["id"].Value<long>());
            result.Name = WebUtility.HtmlDecode(json["name"].Value<string>()).Trim();

            if (json["photo_50"] != null)
                result.Photo = (string)json["photo_50"];

            if (json["photo_100"] != null)
                result.PhotoMedium = json["photo_100"].Value<string>();

            if (json["photo_200_orig"] != null)
                result.PhotoBig = json["photo_200_orig"].Value<string>();

            if (json["photo_200"] != null)
                result.PhotoBigSquare = json["photo_200"].Value<string>();

            if (json["photo_400_orig"] != null)
                result.PhotoLarge = json["photo_400_orig"].Value<string>();

            if (json["photo_max"] != null)
                result.PhotoMaxSquare = json["photo_max"].Value<string>();

            if (json["photo_max_orig"] != null)
                result.PhotoMax = json["photo_max_orig"].Value<string>();

            if (json["is_admin"] != null)
                result.IsAdmin = json["is_admin"].Value<int>() == 1;

            if (json["is_member"] != null)
                result.IsAdmin = json["is_member"].Value<int>() == 1;

            if (json["is_closed"] != null)
                result.IsClosed = json["is_closed"].Value<int>() == 1;

            if (json["type"] != null)
                result.Type = json["type"].Value<string>();

            return result;
        }
Esempio n. 2
0
        private void InitializeCommands()
        {
            AddSocietyCommand = new RelayCommand(async () =>
            {
                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new AddSocietyFlyout();
                var result = await flyout.ShowAsync();
                if (result != null)
                {
                    CancelAsync();

                    if (Societies.Count == 0)
                    {
                        _societies.Add(new VkGroup() { Name = MainResources.AllSocieties });
                    }

                    Societies.Add((VkGroup)result);
                    SaveSocieties();

                    if (SelectedSociety == null)
                        SelectedSociety = _societies.First();
                    else if (SelectedSociety.Id == 0)
                        LoadFeed(_cancellationToken.Token);
                }
            });

            RemoveSocietyCommand = new RelayCommand<VkGroup>(society =>
            {
                bool isActiveSociety = false;
                if (society == SelectedSociety)
                    isActiveSociety = true;

                CancelAsync();
                Societies.Remove(society);

                if (Societies.Count == 1)
                    Societies.Clear();

                SaveSocieties();

                if (!isActiveSociety && (SelectedSociety != null && SelectedSociety.Id != 0))
                {
                    return;
                }

                if (isActiveSociety)
                {
                    if (Societies.Any())
                        SelectedSociety = Societies.First();
                }

                //if (SelectedSociety != null && SelectedSociety.Id == 0)
                //{
                    CancelAsync();

                    LoadFeed(_cancellationToken.Token);
                //}

                //if (isActiveSociety && Societies.Any())
                //    SelectedSociety = Societies.First();
                //else if (isActiveSociety)
                //    LoadFeed(_cancellationToken.Token);
            });

            PlayAudioCommand = new RelayCommand<Audio>(audio =>
            {
                AudioService.Play(audio);
                AudioService.SetCurrentPlaylist(Tracks);
            });
        }
Esempio n. 3
0
        private void LoadSocieties()
        {
            if (Domain.Settings.Instance.FeedSocieties != null)
            {
                _societies = new ObservableCollection<VkGroup>(Domain.Settings.Instance.FeedSocieties);

                if (_societies.Count > 0)
                {
                    _societies.Insert(0, new VkGroup() { Name = MainResources.AllSocieties });
                    SelectedSociety = _societies.First();
                }

                LoadFeed(_cancellationToken.Token);
            }
        }
Esempio n. 4
0
        public async Task <VkItemsResponse <VkGroup> > Search(string query, VkGroupSearchType sort = VkGroupSearchType.ByUsers, int count = 0, int offset = 0)
        {
            if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired)
            {
                throw new Exception("Access token is not valid.");
            }

            var parameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(query))
            {
                parameters.Add("q", query);
            }

            parameters.Add("sort", ((int)sort).ToString());

            if (count > 0)
            {
                parameters.Add("count", count.ToString());
            }

            if (offset > 0)
            {
                parameters.Add("offset", offset.ToString());
            }

            _vkontakte.SignMethod(parameters);

            var response = await new VkRequest(new Uri(VkConst.MethodBase + "groups.search"), parameters).Execute();

            VkErrorProcessor.ProcessError(response);

            if (response.SelectToken("response.items") != null)
            {
                return(new VkItemsResponse <VkGroup>((from g in response["response"]["items"] where g.HasValues select VkGroup.FromJson(g)).ToList(), response["response"]["count"].Value <int>()));
            }

            return(VkItemsResponse <VkGroup> .Empty);
        }
Esempio n. 5
0
        public async Task <VkItemsResponse <VkGroup> > Search(string query, VkGroupSearchType sort = VkGroupSearchType.ByUsers, int count = 0, int offset = 0)
        {
            var parameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(query))
            {
                parameters.Add("q", query);
            }

            parameters.Add("sort", ((int)sort).ToString());

            if (count > 0)
            {
                parameters.Add("count", count.ToString());
            }

            if (offset > 0)
            {
                parameters.Add("offset", offset.ToString());
            }

            _vkontakte.SignMethod(parameters);

            var response = await VkRequest.GetAsync(VkConst.MethodBase + "groups.search", parameters);

            if (response.SelectToken("response.items") != null)
            {
                return(new VkItemsResponse <VkGroup>((from g in response["response"]["items"] where g.HasValues select VkGroup.FromJson(g)).ToList(), response["response"]["count"].Value <int>()));
            }

            return(VkItemsResponse <VkGroup> .Empty);
        }
Esempio n. 6
0
        public static VkGroup FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }

            var result = new VkGroup();

            result.Id   = Math.Abs(json["id"].Value <long>());
            result.Name = WebUtility.HtmlDecode(json["name"].Value <string>()).Trim();

            if (json["photo_50"] != null)
            {
                result.Photo = (string)json["photo_50"];
            }

            if (json["photo_100"] != null)
            {
                result.PhotoMedium = json["photo_100"].Value <string>();
            }

            if (json["photo_200_orig"] != null)
            {
                result.PhotoBig = json["photo_200_orig"].Value <string>();
            }

            if (json["photo_200"] != null)
            {
                result.PhotoBigSquare = json["photo_200"].Value <string>();
            }

            if (json["photo_400_orig"] != null)
            {
                result.PhotoLarge = json["photo_400_orig"].Value <string>();
            }

            if (json["photo_max"] != null)
            {
                result.PhotoMaxSquare = json["photo_max"].Value <string>();
            }

            if (json["photo_max_orig"] != null)
            {
                result.PhotoMax = json["photo_max_orig"].Value <string>();
            }

            if (json["is_admin"] != null)
            {
                result.IsAdmin = json["is_admin"].Value <int>() == 1;
            }

            if (json["is_member"] != null)
            {
                result.IsAdmin = json["is_member"].Value <int>() == 1;
            }

            if (json["is_closed"] != null)
            {
                result.IsClosed = json["is_closed"].Value <int>() == 1;
            }

            if (json["type"] != null)
            {
                result.Type = json["type"].Value <string>();
            }

            return(result);
        }