Ejemplo n.º 1
0
 public void updateFacebookMessage(Domain.Socioboard.Domain.FacebookMessage fbmessage)
 {
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 // Proceed action to Update Data.
                 // And Set the reuired paremeters to find the specific values.
                 session.CreateQuery("Update FacebookMessage set FbLike=:status where Id = :msgid")
                 .SetParameter("msgid", fbmessage.Id)
                 .SetParameter("status", fbmessage.FbLike)
                 .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 // return 0;
             }
         } //End Transaction
     }     //End session
 }
Ejemplo n.º 2
0
 /// <addFacebookMessage>
 /// Add new Facebook Message
 /// </summary>
 /// <param name="fbmsg">Set Values in a FacebookMessage Class Property and Pass the same Object of FacebookMessage Class.(Domain.FacebookMessage)</param>
 public void addFacebookMessage(Domain.Socioboard.Domain.FacebookMessage fbmsg)
 {
     //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 save data.
             session.Save(fbmsg);
             transaction.Commit();
         } //End Transaction
     }     //End session
 }
        //Added By Sumit Gupta[15-02-15]
        private List<Domain.Socioboard.MongoDomain.FacebookMessage> AddNewFacebookUserHome(string UserId, FacebookClient fb, dynamic profile)
        {
            List<Domain.Socioboard.MongoDomain.FacebookMessage> lstFacebookMessage = new List<Domain.Socioboard.MongoDomain.FacebookMessage>();

            Domain.Socioboard.MongoDomain.FacebookMessage objFacebookMessage = new Domain.Socioboard.MongoDomain.FacebookMessage();
            try
            {
                dynamic home = fb.Get("v2.0/me/home");
                if (home != null)
                {
                    int lstfbcount = 0;
                    foreach (dynamic result in home["data"])
                    {
                        objFacebookMessage = new Domain.Socioboard.MongoDomain.FacebookMessage();

                        string message = string.Empty;
                        string imgprof = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small";
                        objFacebookMessage.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss");
                        objFacebookMessage.MessageId = result["id"].ToString();
                        objFacebookMessage.FromId = result["from"]["id"].ToString();
                        objFacebookMessage.FromName = result["from"]["name"].ToString();
                        objFacebookMessage.FromProfileUrl = imgprof;
                        objFacebookMessage.Id = ObjectId.GenerateNewId();
                        objFacebookMessage.MessageDate = DateTime.Parse(result["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss");
                        objFacebookMessage.UserId = UserId;

                        try
                        {
                            objFacebookMessage.Picture = result["picture"].ToString();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                            objFacebookMessage.Picture = null;
                        }
                        try
                        {
                            if (result["message_tags"][0] != null)
                            {
                                if (result["to"] != null)
                                {
                                    foreach (var item in result["to"]["data"])
                                    {
                                        if (result["from"] != null)
                                        {

                                            if (item["id"] != profile["id"])
                                            {
                                                if (result["from"]["id"] == profile["id"])
                                                {
                                                    objFacebookMessage.Type = "fb_tag";
                                                }
                                                else
                                                {
                                                    objFacebookMessage.Type = "fb_home";
                                                }
                                            }
                                            else
                                            {
                                                objFacebookMessage.Type = "fb_home";
                                            }
                                        }
                                    }

                                }
                                else
                                {
                                    objFacebookMessage.Type = "fb_home";

                                }
                            }
                            else
                            {
                                objFacebookMessage.Type = "fb_home";
                            }
                        }
                        catch (Exception ex)
                        {
                            objFacebookMessage.Type = "fb_home";
                            Console.WriteLine(ex.StackTrace);
                        }
                        objFacebookMessage.ProfileId = profile["id"].ToString();
                        objFacebookMessage.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments";
                        dynamic likes = fb.Get("v2.0/" + result["id"].ToString() + "/likes?limit=50000000");
                        string likestatus = "likes";
                        foreach (dynamic like in likes["data"])
                        {
                            try
                            {
                                if (profile["id"].ToString() == like["id"].ToString())
                                {
                                    likestatus = "unlike";
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                likestatus = "likes";

                            }
                        }
                        objFacebookMessage.FbLike = likestatus;
                        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;
                                    }
                                }
                            }
                        }
                        objFacebookMessage.Message = message;

                        MongoRepository mongorepo = new MongoRepository("FacebookMessage");
                        mongorepo.Add<Domain.Socioboard.MongoDomain.FacebookMessage>(objFacebookMessage);
                        ////Check to avoid duplicacy
                        //if (!objFacebookMessageRepository.checkFacebookMessageExists(objFacebookMessage.MessageId))
                        //{
                        //    objFacebookMessageRepository.addFacebookMessage(objFacebookMessage);

                        //    lstFacebookMessage.Add(objFacebookMessage);
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.StackTrace);
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
            }

            return lstFacebookMessage;
        }
 public string FacebookLike(String msgguid, String profileid, string msgid, string userid)
 {
     string ret = "";
     Domain.Socioboard.Domain.FacebookAccount objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(profileid, Guid.Parse(userid));
     FacebookClient fb = new FacebookClient();
     fb.AccessToken = objFacebookAccount.AccessToken;
     objFacebookMessage = objFacebookMessageRepository.GetFacebookUserWallPostDetails(Guid.Parse(msgguid));
     if (objFacebookMessage.FbLike == "likes")
     {
         System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
         var s = fb.Post("v2.0/" + msgid + "/likes", null);
         objFacebookMessage.FbLike = "unlike";
     }
     else
     {
         var s = fb.Delete(msgid + "/likes", null);
         objFacebookMessage.FbLike = "likes";
     }
     objFacebookMessageRepository.updateFacebookMessage(objFacebookMessage);
     return ret;
 }
