public async Task LogAsync(HistoryPost data) { if (!_settings.History.Use || !Utils.UrlHelper.IsUriIsValid(_settings.History.Uri)) { return; } var uriBuilder = new UriBuilder(_settings.History.Uri) { Path = "posts" }; var uri = uriBuilder.Uri; //await ensureDataBase(data); var serialized = JsonConvert.SerializeObject(data); var content = new StringContent(serialized, Encoding.UTF8, "application/json"); try { var result = await _rateLimiter.Perform(() => _httpClient.PostAsync(uri, content)); Debug.WriteLine($"--- HISTORY PUBLISHED AT {DateTimeOffset.Now.Ticks}"); if (result.IsSuccessStatusCode) { var contentResult = result.Content.ReadAsStringAsync(); } } catch (OperationCanceledException) { //ignore } }
private async void SaveEntity() { if (ActiveHistoryPost != null) { ActiveHistoryPost.Date = Date; ActiveHistoryPost.Post = Post; await Repository.SaveEntity(Writer, ActiveHistoryPost, CompanyId); } else { ActiveHistoryPost = new HistoryPost() { Date = this.Date, Post = this.Post }; int id = await Repository.SaveEntity(Writer, ActiveHistoryPost, CompanyId); ActiveHistoryPost.Id = id; } Messenger.Default.Send(new EntityAddedMessenger() { Entity = ActiveHistoryPost, companyId = CompanyId }); }
private void onWallPostSuccessful(object sender, WallPostInfo info) { Task.Run(async() => { try { var userid = 0; var users = await _api.UsersGet.GetAsync(QueryParameters.No()); var user = users.Content?.FirstOrDefault(); if (user != null) { userid = user.ID; } var post = new HistoryPost { OwnerId = userid, WallId = info.OwnerId, Message = info.Message, PostponedDateUnix = info.PostponedDate, IsRepost = false, Date = info.PublishingDate, Attachments = info.Attachments.Exposed.Select(attachment => attachment.Photo.GetLargest()).ToList() }; await _historyPublisher.LogAsync(post); } catch (VkException) { //ignore } }); }
private void AddNewEntity() { IEntity emtpyEntity = null; if (ViewTodos) { emtpyEntity = new Todo(); } if (ViewEmployees) { emtpyEntity = new Employee(); } if (ViewHistories) { emtpyEntity = new HistoryPost(); } Messenger.Default.Send(new SelectedEntityMessenger() { SelectedEntityMessageEntity = emtpyEntity }); }
private List <HistoryPost> ParseHistory(JToken _jHistory, Func <VideoInfo, string> _loadVideoItem) { if (_jHistory is JArray jCopyHistory) { try { var historyCollection = new List <HistoryPost>(); foreach (JObject jHistoryElement in jCopyHistory) { var historyPost = new HistoryPost(); historyPost.Id = jHistoryElement[PId].Value <int>(); historyPost.OwnerId = jHistoryElement[PHistoryOwnerId].Value <int>(); historyPost.FromId = jHistoryElement[PHistoryFromId].Value <int>(); historyPost.Date = EpochTimeConverter.ConvertToDateTime(jHistoryElement[PDate].Value <long>()); historyPost.Text = jHistoryElement[PItemText].Value <string>(); historyPost.PostSource = ParsePostSource((JObject)jHistoryElement[PPostSource]); var attachmentsRaw = jHistoryElement[PAttachments]; if (attachmentsRaw != null) { historyPost.Attachments = ParseAttachments(attachmentsRaw, _loadVideoItem).ToArray(); } historyCollection.Add(historyPost); } return(historyCollection); } catch (Exception ex) { throw new InvalidOperationException($"Failed to parse history \n {_jHistory.ToString()}", ex); } } throw new ArgumentException($"History element not recognized as array \n {_jHistory?.ToString()}"); }
public async Task LogAsync(HistoryPost data) { await Task.Delay(TimeSpan.Zero).ConfigureAwait(false); }
public void Log(HistoryPost data) { }
public HistoryViewModel(IEntity entity, IRepository repository, IWriter writer, int companyId) : base(repository, writer, companyId) { SaveEntityCommand = new RelayCommand(SaveEntity, CanSaveEntity); ActiveHistoryPost = entity as HistoryPost; }