public static VkNewsEntry FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } VkNewsEntry vkNewsEntry = new VkNewsEntry(); if (json["post_id"] != null) { vkNewsEntry.Id = json["post_id"].Value <long>(); } if (json["type"] != null) { vkNewsEntry.Type = json["type"].Value <string>(); } if (json["source_id"] != null) { vkNewsEntry.SourceId = json["source_id"].Value <long>(); } if (json["date"] != null) { vkNewsEntry.Date = DateTimeExtensions.UnixTimeStampToDateTime((double)json["date"].Value <long>()); } if (json["text"] != null) { vkNewsEntry.Text = json["text"].Value <string>(); vkNewsEntry.Text = vkNewsEntry.Text.Replace("<br>", Environment.NewLine); } if (json["attachments"] != null) { vkNewsEntry.Attachments = new List <VkAttachment>(); using (IEnumerator <JToken> enumerator = json["attachments"].AsEnumerable().GetEnumerator()) { while (enumerator.MoveNext()) { JToken current = enumerator.Current; string text; if ((text = current["type"].Value <string>()) != null) { if (!(text == "audio")) { if (text == "photo") { vkNewsEntry.Attachments.Add(VkPhotoAttachment.FromJson(current["photo"])); } } else { vkNewsEntry.Attachments.Add(VkAudioAttachment.FromJson(current["audio"])); } } } } } if (json["comments"] != null) { vkNewsEntry.CommentsCount = json["comments"]["count"].Value <long>(); vkNewsEntry.CanWriteComment = (json["comments"]["can_post"].Value <int>() == 1); } return(vkNewsEntry); }
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 static VkWallEntry FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } var result = new VkWallEntry(); result.Id = json["id"].Value <double>(); if (json["text"] != null) { result.Text = WebUtility.HtmlDecode(json["text"].Value <string>()); result.Text = result.Text.Replace("<br>", Environment.NewLine); } if (json["from_id"] != null) { result.SourceId = json["from_id"].Value <long>(); } if (json["date"] != null) { result.Date = DateTimeExtensions.UnixTimeStampToDateTime(json["date"].Value <long>()); } if (json["attachments"] != null) { result.Attachments = new List <VkAttachment>(); foreach (var a in json["attachments"]) { switch (a["type"].Value <string>()) { case "audio": result.Attachments.Add(VkAudioAttachment.FromJson(a["audio"])); break; case "photo": result.Attachments.Add(VkPhotoAttachment.FromJson(a["photo"])); break; } } } if (json["copy_history"] != null) { result.CopyHistory = new List <VkWallEntry>(); foreach (var p in json["copy_history"]) { try { var post = VkWallEntry.FromJson(p); if (post != null) { result.CopyHistory.Add(post); } } catch (Exception ex) { Debug.WriteLine(ex); } } } return(result); }