public bool checkTubmlrUserExists(TumblrAccount objTumblrAccount)
        {
            //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 Check if FacebookUser is Exist in database or not by UserId and FbuserId.
                        // And Set the reuired paremeters to find the specific values.
                        NHibernate.IQuery query = session.CreateQuery("from TumblrAccount where UserId = :uidd and tblrUserName = :tbuname");
                        query.SetParameter("uidd",objTumblrAccount.UserId);
                        query.SetParameter("tbuname", objTumblrAccount.tblrUserName);
                        var result = query.UniqueResult();

                        if (result == null)
                            return false;
                        else
                            return true;

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

                }//End Transaction
            }//End session
        }
        public TumblrAccount getTumblrAccountDetailsById(string tumblruserid)
        {
           
            TumblrAccount result = new TumblrAccount();
            //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<TumblrAccount> objlsttumb = session.CreateQuery("from TumblrAccount where tblrUserName = :tblruname")
                            .SetParameter("tblruname", tumblruserid)
                       .List<TumblrAccount>().ToList<TumblrAccount>();
                    if (objlsttumb.Count > 0)
                    {
                        result = objlsttumb[0];
                    }
                    return result;
                }//End Transaction
            }//End s


        }
示例#3
0
 public static void Add(SocioBoard.Domain.TumblrAccount tumbler)
 {
     //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.
             session.Save(tumbler);
             transaction.Commit();
         } //End Using trasaction
     }     //End Using session
 }
        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);
            }
        }