// Edited by Antima[20/12/2014] public Domain.Socioboard.Domain.FacebookFeed getFacebookFeedByProfileId(string ProfileId, string FeedId) { //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()) { try { //Proceed action, to get feeds of twitter account by profile id. Domain.Socioboard.Domain.FacebookFeed msg = session.CreateQuery("from FacebookFeed where ProfileId = :ProfileId and FeedId =:FeedId") .SetParameter("ProfileId", ProfileId) .SetParameter("FeedId", FeedId).UniqueResult <Domain.Socioboard.Domain.FacebookFeed>(); return(msg); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } } //End Transaction } //End Session }
/// <addFacebookFeed> /// add new Facebook Feed /// </summary> /// <param name="fbfeed">Set Values in a Facebook feed Class Property and Pass the Object of Facebook feed Class (SocioBoard.Domain.Facebookfeed).</param> public void addFacebookFeed(Domain.Socioboard.Domain.FacebookFeed fbfeed) { //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()) { //Procees action, to save new data. session.Save(fbfeed); transaction.Commit(); } //End Trasaction } //End session }
// Edited by Antima[20/12/2014] public DataSet bindMyTickets(Guid UserId) { Messages mstable = new Messages(); DataSet ds = DataTableGenerator.CreateDataSetForTable(mstable); Api.SentimentalAnalysis.SentimentalAnalysis ApiobjSentimentalAnalysis = new Api.SentimentalAnalysis.SentimentalAnalysis(); List <Domain.Socioboard.Domain.FeedSentimentalAnalysis> lstNegativeFeedsOfUser = new List <Domain.Socioboard.Domain.FeedSentimentalAnalysis>(); lstNegativeFeedsOfUser = (List <Domain.Socioboard.Domain.FeedSentimentalAnalysis>)(new JavaScriptSerializer().Deserialize(ApiobjSentimentalAnalysis.getNegativeFeedsOfUser(UserId.ToString()), typeof(List <Domain.Socioboard.Domain.FeedSentimentalAnalysis>))); if (lstNegativeFeedsOfUser != null) { foreach (var item in lstNegativeFeedsOfUser) { string Network = item.Network; if (Network == "facebook") { Api.FacebookFeed.FacebookFeed ApiobjFacebookFeed = new Api.FacebookFeed.FacebookFeed(); Domain.Socioboard.Domain.FacebookFeed facebookfeed = (Domain.Socioboard.Domain.FacebookFeed)(new JavaScriptSerializer().Deserialize(ApiobjFacebookFeed.getFacebookFeedByProfileId(item.ProfileId, item.FeedId), typeof(Domain.Socioboard.Domain.FacebookFeed))); if (facebookfeed != null) { ds.Tables[0].Rows.Add(facebookfeed.ProfileId, "facebook", facebookfeed.FromId, facebookfeed.FromName, facebookfeed.FromProfileUrl, facebookfeed.FeedDate, facebookfeed.FeedDescription, facebookfeed.FbComment, facebookfeed.FbLike, facebookfeed.FeedId, facebookfeed.Type, ""); } } if (Network == "twitter") { Api.TwitterFeed.TwitterFeed ApiobjTwitterFeed = new Api.TwitterFeed.TwitterFeed(); Domain.Socioboard.Domain.TwitterFeed twtfeed = (Domain.Socioboard.Domain.TwitterFeed)(new JavaScriptSerializer().Deserialize(ApiobjTwitterFeed.getTwitterFeedByProfileId(item.ProfileId, item.FeedId), typeof(Domain.Socioboard.Domain.TwitterFeed))); if (twtfeed != null) { ds.Tables[0].Rows.Add(twtfeed.ProfileId, item.Network, twtfeed.FromId, twtfeed.FromScreenName, twtfeed.FromProfileUrl, twtfeed.FeedDate, twtfeed.Feed, "", "", twtfeed.MessageId, twtfeed.Type, ""); } } } } return(ds); }
public int updateFacebookFeed(Domain.Socioboard.Domain.FacebookFeed fbfeed) { throw new NotImplementedException(); }
public string GetTicketsofGroup(string GroupId, string UserId) { string AssignedUser = string.Empty; try { GroupProfileRepository objGroupProfileRepository = new GroupProfileRepository(); FacebookFeedRepository objFacebookFeedRepository = new FacebookFeedRepository(); TwitterFeedRepository objTwitterFeedRepository = new TwitterFeedRepository(); List <Domain.Socioboard.Domain.FeedSentimentalAnalysis> lstNegativeFeedsOfUser = new List <Domain.Socioboard.Domain.FeedSentimentalAnalysis>(); List <Domain.Socioboard.Domain.GroupProfile> objGroupProfile = new List <Domain.Socioboard.Domain.GroupProfile>(); List <FBTwitterFeeds> objListFBTwitterFeeds = new List <FBTwitterFeeds>(); objGroupProfile = objGroupProfileRepository.getAllGroupProfiles(Guid.Parse(UserId), Guid.Parse(GroupId)); if (objGroupProfile.Count > 0) { lstNegativeFeedsOfUser = _FeedSentimentalAnalysisRepository.getAllNegativeFeedsOfUser(Guid.Parse(UserId)); } else { lstNegativeFeedsOfUser = _FeedSentimentalAnalysisRepository.getNegativeFeedsOfUser(Guid.Parse(UserId)); } if (lstNegativeFeedsOfUser != null) { foreach (var item in lstNegativeFeedsOfUser) { FBTwitterFeeds objFBTwitterFeeds = new FBTwitterFeeds(); UserRepository objUserRepository = new UserRepository(); Domain.Socioboard.Domain.User user = objUserRepository.getUsersById(item.AssigneUserId); if (objGroupProfileRepository.checkProfileExistsingroup(Guid.Parse(GroupId), item.ProfileId)) { string Network = item.Network; if (Network == "facebook") { Domain.Socioboard.Domain.FacebookFeed facebookfeed = objFacebookFeedRepository.getFacebookFeedByProfileId(item.ProfileId, item.FeedId); if (facebookfeed != null) { objFBTwitterFeeds.FacebookFeed = facebookfeed; } } if (Network == "twitter") { Domain.Socioboard.Domain.TwitterFeed twtfeed = objTwitterFeedRepository.getTwitterFeedByProfileId(item.ProfileId, item.FeedId); if (twtfeed != null) { objFBTwitterFeeds.TwitterFeed = twtfeed; } } if (objFBTwitterFeeds.TwitterFeed != null) { try { objFBTwitterFeeds.TicketNo = item.TicketNo; if (user != null) { objFBTwitterFeeds.AssignedUser = user.UserName; } else { objFBTwitterFeeds.AssignedUser = ""; } objListFBTwitterFeeds.Add(objFBTwitterFeeds); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } if (objFBTwitterFeeds.FacebookFeed != null) { try { objFBTwitterFeeds.TicketNo = item.TicketNo; if (user != null) { objFBTwitterFeeds.AssignedUser = user.UserName; } else { objFBTwitterFeeds.AssignedUser = ""; } objListFBTwitterFeeds.Add(objFBTwitterFeeds); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } } } } return(new JavaScriptSerializer().Serialize(objListFBTwitterFeeds)); } catch (Exception ex) { logger.Error(ex.StackTrace); logger.Error(ex.Message); Console.WriteLine(ex.StackTrace); return("SomethingWentWrong"); } }
private List<Domain.Socioboard.Domain.FacebookFeed> AddFacebookFeeds(string UserId, FacebookClient fb, dynamic profile) { //List of new Feeds List<Domain.Socioboard.Domain.FacebookFeed> lstFacebookFeeds = new List<Domain.Socioboard.Domain.FacebookFeed>(); try { Domain.Socioboard.Domain.FacebookFeed objFacebookFeed = new Domain.Socioboard.Domain.FacebookFeed(); System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; string nexturl = "v2.0/me/feed";//"v2.0/me/posts"; //for (int i = 0; i < 10; i++) { dynamic feeds = fb.Get(nexturl); //dynamic feedss = fb.Get("/338818712957141/posts"); //dynamic feedsss = fb.Get("/338818712957141/feed"); if (feeds != null) { try { nexturl = feeds["paging"]["next"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); } foreach (var result in feeds["data"]) { objFacebookFeed = new Domain.Socioboard.Domain.FacebookFeed(); objFacebookFeed.Type = "fb_feed"; try { objFacebookFeed.UserId = Guid.Parse(UserId); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFacebookFeed.ProfileId = profile["id"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFacebookFeed.Id = Guid.NewGuid(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } objFacebookFeed.FromProfileUrl = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small"; objFacebookFeed.FromName = result["from"]["name"].ToString(); objFacebookFeed.FromId = result["from"]["id"].ToString(); objFacebookFeed.FeedId = result["id"].ToString(); objFacebookFeed.FeedDate = DateTime.Parse(result["created_time"].ToString()); objFacebookFeed.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments"; objFacebookFeed.FbLike = "http://graph.facebook.com/" + result["id"] + "/likes"; //Commented as these cause errors on API //Added by Sumit Gupta [31-01-15] to get post Shares/Likes/Comments #region Added by Sumit Gupta [31-01-15] //try //{ // dynamic like = fb.Get("v2.0/" + objFbPagePost.PostId + "/likes?summary=1&limit=0"); // objFbPagePost.Likes = Convert.ToInt32(like["summary"]["total_count"]); //} //catch (Exception ex) //{ // Console.WriteLine(ex.StackTrace); //} //try //{ // dynamic comment = fb.Get("v2.0/" + objFbPagePost.PostId + "/comments?summary=1&limit=0"); // objFbPagePost.Comments = Convert.ToInt32(comment["summary"]["total_count"]); //} //catch (Exception ex) //{ // Console.WriteLine(ex.StackTrace); //} //try //{ // dynamic shares = fb.Get("v2.0/" + objFbPagePost.PostId); // objFbPagePost.Shares = Convert.ToInt32(shares["shares"]["count"]); //} //catch (Exception ex) //{ // Console.WriteLine(ex.StackTrace); // logger.Error(ex.StackTrace); //} #endregion //Added by Sumit Gupta [17-02-15] try { objFacebookFeed.Picture = result["picture"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); objFacebookFeed.Picture = ""; } string message = string.Empty; int lstfbcount = 0; if (lstfbcount < 25) { try { if (result["message"] != null) { message = result["message"]; lstfbcount++; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); try { if (result["description"] != null) { message = result["description"]; lstfbcount++; } } catch (Exception exx) { try { Console.WriteLine(exx.StackTrace); if (result["story"] != null) { message = result["story"]; lstfbcount++; } } catch (Exception exxx) { Console.WriteLine(exxx.StackTrace); message = string.Empty; } } } } if (message == null) { message = ""; } objFacebookFeed.FeedDescription = message; objFacebookFeed.EntryDate = DateTime.Now; //Check to avoid duplicacy if (!objFacebookFeedRepository.checkFacebookFeedExists(objFacebookFeed.FeedId)) { objFacebookFeedRepository.addFacebookFeed(objFacebookFeed); lstFacebookFeeds.Add(objFacebookFeed); } } } else { //break; } } } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.Write(ex.StackTrace); } return lstFacebookFeeds; }
//Added by Avinash Verma & Sumit Gupta [30-01-15] private void AddFacebookFeedsWithPagination(string UserId, FacebookClient fb, dynamic profile) { int I = 0; try { objFacebookFeed = new Domain.Socioboard.Domain.FacebookFeed(); System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; string nexturl = "v2.0/me/feed";//"v2.0/me/posts"; for (int i = 0; i < 50; i++) { dynamic feeds = fb.Get(nexturl); //dynamic feedss = fb.Get("/338818712957141/posts"); //dynamic feedsss = fb.Get("/338818712957141/feed"); if (feeds != null) { try { nexturl = feeds["paging"]["next"].ToString(); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); } foreach (var result in feeds["data"]) { objFacebookFeed.Type = "fb_feed"; try { objFacebookFeed.UserId = Guid.Parse(UserId); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFacebookFeed.ProfileId = profile["id"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFacebookFeed.Id = Guid.NewGuid(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } objFacebookFeed.FromProfileUrl = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small"; objFacebookFeed.FromName = result["from"]["name"].ToString(); objFacebookFeed.FromId = result["from"]["id"].ToString(); objFacebookFeed.FeedId = result["id"].ToString(); objFacebookFeed.FeedDate = DateTime.Parse(result["created_time"].ToString()); objFacebookFeed.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments"; objFacebookFeed.FbLike = "http://graph.facebook.com/" + result["id"] + "/likes"; //Added by Sumit Gupta [17-02-15] try { objFacebookFeed.Picture = result["picture"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); objFacebookFeed.Picture = null; } string message = string.Empty; int lstfbcount = 0; if (lstfbcount < 25) { try { if (result["message"] != null) { message = result["message"]; lstfbcount++; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); try { if (result["description"] != null) { message = result["description"]; lstfbcount++; } } catch (Exception exx) { try { Console.WriteLine(exx.StackTrace); if (result["story"] != null) { message = result["story"]; lstfbcount++; } } catch (Exception exxx) { Console.WriteLine(exxx.StackTrace); message = string.Empty; } } } } objFacebookFeed.FeedDescription = message; objFacebookFeed.EntryDate = DateTime.Now; //// Edited by Antima[20/12/2014] //SentimentalAnalysis _SentimentalAnalysis = new SentimentalAnalysis(); //FeedSentimentalAnalysisRepository _FeedSentimentalAnalysisRepository = new FeedSentimentalAnalysisRepository(); //try //{ // if (_FeedSentimentalAnalysisRepository.checkFeedExists(objFacebookFeed.ProfileId.ToString(), Guid.Parse(UserId), objFacebookFeed.Id.ToString())) // { // if (!string.IsNullOrEmpty(message)) // { // string Network = "facebook"; // _SentimentalAnalysis.GetPostSentimentsFromUclassify(Guid.Parse(UserId), objFacebookFeed.ProfileId, objFacebookFeed.MessageId, message, Network); // } // } //} //catch (Exception ex) //{ // logger.Error(ex.Message); // logger.Error(ex.StackTrace); //} if (!objFacebookFeedRepository.checkFacebookFeedExists(objFacebookFeed.FeedId)) { I++; objFacebookFeedRepository.addFacebookFeed(objFacebookFeed); logger.Error("AddFacebookFeedsWithPaginationCount>>>"+I); } } } else { break; } } } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.Write(ex.StackTrace); } }
// Saving FacebookFeeds of user into database i.e. FacebookFeed Table public void getFacebookUserFeeds(dynamic data, dynamic profile) { FacebookFeed fbfeed = new FacebookFeed(); User user = (User)HttpContext.Current.Session["LoggedUser"]; FacebookFeedRepository fbfeedrepo = new FacebookFeedRepository(); if (data != null) { foreach (var result in data["data"]) { fbfeed.Type = "fb_feed"; try { fbfeed.UserId = user.Id; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbfeed.ProfileId = profile["id"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbfeed.Id = Guid.NewGuid(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } fbfeed.FromProfileUrl = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small"; fbfeed.FromName = result["from"]["name"].ToString(); fbfeed.FromId = result["from"]["id"].ToString(); fbfeed.FeedId = result["id"].ToString(); fbfeed.FeedDate = DateTime.Parse(result["created_time"].ToString()); fbfeed.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments"; fbfeed.FbLike = "http://graph.facebook.com/" + result["id"] + "/likes"; string message = string.Empty; int lstfbcount = 0; if (lstfbcount < 25) { try { if (result["message"] != null) { message = result["message"]; lstfbcount++; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); try { if (result["description"] != null) { message = result["description"]; lstfbcount++; } } catch (Exception exx) { try { Console.WriteLine(exx.StackTrace); if (result["story"] != null) { message = result["story"]; lstfbcount++; } } catch (Exception exxx) { Console.WriteLine(exxx.StackTrace); message = string.Empty; } } } } fbfeed.FeedDescription = message; fbfeed.EntryDate = DateTime.Now; if (!fbfeedrepo.checkFacebookFeedExists(fbfeed.FeedId)) { fbfeedrepo.addFacebookFeed(fbfeed); } } } }