public string ShareFeed(string fbAccesstoken, string FeedId, string pageId, string message, string fbUserId, string FbPageName) { string ret = ""; try { MongoRepository mongorepo = new Helper.MongoRepository("SharethonPagePost"); Domain.Socioboard.Models.Mongo.SharethonPagePost objshrpost = new Domain.Socioboard.Models.Mongo.SharethonPagePost(); string link = "https://www.facebook.com/" + pageId + "/posts/" + FeedId; FacebookClient fb = new FacebookClient(); fb.AccessToken = fbAccesstoken; var args = new Dictionary <string, object>(); args["link"] = link; var ret1 = mongorepo.Find <Domain.Socioboard.Models.Mongo.SharethonPagePost>(t => t.Facebookaccountid == fbUserId && t.Facebookpageid == pageId && t.PostId == FeedId); var task = Task.Run(async() => { return(await ret1); }); int count = task.Result.Count; try { //if (pageapiHitsCount < pageMaxapiHitsCount) //{ dynamic output = fb.Post("v2.1/" + fbUserId + "/feed", args); string feed_id = output["id"].ToString(); if (!string.IsNullOrEmpty(feed_id)) { pageapiHitsCount++; } if (count < 1) { objshrpost.Id = ObjectId.GenerateNewId(); objshrpost.Facebookaccountid = fbUserId; objshrpost.Facebookpageid = pageId; objshrpost.PostId = FeedId; objshrpost.PostedTime = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow); objshrpost.Facebookpagename = FbPageName; mongorepo.Add <Domain.Socioboard.Models.Mongo.SharethonPagePost>(objshrpost); ret = "success"; } // } } catch (Exception ex) { Console.Write(ex.StackTrace); pageapiHitsCount = pageMaxapiHitsCount; return(""); } // } } catch (Exception ex) { } return(ret); }
public void ShceduleConetentStudioFeeds(object o) { MongoRepository mongorepo = new Helper.MongoRepository("ContentFeedsShareathon"); int pageapiHitsCount; object[] arr = o as object[]; ContentStudioShareathonIdData shareathon = (ContentStudioShareathonIdData)arr[0]; Model.DatabaseRepository dbr = (Model.DatabaseRepository)arr[1]; MongoRepository _ShareathonRepository = (MongoRepository)arr[2]; string[] ids = shareathon.FbPageId.Split(','); foreach (string id in ids) { try { pageapiHitsCount = 0; // List<ContentFeedsShareathon> lstcontent = new List<ContentFeedsShareathon>(); Domain.Socioboard.Models.Facebookaccounts lstFbAcc = dbr.Single <Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == id); Domain.Socioboard.Models.Facebookaccounts fbAcc = dbr.Single <Domain.Socioboard.Models.Facebookaccounts>(t => t.UserId == lstFbAcc.UserId); Domain.Socioboard.Models.Facebookaccounts facebookPage = null; MongoRepository mongoshare = new Helper.MongoRepository("ContentFeedsShareathon"); if (lstFbAcc != null) { facebookPage = lstFbAcc; } if (facebookPage != null) { if (pageapiHitsCount < pageMaxapiHitsCount) { // var lstcontent = mongorepo.Find<ContentFeedsShareathon>(t => t.FbPageId == id && t.UserId == fbAcc.UserId && t.status == 0); var resultshare = mongorepo.Find <ContentFeedsShareathon>(t => t.FbPageId == shareathon.FbPageId && t.Status == false); var task = Task.Run(async() => { return(await resultshare); }); int count = task.Result.Count; var feedsData = task.Result.ToList(); if (facebookPage.contenetShareathonUpdate.AddHours(1) <= DateTime.UtcNow) { if (count != 0) { pageapiHitsCount++; //!shareathon.FbPageId.Equals(obj.FbPageId) && !shareathon.postId.Equals(obj.postId) foreach (var obj in feedsData) { try { DateTime dt = SBHelper.ConvertFromUnixTimestamp(obj.lastsharestamp); dt = dt.AddMinutes(obj.Timeintervalminutes); if ((obj.Status == false && SBHelper.ConvertToUnixTimestamp(dt) <= SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow))) { string ret = Helper.FBPostContentFeeds.FacebookComposeMessageRss(obj.title, facebookPage.AccessToken, facebookPage.FbUserId, "", obj.postUrl, obj.postId); if (ret == "Messages Posted Successfully") { obj.Status = true; shareathon.Status = true; FilterDefinition <BsonDocument> filter = new BsonDocument("strId", obj.strId); var update = Builders <BsonDocument> .Update.Set("Status", true); mongorepo.Update <Domain.Socioboard.Models.Mongo.ContentFeedsShareathon>(update, filter); FilterDefinition <BsonDocument> filterId = new BsonDocument("strId", shareathon.strId); var updateId = Builders <BsonDocument> .Update.Set("Status", true); mongorepo.Update <Domain.Socioboard.Models.Mongo.ContentStudioShareathonIdData>(updateId, filterId); } if (!string.IsNullOrEmpty(ret)) { Thread.Sleep(1000 * 60 * shareathon.Timeintervalminutes); } } } catch { pageapiHitsCount = pageMaxapiHitsCount; } } fbAcc.contenetShareathonUpdate = DateTime.UtcNow; facebookPage.contenetShareathonUpdate = DateTime.UtcNow; dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(fbAcc); dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(facebookPage); } else { FilterDefinition <BsonDocument> filter = new BsonDocument("strId", shareathon.strId); var update = Builders <BsonDocument> .Update.Set("Status", false); _ShareathonRepository.Update <Domain.Socioboard.Models.Mongo.ContentFeedsShareathon>(update, filter); } } else { pageapiHitsCount = 0; } } } } catch { pageapiHitsCount = pageMaxapiHitsCount; } } }
public void ShareFeedonGroup(string fbAccesstoken, string FeedId, string pageId, string message, string fbgroupId, int time, string faceaccountId, double lastupdatetime, string Facebooknameid) { List <string> lstPost = new List <string>(); int lstCout = 0; string[] feedid = FeedId.TrimEnd(',').Split(','); string[] grpid = Facebooknameid.TrimEnd(',').Split(','); Random r = new Random(); int length = feedid.Length; Domain.Socioboard.Models.Mongo.SharethonGroupPost objshrgrp = new Domain.Socioboard.Models.Mongo.SharethonGroupPost(); MongoRepository mongorepo = new Helper.MongoRepository("SharethonGroupPost"); while (length >= lstCout) { int i = r.Next(0, length - 1); if (!lstPost.Contains(feedid[i])) { lstPost.Add(feedid[i]); lstCout++; foreach (var item in grpid) { string[] grpdata = Regex.Split(item, "<:>"); var ret1 = mongorepo.Find <Domain.Socioboard.Models.Mongo.SharethonGroupPost>(t => t.Facebookgroupid == grpdata[1] && t.PostId == FeedId[i].ToString()); var task = Task.Run(async() => { return(await ret1); }); int count = task.Result.Count; string link = "https://www.facebook.com/" + pageId + "/posts/" + feedid[i]; FacebookClient fb = new FacebookClient(); fb.AccessToken = fbAccesstoken; var args = new Dictionary <string, object>(); args["link"] = link; try { dynamic output = fb.Post("v2.7/" + grpdata[1] + "/feed", args); try { string feed_id = output["id"].ToString(); if (!string.IsNullOrEmpty(feed_id)) { groupapiHitsCount++; } } catch (Exception) { groupapiHitsCount = groupMaxapiHitsCount; } if (count < 1) { objshrgrp.Id = ObjectId.GenerateNewId(); objshrgrp.Facebookaccountid = faceaccountId; objshrgrp.Facebookgroupid = grpdata[1]; objshrgrp.Facebookgroupname = grpdata[0]; objshrgrp.PostId = feedid[i]; objshrgrp.PostedTime = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow); mongorepo.Add <Domain.Socioboard.Models.Mongo.SharethonGroupPost>(objshrgrp); } } catch (Exception ex) { groupapiHitsCount = groupMaxapiHitsCount; } } Thread.Sleep(1000 * 50); } Thread.Sleep(1000 * 60 * time); } }
public static void PostTwitterMessage(Domain.Socioboard.Models.Mongo.FacebookPageFeedShare fbPagefeedshare, Domain.Socioboard.Models.TwitterAccount _TwitterAccount, Domain.Socioboard.Models.LinkedInAccount _LinkedinAcc, Domain.Socioboard.Models.User _user) { try { DatabaseRepository dbr = new DatabaseRepository(); MongoRepository _mongofbpostdata = new Helper.MongoRepository("MongoFacebookFeed"); MongoRepository mongofacebooksharedata = new Helper.MongoRepository("FacebookPageFeedShare"); var result = _mongofbpostdata.Find <Domain.Socioboard.Models.Mongo.MongoFacebookFeed>(t => t.ProfileId == fbPagefeedshare.pageId && t.shareStatus == false); var task = Task.Run(async() => { return(await result); }); IList <Domain.Socioboard.Models.Mongo.MongoFacebookFeed> lstfbpagefeeds = task.Result.ToList(); foreach (var item in lstfbpagefeeds) { string twitterdata = null; string linkedindata = null; try { if (fbPagefeedshare.scheduleTime <= DateTime.UtcNow) { if (_TwitterAccount != null) { twitterdata = ComposeTwitterMessage(item.FeedDescription, item.ProfileId, fbPagefeedshare.userId, item.Picture, false, dbr, _TwitterAccount, _user); } else { linkedindata = ComposeLinkedInMessage(item.Picture, fbPagefeedshare.userId, item.FeedDescription, item.ProfileId, "", _LinkedinAcc, dbr, _user); } if (!string.IsNullOrEmpty(twitterdata) && twitterdata != "feed has not posted" || !string.IsNullOrEmpty(linkedindata) && linkedindata != "feed has not posted") { apiHitsCount++; item.shareStatus = true; fbPagefeedshare.lastsharestamp = DateTime.UtcNow; FilterDefinition <BsonDocument> filter = new BsonDocument("FeedId", item.FeedId); var updatemongo = Builders <BsonDocument> .Update.Set("shareStatus", true); _mongofbpostdata.Update <MongoFacebookFeed>(updatemongo, filter); } else if (twitterdata == "Message not posted") { } } } catch (Exception ex) { } } FilterDefinition <BsonDocument> filters = new BsonDocument("strId", fbPagefeedshare.strId); //new BsonDocument("FeedId", item.FeedId); var updatefbshare = Builders <BsonDocument> .Update.Set("status", Domain.Socioboard.Enum.RealTimeShareFeedStatus.running).Set("scheduleTime", DateTime.UtcNow); mongofacebooksharedata.Update <FacebookPageFeedShare>(updatefbshare, filters); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } }