public IActionResult AddProfileToGroup(string profileId, long groupId, long userId, Domain.Socioboard.Enum.SocialProfileType profileType) { DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv); List <Domain.Socioboard.Models.Groupprofiles> lstGroupProfiles = GroupProfilesRepository.getGroupProfiles(groupId, _redisCache, dbr); if (lstGroupProfiles.Where(t => t.profileId.Equals(profileId)).Count() > 0) { return(BadRequest("profile already added")); } else { Domain.Socioboard.Models.Groups grp = dbr.Find <Domain.Socioboard.Models.Groups>(t => t.id == groupId).FirstOrDefault(); if (grp == null) { return(BadRequest("Invalid groupId")); } else { Domain.Socioboard.Models.Groupprofiles grpProfile = new Domain.Socioboard.Models.Groupprofiles(); if (profileType == Domain.Socioboard.Enum.SocialProfileType.Facebook || profileType == Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage || profileType == Domain.Socioboard.Enum.SocialProfileType.FacebookPublicPage) { Domain.Socioboard.Models.Facebookaccounts fbAcc = Repositories.FacebookRepository.getFacebookAccount(profileId, _redisCache, dbr); if (fbAcc == null) { return(BadRequest("Invalid profileId")); } if (fbAcc.UserId != userId) { return(BadRequest("profile is added by other user")); } grpProfile.profileName = fbAcc.FbUserName; grpProfile.profileOwnerId = userId; grpProfile.profilePic = "http://graph.facebook.com/" + fbAcc.FbUserId + "/picture?type=small"; grpProfile.profileType = profileType; } else if (profileType == Domain.Socioboard.Enum.SocialProfileType.Twitter) { Domain.Socioboard.Models.TwitterAccount twtAcc = Repositories.TwitterRepository.getTwitterAccount(profileId, _redisCache, dbr); if (twtAcc == null) { return(BadRequest("Invalid profileId")); } if (twtAcc.userId != userId) { return(BadRequest("profile is added by other user")); } grpProfile.profileName = twtAcc.twitterScreenName; grpProfile.profileOwnerId = userId; grpProfile.profilePic = twtAcc.profileImageUrl; grpProfile.profileType = Domain.Socioboard.Enum.SocialProfileType.Twitter; } else if (profileType == Domain.Socioboard.Enum.SocialProfileType.GPlus) { Domain.Socioboard.Models.Googleplusaccounts gplusAccount = Repositories.GplusRepository.getGPlusAccount(profileId, _redisCache, dbr); if (gplusAccount == null) { return(BadRequest("Invalid ProfileId")); } if (gplusAccount.UserId != userId) { return(BadRequest("profile is added by other user")); } grpProfile.profileName = gplusAccount.GpUserName; grpProfile.profileOwnerId = userId; grpProfile.profilePic = gplusAccount.GpProfileImage; } else if (profileType == Domain.Socioboard.Enum.SocialProfileType.GoogleAnalytics) { Domain.Socioboard.Models.GoogleAnalyticsAccount gplusAccount = Repositories.GplusRepository.getGAAccount(profileId, _redisCache, dbr); if (gplusAccount == null) { return(BadRequest("Invalid ProfileId")); } if (gplusAccount.UserId != userId) { return(BadRequest("profile is added by other user")); } grpProfile.profileName = gplusAccount.GaProfileName; grpProfile.profileOwnerId = userId; grpProfile.profilePic = gplusAccount.ProfilePicUrl; } else if (profileType == Domain.Socioboard.Enum.SocialProfileType.Instagram) { Domain.Socioboard.Models.Instagramaccounts _Instagramaccounts = Repositories.InstagramRepository.getInstagramAccount(profileId, _redisCache, dbr); if (_Instagramaccounts == null) { return(BadRequest("Invalid ProfileId")); } if (_Instagramaccounts.UserId != userId) { return(BadRequest("profile is added by other user")); } grpProfile.profileName = _Instagramaccounts.InsUserName; grpProfile.profileOwnerId = userId; grpProfile.profilePic = _Instagramaccounts.ProfileUrl; } else if (profileType == Domain.Socioboard.Enum.SocialProfileType.LinkedIn) { Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount = Repositories.LinkedInAccountRepository.getLinkedInAccount(profileId, _redisCache, dbr); if (_LinkedInAccount == null) { return(BadRequest("Invalid ProfileId")); } if (_LinkedInAccount.UserId != userId) { return(BadRequest("profile is added by other user")); } grpProfile.profileName = _LinkedInAccount.LinkedinUserName; grpProfile.profileOwnerId = userId; grpProfile.profilePic = _LinkedInAccount.ProfileImageUrl; } else if (profileType == Domain.Socioboard.Enum.SocialProfileType.LinkedInComapanyPage) { Domain.Socioboard.Models.LinkedinCompanyPage _LinkedInAccount = Repositories.LinkedInAccountRepository.getLinkedinCompanyPage(profileId, _redisCache, dbr); if (_LinkedInAccount == null) { return(BadRequest("Invalid ProfileId")); } if (_LinkedInAccount.UserId != userId) { return(BadRequest("profile is added by other user")); } grpProfile.profileName = _LinkedInAccount.LinkedinPageName; grpProfile.profileOwnerId = userId; grpProfile.profilePic = _LinkedInAccount.LogoUrl; } else if (profileType == Domain.Socioboard.Enum.SocialProfileType.YouTube) { Domain.Socioboard.Models.YoutubeChannel _YoutubeChannel = Repositories.GplusRepository.getYTChannel(profileId, _redisCache, dbr); if (_YoutubeChannel == null) { return(BadRequest("Invalid ProfileId")); } if (_YoutubeChannel.UserId != userId) { return(BadRequest("profile is added by other user")); } grpProfile.profileName = _YoutubeChannel.YtubeChannelName; grpProfile.profileOwnerId = userId; grpProfile.profilePic = _YoutubeChannel.ChannelpicUrl; } if (profileType == Domain.Socioboard.Enum.SocialProfileType.Pinterest) { Domain.Socioboard.Models.PinterestAccount pinAcc = dbr.Find <Domain.Socioboard.Models.PinterestAccount>(t => t.username.Equals(profileId)).FirstOrDefault(); if (pinAcc == null) { return(BadRequest("Invalid profileId")); } if (pinAcc.userid != userId) { return(BadRequest("profile is added by other user")); } grpProfile.profileName = pinAcc.firstname + " " + pinAcc.lastname; grpProfile.profileOwnerId = userId; grpProfile.profilePic = pinAcc.profileimgaeurl; grpProfile.profileType = profileType; } grpProfile.entryDate = DateTime.UtcNow; grpProfile.groupId = grp.id; grpProfile.profileId = profileId; grpProfile.profileType = profileType; dbr.Add <Domain.Socioboard.Models.Groupprofiles>(grpProfile); //codes to clear cache _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId); //end codes to clear cache return(Ok("Added Successfully")); } } }
public static string ParseXMLFeedUrl(string TextUrl, Domain.Socioboard.Enum.SocialProfileType profiletype, string profileid, long userId, string profileName, string profileImageUrl, Domain.Socioboard.Models.RssFeedUrl rssobj, Helper.AppSettings _appSettings) { MongoRepository _RssFeedRepository = new MongoRepository("RssFeed", _appSettings); MongoRepository _RssRepository = new MongoRepository("Rss", _appSettings); var rets = _RssRepository.Find <Domain.Socioboard.Models.Mongo.Rss>(t => t.RssFeedUrl.Equals(TextUrl) && t.ProfileId.Contains(profileid) && t.ProfileType == profiletype && t.UserId.Equals(userId)); var tasks = Task.Run(async() => { return(await rets); }); int counts = tasks.Result.Count; if (counts < 1) { Domain.Socioboard.Models.Mongo.Rss _Rss = new Domain.Socioboard.Models.Mongo.Rss(); _Rss.Id = ObjectId.GenerateNewId(); _Rss.strId = ObjectId.GenerateNewId().ToString(); _Rss.RssFeedUrl = TextUrl; _Rss.ProfileType = profiletype; _Rss.ProfileId = profileid; _Rss.UserId = userId; _Rss.ProfileImageUrl = profileImageUrl; _Rss.ProfileName = profileName; _Rss.rssFeedUrl = rssobj; _Rss.CreatedOn = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); try { _RssRepository.Add(_Rss); } catch (Exception ex) { } } try { XmlDocument xmlDoc = new XmlDocument(); // Create an XML document object xmlDoc.Load(TextUrl); string datevalue = null; string urlvalue = null; var abc = xmlDoc.DocumentElement.GetElementsByTagName("sitemap"); var urls = xmlDoc.DocumentElement.GetElementsByTagName("url"); if (abc.Count != 0) { try { foreach (XmlElement siteval in abc) { Domain.Socioboard.Models.Mongo.RssFeed objRssFeeds = new Domain.Socioboard.Models.Mongo.RssFeed(); try { urlvalue = siteval.ChildNodes[0].InnerText; } catch (Exception ex) { urlvalue = ""; } try { datevalue = siteval.ChildNodes[1].InnerText; } catch (Exception ex) { datevalue = ""; } DateTime todate = DateTime.Now; DateTime fromDate = DateTime.Now; fromDate = fromDate.AddYears(-1); fromDate = fromDate.AddMonths(5); DateTime dt = Convert.ToDateTime(datevalue); if (dt > fromDate && dt < todate) { xmlDoc.Load(urlvalue); var sitedatalist = xmlDoc.DocumentElement.GetElementsByTagName("url"); foreach (XmlElement item in sitedatalist) { objRssFeeds.Id = ObjectId.GenerateNewId(); objRssFeeds.strId = ObjectId.GenerateNewId().ToString(); objRssFeeds.ProfileName = profileName; objRssFeeds.ProfileImageUrl = profileImageUrl; objRssFeeds.RssFeedUrl = TextUrl; objRssFeeds.ProfileId = profileid; objRssFeeds.ProfileType = profiletype; objRssFeeds.Status = false; try { objRssFeeds.Link = item.ChildNodes[0].InnerText; // objRssFeeds.Link = getBetween(objRssFeeds.Link, "<a href=\"", "\">"); } catch (Exception ex) { objRssFeeds.Link = ""; } objRssFeeds.PublishingDate = item.ChildNodes[1].InnerText; var ret = _RssFeedRepository.Find <Domain.Socioboard.Models.Mongo.RssFeed>(t => t.Link.Equals(objRssFeeds.Link) && t.ProfileId.Equals(profileid) && t.ProfileType.Equals(profiletype)); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { _RssFeedRepository.Add(objRssFeeds); } } } } } catch (Exception ex) { } } else { xmlDoc.Load(TextUrl); var sitedatalist = xmlDoc.DocumentElement.GetElementsByTagName("url"); try { foreach (XmlElement item in sitedatalist) { Domain.Socioboard.Models.Mongo.RssFeed objRssFeeds = new Domain.Socioboard.Models.Mongo.RssFeed(); objRssFeeds.Id = ObjectId.GenerateNewId(); objRssFeeds.strId = ObjectId.GenerateNewId().ToString(); objRssFeeds.ProfileName = profileName; objRssFeeds.ProfileImageUrl = profileImageUrl; objRssFeeds.RssFeedUrl = TextUrl; objRssFeeds.ProfileId = profileid; objRssFeeds.ProfileType = profiletype; objRssFeeds.Status = false; try { objRssFeeds.Link = item.ChildNodes[0].InnerText; objRssFeeds.Link = objRssFeeds.Link.Replace("\r", "").Replace("\n", ""); } catch (Exception ex) { } try { objRssFeeds.PublishingDate = item.ChildNodes[1].InnerText; } catch (Exception ex) { } var ret = _RssFeedRepository.Find <Domain.Socioboard.Models.Mongo.RssFeed>(t => t.Link.Equals(objRssFeeds.Link) && t.ProfileId.Equals(profileid) && t.ProfileType.Equals(profiletype)); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { _RssFeedRepository.Add(objRssFeeds); } } } catch (Exception ex) { } } return("ok"); } catch (Exception ex) { return("invalid url"); } }
public static string AddRssFeed(string TextUrl, long Userid, string profileId, Domain.Socioboard.Enum.SocialProfileType ProfileType, string profileimageurl, string profilename, string xmldata, Model.DatabaseRepository dbr, Helper.AppSettings _appSettings) { int UrlAdded = 0; string RetMsg = string.Empty; MongoRepository _RssRepository = new MongoRepository("Rss", _appSettings); Domain.Socioboard.Models.RssFeedUrl rssobj = new Domain.Socioboard.Models.RssFeedUrl(); rssobj = dbr.FindSingle <Domain.Socioboard.Models.RssFeedUrl>(t => t.ProfileId == profileId && t.rssurl == TextUrl); string rt = null; if (xmldata != null) { rt = ParseXMLFeedUrl(TextUrl, ProfileType, profileId, Userid, profilename, profileimageurl, rssobj, _appSettings); } else { rt = ParseFeedUrl(TextUrl, ProfileType, profileId, Userid, profilename, profileimageurl, _appSettings); } var ret = _RssRepository.Find <Domain.Socioboard.Models.Mongo.Rss>(t => t.RssFeedUrl.Equals(TextUrl) && t.ProfileId.Contains(profileId) && t.ProfileType == ProfileType && t.UserId.Equals(Userid)); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { if (rt == "ok") { Domain.Socioboard.Models.Mongo.Rss _Rss = new Domain.Socioboard.Models.Mongo.Rss(); _Rss.Id = ObjectId.GenerateNewId(); _Rss.strId = ObjectId.GenerateNewId().ToString(); _Rss.RssFeedUrl = TextUrl; _Rss.ProfileType = ProfileType; _Rss.ProfileId = profileId; _Rss.UserId = Userid; _Rss.ProfileImageUrl = profileimageurl; _Rss.ProfileName = profilename; _Rss.rssFeedUrl = rssobj; _Rss.CreatedOn = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); _RssRepository.Add(_Rss); UrlAdded++; } else { return("Please Fill Correct Url For Feeds"); } } else { } if (UrlAdded == 1) { RetMsg = "Url for " + UrlAdded.ToString() + " account is added"; } else if (UrlAdded > 1) { RetMsg = "Url for " + UrlAdded.ToString() + " accounts is added"; } else { RetMsg = "Url has already added"; } return(RetMsg); }
public static string ParseFeedUrl(string TextUrl, Domain.Socioboard.Enum.SocialProfileType profiletype, string profileid, long userId, string profileName, string profileImageUrl, Helper.AppSettings _appSettings) { MongoRepository _RssFeedRepository = new MongoRepository("RssFeed", _appSettings); try { XmlDocument xmlDoc = new XmlDocument(); // Create an XML document object xmlDoc.Load(TextUrl); var abc = xmlDoc.DocumentElement.GetElementsByTagName("item"); foreach (XmlElement item in abc) { Domain.Socioboard.Models.Mongo.RssFeed objRssFeeds = new Domain.Socioboard.Models.Mongo.RssFeed(); try { objRssFeeds.Id = ObjectId.GenerateNewId(); objRssFeeds.strId = ObjectId.GenerateNewId().ToString(); objRssFeeds.ProfileName = profileName; objRssFeeds.ProfileImageUrl = profileImageUrl; try { objRssFeeds.Message = item.ChildNodes[9].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } catch (Exception ex) { try { if (item.ChildNodes[2].InnerText.Contains("www") && item.ChildNodes[2].InnerText.Contains("http")) { objRssFeeds.Message = item.ChildNodes[1].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } else if (item.ChildNodes[2].InnerText.Contains("http")) { objRssFeeds.Message = item.ChildNodes[1].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } else { objRssFeeds.Message = item.ChildNodes[2].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } } catch { objRssFeeds.Message = item.ChildNodes[1].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } } try { if (item.ChildNodes[3].Name == "pubDate") { objRssFeeds.PublishingDate = DateTime.Parse(item.ChildNodes[3].InnerText).ToString("yyyy/MM/dd HH:mm:ss"); } else { objRssFeeds.PublishingDate = DateTime.Parse(item.ChildNodes[4].InnerText).ToString("yyyy/MM/dd HH:mm:ss"); } } catch (Exception ex) { objRssFeeds.PublishingDate = DateTime.Parse(item.ChildNodes[5].InnerText).ToString("yyyy/MM/dd HH:mm:ss"); } objRssFeeds.Title = item.ChildNodes[0].InnerText; if (item.ChildNodes[1].InnerText.Contains("www") || item.ChildNodes[1].InnerText.Contains("http")) { try { //objRssFeeds.Image = item.ChildNodes[1].InnerText; // objRssFeeds.Image = getBetween(objRssFeeds.Image, "src=\"", "\""); if (item.ChildNodes[2].Name == "link") { objRssFeeds.Link = item.ChildNodes[2].InnerText; } else { objRssFeeds.Link = item.ChildNodes[1].InnerText; objRssFeeds.Link = getBetween(objRssFeeds.Link, "<a href=\"", "\">"); } if (objRssFeeds.Link == "") { objRssFeeds.Link = item.ChildNodes[1].InnerText; } } catch (Exception ex) { objRssFeeds.Link = item.ChildNodes[2].InnerText; objRssFeeds.Link = getBetween(objRssFeeds.Link, "<a href=\"", "\">"); } } else if (item.ChildNodes[3].InnerText.Contains("www") || item.ChildNodes[3].InnerText.Contains("https")) { try { objRssFeeds.Message = item.ChildNodes[4].InnerText; objRssFeeds.Message = getBetween(objRssFeeds.Message, "<a href=\"", "\">"); } catch (Exception ex) { objRssFeeds.Link = ""; } try { objRssFeeds.Link = item.ChildNodes[3].InnerText; } catch (Exception ex) { objRssFeeds.Link = ""; } } else if (item.ChildNodes[2].InnerText.Contains("https")) { try { objRssFeeds.Link = item.ChildNodes[2].InnerText; } catch (Exception ex) { objRssFeeds.Link = ""; } try { if (item.ChildNodes[7].Name == "description") { objRssFeeds.Message = item.ChildNodes[7].InnerText; } else { objRssFeeds.Message = item.ChildNodes[6].InnerText; //objRssFeeds.Message = getBetween(objRssFeeds.Message, "<a href=\"", "\">"); } } catch (Exception ex) { objRssFeeds.Message = ""; } try { objRssFeeds.Title = item.ChildNodes[1].InnerText; } catch (Exception ex) { objRssFeeds.Message = ""; } try { if (item.ChildNodes[8].Name != "media") { objRssFeeds.Image = item.ChildNodes[8].InnerText; } else { objRssFeeds.Image = ""; } } catch (Exception ex) { objRssFeeds.Message = ""; } } else { objRssFeeds.Link = item.ChildNodes[2].InnerText; // objRssFeeds.Link = getBetween(objRssFeeds.Link, "<a href=\"", "\">"); } objRssFeeds.RssFeedUrl = TextUrl; objRssFeeds.ProfileId = profileid; objRssFeeds.ProfileType = profiletype; objRssFeeds.Status = false; var ret = _RssFeedRepository.Find <Domain.Socioboard.Models.Mongo.RssFeed>(t => t.Link.Equals(objRssFeeds.Link) && t.ProfileId.Equals(profileid) && t.ProfileType.Equals(profiletype)); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { _RssFeedRepository.Add(objRssFeeds); } } catch (Exception ex) { } } return("ok"); } catch (Exception ex) { return("invalid url"); } }
public static string DaywiseScheduleMessage(string profileId, string socialprofileName, string weekdays, string shareMessage, Domain.Socioboard.Enum.SocialProfileType profiletype, long userId, string link, string url, string picUrl, string localscheduletime, AppSettings _AppSettings, Cache _redisCache, DatabaseRepository dbr, ILogger _logger) { DaywiseSchedule scheduledMessage = new DaywiseSchedule(); scheduledMessage.shareMessage = shareMessage; //scheduledMessage.calendertime = Convert.ToDateTime(localscheduletime); string userlocalscheduletime = localscheduletime; try { // _logger.LogError("ScheduleMessageHelperscheduleTime>>>>" + scheduleTime); // var dt = DateTime.Parse(scheduleTime); // scheduledMessage.scheduleTime = Convert.ToDateTime(TimeZoneInfo.ConvertTimeToUtc(dt)); //scheduledMessage.scheduleTime = Convert.ToDateTime(scheduleTime) ; // scheduledMessage.scheduleTime = Convert.ToDateTime(CompareDateWithclient(DateTime.UtcNow.ToString(),scheduleTime)); } catch (Exception ex) { _logger.LogError(ex.StackTrace); } DateTime fromTime = scheduledMessage.scheduleTime.AddMinutes(-scheduledMessage.scheduleTime.Minute); DateTime toTime = scheduledMessage.scheduleTime.AddMinutes(-scheduledMessage.scheduleTime.Minute).AddHours(1); try { int count = dbr.Find <ScheduledMessage>(t => t.scheduleTime > fromTime && t.scheduleTime <= toTime && t.profileId == profileId).Count(); if (count > _AppSettings.FacebookScheduleMessageMaxLimit) { _logger.LogError("Facebook Max limit Reached."); return("Max limit Reached."); } } catch (Exception) { } scheduledMessage.status = Domain.Socioboard.Enum.ScheduleStatus.Pending; scheduledMessage.userId = userId; scheduledMessage.profileType = profiletype; scheduledMessage.profileId = profileId; scheduledMessage.weekdays = weekdays; scheduledMessage.url = url; scheduledMessage.link = link; scheduledMessage.picUrl = picUrl; scheduledMessage.createTime = DateTime.UtcNow; scheduledMessage.clientTime = DateTime.Now; scheduledMessage.scheduleTime = Convert.ToDateTime(userlocalscheduletime); scheduledMessage.localscheduletime = userlocalscheduletime; // scheduledMessage.localscheduletime = userlocalscheduletime; scheduledMessage.socialprofileName = socialprofileName; int ret = dbr.Add <DaywiseSchedule>(scheduledMessage); if (ret == 1) { return("Scheduled."); } else { return("Not Scheduled."); } }
public static int AddGroupProfile(Int64 GroupId, string ProfileId, string ProfileName, Int64 ProfileOwnerId, string ProfilePic, Domain.Socioboard.Enum.SocialProfileType profileType, Model.DatabaseRepository dbr) { Domain.Socioboard.Models.Groupprofiles grpProfile = new Domain.Socioboard.Models.Groupprofiles(); grpProfile.groupId = GroupId; grpProfile.profileId = ProfileId; grpProfile.profileName = ProfileName; grpProfile.profileOwnerId = ProfileOwnerId; grpProfile.profilePic = ProfilePic; grpProfile.profileType = profileType; return(dbr.Add <Domain.Socioboard.Models.Groupprofiles>(grpProfile)); }
public static string PostRssfeed(Domain.Socioboard.Enum.SocialProfileType profiletype, Helper.AppSettings _appSettings, Model.DatabaseRepository dbr, Helper.Cache _redisCache) { string ret = ""; MongoRepository _RssFeedRepository = new MongoRepository("RssFeed", _appSettings); List <Domain.Socioboard.Models.Mongo.RssFeed> objrssdata = new List <Domain.Socioboard.Models.Mongo.RssFeed>(); var rt = _RssFeedRepository.Find <Domain.Socioboard.Models.Mongo.RssFeed>(t => t.Status == false && t.ProfileType.Equals(profiletype)); var task = Task.Run(async() => { return(await rt); }); IList <Domain.Socioboard.Models.Mongo.RssFeed> _objrssdata = task.Result; objrssdata = _objrssdata.ToList(); foreach (var item in objrssdata) { if (profiletype == Domain.Socioboard.Enum.SocialProfileType.Facebook) { try { Domain.Socioboard.Models.Facebookaccounts _Facebookaccounts = Repositories.FacebookRepository.getFacebookAccount(item.ProfileId, _redisCache, dbr); ret = Helper.FacebookHelper.FacebookComposeMessageRss(item.Message, _Facebookaccounts.AccessToken, _Facebookaccounts.FbUserId, item.Title, item.Link, item.strId, _appSettings); } catch (Exception ex) { return(""); } } else if (profiletype == Domain.Socioboard.Enum.SocialProfileType.Twitter) { try { string message = ""; string UrlShortendata = GetShortenUrl(item.Link, _appSettings); string shortenUrl = string.Empty; try { JObject JData = JObject.Parse(UrlShortendata); if (JData["status_txt"].ToString() == "OK") { shortenUrl = JData["data"]["url"].ToString(); } } catch (Exception ex) { } if (item.Message.Length > 115) { message = item.Message.Substring(0, 115); } else { message = item.Message; } message += " " + shortenUrl; Domain.Socioboard.Models.TwitterAccount _TwitterAccount = Repositories.TwitterRepository.getTwitterAccount(item.ProfileId, _redisCache, dbr); ret = Helper.TwitterHelper.TwitterComposeMessageRss(message, _TwitterAccount.oAuthToken, _TwitterAccount.oAuthSecret, _TwitterAccount.twitterUserId, _TwitterAccount.twitterScreenName, item.strId, _appSettings); } catch (Exception ex) { return(""); } } } return(ret); }
public static string ParseFeedUrl(string TextUrl, Domain.Socioboard.Enum.SocialProfileType profiletype, string profileid, long userId, string profileName, string profileImageUrl) { MongoRepository _RssFeedRepository = new MongoRepository("RssFeed"); try { XmlDocument xmlDoc = new XmlDocument(); // Create an XML document object xmlDoc.Load(TextUrl); var abc = xmlDoc.DocumentElement.GetElementsByTagName("item"); if (profiletype == Domain.Socioboard.Enum.SocialProfileType.Facebook || profiletype == Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage) { Model.DatabaseRepository dbr = new DatabaseRepository(); Domain.Socioboard.Models.Facebookaccounts _Facebookaccounts = dbr.Find <Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == profileid).First(); if (_Facebookaccounts != null) { if (_Facebookaccounts.IsActive) { foreach (XmlElement item in abc) { Domain.Socioboard.Models.Mongo.RssFeed objRssFeeds = new Domain.Socioboard.Models.Mongo.RssFeed(); try { objRssFeeds.Id = ObjectId.GenerateNewId(); objRssFeeds.strId = ObjectId.GenerateNewId().ToString(); objRssFeeds.ProfileName = profileName; objRssFeeds.ProfileImageUrl = profileImageUrl; try { objRssFeeds.Message = item.ChildNodes[9].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } catch (Exception ex) { try { if (item.ChildNodes[2].InnerText.Contains("www") && item.ChildNodes[2].InnerText.Contains("http")) { objRssFeeds.Message = item.ChildNodes[1].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } else { objRssFeeds.Message = item.ChildNodes[2].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } } catch { objRssFeeds.Message = item.ChildNodes[1].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } } try { objRssFeeds.PublishingDate = DateTime.Parse(item.ChildNodes[4].InnerText).ToString("yyyy/MM/dd HH:mm:ss"); } catch (Exception ex) { objRssFeeds.PublishingDate = DateTime.Parse(item.ChildNodes[3].InnerText).ToString("yyyy/MM/dd HH:mm:ss"); } objRssFeeds.Title = item.ChildNodes[0].InnerText; if (item.ChildNodes[1].InnerText.Contains("www") || item.ChildNodes[1].InnerText.Contains("http")) { try { objRssFeeds.Link = item.ChildNodes[1].InnerText; } catch (Exception ex) { objRssFeeds.Link = item.ChildNodes[2].InnerText; } } else { objRssFeeds.Link = item.ChildNodes[2].InnerText; } objRssFeeds.RssFeedUrl = TextUrl; objRssFeeds.ProfileId = profileid; objRssFeeds.ProfileType = profiletype; objRssFeeds.Status = false; var ret = _RssFeedRepository.Find <Domain.Socioboard.Models.Mongo.RssFeed>(t => t.Link.Equals(objRssFeeds.Link) && t.ProfileId.Equals(profileid) && t.ProfileType.Equals(profiletype)); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { _RssFeedRepository.Add <Domain.Socioboard.Models.Mongo.RssFeed>(objRssFeeds); } } catch (Exception ex) { } if (apiHitsCount < MaxapiHitsCount) { string facebookdata = FacebookComposeMessageRss(objRssFeeds.Message, _Facebookaccounts.AccessToken, _Facebookaccounts.FbUserId, objRssFeeds.Title, objRssFeeds.Link, objRssFeeds.strId); if (!string.IsNullOrEmpty(facebookdata)) { apiHitsCount++; } } else { apiHitsCount = 0; return("ok"); } } _Facebookaccounts.SchedulerUpdate = DateTime.UtcNow; dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(_Facebookaccounts); } } } if (profiletype == Domain.Socioboard.Enum.SocialProfileType.Twitter) { Model.DatabaseRepository dbr = new DatabaseRepository(); Domain.Socioboard.Models.TwitterAccount _TwitterAccount = dbr.Find <Domain.Socioboard.Models.TwitterAccount>(t => t.twitterUserId == profileid).First(); if (_TwitterAccount != null) { if (_TwitterAccount.isActive) { foreach (XmlElement item in abc) { Domain.Socioboard.Models.Mongo.RssFeed objRssFeeds = new Domain.Socioboard.Models.Mongo.RssFeed(); try { objRssFeeds.Id = ObjectId.GenerateNewId(); objRssFeeds.strId = ObjectId.GenerateNewId().ToString(); objRssFeeds.ProfileName = profileName; objRssFeeds.ProfileImageUrl = profileImageUrl; try { objRssFeeds.Message = item.ChildNodes[9].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } catch (Exception ex) { try { if (item.ChildNodes[2].InnerText.Contains("www") && item.ChildNodes[2].InnerText.Contains("http")) { objRssFeeds.Message = item.ChildNodes[1].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } else { objRssFeeds.Message = item.ChildNodes[2].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } } catch { objRssFeeds.Message = item.ChildNodes[1].InnerText; objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "<.*?>", string.Empty).Replace("[…]", ""); objRssFeeds.Message = Regex.Replace(objRssFeeds.Message, "@<[^>]+>| ", string.Empty); } } try { objRssFeeds.PublishingDate = DateTime.Parse(item.ChildNodes[4].InnerText).ToString("yyyy/MM/dd HH:mm:ss"); } catch (Exception ex) { objRssFeeds.PublishingDate = DateTime.Parse(item.ChildNodes[3].InnerText).ToString("yyyy/MM/dd HH:mm:ss"); } objRssFeeds.Title = item.ChildNodes[0].InnerText; if (item.ChildNodes[1].InnerText.Contains("www") || item.ChildNodes[1].InnerText.Contains("http")) { try { objRssFeeds.Link = item.ChildNodes[1].InnerText; } catch (Exception ex) { objRssFeeds.Link = item.ChildNodes[2].InnerText; } } else { objRssFeeds.Link = item.ChildNodes[2].InnerText; } objRssFeeds.RssFeedUrl = TextUrl; objRssFeeds.ProfileId = profileid; objRssFeeds.ProfileType = profiletype; objRssFeeds.Status = false; var ret = _RssFeedRepository.Find <Domain.Socioboard.Models.Mongo.RssFeed>(t => t.Link.Equals(objRssFeeds.Link) && t.ProfileId.Equals(profileid) && t.ProfileType.Equals(profiletype)); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { _RssFeedRepository.Add <Domain.Socioboard.Models.Mongo.RssFeed>(objRssFeeds); } } catch (Exception ex) { } if (twtapiHitsCount < twtMaxapiHitsCount) { string twitterdata = TwitterComposeMessageRss(objRssFeeds.Message, _TwitterAccount.oAuthToken, _TwitterAccount.oAuthSecret, _TwitterAccount.twitterUserId, _TwitterAccount.twitterScreenName, objRssFeeds.strId); if (!string.IsNullOrEmpty(twitterdata)) { twtapiHitsCount++; } } else { twtapiHitsCount = 0; return("ok"); } } _TwitterAccount.SchedulerUpdate = DateTime.UtcNow; dbr.Update <Domain.Socioboard.Models.TwitterAccount>(_TwitterAccount); } } } return("ok"); } catch (Exception ex) { return("invalid url"); } }