//VK Api v3.0
        private static VkPhotoAttachment ParseV3(JToken json)
        {
            var result = new VkPhotoAttachment();

            result.Id      = json["pid"].Value <long>();
            result.OwnerId = json["owner_id"].Value <long>();
            if (json["src"] != null)
            {
                result.Source = json["src"].Value <string>();
            }
            if (json["src_big"] != null)
            {
                result.SourceBig = json["src_big"].Value <string>();
            }
            return(result);
        }
Exemple #2
0
        public static List <VkAttachment> FromJson(JToken json)
        {
            var result = new List <VkAttachment>();

            foreach (var a in json)
            {
                switch (a["type"].Value <string>())
                {
                case "audio":
                    result.Add(VkAudioAttachment.FromJson(a["audio"]));
                    break;

                case "photo":
                    result.Add(VkPhotoAttachment.FromJson(a["photo"]));
                    break;

                case "sticker":
                    result.Add(VkStickerAttachment.FromJson(a["sticker"]));
                    break;

                case "gift":
                    result.Add(VkGiftAttachment.FromJson(a["gift"]));
                    break;

                case "link":
                    result.Add(VkLinkAttachment.FromJson(a["link"]));
                    break;

                case "doc":
                    result.Add(VkDocumentAttachment.FromJson(a["doc"]));
                    break;

                case "video":
                    result.Add(VkVideoAttachment.FromJson(a["video"]));
                    break;

                case "wall":
                    result.Add(VkWallPostAttachment.FromJson(a["wall"]));
                    break;
                }
            }

            return(result);
        }
Exemple #3
0
        public static List <VkAttachment> FromJson(JToken json, string apiVersion = null)
        {
            var result = new List <VkAttachment>();

            foreach (var a in json)
            {
                switch (a["type"].Value <string>())
                {
                case "audio":
                    result.Add(VkAudioAttachment.FromJson(a["audio"]));
                    break;

                case "photo":
                    result.Add(VkPhotoAttachment.FromJson(a["photo"]));
                    break;
                }
            }

            return(result);
        }
        //VK Api v5.0
        private static VkPhotoAttachment ParseV5(JToken json)
        {
            var result = new VkPhotoAttachment();

            result.Id = (long)json["id"];

            result.OwnerId = (long)json["owner_id"];

            if (json["album_id"] != null)
            {
                result.AlbumId = (long)json["album_id"];
            }

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

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

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

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

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

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

            if (json["width"] != null)
            {
                result.Width = (int)json["width"];
            }

            if (json["height"] != null)
            {
                result.Height = (int)json["height"];
            }

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

            if (json["date"] != null)
            {
                result.Date = DateTimeExtensions.UnixTimeStampToDateTime((long)json["date"]);
            }

            return(result);
        }
 //VK Api v3.0
 private static VkPhotoAttachment ParseV3(JToken json)
 {
     var result = new VkPhotoAttachment();
     result.Id = json["pid"].Value<long>();
     result.OwnerId = json["owner_id"].Value<long>();
     if (json["src"] != null)
         result.Source = json["src"].Value<string>();
     if (json["src_big"] != null)
         result.SourceBig = json["src_big"].Value<string>();
     return result;
 }
        //VK Api v5.0
        private static VkPhotoAttachment ParseV5(JToken json)
        {
            var result = new VkPhotoAttachment();

            result.Id = (long)json["id"];

            result.OwnerId = (long)json["owner_id"];

            if (json["album_id"] != null)
                result.AlbumId = (long)json["album_id"];

            if (json["photo_75"] != null)
                result.SourceSmall = (string)json["photo_75"];

            if (json["photo_130"] != null)
                result.Source = (string)json["photo_130"];

            if (json["photo_604"] != null)
                result.SourceBig = (string)json["photo_604"];

            if (json["photo_807"] != null)
                result.SourceXBig = (string)json["photo_807"];

            if (json["photo_1280"] != null)
                result.SourceXXBig = (string)json["photo_1280"];

            if (json["photo_2560"] != null)
                result.SourceXXXBig = (string)json["photo_2560"];

            if (json["width"] != null)
                result.Width = (int)json["width"];

            if (json["height"] != null)
                result.Height = (int)json["height"];

            if (json["text"] != null)
                result.Text = (string)json["text"];

            if (json["date"] != null)
                result.Date = DateTimeExtensions.UnixTimeStampToDateTime((long)json["date"]);

            return result;
        }
Exemple #7
0
        private async void Share(IProgress<int> progress, CancellationToken token)
        {
            Progress = 0;
            if (Tracks != null)
                ProgressMaximum = Tracks.Count;

            IsWorking = true;
            CanGoNext = false;

            VkPhotoAttachment photoAttachment = null;
            if (!string.IsNullOrEmpty(ImagePath))
            {
                try
                {
                    var server = await ViewModelLocator.Vkontakte.Photos.GetWallUploadServer(0, ShareToSociety ? _selectedSociety.Id : 0);
                    var o = await ViewModelLocator.Vkontakte.Photos.UploadWallPhoto(server, Path.GetFileName(ImagePath), File.OpenRead(ImagePath));
                    if (o != null)
                    {
                        var photo = await ViewModelLocator.Vkontakte.Photos.SaveWallPhoto(o.Server, o.Photo, o.Hash, ShareToUser ? _selectedFriend.Id : 0, ShareToSociety ? _selectedSociety.Id : 0);
                        if (photo != null)
                            photoAttachment = new VkPhotoAttachment(photo);
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
            }

            if (token.IsCancellationRequested)
                return;

            progress.Report(1);
            try
            {
                var attachments = new List<VkAttachment>();
                if (photoAttachment != null)
                    attachments.Add(photoAttachment);

                if (Tracks != null)
                {
                    var audioAttachments = await GetAudioList(progress, token);
                    if (audioAttachments != null)
                        attachments.AddRange(audioAttachments);
                }

                if (token.IsCancellationRequested)
                    return;

                long targetId = 0;
                if (ShareToSociety)
                    targetId = -_selectedSociety.Id;
                else if (ShareToUser)
                    targetId = _selectedFriend.Id;

                var postId = await ViewModelLocator.Vkontakte.Wall.Post(targetId, null, attachments, _shareAsSociety, _shareSigned);
                if (postId > 0)
                {
                    Close();
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);
            }

            IsWorking = false;
            CanGoNext = true;
        }
        public new static VkPhotoAttachment FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }

            var result = new VkPhotoAttachment();

            result.Id = (long)json["id"];

            result.OwnerId = (long)json["owner_id"];

            if (json["album_id"] != null)
            {
                result.AlbumId = (long)json["album_id"];
            }

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

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

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

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

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

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

            if (json["width"] != null)
            {
                result.Width = (int)json["width"];
            }

            if (json["height"] != null)
            {
                result.Height = (int)json["height"];
            }

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

            if (json["date"] != null)
            {
                result.Date = DateTimeExtensions.UnixTimeStampToDateTime((long)json["date"]);
            }

            return(result);
        }