public bool checkTumblrMessageExists(TumblrFeed tumblrFeed) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //Begin session trasaction and opens up. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { //Proceed action, to get all data of facebook feed by user feed id and User id(Guid). NHibernate.IQuery query = session.CreateQuery("from TumblrFeed where UserId = :userid and blogId = :msgid"); query.SetParameter("userid", tumblrFeed.UserId); query.SetParameter("msgid", tumblrFeed.blogId); var resutl = query.UniqueResult(); if (resutl == null) { return(false); } else { return(true); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(true); } } //End Transaction } //End session }
/// <summary> /// /// </summary> /// <param name="UserId">Tumblr User id</param> public string GetData(object UserId, string TumblrId) { string ret = string.Empty; try { Guid userId = (Guid)UserId; TumblrFeed objTumblrFeed = new TumblrFeed(); Api.TumblrFeed.TumblrFeed ApiObjTumblrFeed = new Api.TumblrFeed.TumblrFeed(); Api.TumblrAccount.TumblrAccount ApiObjTumblrAccount = new Api.TumblrAccount.TumblrAccount(); List <Domain.Socioboard.Domain.TumblrAccount> lstTumblrAccount = (List <Domain.Socioboard.Domain.TumblrAccount>)(new JavaScriptSerializer().Deserialize(ApiObjTumblrAccount.GetAllTumblrAccountsOfUser(userId.ToString()), typeof(List <Domain.Socioboard.Domain.TumblrAccount>))); foreach (TumblrAccount lstItem in lstTumblrAccount) { try { Api.Tumblr.Tumblr ApiObjTumblr = new Api.Tumblr.Tumblr(); ret = ApiObjTumblr.getTumblrData(lstItem.UserId.ToString(), lstItem.tblrUserName); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(ret); }
/// <summary> /// Initializes a new instance of the <see cref="Terradue.TepQW.Controller.TumblrNews"/> class. /// </summary> /// <param name="context">Context.</param> /// <param name="feed">Feed.</param> public TumblrNews(IfyContext context, TumblrFeed feed) : base(context) { this.Identifier = feed.Identifier; this.Title = feed.Title; this.Tags = feed.Tags; this.Time = feed.Time; this.Url = feed.Url; this.Author = feed.Author; this.Content = feed.Content; this.Abstract = feed.Abstract; }
public static void Add(TumblrFeed tumblrFeed) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start and open Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action to save data. try { session.Save(tumblrFeed); transaction.Commit(); } catch (Exception ex) { logger.Error("Add mien prob hai :" + ex.Message); } } //End Using trasaction } //End Using session }
public TumblrFeed getFeedOfProfilebyIdProfileId(string profileid, Guid id) { TumblrFeed result = new TumblrFeed(); //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { // proceed action, to get all Facebook Account of User by UserId(Guid) and FbUserId(string). List <TumblrFeed> objlstfb = session.CreateQuery("from TumblrFeed where ProfileId = :profid and Id=:id ") .SetParameter("profid", profileid) .SetParameter("id", id) .List <TumblrFeed>().ToList <TumblrFeed>(); if (objlstfb.Count > 0) { result = objlstfb[0]; } return(result); } //End Transaction } //End session }
// <summary> /// Loads the tumblr feeds. /// </summary> /// <returns>The tumblr feeds.</returns> /// <param name="context">Context.</param> public static List <TumblrFeed> LoadTumblrFeeds(IfyContext context, string apiType, string apiMethod, string apiUrl) { List <TumblrFeed> result = new List <TumblrFeed>(); TumblrApplication app = new TumblrApplication(context.GetConfigValue("Tumblr-apiKey"), apiMethod, apiType, apiUrl); EntityList <TumblrNews> tumblrs = new EntityList <TumblrNews>(context); tumblrs.Load(); foreach (TumblrNews news in tumblrs) { TumblrFeed feed = new TumblrFeed(app, context.BaseUrl); feed.Identifier = news.Identifier; feed.Title = news.Title; feed.Tags = news.Tags; feed.Time = news.Time; feed.Url = news.Url; feed.Author = news.Author; feed.Content = news.Content; feed.Abstract = news.Abstract; result.Add(feed); } return(result); }
/// <summary> /// /// </summary> /// <param name="UserId">Tumblr User id</param> public void GetData(object UserId) { Guid userId = (Guid)UserId; TumblrFeed objTumblrFeed = new TumblrFeed(); TumblrFeedRepository objTumblrFeedRepository = new TumblrFeedRepository(); //LinkedInHelper objliHelper = new LinkedInHelper(); //LinkedInAccountRepository objLiRepo = new LinkedInAccountRepository(); TumblrAccountRepository objLiRepo = new TumblrAccountRepository(); //oAuthLinkedIn _oauth = new oAuthLinkedIn(); List <TumblrAccount> arrTumbAccount = objLiRepo.getTumblrAccountDetailsById(userId); foreach (TumblrAccount itemLi in arrTumbAccount) { //_oauth.Token = itemLi.OAuthToken; //_oauth.TokenSecret = itemLi.OAuthSecret; //_oauth.Verifier = itemLi.OAuthVerifier; //objliHelper.GetUserProfile(_oauth, itemLi.LinkedinUserId, userId); //objliHelper.GetLinkedInFeeds(_oauth, itemLi.LinkedinUserId, userId); KeyValuePair <string, string> LoginDetails = new KeyValuePair <string, string>(itemLi.tblrAccessToken, itemLi.tblrAccessTokenSecret); string sstr = oAuthTumbler.OAuthData(Globals.UsersDashboardUrl, "GET", LoginDetails.Key, LoginDetails.Value, null); JObject profile = JObject.Parse(oAuthTumbler.OAuthData(Globals.UsersInfoUrl, "GET", LoginDetails.Key, LoginDetails.Value, null)); JObject UserDashboard = JObject.Parse(oAuthTumbler.OAuthData(Globals.UsersDashboardUrl, "GET", LoginDetails.Key, LoginDetails.Value, null)); JArray objJarray = (JArray)UserDashboard["response"]["posts"]; foreach (var item in objJarray) { objTumblrFeed.Id = Guid.NewGuid(); objTumblrFeed.UserId = userId; try { objTumblrFeed.ProfileId = profile["response"]["user"]["name"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { objTumblrFeed.blogname = item["blog_name"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { objTumblrFeed.blogId = item["id"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { objTumblrFeed.blogposturl = item["post_url"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { String result = item["caption"].ToString(); objTumblrFeed.description = Regex.Replace(result, @"<[^>]*>", String.Empty); } catch (Exception ex) { objTumblrFeed.description = null; Console.WriteLine(ex.Message); } try { objTumblrFeed.slug = item["slug"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { objTumblrFeed.type = item["type"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { string test = item["date"].ToString(); DateTime dt; if (test.Contains("GMT")) { test = test.Replace("GMT", "").Trim().ToString(); dt = Convert.ToDateTime(test); } else { test = test.Replace("GMT", "").Trim().ToString(); dt = Convert.ToDateTime(test); } objTumblrFeed.date = dt; } catch (Exception ex) { Console.WriteLine(ex.Message); } try { objTumblrFeed.reblogkey = item["reblog_key"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { string str = item["liked"].ToString(); if (str == "False") { objTumblrFeed.liked = 0; } else { objTumblrFeed.liked = 1; } } catch (Exception ex) { Console.WriteLine(ex.Message); } try { string str = item["followed"].ToString(); if (str == "false") { objTumblrFeed.followed = 0; } else { objTumblrFeed.followed = 1; } } catch (Exception ex) { Console.WriteLine(ex.Message); } try { objTumblrFeed.canreply = Convert.ToInt16(item["can_reply"]); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { objTumblrFeed.sourceurl = item["source_url"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { objTumblrFeed.sourcetitle = item["source_title"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { JArray obj = (JArray)item["photos"]; foreach (var item1 in obj) { objTumblrFeed.imageurl = item1["original_size"]["url"].ToString(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } try { objTumblrFeed.videourl = item["permalink_url"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { string str = item["note_count"].ToString(); objTumblrFeed.notes = Convert.ToInt16(str); } catch (Exception ex) { Console.WriteLine(ex.Message); } objTumblrFeed.timestamp = DateTime.Now; if (!objTumblrFeedRepository.checkTumblrMessageExists(objTumblrFeed)) { TumblrFeedRepository.Add(objTumblrFeed); } } } }
private void GetAccessToken() { try { User user = (User)Session["LoggedUser"]; if (user == null) { Response.Redirect("Default.aspx"); } oAuthTumbler requestHelper = new oAuthTumbler(); string code = Request.QueryString["oauth_verifier"]; string AccessTokenResponse = string.Empty; try { AccessTokenResponse = requestHelper.GetAccessToken(oAuthTumbler.TumblrToken, code); } catch (Exception ex) { logger.Error("AccessTokenResponse: " + ex.Message); logger.Error("AccessTokenResponse: " + ex.StackTrace); } string[] tokens = AccessTokenResponse.Split('&'); //extract access token & secret from response string accessToken = tokens[0].Split('=')[1]; string accessTokenSecret = tokens[1].Split('=')[1]; KeyValuePair <string, string> LoginDetails = new KeyValuePair <string, string>(accessToken, accessTokenSecret); string sstr = string.Empty; try { sstr = oAuthTumbler.OAuthData(Globals.UsersDashboardUrl, "GET", LoginDetails.Key, LoginDetails.Value, null); } catch (Exception ex) { logger.Error("sstr: " + ex.Message); logger.Error("sstr: " + ex.StackTrace); } JObject profile = new JObject(); try { profile = JObject.Parse(oAuthTumbler.OAuthData(Globals.UsersInfoUrl, "GET", LoginDetails.Key, LoginDetails.Value, null)); } catch (Exception ex) { logger.Error("profile: " + ex.Message); logger.Error("profile: " + ex.StackTrace); } JObject UserDashboard = JObject.Parse(oAuthTumbler.OAuthData(Globals.UsersDashboardUrl, "GET", LoginDetails.Key, LoginDetails.Value, null)); TumblrAccount objTumblrAccount = new TumblrAccount(); TumblrAccountRepository objTumblrAccountRepository = new TumblrAccountRepository(); SocialProfile objSocialProfile = new SocialProfile(); SocialProfilesRepository objSocialProfilesRepository = new SocialProfilesRepository(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.UserId = user.Id; objSocialProfile.ProfileId = profile["response"]["user"]["name"].ToString(); objSocialProfile.ProfileType = "tumblr"; objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; objTumblrAccount.Id = Guid.NewGuid(); objTumblrAccount.tblrUserName = profile["response"]["user"]["name"].ToString(); objTumblrAccount.UserId = user.Id; objTumblrAccount.tblrAccessToken = accessToken; objTumblrAccount.tblrAccessTokenSecret = accessTokenSecret; objTumblrAccount.tblrProfilePicUrl = profile["response"]["user"]["name"].ToString(); objTumblrAccount.IsActive = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); if (!objTumblrAccountRepository.checkTubmlrUserExists(objTumblrAccount)) { TumblrAccountRepository.Add(objTumblrAccount); GroupRepository objGroupRepository = new GroupRepository(); SocioBoard.Domain.Team team = (SocioBoard.Domain.Team)HttpContext.Current.Session["GroupName"]; Groups lstDetails = objGroupRepository.getGroupName(team.GroupId); if (lstDetails.GroupName == "Socioboard") { TeamMemberProfileRepository objTeamMemberProfileRepository = new TeamMemberProfileRepository(); TeamMemberProfile teammemberprofile = new TeamMemberProfile(); teammemberprofile.Id = Guid.NewGuid(); teammemberprofile.TeamId = team.Id; teammemberprofile.ProfileId = objTumblrAccount.tblrUserName; teammemberprofile.ProfileType = "tumblr"; teammemberprofile.StatusUpdateDate = DateTime.Now; objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile); } } } else { if (!objTumblrAccountRepository.checkTubmlrUserExists(objTumblrAccount)) { TumblrAccountRepository.Add(objTumblrAccount); } else { Response.Redirect("Home.aspx"); } } JArray objJarray = (JArray)UserDashboard["response"]["posts"]; logger.Error("objJarray: " + objJarray); if (objJarray != null) { logger.Error("objJarray lenght : " + objJarray.Count); } else { logger.Error("objJarray is NULL"); } TumblrFeed objTumblrFeed = new TumblrFeed(); TumblrFeedRepository objTumblrFeedRepository = new TumblrFeedRepository(); foreach (var item in objJarray) { objTumblrFeed.Id = Guid.NewGuid(); objTumblrFeed.UserId = user.Id; try { objTumblrFeed.ProfileId = profile["response"]["user"]["name"].ToString(); logger.Error("objTumblrFeed.ProfileId : " + objTumblrFeed.ProfileId); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.blogname = item["blog_name"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.blogId = item["id"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.blogposturl = item["post_url"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { String result = item["caption"].ToString(); objTumblrFeed.description = Regex.Replace(result, @"<[^>]*>", String.Empty); } catch (Exception ex) { objTumblrFeed.description = null; logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.slug = item["slug"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.type = item["type"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { string test = item["date"].ToString(); DateTime dt; if (test.Contains("GMT")) { test = test.Replace("GMT", "").Trim().ToString(); dt = Convert.ToDateTime(test); } else { test = test.Replace("GMT", "").Trim().ToString(); dt = Convert.ToDateTime(test); } objTumblrFeed.date = dt; } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.reblogkey = item["reblog_key"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { string str = item["liked"].ToString(); if (str == "False") { objTumblrFeed.liked = 0; } else { objTumblrFeed.liked = 1; } } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { string str = item["followed"].ToString(); if (str == "false") { objTumblrFeed.followed = 0; } else { objTumblrFeed.followed = 1; } // objTumblrDashboard.followed = Convert.ToInt16(item["followed"]); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.canreply = Convert.ToInt16(item["can_reply"]); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.sourceurl = item["source_url"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.sourcetitle = item["source_title"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { JArray asdasd12 = (JArray)item["photos"]; foreach (var item1 in asdasd12) { objTumblrFeed.imageurl = item1["original_size"]["url"].ToString(); } } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { objTumblrFeed.videourl = item["permalink_url"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } try { string str = item["note_count"].ToString(); objTumblrFeed.notes = Convert.ToInt16(str); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.Message); } objTumblrFeed.timestamp = DateTime.Now; if (!objTumblrFeedRepository.checkTumblrMessageExists(objTumblrFeed)) { try { logger.Error("objTumblrFeedRepository.checkTumblrMessageExists " + objTumblrAccount.Id); TumblrFeedRepository.Add(objTumblrFeed); } catch (Exception ex) { logger.Error("Exception : objTumblrFeedRepository.checkTumblrMessageExists " + objTumblrAccount.Id); logger.Error(ex.Message); logger.Error(ex.StackTrace); } } } Response.Redirect("Home.aspx"); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); } }