Ejemplo n.º 5
0
        private void AddFacebookUserHome(string UserId, FacebookClient fb, dynamic profile)
        {
            int K = 0;

            objFacebookMessage = new Domain.Socioboard.Domain.FacebookMessage();
            try
            {
                dynamic home = fb.Get("v2.0/me/home");
                if (home != null)
                {
                    int lstfbcount = 0;
                    foreach (dynamic result in home["data"])
                    {
                        string message = string.Empty;
                        string imgprof = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small";
                        objFacebookMessage.EntryDate = DateTime.Now;
                        objFacebookMessage.MessageId = result["id"].ToString();
                        objFacebookMessage.FromId = result["from"]["id"].ToString();
                        objFacebookMessage.FromName = result["from"]["name"].ToString();
                        objFacebookMessage.FromProfileUrl = imgprof;
                        objFacebookMessage.Id = Guid.NewGuid();
                        objFacebookMessage.MessageDate = DateTime.Parse(result["created_time"].ToString());
                        objFacebookMessage.UserId = Guid.Parse(UserId);

                        try
                        {
                            objFacebookMessage.Picture = result["picture"].ToString();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                            objFacebookMessage.Picture = null;
                        }
                        try
                        {
                            if (result["message_tags"][0] != null)
                            {
                                if (result["to"] != null)
                                {
                                    foreach (var item in result["to"]["data"])
                                    {
                                        if (result["from"] != null)
                                        {

                                            if (item["id"] != profile["id"])
                                            {
                                                if (result["from"]["id"] == profile["id"])
                                                {
                                                    objFacebookMessage.Type = "fb_tag";
                                                }
                                                else
                                                {
                                                    objFacebookMessage.Type = "fb_home";
                                                }
                                            }
                                            else
                                            {
                                                objFacebookMessage.Type = "fb_home";
                                            }
                                        }
                                    }

                                }
                                else
                                {
                                    objFacebookMessage.Type = "fb_home";

                                }
                            }
                            else
                            {
                                objFacebookMessage.Type = "fb_home";
                            }
                        }
                        catch (Exception ex)
                        {
                            objFacebookMessage.Type = "fb_home";
                            Console.WriteLine(ex.StackTrace);
                        }
                        objFacebookMessage.ProfileId = profile["id"].ToString();
                        objFacebookMessage.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments";
                        dynamic likes = fb.Get("v2.0/" + result["id"].ToString() + "/likes?limit=50000000");
                        string likestatus = "likes";
                        foreach (dynamic like in likes["data"])
                        {
                            try
                            {
                                if (profile["id"].ToString() == like["id"].ToString())
                                {
                                    likestatus = "unlike";
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                likestatus = "likes";

                            }
                        }
                        objFacebookMessage.FbLike = likestatus;
                        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;
                                    }
                                }
                            }
                        }
                        objFacebookMessage.Message = message;

                        if (!objFacebookMessageRepository.checkFacebookMessageExists(objFacebookMessage.MessageId))
                        {
                            K++;
                            objFacebookMessageRepository.addFacebookMessage(objFacebookMessage);
                            logger.Error("AddFacebookUserHomeCount>>>"+K);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.StackTrace);
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
            }
        }
