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; } }
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 static string ComposeMessage(Domain.Socioboard.Enum.FbProfileType profiletype, string accessToken, string fbUserId, string message, string profileId, long userId, string imagePath, string link, Domain.Socioboard.Models.Mongo.SavedFeedsManagement schmessage, Domain.Socioboard.Models.User _user) { string ret = ""; DatabaseRepository dbr = new DatabaseRepository(); FacebookClient fb = new FacebookClient(); fb.AccessToken = accessToken; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; var args = new Dictionary <string, object>(); if (profiletype == Domain.Socioboard.Enum.FbProfileType.FacebookProfile) { args["privacy"] = FbUser.SetPrivacy("Public", fb, profileId); } try { if (string.IsNullOrEmpty(link)) { if (!string.IsNullOrEmpty(imagePath)) { if (!string.IsNullOrEmpty(message)) { args["message"] = message; } if (!imagePath.Contains("mp4") && !imagePath.Contains("mov") && !imagePath.Contains("mpeg") && !imagePath.Contains("wmv") && !imagePath.Contains("avi") && !imagePath.Contains("flv") && !imagePath.Contains("3gp")) { Uri u = new Uri(imagePath); string filename = string.Empty; string extension = string.Empty; extension = System.IO.Path.GetExtension(u.AbsolutePath).Replace(".", ""); var media = new FacebookMediaObject { FileName = "filename", ContentType = "image/" + extension }; var webClient = new WebClient(); byte[] img = webClient.DownloadData(imagePath); media.SetValue(img); args["source"] = media; ret = fb.Post("v2.7/" + fbUserId + "/photos", args).ToString(); } else { Uri u = new Uri(imagePath); string filename = string.Empty; string extension = string.Empty; filename = imagePath.Substring(imagePath.IndexOf("get?id=") + 7); if (!string.IsNullOrWhiteSpace(filename)) { extension = filename.Substring(filename.IndexOf(".") + 1); } var media = new FacebookMediaObject { FileName = filename, ContentType = "video/" + extension }; //byte[] img = System.IO.File.ReadAllBytes(imagepath); var webClient = new WebClient(); byte[] img = webClient.DownloadData(imagePath); media.SetValue(img); args["title"] = message; args["description"] = message; args["source"] = media; ret = fb.Post("v2.7/" + fbUserId + "/videos", args).ToString();//v2.1 } } else { args["message"] = message; ret = fb.Post("v2.7/" + fbUserId + "/feed", args).ToString(); } } else { if (!string.IsNullOrEmpty(link)) { if (message.Contains("https://") || message.Contains("http://")) { link = message; if (link.Contains("https://")) { string links = getBetween(link + "###", "https", "###"); links = "https" + links; try { link = links.Split(' ')[0].ToString(); } catch (Exception) { link = links; } } if (link.Contains("http://")) { string links = getBetween(link + "###", "http", "###"); links = "http" + links; try { link = links.Split(' ')[0].ToString(); } catch (Exception) { link = links; } } message = message.Replace(link, ""); args["message"] = message; } else { args["message"] = message; } } else { args["message"] = message; } if (!string.IsNullOrEmpty(link)) { args["link"] = link; } if (!string.IsNullOrEmpty(imagePath)) { args["picture"] = imagePath.Replace("&", "&"); } ret = fb.Post("v2.7/" + fbUserId + "/feed", args).ToString(); } MongoRepository mongorepo = new Helper.MongoRepository("SavedFeedsComments"); schmessage.status = Domain.Socioboard.Enum.ScheduledStatusFeedsManager.Published; FilterDefinition <BsonDocument> filterIds = new BsonDocument("strId", schmessage.strId); var updatetime = Builders <BsonDocument> .Update.Set("status", schmessage.status); mongorepo.Update <Domain.Socioboard.Models.Mongo.SavedFeedsComments>(updatetime, filterIds); } catch (Exception ex) { } return(ret); }