private void CheckForSources() { if (userId == 339) { return; //pageadmin } string srcId = FindFBSource(activity.RawActivity.BodyStr); if (!string.IsNullOrEmpty(srcId)) { Logger.Instance.Debug($"found fb source {srcId} in post.looking for page"); PageSource record = PageSources.GetBySourceId(srcId, "fb_page"); if (record == null) { //create a page and assign this action to it Task.Run(() => CreatePageAndAssignActivity(srcId, activity.ActivityId)); } else { //like or increase like to this page LikeSourceIfPossible(record.page_id, "sitepage_page"); } } }
private bool PublishPost(KoobecaService service, FBPost item, out double timeSpanMiliSec) { DateTime start = DateTime.Now; CurrentlyPublished = item; try { //if (string.IsNullOrEmpty(item.Link)) // item.Link = item.URL; Logger.Instance.Info($"Publishing {item.source_type} {item.source} : {item.message} : link {item.link}"); if (item.Photos == null) { var effectiveLink = UrlUnshortener.GetRealUrl(item.link); if (effectiveLink != item.link) { Logger.Instance.Info($"effective link is: {effectiveLink}"); item.link = effectiveLink; } } else { //no link in case of photo item.link = string.Empty; } if (!_PageSourceCache.TryGetValue(item.source, out PageSource source)) { source = PageSources.GetBySourceId(item.source, item.source_type); if (source == null) { throw new Exception($"{item.source}:{item.link} not found in page ids"); } else { //add it to the cache _PageSourceCache[item.source] = source; } } ulong pageId = source.page_id; //target id (legacy is page) if (ActualPublishing) { KoobecaService.PostTarget targetType = source.source_type == "fb_page" ? KoobecaService.PostTarget.Page : KoobecaService.PostTarget.User; int videoId = 0; if (item.link.Contains(".youtube.com")) { //post video var vidReult = service.PostVideoAsync("1", "everyone", item.name, item.description, item.link).Result; if (!vidReult.error) { videoId = vidReult.body.response.video_id; } } var result = service.PostOnWallAsync(item.Privacy, videoId, item.message, item.link, targetType, (int)pageId, item.Photos).Result; if (result.error) { Logger.Instance.Error(result.ToString()); } } else { Thread.Sleep(1000); // just sleep second } timeSpanMiliSec = (DateTime.Now - start).TotalMilliseconds; Logger.Instance.Info($"Time Spent in {timeSpanMiliSec} ms"); //File.AppendAllText(_PublishedPath,item.ID + "\n"); PublishCount++; return(true); } catch (Exception e) { Logger.Instance.Error(e.ToString()); PublishErrorCount++; timeSpanMiliSec = (DateTime.Now - start).TotalMilliseconds; return(false); } finally { CurrentlyPublished = null; } }