Ejemplo n.º 6
0
        //Added by Sumit Gupta [02-02-15]
        private void AddFacebookMessageWithPagination(string UserId, FacebookClient fb, dynamic profile)
        {
            int J = 0;
            objFacebookMessage = new Domain.Socioboard.Domain.FacebookMessage();
            try
            {
                string nexturl = "v2.0/me/inbox";

                for (int i = 0; i < 50; i++)
                {
                    dynamic messages = fb.Get(nexturl);
                    if (messages != null)
                    {
                        try
                        {
                            nexturl = messages["paging"]["next"].ToString();
                            logger.Error("Facebook.asmx >> AddFacebookMessageWithPagination >> nexturl : " + nexturl);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                            logger.Error(ex.StackTrace);
                        }

                        foreach (dynamic result in messages["data"])
                        {
                            try
                            {
                                foreach (dynamic message in result["comments"]["data"])
                                {
                                    objFacebookMessage.MessageId = message["id"];
                                    objFacebookMessage.FromName = message["from"]["name"];
                                    objFacebookMessage.FromId = message["from"]["id"];
                                    objFacebookMessage.Message = message["message"];
                                    objFacebookMessage.MessageDate = DateTime.Parse(message["created_time"].ToString());
                                    objFacebookMessage.FromProfileUrl = "http://graph.facebook.com/" + message["from"]["id"] + "/picture?type=small";
                                    objFacebookMessage.EntryDate = DateTime.Now;
                                    objFacebookMessage.Id = Guid.NewGuid();
                                    objFacebookMessage.ProfileId = profile["id"].ToString();
                                    objFacebookMessage.Type = "inbox_message";
                                    objFacebookMessage.UserId = Guid.Parse(UserId);
                                    if (!objFacebookMessageRepository.checkFacebookMessageExists(objFacebookMessage.MessageId))
                                    {
                                        J++;
                                        objFacebookMessageRepository.addFacebookMessage(objFacebookMessage);
                                        logger.Error("AddFacebookMessageWithPaginationCount>>>>"+J);
                                    }

                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.StackTrace);
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                Console.WriteLine(ex.StackTrace);
            }
        }
Ejemplo n.º 7
0
        public void getInboxMessages(dynamic data, dynamic profile, Guid userId)
        {
            FacebookMessage fbmsg = new FacebookMessage();
            FacebookMessageRepository fbmsgrepo = new FacebookMessageRepository();

            string profileid = string.Empty;
            User user = (User)HttpContext.Current.Session["LoggedUser"];

            if (data != null)
            {
                int lstfbcount = 0;
                foreach (dynamic result in data["data"])
                {


                    try
                    {
                        foreach (dynamic message in result["comments"]["data"])
                        {
                            //Do want you want with the messages
                            fbmsg.MessageId = message["id"];
                            fbmsg.FromName = message["from"]["name"];
                            fbmsg.FromId = message["from"]["id"];
                            fbmsg.Message = message["message"];
                            fbmsg.MessageDate = DateTime.Parse(message["created_time"].ToString()); ;
                            fbmsg.FromProfileUrl = "http://graph.facebook.com/" + message["from"]["id"] + "/picture?type=small";
                            fbmsg.EntryDate = DateTime.Now;
                            fbmsg.Id = Guid.NewGuid();
                            fbmsg.ProfileId = profile["id"].ToString();
                            fbmsg.Type = "inbox_message";
                            fbmsg.UserId = userId;
                            if (!fbmsgrepo.checkFacebookMessageExists(fbmsg.MessageId))
                            {
                                fbmsgrepo.addFacebookMessage(fbmsg);
                            }

                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }

                }
            }
        }
Ejemplo n.º 8
0
        //Saving FacebookWall of user into database i.e. FacebookMessage table
        public void getFacebookUserHome(dynamic data, dynamic profile)
        {
            FacebookMessage fbmsg = new FacebookMessage();
            FacebookMessageRepository fbmsgrepo = new FacebookMessageRepository();

            string profileid = string.Empty;
            User user = (User)HttpContext.Current.Session["LoggedUser"];

            if (data != null)
            {
                int lstfbcount = 0;
                foreach (dynamic result in data["data"])
                {
                    string message = string.Empty;
                    string imgprof = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small";
                    fbmsg.EntryDate = DateTime.Now;
                    fbmsg.MessageId = result["id"].ToString();
                    fbmsg.FromId = result["from"]["id"].ToString();
                    fbmsg.FromName = result["from"]["name"].ToString();
                    fbmsg.FromProfileUrl = imgprof;
                    fbmsg.Id = Guid.NewGuid();
                    fbmsg.MessageDate = DateTime.Parse(result["created_time"].ToString());
                    fbmsg.UserId = user.Id;

                    try
                    {
                        fbmsg.Picture = result["picture"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        fbmsg.Picture = null;
                    }

                    try
                    {
                        if (result["message_tags"][0] != null)
                        {




                            if (result["to"] != null)
                            {
                                foreach (var item in result["to"]["data"])
                                {
                                    if (result["from"] != null)
                                    {

                                        if (item["id"] != profile["id"])
                                        {
                                            if (result["from"]["id"] == profile["id"])
                                            {
                                                fbmsg.Type = "fb_tag";
                                            }
                                            else
                                            {
                                                fbmsg.Type = "fb_home";
                                            }
                                        }
                                        else
                                        {
                                            fbmsg.Type = "fb_home";
                                        }
                                    }
                                }

                            }
                            else
                            {
                                fbmsg.Type = "fb_home";

                            }
                        }
                        else
                        {
                            fbmsg.Type = "fb_home";
                        }
                    }
                    catch (Exception ex)
                    {
                        fbmsg.Type = "fb_home";
                        Console.WriteLine(ex.StackTrace);
                    }

                    fbmsg.ProfileId = profile["id"].ToString();
                    fbmsg.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments";
                    fbmsg.FbLike = "http://graph.facebook.com/" + result["id"] + "/likes";


                    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;
                                }
                            }

                        }

                    }
                    fbmsg.Message = message;

                    if (!fbmsgrepo.checkFacebookMessageExists(fbmsg.MessageId))
                    {
                        fbmsgrepo.addFacebookMessage(fbmsg);
                    }


                }
            }
        }
        /// <getAllWallpostsOfProfile>
        ///  Get all Wallpost of User by ProfileId(string)
        /// </summary>
        /// <param name="profileid">profileId FacebookMessage(String)</param>
        /// <param name="count">Count is used for counting upto 10 results.</param>
        /// <returns>Return all Message on behalf of ProfileId in form List type.</returns>
        public List<Domain.Socioboard.Domain.FacebookMessage> GetAllWallpostsOfProfileAccordingtoGroup(string profileid, int count, Guid UserId)
        {
            //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
                    {
                        List<Domain.Socioboard.Domain.FacebookMessage> lstFacebookMessage = new List<Domain.Socioboard.Domain.FacebookMessage>();

                        //Proceed action to get all Wallpost of User from FacebookMessage.
                        string query = "SELECT * from FacebookMessage use index (MessageDate_ProfileId_UserId) where UserId=:userid and ProfileId = :profileId and Type='fb_home' order by MessageDate Desc";
                        IList lst = session.CreateSQLQuery(query)
                        .SetParameter("profileId", profileid)
                        .SetParameter("userid", UserId)
                        .SetFirstResult(count)
                        .SetMaxResults(10).List();

                        foreach (var item in lst)
                        {
                            try
                            {
                                Domain.Socioboard.Domain.FacebookMessage fbmsg = new Domain.Socioboard.Domain.FacebookMessage();
                                Array arr = new object[] { };
                                arr = (Array)item;
                                fbmsg.Id = (Guid)arr.GetValue(0);
                                fbmsg.Message = (string)arr.GetValue(1);
                                fbmsg.MessageDate = (DateTime)arr.GetValue(2);
                                fbmsg.EntryDate = (DateTime)arr.GetValue(3);
                                fbmsg.ProfileId = (string)arr.GetValue(4);
                                fbmsg.FromId = (string)arr.GetValue(5);
                                fbmsg.FromName = (string)arr.GetValue(6);
                                fbmsg.FromProfileUrl = (string)arr.GetValue(7);
                                fbmsg.FbComment = (string)arr.GetValue(8);
                                fbmsg.FbLike = (string)arr.GetValue(9);
                                fbmsg.MessageId = (string)arr.GetValue(10);
                                fbmsg.Type = (string)arr.GetValue(11);
                                fbmsg.UserId = (Guid)arr.GetValue(12);
                                fbmsg.Picture = (string)arr.GetValue(13);
                                fbmsg.IsArchived = (int)arr.GetValue(14);

                                lstFacebookMessage.Add(fbmsg);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.StackTrace);
                            }
                        }
                        //.List<Domain.Socioboard.Domain.FacebookMessage>();
                        //.ToList<Domain.Socioboard.Domain.FacebookMessage>();
                        // List<Domain.Socioboard.Domain.FacebookMessage> lst = session.Query<Domain.Socioboard.Domain.FacebookMessage>().Where(x => x.UserId.Equals(UserId) && x.ProfileId.Equals(profileid) && x.Type.Equals("fb_home")).OrderByDescending(x => x.MessageDate).Take(10)//.CreateQuery("from FacebookFeed where  UserId = :UserId and FeedDescription like %' =:keyword '% ORDER BY FeedDate DESC")
                        //     //.List<Domain.Socioboard.Domain.FacebookFeed>()
                        //.ToList<Domain.Socioboard.Domain.FacebookMessage>();


                        return lstFacebookMessage;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        return null;
                    }

                }//End Transaction
            }//End session
        }
Ejemplo n.º 10
0
 public int deleteFacebookMessage(Domain.Socioboard.Domain.FacebookMessage fbaccount)
 {
     throw new NotImplementedException();
 }