public void updateImage(Domain.Socioboard.Domain.TwitterDirectMessages _TwitterDirectMessages)
 {
     //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 Update Data.
                 // And Set the reuired paremeters to find the specific values.
                 session.CreateQuery("Update TwitterDirectMessages set Image =:Image where MessageId = :MessageId and UserId = :userid")
                 .SetParameter("Image", _TwitterDirectMessages.Image)
                 .SetParameter("MessageId", _TwitterDirectMessages.MessageId)
                 .SetParameter("userid", _TwitterDirectMessages.UserId)
                 .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 // return 0;
             }
         } //End Transaction
     }     //End session
 }
 /// <addNewDirectMessage>
 /// Add New Direct Message
 /// </summary>
 /// <param name="twtDirectMessages">Set Values in a TwitterDirectMessages Class Property and Pass the Object of TwitterDirectMessages Class.(Domein.TwitterDirectMessages)</param>
 public void addNewDirectMessage(Domain.Socioboard.Domain.TwitterDirectMessages twtDirectMessages)
 {
     //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(twtDirectMessages);
             transaction.Commit();
         } //End Transaction
     }     //End Session
 }
        public void getTwittwrDirectMessageRecieved(oAuthTwitter OAuth, string UserId)
        {
            #region Add Twitter Direct Message
            TwitterUser twtuser = new TwitterUser();
            try
            {
                JArray Messages_Sent = twtuser.GetDirect_Messages(OAuth, 20);

                objTwitterDirectMessages = new Domain.Socioboard.Domain.TwitterDirectMessages();
                foreach (var item in Messages_Sent)
                {
                    objTwitterDirectMessages.UserId = Guid.Parse(UserId);
                    objTwitterDirectMessages.Type = "twt_directmessages_received";
                    objTwitterDirectMessages.Id = Guid.NewGuid();

                    try
                    {
                        objTwitterDirectMessages.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterDirectMessages.CreatedDate = Utility.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"'));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterDirectMessages.Message = item["text"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }

                    try
                    {
                        objTwitterDirectMessages.RecipientId = item["recipient"]["id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }

                    try
                    {
                        objTwitterDirectMessages.RecipientScreenName = item["recipient"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }

                    try
                    {
                        objTwitterDirectMessages.RecipientProfileUrl = item["recipient"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }

                    try
                    {
                        objTwitterDirectMessages.SenderId = item["sender"]["id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }

                    try
                    {
                        objTwitterDirectMessages.SenderScreenName = item["sender"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    } try
                    {
                        objTwitterDirectMessages.SenderProfileUrl = item["sender"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    } try
                    {
                        objTwitterDirectMessages.EntryDate = DateTime.Now;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    if (!objTwitterDirectMessageRepository.checkExistsDirectMessages(objTwitterDirectMessages.MessageId))
                    {
                        try
                        {
                            objTwitterDirectMessageRepository.addNewDirectMessage(objTwitterDirectMessages);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                logger.Error("twtuser.GetDirect_Messages_Sent ex.StackTrace >> " + ex.StackTrace);
                logger.Error("twtuser.GetDirect_Messages_Sent ex.Message >> " + ex.Message);
            }
            #endregion
        }
        public void getPageConversations(string UserId, FacebookClient fb, dynamic profile)
        {
            try
            {
                TwitterDirectMessageRepository _TwitterDirectMessageRepository = new TwitterDirectMessageRepository();
                Domain.Socioboard.Domain.TwitterDirectMessages _TwitterDirectMessages;
                dynamic data = fb.Get("v2.0/me/conversations");
                foreach (var item in data["data"])
                {
                    foreach (var msg_item in item["messages"]["data"])
                    {
                        _TwitterDirectMessages = new Domain.Socioboard.Domain.TwitterDirectMessages();

                        _TwitterDirectMessages.UserId = Guid.Parse(UserId);
                        _TwitterDirectMessages.EntryDate = DateTime.Now;



                        try
                        {
                            _TwitterDirectMessages.MessageId = msg_item["id"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        try
                        {
                            _TwitterDirectMessages.CreatedDate = Convert.ToDateTime(msg_item["created_time"].ToString());
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        try
                        {
                            _TwitterDirectMessages.SenderId = msg_item["from"]["id"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        try
                        {
                            _TwitterDirectMessages.SenderScreenName = msg_item["from"]["name"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        try
                        {
                            _TwitterDirectMessages.SenderProfileUrl = "http://graph.facebook.com/" + _TwitterDirectMessages.SenderId + "/picture?type=small";
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        try
                        {
                            _TwitterDirectMessages.RecipientId = msg_item["to"]["data"][0]["id"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        try
                        {
                            _TwitterDirectMessages.RecipientScreenName = msg_item["to"]["data"][0]["name"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        try
                        {
                            _TwitterDirectMessages.RecipientProfileUrl = "http://graph.facebook.com/" + _TwitterDirectMessages.RecipientId + "/picture?type=small";
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        try
                        {
                            _TwitterDirectMessages.Message = msg_item["message"].ToString();
                            if (string.IsNullOrEmpty(_TwitterDirectMessages.Message))
                            {
                                if ((msg_item["attachments"]["data"][0]["mime_type"].ToString()).Contains("image"))
                                {
                                    _TwitterDirectMessages.Image = msg_item["attachments"]["data"][0]["image_data"]["url"].ToString();
                                }
                                else
                                {
                                    _TwitterDirectMessages.Message = msg_item["attachments"]["data"][0]["name"].ToString();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        try
                        {
                            _TwitterDirectMessages.Image = msg_item["shares"]["data"][0]["link"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Facebook.asmx = > getPageConversations = > " + ex.Message);
                        }
                        if (_TwitterDirectMessages.SenderId == profile["id"].ToString())
                        {
                            _TwitterDirectMessages.Type = "fb_sent";
                        }
                        else
                        {
                            _TwitterDirectMessages.Type = "fb_received";
                        }

                        if (!_TwitterDirectMessageRepository.checkExistsDirectMessages(Guid.Parse(UserId), _TwitterDirectMessages.MessageId))
                        {
                            _TwitterDirectMessageRepository.addNewDirectMessage(_TwitterDirectMessages);
                        }
                        else
                        {
                            _TwitterDirectMessageRepository.updateImage(_TwitterDirectMessages);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("getPageConversations = > " + ex.Message);
            }
        }
        public string PostTwitterDirectmessage(string message, string userId, string fromId, string toId)
        {
            Domain.Socioboard.Domain.TwitterDirectMessages _TwitterDirectMessages = new Domain.Socioboard.Domain.TwitterDirectMessages();
            Domain.Socioboard.Domain.TwitterAccount objTwitterAccount = objTwitterAccountRepository.GetUserInformation(Guid.Parse(userId), fromId);
            oAuthTwitter OAuthTwt = new oAuthTwitter(ConfigurationManager.AppSettings["consumerKey"], ConfigurationManager.AppSettings["consumerSecret"], ConfigurationManager.AppSettings["callbackurl"]);
            OAuthTwt.AccessToken = objTwitterAccount.OAuthToken;
            OAuthTwt.AccessTokenSecret = objTwitterAccount.OAuthSecret;
            OAuthTwt.TwitterScreenName = objTwitterAccount.TwitterScreenName;
            OAuthTwt.TwitterUserId = objTwitterAccount.TwitterUserId;
          
            TwitterUser twtuser = new TwitterUser();
            JArray ret = new JArray();
            try
            {
                ret = twtuser.PostDirect_Messages_New(OAuthTwt, message, toId);
                _TwitterDirectMessages.MessageId = ret[0]["id_str"].ToString();
                _TwitterDirectMessages.Message = ret[0]["text"].ToString();
                _TwitterDirectMessages.CreatedDate = Utility.ParseTwitterTime(ret[0]["created_at"].ToString());
                _TwitterDirectMessages.EntryDate = DateTime.Now;
                _TwitterDirectMessages.RecipientId = ret[0]["recipient"]["id_str"].ToString();
                _TwitterDirectMessages.RecipientProfileUrl = ret[0]["recipient"]["profile_image_url_https"].ToString();
                _TwitterDirectMessages.RecipientScreenName = ret[0]["recipient"]["screen_name"].ToString();
                _TwitterDirectMessages.SenderId = ret[0]["sender"]["id_str"].ToString();
                _TwitterDirectMessages.SenderProfileUrl = ret[0]["sender"]["profile_image_url_https"].ToString();
                _TwitterDirectMessages.SenderScreenName = ret[0]["sender"]["screen_name"].ToString();
                _TwitterDirectMessages.Type = "twt_directmessages_sent";
                _TwitterDirectMessages.UserId = Guid.Parse(userId);
                objTwitterDirectMessageRepository.addNewDirectMessage(_TwitterDirectMessages);
            }
            catch (Exception ex)
            {

            }
            return ret.ToString();
        }
 public void updateDirectMessage(Domain.Socioboard.Domain.TwitterDirectMessages twtDirectMessages)
 {
     throw new NotImplementedException();
 }