public static void PostTwitterMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.TwitterAccount _TwitterAccount, Domain.Socioboard.Models.User _user) { try { DatabaseRepository dbr = new DatabaseRepository(); if (_TwitterAccount != null) { if (_TwitterAccount.isActive) { if (schmessage.scheduleTime <= DateTime.UtcNow) { string twitterdata = ComposeTwitterMessage(schmessage.shareMessage, schmessage.profileId, schmessage.userId, schmessage.url, false, dbr, _TwitterAccount, schmessage, _user); if (!string.IsNullOrEmpty(twitterdata) && twitterdata != "Message not posted") { apiHitsCount++; } else if (twitterdata == "Message not posted") { _TwitterAccount.isActive = false; dbr.Update <TwitterAccount>(_TwitterAccount); } } } else { } } } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } }
public static List <Domain.Socioboard.Models.ScheduledMessage> DeleteSocialMessages(long socioqueueId, long userId, long GroupId, Helper.Cache _redisCache, Helper.AppSettings _appSeetings, Model.DatabaseRepository dbr) { string[] profileids = null; Domain.Socioboard.Models.ScheduledMessage ScheduledMessage = dbr.Find <Domain.Socioboard.Models.ScheduledMessage>(t => t.id == socioqueueId).FirstOrDefault(); ScheduledMessage.status = Domain.Socioboard.Enum.ScheduleStatus.Deleted; dbr.Update <Domain.Socioboard.Models.ScheduledMessage>(ScheduledMessage); List <Domain.Socioboard.Models.Groupprofiles> iMmemGroupprofiles = _redisCache.Get <List <Domain.Socioboard.Models.Groupprofiles> >(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + GroupId); List <Domain.Socioboard.Models.Groupprofiles> lstGroupprofiles = new List <Groupprofiles>(); if (iMmemGroupprofiles != null && iMmemGroupprofiles.Count > 0) { lstGroupprofiles = iMmemGroupprofiles; } else { lstGroupprofiles = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.groupId == GroupId).ToList(); _redisCache.Set(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + GroupId, lstGroupprofiles); } profileids = lstGroupprofiles.Select(t => t.profileId).ToArray(); List <Domain.Socioboard.Models.ScheduledMessage> lstScheduledMessage = dbr.Find <Domain.Socioboard.Models.ScheduledMessage>(t => profileids.Contains(t.profileId) && t.status == 0).ToList(); if (lstScheduledMessage != null && lstScheduledMessage.Count > 0) { _redisCache.Set(Domain.Socioboard.Consatants.SocioboardConsts.CacheScheduleMessage + GroupId, lstScheduledMessage); return(lstScheduledMessage); } else { return(null); } }
public static void PostLinkedInCompanyPageMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.LinkedinCompanyPage _LinkedinCompanyPage, Domain.Socioboard.Models.User _user) { try { DatabaseRepository dbr = new DatabaseRepository(); if (_LinkedinCompanyPage != null) { if (_LinkedinCompanyPage.IsActive) { if (schmessage.scheduleTime <= DateTime.UtcNow) { string linkedindata = ComposeLinkedInCompanyPagePost(schmessage.url, schmessage.userId, schmessage.shareMessage, _LinkedinCompanyPage.LinkedinPageId, dbr, _LinkedinCompanyPage, schmessage, _user); if (!string.IsNullOrEmpty(linkedindata)) { apiHitsCount++; } } } else { apiHitsCount = 0; } } } catch (Exception exs) { apiHitsCount = MaxapiHitsCount; } }
public static void PostLinkedInMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount) { try { DatabaseRepository dbr = new DatabaseRepository(); if (_LinkedInAccount != null && _LinkedInAccount.IsActive) { string linkedindata = ComposeLinkedInMessage(schmessage.url, schmessage.userId, schmessage.shareMessage, _LinkedInAccount.LinkedinUserId, schmessage.picUrl, _LinkedInAccount, dbr, schmessage); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
public static void PostLinkedInMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount) { try { DatabaseRepository dbr = new DatabaseRepository(); if (_LinkedInAccount.SchedulerUpdate.AddHours(1) <= DateTime.UtcNow) { if (_LinkedInAccount != null) { if (_LinkedInAccount.IsActive) { if (apiHitsCount < MaxapiHitsCount) { if (schmessage.scheduleTime <= DateTime.UtcNow) { string linkedindata = ComposeLinkedInMessage(schmessage.url, schmessage.userId, schmessage.shareMessage, _LinkedInAccount.LinkedinUserId, schmessage.picUrl, _LinkedInAccount, dbr, schmessage); if (!string.IsNullOrEmpty(linkedindata)) { apiHitsCount++; } } } else { apiHitsCount = 0; } } else { apiHitsCount = 0; } } } else { apiHitsCount = 0; } } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } }
public static void PostFacebookMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.Facebookaccounts _facebook, Domain.Socioboard.Models.User _user) { try { if (_facebook != null) { if (_facebook.IsActive) { if (schmessage.scheduleTime <= DateTime.UtcNow) { string data = ComposeMessage(_facebook.FbProfileType, _facebook.AccessToken, _facebook.FbUserId, schmessage.shareMessage, schmessage.profileId, schmessage.userId, schmessage.url, schmessage.link, schmessage, _user); } } } } catch (Exception ex) { } }
public static void PostTwitterMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.TwitterAccount _TwitterAccount) { try { DatabaseRepository dbr = new DatabaseRepository(); //if (_TwitterAccount.SchedulerUpdate.AddMinutes(15) <= DateTime.UtcNow) //{ if (_TwitterAccount != null) { if (_TwitterAccount.isActive) { //if (apiHitsCount < MaxapiHitsCount) //{ if (schmessage.scheduleTime <= DateTime.UtcNow) { string twitterdata = ComposeTwitterMessage(schmessage.shareMessage, schmessage.profileId, schmessage.userId, schmessage.url, false, dbr, _TwitterAccount, schmessage); if (!string.IsNullOrEmpty(twitterdata) && twitterdata != "Message not posted") { apiHitsCount++; } } //} //_TwitterAccount.lastUpdate = DateTime.UtcNow; //dbr.Update<Domain.Socioboard.Models.TwitterAccount>(_TwitterAccount); } else { // apiHitsCount = MaxapiHitsCount; } } //} //else //{ // apiHitsCount = 0; //} } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } }
public static string ComposeTwitterMessage(string message, string profileid, long userid, string picurl, bool isScheduled, DatabaseRepository dbr, Domain.Socioboard.Models.TwitterAccount TwitterAccount, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user) { bool rt = false; string ret = ""; string str = "Message posted"; if (message.Length > 140) { message = message.Substring(0, 135); } Domain.Socioboard.Models.TwitterAccount objTwitterAccount = TwitterAccount; oAuthTwitter OAuthTwt = new oAuthTwitter(AppSettings.twitterConsumerKey, AppSettings.twitterConsumerScreatKey, AppSettings.twitterRedirectionUrl); OAuthTwt.AccessToken = objTwitterAccount.oAuthToken; OAuthTwt.AccessTokenSecret = objTwitterAccount.oAuthSecret; OAuthTwt.TwitterScreenName = objTwitterAccount.twitterScreenName; OAuthTwt.TwitterUserId = objTwitterAccount.twitterUserId; Tweet twt = new Tweet(); if (!string.IsNullOrEmpty(picurl)) { try { PhotoUpload ph = new PhotoUpload(); string res = string.Empty; rt = ph.NewTweet(picurl, message, OAuthTwt, ref res); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } else { try { JArray post = twt.Post_Statuses_Update(OAuthTwt, message); ret = post[0]["id_str"].ToString(); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } if (!string.IsNullOrEmpty(ret) || rt == true) { schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; //schmessage.url = ret; dbr.Update <ScheduledMessage>(schmessage); Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Scheduled"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Successfully"; notify.ReadOrUnread = "Unread"; notify.UserId = userid; dbr.Add <Notifications>(notify); if (_user.scheduleSuccessUpdates) { string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } else { //if (_user.scheduleSuccessUpdates) //{ // string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); //} } } else { str = "Message not posted"; Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Failed"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Failed"; notify.ReadOrUnread = "Unread"; notify.UserId = userid; dbr.Add <Notifications>(notify); if (_user.scheduleFailureUpdates) { string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } else { //if (_user.scheduleFailureUpdates) //{ // string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); //} } } return(str); }
public static string ComposeTwitterMessage(string message, string profileid, long userid, string picurl, bool isScheduled, DatabaseRepository dbr, Domain.Socioboard.Models.TwitterAccount TwitterAccount, Domain.Socioboard.Models.ScheduledMessage schmessage) { bool rt = false; string ret = ""; string str = "Message posted"; Domain.Socioboard.Models.TwitterAccount objTwitterAccount = TwitterAccount; oAuthTwitter OAuthTwt = new oAuthTwitter(Helper.AppSettings.twitterConsumerKey, Helper.AppSettings.twitterConsumerScreatKey, Helper.AppSettings.twitterRedirectionUrl); OAuthTwt.AccessToken = objTwitterAccount.oAuthToken; OAuthTwt.AccessTokenSecret = objTwitterAccount.oAuthSecret; OAuthTwt.TwitterScreenName = objTwitterAccount.twitterScreenName; OAuthTwt.TwitterUserId = objTwitterAccount.twitterUserId; Tweet twt = new Tweet(); if (!string.IsNullOrEmpty(picurl)) { try { PhotoUpload ph = new PhotoUpload(); string res = string.Empty; rt = ph.NewTweet(picurl, message, OAuthTwt, ref res); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } else { try { JArray post = twt.Post_Statuses_Update(OAuthTwt, message); ret = post[0]["id_str"].ToString(); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } if (!string.IsNullOrEmpty(ret) || rt == true) { schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; schmessage.url = ret; dbr.Update <ScheduledMessage>(schmessage); } else { str = "Message not posted"; } return(str); }
public static string ComposeLinkedInCompanyPagePost(string ImageUrl, long userid, string comment, string LinkedinPageId, Model.DatabaseRepository dbr, Domain.Socioboard.Models.LinkedinCompanyPage objLinkedinCompanyPage, Domain.Socioboard.Models.ScheduledMessage schmessage) { string json = ""; Domain.Socioboard.Models.LinkedinCompanyPage objlicompanypage = objLinkedinCompanyPage; oAuthLinkedIn Linkedin_oauth = new oAuthLinkedIn(); //Linkedin_oauth.ConsumerKey = "81k55eukagnqfa"; //Linkedin_oauth.ConsumerSecret = "d9rqHEf7ewdSbsF1"; Linkedin_oauth.ConsumerKey = "754ysxdp72ulk5"; Linkedin_oauth.ConsumerSecret = "vbU52SjK7xS6cT8H"; Linkedin_oauth.Verifier = objlicompanypage.OAuthVerifier; Linkedin_oauth.TokenSecret = objlicompanypage.OAuthSecret; Linkedin_oauth.Token = objlicompanypage.OAuthToken; Linkedin_oauth.Id = objlicompanypage.LinkedinPageId; Linkedin_oauth.FirstName = objlicompanypage.LinkedinPageName; Company company = new Company(); if (string.IsNullOrEmpty(ImageUrl)) { json = company.SetPostOnPage(Linkedin_oauth, objlicompanypage.LinkedinPageId, comment); } else { json = company.SetPostOnPageWithImage(Linkedin_oauth, objlicompanypage.LinkedinPageId, ImageUrl, comment); } if (!string.IsNullOrEmpty(json)) { apiHitsCount++; schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; schmessage.url = json; dbr.Update <ScheduledMessage>(schmessage); return("posted"); } else { apiHitsCount = MaxapiHitsCount; json = "Message not posted"; return(json); } }
public static string ComposeLinkedInMessage(string ImageUrl, long userid, string comment, string ProfileId, string imagepath, Domain.Socioboard.Models.LinkedInAccount _objLinkedInAccount, Model.DatabaseRepository dbr, Domain.Socioboard.Models.ScheduledMessage schmessage) { string json = ""; Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount = _objLinkedInAccount; oAuthLinkedIn _oauth = new oAuthLinkedIn(); _oauth.ConsumerKey = Helper.AppSettings.LinkedinApiKey; _oauth.ConsumerSecret = Helper.AppSettings.LinkedinSecretKey; _oauth.Token = _LinkedInAccount.OAuthToken; string PostUrl = "https://api.linkedin.com/v1/people/~/shares?format=json"; if (string.IsNullOrEmpty(ImageUrl)) { json = _oauth.LinkedProfilePostWebRequest("POST", PostUrl, comment); } else { json = _oauth.LinkedProfilePostWebRequestWithImage("POST", PostUrl, comment, ImageUrl); } if (!string.IsNullOrEmpty(json)) { apiHitsCount++; schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; schmessage.url = json; dbr.Update <ScheduledMessage>(schmessage); return("posted"); } else { apiHitsCount = MaxapiHitsCount; json = "Message not posted"; return(json); } }
public static string ComposeLinkedInMessage(string ImageUrl, long userid, string comment, string ProfileId, string imagepath, Domain.Socioboard.Models.LinkedInAccount _objLinkedInAccount, Model.DatabaseRepository dbr, Domain.Socioboard.Models.ScheduledMessage schmessage) { string json = ""; Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount = _objLinkedInAccount; oAuthLinkedIn _oauth = new oAuthLinkedIn(); //_oauth.ConsumerKey = "81k55eukagnqfa"; //_oauth.ConsumerSecret = "d9rqHEf7ewdSbsF1"; _oauth.ConsumerKey = "754ysxdp72ulk5"; _oauth.ConsumerSecret = "vbU52SjK7xS6cT8H"; _oauth.Token = _LinkedInAccount.OAuthToken; string PostUrl = "https://api.linkedin.com/v1/people/~/shares?format=json"; if (string.IsNullOrEmpty(ImageUrl)) { json = _oauth.LinkedProfilePostWebRequest("POST", PostUrl, comment); } else { json = _oauth.LinkedProfilePostWebRequestWithImage("POST", PostUrl, comment, imagepath); } if (!string.IsNullOrEmpty(json)) { apiHitsCount++; schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; schmessage.url = json; dbr.Add <ScheduledMessage>(schmessage); return("posted"); } else { apiHitsCount = MaxapiHitsCount; json = "Message not posted"; return(json); } }
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.ScheduledMessage 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(); } schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; //schmessage.url = ret; dbr.Update <ScheduledMessage>(schmessage); Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Scheduled"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Successfully"; notify.ReadOrUnread = "Unread"; notify.UserId = userId; dbr.Add <Notifications>(notify); if (_user.scheduleSuccessUpdates) { string sucResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } else { if (_user.scheduleSuccessUpdates) { string sucResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Failed"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Failed"; notify.ReadOrUnread = "Unread"; notify.UserId = userId; dbr.Add <Notifications>(notify); if (_user.scheduleFailureUpdates) { string falResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } else { if (_user.scheduleFailureUpdates) { string falResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } } return(ret); }
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.ScheduledMessage schmessage) { 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; } 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 { 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; link = links; } if (link.Contains("http://")) { string links = getBetween(link + "###", "http", "###"); links = "http" + links; 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(); } schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; //schmessage.url = ret; dbr.Update <ScheduledMessage>(schmessage); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } return(ret); }
public static string ComposeTwitterMessage(string message, string profileid, long userid, string picurl, bool isScheduled, DatabaseRepository dbr, Domain.Socioboard.Models.TwitterAccount TwitterAccount, Domain.Socioboard.Models.ScheduledMessage schmessage) { bool rt = false; string ret = ""; string str = "Message posted"; if (message.Length > 140) { message = message.Substring(0, 135); } Domain.Socioboard.Models.TwitterAccount objTwitterAccount = TwitterAccount; // oAuthTwitter OAuthTwt = new oAuthTwitter("MbOQl85ZcvRGvp3kkOOJBlbFS", "GF0UIXnTAX28hFhN1ISNf3tURHARZdKWlZrsY4PlHm9A4llYjZ", "http://serv1.socioboard.com/TwitterManager/Twitter"); oAuthTwitter OAuthTwt = new oAuthTwitter("h4FT0oJ46KBBMwbcifqZMw", "yfowGI2g21E2mQHjtHjUvGqkfbI7x26WDCvjiSZOjas", "https://www.socioboard.com/TwitterManager/Twitter"); OAuthTwt.AccessToken = objTwitterAccount.oAuthToken; OAuthTwt.AccessTokenSecret = objTwitterAccount.oAuthSecret; OAuthTwt.TwitterScreenName = objTwitterAccount.twitterScreenName; OAuthTwt.TwitterUserId = objTwitterAccount.twitterUserId; Tweet twt = new Tweet(); if (!string.IsNullOrEmpty(picurl)) { try { PhotoUpload ph = new PhotoUpload(); string res = string.Empty; rt = ph.NewTweet(picurl, message, OAuthTwt, ref res); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } else { try { JArray post = twt.Post_Statuses_Update(OAuthTwt, message); ret = post[0]["id_str"].ToString(); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } if (!string.IsNullOrEmpty(ret) || rt == true) { schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; schmessage.url = ret; dbr.Update <ScheduledMessage>(schmessage); } else { str = "Message not posted"; } return(str); }
public static string ComposeLinkedInMessage(string ImageUrl, long userid, string comment, string ProfileId, string imagepath, Domain.Socioboard.Models.LinkedInAccount _objLinkedInAccount, Model.DatabaseRepository dbr, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user) { string json = ""; var img = ""; Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount = _objLinkedInAccount; oAuthLinkedIn _oauth = new oAuthLinkedIn(); _oauth.ConsumerKey = AppSettings.LinkedinApiKey; _oauth.ConsumerSecret = AppSettings.LinkedinSecretKey; _oauth.Token = _LinkedInAccount.OAuthToken; string PostUrl = "https://api.linkedin.com/v1/people/~/shares?format=json"; if (string.IsNullOrEmpty(ImageUrl)) { json = _oauth.LinkedProfilePostWebRequest("POST", PostUrl, comment); } else { var client = new ImgurClient(AppSettings.imgurclietId, AppSettings.imgurclietSecret); var endpoint = new ImageEndpoint(client); IImage image; using (var fs = new FileStream(imagepath, FileMode.Open)) { image = endpoint.UploadImageStreamAsync(fs).GetAwaiter().GetResult(); } var imgs = image.Link; json = _oauth.LinkedProfilePostWebRequestWithImage("POST", PostUrl, comment, imgs); } if (!string.IsNullOrEmpty(json)) { apiHitsCount++; schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; schmessage.url = json; dbr.Update <ScheduledMessage>(schmessage); Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Scheduled"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Successfully"; notify.ReadOrUnread = "Unread"; notify.UserId = userid; dbr.Add <Notifications>(notify); if (_user.scheduleSuccessUpdates) { string sucResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } return("posted"); } else { if (_user.scheduleSuccessUpdates) { string sucResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } return("posted"); } } else { apiHitsCount = MaxapiHitsCount; json = "Message not posted"; Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Failed"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Failed"; notify.ReadOrUnread = "Unread"; notify.UserId = userid; dbr.Add <Notifications>(notify); if (_user.scheduleFailureUpdates) { string falResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } return(json); } else { if (_user.scheduleFailureUpdates) { string falResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } return(json); } } }
public static string ComposeLinkedInCompanyPagePost(string ImageUrl, long userid, string comment, string LinkedinPageId, Model.DatabaseRepository dbr, Domain.Socioboard.Models.LinkedinCompanyPage objLinkedinCompanyPage, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user) { string json = ""; Domain.Socioboard.Models.LinkedinCompanyPage objlicompanypage = objLinkedinCompanyPage; oAuthLinkedIn Linkedin_oauth = new oAuthLinkedIn(); Linkedin_oauth.ConsumerKey = AppSettings.LinkedinApiKey; Linkedin_oauth.ConsumerSecret = AppSettings.LinkedinSecretKey; Linkedin_oauth.Verifier = objlicompanypage.OAuthVerifier; Linkedin_oauth.TokenSecret = objlicompanypage.OAuthSecret; Linkedin_oauth.Token = objlicompanypage.OAuthToken; Linkedin_oauth.Id = objlicompanypage.LinkedinPageId; Linkedin_oauth.FirstName = objlicompanypage.LinkedinPageName; Company company = new Company(); if (string.IsNullOrEmpty(ImageUrl)) { json = company.SetPostOnPage(Linkedin_oauth, objlicompanypage.LinkedinPageId, comment); } else { var client = new ImgurClient(AppSettings.imgurclietId, AppSettings.imgurclietSecret); var endpoint = new ImageEndpoint(client); IImage image; using (var fs = new FileStream(ImageUrl, FileMode.Open)) { image = endpoint.UploadImageStreamAsync(fs).GetAwaiter().GetResult(); } var imgs = image.Link; json = company.SetPostOnPageWithImage(Linkedin_oauth, objlicompanypage.LinkedinPageId, imgs, comment); } if (!string.IsNullOrEmpty(json)) { apiHitsCount++; schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; schmessage.url = json; dbr.Update <ScheduledMessage>(schmessage); Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Scheduled"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Successfully"; notify.ReadOrUnread = "Unread"; notify.UserId = userid; dbr.Add <Notifications>(notify); if (_user.scheduleSuccessUpdates) { string sucResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } return("posted"); } else { if (_user.scheduleSuccessUpdates) { string sucResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } return("posted"); } } else { apiHitsCount = MaxapiHitsCount; json = "Message not posted"; Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Failed"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Failed"; notify.ReadOrUnread = "Unread"; notify.UserId = userid; dbr.Add <Notifications>(notify); if (_user.scheduleFailureUpdates) { string falResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } return(json); } else { if (_user.scheduleFailureUpdates) { string falResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } return(json); } } }
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.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user) { string ret = ""; var dbr = new DatabaseRepository(); try { var pageAccessToken = FacebookApiHelper.GetPageAccessToken(fbUserId, accessToken, string.Empty); var response = FacebookApiHelper.PublishPostOnPage(pageAccessToken, fbUserId, message, imagePath, link); var isPublished = response.Contains("id"); // if (isPublished) { schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; dbr.Update(schmessage); var notify = new Notifications(); var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (notifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Scheduled"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Successfully"; notify.ReadOrUnread = "Unread"; notify.UserId = userId; dbr.Add(notify); if (_user.scheduleSuccessUpdates) { var sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } } } catch (Exception ex) { schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.error; dbr.Update(schmessage); apiHitsCount = MaxapiHitsCount; var notify = new Notifications(); var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (notifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Failed"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Failed"; notify.ReadOrUnread = "Unread"; notify.UserId = userId; dbr.Add(notify); if (_user.scheduleFailureUpdates) { var falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } } return(ret); }