public async Task <IHttpActionResult> SendByNickname([FromBody] Message i_Message)
        {
            string nickname = Thread.CurrentPrincipal.Identity.Name;

            if (i_Message.Sender != nickname)
            {
                return(BadRequest("Nicknames do not match."));
            }

            using (CarWatchDBEntities entities = new CarWatchDBEntities())
            {
                FacebookAccount account = await entities.FacebookAccounts.FirstOrDefaultAsync(e => e.Nickname == i_Message.Receiver);

                if (account == null)
                {
                    return(BadRequest("The receiver nickname was not found."));
                }
                i_Message.Time = DateTime.UtcNow;
                entities.Messages.Add(i_Message);
                if (account.ChatPartner != i_Message.Sender)
                {
                    TodoItem todoItem = new TodoItem();
                    todoItem.Text = i_Message.Sender + ";" + account.Nickname + ";sendChatMessage;" + i_Message.Content;
                    var response = await client.PostAsJsonAsync("tables/TodoItem/PostTodoItem?ZUMO-API-VERSION=2.0.0", todoItem);
                }
                await entities.SaveChangesAsync();

                return(Ok());
            }
        }
Exemple #2
0
        public async Task <IHttpActionResult> AddProposal([FromBody] Proposal i_ParkingSpotProposal)
        {
            string nickname = Thread.CurrentPrincipal.Identity.Name;

            if (i_ParkingSpotProposal.Nickname != nickname)
            {
                return(BadRequest("Nicknames do not match."));
            }

            using (CarWatchDBEntities entities = new CarWatchDBEntities())
            {
                Proposal result = await entities.Proposals.FirstOrDefaultAsync(e => e.Nickname == nickname);

                if (result != null)
                {
                    entities.Proposals.Remove(result);
                }
                i_ParkingSpotProposal.TimeOpened = DateTime.UtcNow;
                entities.Proposals.Add(i_ParkingSpotProposal);
                FacebookAccount proposerAccount = await entities.FacebookAccounts.FirstOrDefaultAsync(e => e.Nickname == nickname);

                proposerAccount.Rank++;
                await entities.SaveChangesAsync();

                return(Ok());
            }
        }
        //public List<FacebookAccount> getAllFbAccountDetail(string ProfileId)
        //{
        //    using (NHibernate.ISession session = SessionFactory.GetNewSession())
        //    {
        //        using (NHibernate.ITransaction transaction = session.BeginTransaction())
        //        {
        //            try
        //            {
        //                string str = "from FacebookAccount where FbUserId IN(";
        //                string[] arrst = ProfileId.Split(',');
        //                foreach (string strr in arrst)
        //                {
        //                    str += Convert.ToInt64(strr) + ",";
        //                }
        //                str = str.Substring(0, str.Length - 1);
        //                str += ")and Type=:page group by FbUserId";
        //                List<FacebookAccount> alst = session.CreateQuery(str).List<FacebookAccount>().ToList<FacebookAccount>();
        //                return alst;
        //            }
        //            catch (Exception ex)
        //            {
        //                Console.WriteLine(ex.StackTrace);
        //                return null;
        //            }
        //        }
        //    }
        //}


        public FacebookAccount getAllFbAccountDetail(string ProfileId)
        {
            List <FacebookAccount> objFbAcnt   = new List <FacebookAccount>();
            FacebookAccount        objfcbkacnt = new FacebookAccount();

            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                //After Session creation, start Transaction.
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    //Proceed action, to Get all FacebookAccount by UserId(Guid) and Type.
                    objFbAcnt = session.CreateQuery("from FacebookAccount where FbUserId =:profileId And Type=:page")
                                .SetParameter("profileId", ProfileId)
                                .SetParameter("page", "page")
                                .List <FacebookAccount>().ToList <FacebookAccount>();
                    if (objFbAcnt.Count != 0)
                    {
                        objfcbkacnt = objFbAcnt[0];
                    }
                    //ArrayList alstFBAccounts = new ArrayList();

                    //foreach (var item in query.Enumerable())
                    //{
                    //    alstFBAccounts.Add(item);
                    //}
                    return(objfcbkacnt);
                } //End Transaction
            }     //End session
        }
 public void updateFacebookUserStatus(FacebookAccount fbaccount)
 {
     //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 FacebookAccount set IsActive=:status where FbUserId = :fbuserid and UserId = :userid")
                 .SetParameter("fbuserid", fbaccount.FbUserId)
                 .SetParameter("userid", fbaccount.UserId)
                 .SetParameter("status", fbaccount.IsActive)
                 .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 // return 0;
             }
         } //End Transaction
     }     //End session
 }
Exemple #5
0
        public IHttpActionResult EditShareathon(ShareathonGroupViewModel sharethon)
        {
            string          groupId         = "";
            string          nameId          = "";
            ShareathonGroup eidtShareathon  = sharegrprepo.getShareathon(sharethon.Id);
            FacebookAccount facebookAccount = sharepo.getFbAccount(sharethon.Facebookaccountid);
            string          pageid          = FacebookHelper.GetFbPageDetails(sharethon.FacebookPageUrl, facebookAccount.AccessToken);

            eidtShareathon.Facebookaccountid   = facebookAccount.Id;
            eidtShareathon.Facebookpageid      = pageid;
            eidtShareathon.FacebookPageUrl     = sharethon.FacebookPageUrl;
            eidtShareathon.Timeintervalminutes = sharethon.Timeintervalminutes;
            for (int i = 0; i < sharethon.FacebookGroupId.Length; i++)
            {
                string   dataid = sharethon.FacebookGroupId[i];
                string[] grpid  = Regex.Split(dataid, "###");
                groupId = grpid[0] + "," + groupId;
                nameId  = sharethon.FacebookGroupId[i] + "," + nameId;
            }
            eidtShareathon.Facebookgroupid = groupId.TrimEnd(',');
            eidtShareathon.Facebooknameid  = nameId.TrimEnd(',');
            if (sharegrprepo.updateShareathon(eidtShareathon))
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemple #6
0
        public async Task <LoginResult> AuthenticateAsync(FacebookAccount account, RemoteUser user)
        {
            FacebookUserInfo facebookUser = GetFacebookUserInfo(account.Token);

            if (!Validate(facebookUser, account.FacebookUserId, account.Email))
            {
                return(new LoginResult
                {
                    Status = false,
                    Message = "Access is denied"
                });
            }

            LoginResult result = FacebookSignIn.SignIn(account.FacebookUserId, account.Email, account.OfficeId, facebookUser.Name, account.Token, user.Browser,
                                                       user.IpAddress, account.Culture);

            if (result.Status)
            {
                if (!Registration.HasAccount(account.Email))
                {
                    string       template     = "~/Catalogs/{catalog}/Areas/Frapid.Account/EmailTemplates/welcome-3rd-party.html";
                    WelcomeEmail welcomeEmail = new WelcomeEmail(facebookUser, template, ProviderName);
                    await welcomeEmail.SendAsync();
                }
            }
            return(result);
        }
        public void getfbFriendsGenderStatsForFanPage(dynamic profile, Guid userId, ref FacebookAccount objfbacnt)
        {
            FacebookStats           objfbStats     = new FacebookStats();
            FacebookStatsRepository objFBStatsRepo = new FacebookStatsRepository();

            //int malecount = 0;
            //int femalecount = 0;
            //foreach (var item in data["data"])
            //{
            //    if (item["gender"] == "male")
            //        malecount++;
            //    else if (item["gender"] == "female")
            //        femalecount++;
            //}
            objfbStats.EntryDate = DateTime.Now;
            objfbStats.FbUserId  = profile["id"].ToString();
            //objfbStats.FemaleCount = femalecount;
            objfbStats.Id = Guid.NewGuid();
            //objfbStats.MaleCount = malecount;
            objfbStats.UserId   = userId;
            objfbStats.FanCount = objfbacnt.Friends;
            //objfbStats.ShareCount = getShareCount();
            //objfbStats.CommentCount = getCommentCount();
            //objfbStats.LikeCount = getLikeCount();
            objFBStatsRepo.addFacebookStats(objfbStats);
            FacebookInsightStatsHelper objfbinshlpr = new FacebookInsightStatsHelper();
            string pId = profile["id"].ToString();

            //string pId = "329139457226886";
            objfbinshlpr.getPageImpresion(pId, userId, 7);
        }
Exemple #8
0
        public void PostData(ShareathonGroup item)
        {
            FacebookAccount facebookAccount = sharegrprepo.getFbAccount(item.Facebookaccountid);
            string          feedId          = string.Empty;

            string[] pageid = item.Facebookpageid.Split(',');

            foreach (string item_str in pageid)
            {
                string feeds = FacebookHelper.getFacebookRecentPost(item.AccessToken, item_str);

                try
                {
                    if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]"))
                    {
                        JObject fbpageNotes = JObject.Parse(feeds);
                        foreach (JObject obj in JArray.Parse(fbpageNotes["data"].ToString()))
                        {
                            try
                            {
                                string feedid = obj["id"].ToString();
                                feedid = feedid.Split('_')[1];
                                feedId = feedid + "," + feedId;
                            }
                            catch { }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            FacebookHelper.postfeedGroup(item.AccessToken, item.Facebookgroupid, feedId, facebookAccount.FbUserId, item.Timeintervalminutes);
        }
Exemple #9
0
        public ActionResult scheduler(string network, string profileid)
        {
            Dictionary <object, List <ScheduledMessage> > dictscheduler = new Dictionary <object, List <ScheduledMessage> >();

            Api.Groups.Groups ApiobjGroups            = new Api.Groups.Groups();
            Domain.Socioboard.Domain.Groups objGroups = (Domain.Socioboard.Domain.Groups)(new JavaScriptSerializer().Deserialize(ApiobjGroups.GetGroupDetailsByGroupId(Session["group"].ToString()), typeof(Domain.Socioboard.Domain.Groups)));
            if (network == "facebook")
            {
                Api.FacebookAccount.FacebookAccount ApiobjFacebookAccount = new Api.FacebookAccount.FacebookAccount();
                FacebookAccount objFacebookAccount = (FacebookAccount)(new JavaScriptSerializer().Deserialize(ApiobjFacebookAccount.getFacebookAccountDetailsById(objGroups.UserId.ToString(), profileid.ToString()), typeof(FacebookAccount)));
                Api.ScheduledMessage.ScheduledMessage ApiobjScheduledMessage = new Api.ScheduledMessage.ScheduledMessage();
                List <ScheduledMessage> objScheduledMessage = (List <ScheduledMessage>)(new JavaScriptSerializer().Deserialize(ApiobjScheduledMessage.GetAllUnSentMessagesAccordingToGroup(objGroups.UserId.ToString(), profileid.ToString(), network), typeof(List <ScheduledMessage>)));
                dictscheduler.Add(objFacebookAccount, objScheduledMessage);
            }
            else if (network == "twitter")
            {
                Api.TwitterAccount.TwitterAccount ApiobjTwitterAccount = new Api.TwitterAccount.TwitterAccount();
                TwitterAccount objTwitterAccount = (TwitterAccount)(new JavaScriptSerializer().Deserialize(ApiobjTwitterAccount.GetTwitterAccountDetailsById(objGroups.UserId.ToString(), profileid.ToString()), typeof(TwitterAccount)));
                Api.ScheduledMessage.ScheduledMessage ApiobjScheduledMessage = new Api.ScheduledMessage.ScheduledMessage();
                List <ScheduledMessage> objScheduledMessage = (List <ScheduledMessage>)(new JavaScriptSerializer().Deserialize(ApiobjScheduledMessage.GetAllUnSentMessagesAccordingToGroup(objGroups.UserId.ToString(), profileid.ToString(), network), typeof(List <ScheduledMessage>)));
                dictscheduler.Add(objTwitterAccount, objScheduledMessage);
            }
            else if (network == "linkedin")
            {
                Api.LinkedinAccount.LinkedinAccount ApiobjLinkedinAccount = new Api.LinkedinAccount.LinkedinAccount();
                LinkedInAccount objLinkedInAccount = (LinkedInAccount)(new JavaScriptSerializer().Deserialize(ApiobjLinkedinAccount.GetLinkedinAccountDetailsById(objGroups.UserId.ToString(), profileid.ToString()), typeof(LinkedInAccount)));
                Api.ScheduledMessage.ScheduledMessage ApiobjScheduledMessage = new Api.ScheduledMessage.ScheduledMessage();
                List <ScheduledMessage> objScheduledMessage = (List <ScheduledMessage>)(new JavaScriptSerializer().Deserialize(ApiobjScheduledMessage.GetAllUnSentMessagesAccordingToGroup(objGroups.UserId.ToString(), profileid.ToString(), network), typeof(List <ScheduledMessage>)));
                dictscheduler.Add(objLinkedInAccount, objScheduledMessage);
            }

            return(PartialView("_Panel3Partial", dictscheduler));
        }
Exemple #10
0
        public async Task <LoginResult> AuthenticateAsync(FacebookAccount account, RemoteUser user)
        {
            var facebookUser = this.GetFacebookUserInfo(account.Token);

            if (!this.Validate(facebookUser, account.FacebookUserId, account.Email))
            {
                return(new LoginResult
                {
                    Status = false,
                    Message = Resources.AccessIsDenied
                });
            }

            var result =
                await
                FacebookSignIn.SignInAsync(this.Tenant, account.FacebookUserId, account.Email, account.OfficeId, facebookUser.Name, account.Token, user.Browser, user.IpAddress, account.Culture)
                .ConfigureAwait(false);

            if (result.Status)
            {
                if (!await Registrations.HasAccountAsync(this.Tenant, account.Email).ConfigureAwait(false))
                {
                    string template     = "~/Tenants/{tenant}/Areas/Frapid.Account/EmailTemplates/welcome-email-other.html";
                    var    welcomeEmail = new WelcomeEmail(facebookUser, template, this.ProviderName);
                    await welcomeEmail.SendAsync(this.Tenant).ConfigureAwait(false);
                }
            }
            return(result);
        }
Exemple #11
0
        public IHttpActionResult EditShareathon(ShareathonViewModel sharethon)
        {
            Shareathon      eidtShareathon  = sharepo.getShareathon(sharethon.Id);
            FacebookAccount facebookAccount = sharepo.getFbAccount(sharethon.Facebookaccountid);

            eidtShareathon.Facebookaccountid = facebookAccount.Id;
            string id = "";

            for (int i = 0; i < sharethon.FacebookPageId.Length; i++)
            {
                string dataid = sharethon.FacebookPageId[i];
                id = dataid + "," + id;
            }
            eidtShareathon.Facebookpageid      = id.TrimEnd(',');
            eidtShareathon.Timeintervalminutes = sharethon.Timeintervalminutes;

            if (sharepo.updateShareathon(eidtShareathon))
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemple #12
0
        public void getStories(string pageId, Guid UserId, int days)
        {
            try
            {
                string                    strStories = "https://graph.facebook.com/" + pageId + "/insights/post_stories";
                FacebookClient            fb         = new FacebookClient();
                FacebookAccountRepository fbAccRepo  = new FacebookAccountRepository();
                FacebookAccount           acc        = fbAccRepo.getUserDetails(pageId);
                fb.AccessToken = acc.AccessToken;


                JsonObject                     outputreg  = (JsonObject)fb.Get(strStories);
                JArray                         data       = (JArray)JsonConvert.DeserializeObject(outputreg["data"].ToString());
                FacebookInsightStats           objFbi     = new FacebookInsightStats();
                FacebookInsightStatsRepository objfbiRepo = new FacebookInsightStatsRepository();
                foreach (var item in data)
                {
                    var values = item["values"];
                    foreach (var age in values)
                    {
                        objFbi.EntryDate    = DateTime.Now;
                        objFbi.FbUserId     = pageId;
                        objFbi.Id           = Guid.NewGuid();
                        objFbi.StoriesCount = int.Parse(age["value"].ToString());
                        objFbi.UserId       = UserId;
                        objFbi.CountDate    = age["end_time"].ToString();
                        objfbiRepo.addFacebookInsightStats(objFbi);
                    }
                }
            }
            catch (Exception Err)
            {
                Console.Write(Err.StackTrace);
            }
        }
        public async Task <IHttpActionResult> Register([FromBody] FacebookAccount i_Account)
        {
            using (CarWatchDBEntities entities = new CarWatchDBEntities())
            {
                var isExistNickname = await entities.FacebookAccounts.AnyAsync(e => e.Nickname == i_Account.Nickname);

                if (isExistNickname)
                {
                    return(BadRequest("nameinuse"));
                }

                if (i_Account.LicensePlate != null)
                {
                    var isExistLicensePlate = await entities.FacebookAccounts.AnyAsync(e => e.LicensePlate == i_Account.LicensePlate);

                    if (isExistLicensePlate)
                    {
                        return(BadRequest("licenseinuse"));
                    }
                }

                entities.FacebookAccounts.Add(i_Account);
                await entities.SaveChangesAsync();

                return(Ok());
            }
        }
        /// <getUserDetails>
        /// Get User's all Detail from FacebookAccount by FbUserId.
        /// </summary>
        /// <param name="FbUserId">FbUserId of FacebookAccount(string)</param>
        /// <returns>Return a object of FacebookAccount with  value of each member.</returns>
        public FacebookAccount getUserDetails(string FbUserId)
        {
            //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 User's all Detail from FacebookAccount by FbUserId.
                        NHibernate.IQuery query = session.CreateQuery("from FacebookAccount where FbUserId = :fbuserid");

                        query.SetParameter("fbuserid", FbUserId);
                        List <FacebookAccount> lst = new List <FacebookAccount>();

                        foreach (FacebookAccount item in query.Enumerable())
                        {
                            lst.Add(item);
                            break;
                        }
                        FacebookAccount fbacc = lst[0];
                        return(fbacc);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        return(null);
                    }
                } //End Transaction
            }     //End session
        }
Exemple #15
0
        public void PostDataPage(Shareathon item, string pageid)
        {
            FacebookAccount facebookpage    = sharegrprepo.getFbAccount(Guid.Parse(pageid));
            FacebookAccount facebookAccount = sharegrprepo.getFbAccount(item.Facebookaccountid);

            string feeds = FacebookHelper.getFacebookRecentPost(facebookpage.AccessToken, facebookpage.FbUserId);


            string feedId = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]"))
                {
                    JObject fbpageNotes = JObject.Parse(feeds);
                    foreach (JObject obj in JArray.Parse(fbpageNotes["data"].ToString()))
                    {
                        try
                        {
                            string feedid = obj["id"].ToString();
                            feedid = feedid.Split('_')[1];
                            FacebookHelper.ShareFeed(facebookAccount.AccessToken, feedid, facebookpage.FbUserId, "", facebookAccount.FbUserId, "", item.Timeintervalminutes);
                        }
                        catch { }
                        Thread.Sleep(1000 * 60 * item.Timeintervalminutes);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        public static FacebookAccount GetFacebookAccount(string FbUserId)
        {
            Api.FacebookAccount.FacebookAccount objApiFacebookAccount = new Api.FacebookAccount.FacebookAccount();

            FacebookAccount objDomainFacebookAccount = (FacebookAccount) new JavaScriptSerializer().Deserialize(objApiFacebookAccount.getUserDetails(FbUserId), typeof(FacebookAccount));

            return(objDomainFacebookAccount);
        }
		public void OnLoggedOut()
		{
			_facebookAccountData = null;
			if (LogoutCompleted != null)
			{
				LogoutCompleted();
			}
		}
		private async Task SetAccessTokenAsync(FacebookAccess facebookAccessData)
		{
			FacebookProfile profile = await _facebookFacade.GetUserProfile(facebookAccessData.AccessToken);
			_facebookAccountData = new FacebookAccount(facebookAccessData, profile);
			if (LoginCompleted != null)
			{
				LoginCompleted(_facebookAccountData);
			}
		}
        private static string GetFbPost(object objFacebookAccount)
        {
            FacebookAccount        itemFb           = (FacebookAccount)objFacebookAccount;
            clsFacebookDataScraper objFbDataScraper = new clsFacebookDataScraper();

            objFbDataScraper.GetFbPost(itemFb.UserId.ToString(), itemFb.FbUserId);

            return("");
        }
Exemple #20
0
        public void exec(Uri redirectUrl)
        {
            var credentials = facebookClient.FetchCredentialsFromRedirectUrl(redirectUrl);
            var userId      = facebookClient.GetUserId(credentials);
            var accountName = facebookClient.GetAccountName(userId, credentials.AccessToken);
            var account     = new FacebookAccount(userId, credentials, accountName);

            facebookAccountRepository.Add(account);
        }
Exemple #21
0
        public void getFanPageLikesByGenderAge(string pageId, Guid UserId, int days)
        {
            try
            {
                string                    strAge    = "https://graph.facebook.com/" + pageId + "/insights/page_fans_gender_age";
                FacebookClient            fb        = new FacebookClient();
                FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
                FacebookAccount           acc       = fbAccRepo.getUserDetails(pageId);
                fb.AccessToken = acc.AccessToken;
                ///////////////////////////////////////////////////
                // string codedataurlgraphic = objAuthentication.RequestUrl(strAge, strToken);
                //if (txtDateSince.Text != "")
                //    strAge = strAge + "&since=" + txtDateSince.Text;
                //if (txtDateUntill.Text != "")
                //    strAge = strAge + "&until=" + txtDateUntill.Text;

                JsonObject                     outputreg  = (JsonObject)fb.Get(strAge);
                JArray                         data       = (JArray)JsonConvert.DeserializeObject(outputreg["data"].ToString());
                FacebookInsightStats           objFbi     = new FacebookInsightStats();
                FacebookInsightStatsRepository objfbiRepo = new FacebookInsightStatsRepository();
                foreach (var item in data)
                {
                    var values = item["values"];
                    foreach (var age in values)
                    {
                        var ageVal      = age["value"];
                        var agevalarray = ageVal.ToString().Substring(1, ageVal.ToString().Length - 2).Split(',');
                        for (int i = 0; i < agevalarray.Count(); i++)
                        {
                            var genderagearray = agevalarray[i].Split(':');
                            var gender         = genderagearray[0].Split('.');
                            objFbi.AgeDiff     = gender[1].Trim();
                            objFbi.Gender      = gender[0].Trim();
                            objFbi.EntryDate   = DateTime.Now;
                            objFbi.FbUserId    = pageId;
                            objFbi.Id          = Guid.NewGuid();
                            objFbi.PeopleCount = int.Parse(genderagearray[1]);
                            objFbi.UserId      = UserId;
                            objFbi.CountDate   = age["end_time"].ToString();
                            if (!objfbiRepo.checkFacebookInsightStatsExists(pageId, UserId, age["end_time"].ToString(), gender[1].Trim()))
                            {
                                objfbiRepo.addFacebookInsightStats(objFbi);
                            }
                            else
                            {
                                objfbiRepo.updateFacebookInsightStats(objFbi);
                            }
                        }
                        // strFbAgeArray=strFbAgeArray+
                    }
                }
            }
            catch (Exception Err)
            {
                Console.Write(Err.StackTrace);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    if (Session["AdminProfile"] == null)
                    {
                        Response.Redirect("Default.aspx");
                    }

                    string id     = Request.QueryString["id"].ToString();
                    string type   = Request.QueryString["type"].ToString();
                    string userid = Request.QueryString["userid"].ToString();

                    if (type == "twt")
                    {
                        TwtAcc = objTwtRepo.getUserInformation(Guid.Parse(userid), id);
                        Session["updateData"] = TwtAcc;
                        txtName.Text          = TwtAcc.TwitterScreenName;
                        //ddltatus.SelectedValue = TwtAcc.IsActive.ToString();
                    }
                    if (type == "fb")
                    {
                        FBAcc = objFbRepo.getFacebookAccountDetailsById(id, Guid.Parse(userid));
                        Session["updateData"] = FBAcc;
                        txtName.Text          = FBAcc.FbUserName;
                        // ddltatus.SelectedValue = FBAcc.IsActive.ToString();
                    }
                    if (type == "li")
                    {
                        liAcc = objLiRepo.getLinkedinAccountDetailsById(id);
                        Session["updateData"] = liAcc;
                        txtName.Text          = liAcc.LinkedinUserName;
                        // ddltatus.SelectedValue = liAcc.IsActive.ToString();
                    }
                    if (type == "ins")
                    {
                        InsAcc = objInsRepo.getInstagramAccountDetailsById(id, Guid.Parse(userid));
                        Session["updateData"] = InsAcc;
                        txtName.Text          = InsAcc.InsUserName;
                        //   ddltatus.SelectedValue = InsAcc.IsActive.ToString();
                    }
                    if (type == "gp")
                    {
                        GpAcc = objgpRepo.getGooglePlusAccountDetailsById(id, Guid.Parse(userid));
                        Session["updateData"] = GpAcc;
                        txtName.Text          = GpAcc.GpUserName;
                        //ddltatus.SelectedValue = GpAcc.IsActive.ToString();
                    }
                }
            }
            catch (Exception Err)
            {
                logger.Error(Err.Message);
            }
        }
Exemple #23
0
        public ActionResult EditProfileDetails(string ProfileId, string UserId, string Network)
        {
            Dictionary <string, object> objProfileToEdit = new Dictionary <string, object>();

            if (Network == "Facebook")
            {
                Api.FacebookAccount.FacebookAccount Apiobjfb = new Api.FacebookAccount.FacebookAccount();
                FacebookAccount objFbAccount = (FacebookAccount)(new JavaScriptSerializer().Deserialize(Apiobjfb.getFacebookAccountDetailsById(UserId, ProfileId), typeof(FacebookAccount)));
                Session["UpdateProfileData"] = objFbAccount;
                objProfileToEdit.Add("Facebook", objFbAccount);
            }
            if (Network == "Twitter")
            {
                Api.TwitterAccount.TwitterAccount Apiobjtwt = new Api.TwitterAccount.TwitterAccount();
                TwitterAccount objtwtAccount = (TwitterAccount)(new JavaScriptSerializer().Deserialize(Apiobjtwt.GetTwitterAccountDetailsById(UserId, ProfileId), typeof(TwitterAccount)));
                Session["UpdateProfileData"] = objtwtAccount;
                objProfileToEdit.Add("Twitter", objtwtAccount);
            }
            if (Network == "Linkedin")
            {
                Api.LinkedinAccount.LinkedinAccount Apiobjlin = new Api.LinkedinAccount.LinkedinAccount();
                LinkedInAccount objLinAccount = (LinkedInAccount)(new JavaScriptSerializer().Deserialize(Apiobjlin.GetLinkedinAccountDetailsById(UserId, ProfileId), typeof(LinkedInAccount)));
                Session["UpdateProfileData"] = objLinAccount;
                objProfileToEdit.Add("Linkedin", objLinAccount);
            }
            if (Network == "Instagram")
            {
                Api.InstagramAccount.InstagramAccount ApiobjIns = new Api.InstagramAccount.InstagramAccount();
                InstagramAccount objInsAccount = (InstagramAccount)(new JavaScriptSerializer().Deserialize(ApiobjIns.UserInformation(UserId, ProfileId), typeof(InstagramAccount)));
                Session["UpdateProfileData"] = objInsAccount;
                objProfileToEdit.Add("Instagram", objInsAccount);
            }
            if (Network == "Tumblr")
            {
                Api.TumblrAccount.TumblrAccount Apiobjtmb = new Api.TumblrAccount.TumblrAccount();
                TumblrAccount objTmbAccount = (TumblrAccount)(new JavaScriptSerializer().Deserialize(Apiobjtmb.GetTumblrAccountDetailsById(UserId, ProfileId), typeof(TumblrAccount)));
                Session["UpdateProfileData"] = objTmbAccount;
                objProfileToEdit.Add("Tumblr", objTmbAccount);
            }
            if (Network == "Youtube")
            {
                Api.YoutubeAccount.YoutubeAccount ApiobjYoutb = new Api.YoutubeAccount.YoutubeAccount();
                YoutubeAccount objYouTbAccount = (YoutubeAccount)(new JavaScriptSerializer().Deserialize(ApiobjYoutb.GetYoutubeAccountDetailsById(UserId, ProfileId), typeof(YoutubeAccount)));
                Session["UpdateProfileData"] = objYouTbAccount;
                objProfileToEdit.Add("Youtube", objYouTbAccount);
            }
            if (Network == "GooglePlus")
            {
                Api.GooglePlusAccount.GooglePlusAccount Apiobjgplus = new Api.GooglePlusAccount.GooglePlusAccount();
                GooglePlusAccount objGPAccount = (GooglePlusAccount)(new JavaScriptSerializer().Deserialize(Apiobjgplus.GetGooglePlusAccountDetailsById(UserId, ProfileId), typeof(GooglePlusAccount)));
                Session["UpdateProfileData"] = objGPAccount;
                objProfileToEdit.Add("GooglePlus", objGPAccount);
            }

            return(View(objProfileToEdit));
        }
        private FacebookPage MapFacebookAccount(FacebookAccount reader)
        {
            FacebookPage fbPage = new FacebookPage()
            {
                Id   = reader.Id,
                Name = reader.Name,
            };

            return(fbPage);
        }
Exemple #25
0
        public void getFanPost(string pageId, Guid UserId, int days)
        {
            string                    strStories = "https://graph.facebook.com/" + pageId + "/feed";
            FacebookClient            fb         = new FacebookClient();
            FacebookAccountRepository fbAccRepo  = new FacebookAccountRepository();
            FacebookAccount           acc        = fbAccRepo.getUserDetails(pageId);

            fb.AccessToken = acc.AccessToken;
            JsonObject outputreg = (JsonObject)fb.Get(strStories);
            JArray     data      = (JArray)JsonConvert.DeserializeObject(outputreg["data"].ToString());
            FacebookInsightPostStats           objFbiPost     = new FacebookInsightPostStats();
            FacebookInsightPostStatsRepository objfbiPostRepo = new FacebookInsightPostStatsRepository();

            foreach (var item in data)
            {
                try
                {
                    objFbiPost.Id        = Guid.NewGuid();
                    objFbiPost.EntryDate = DateTime.Now;
                    objFbiPost.PageId    = pageId;
                    try
                    {
                        objFbiPost.PostMessage = item["story"].ToString();
                    }
                    catch (Exception Err)
                    {
                        objFbiPost.PostMessage = item["message"].ToString();
                    }
                    objFbiPost.PostDate = item["created_time"].ToString();
                    JArray arrComment = (JArray)item["comment"];
                    if (arrComment != null)
                    {
                        objFbiPost.PostComments = arrComment.Count;
                    }
                    else
                    {
                        objFbiPost.PostComments = 0;
                    }
                    objFbiPost.PostId = item["id"].ToString();
                    objFbiPost.UserId = UserId;
                    if (!objfbiPostRepo.checkFacebookInsightPostStatsExists(pageId, item["id"].ToString(), UserId, item["created_time"].ToString()))
                    {
                        objfbiPostRepo.addFacebookInsightPostStats(objFbiPost);
                    }
                    else
                    {
                        objfbiPostRepo.updateFacebookInsightPostStats(objFbiPost);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        public User FacebookLogin(FacebookAccount model)
        {
            var user = context.Users.Include(x => x.Role).Include(y => y.Courses).FirstOrDefault(z => z.Email.ToUpper() == model.Email.ToUpper());

            if (user == null)
            {
                return(null);
            }

            return(user);
        }
Exemple #27
0
        public FacebookAccount GetFacebookAccount(dynamic obj)
        {
            var account = new FacebookAccount
            {
                Id        = obj.id,
                Name      = obj.name,
                FirstName = obj.first_name,
                LastName  = obj.last_name
            };

            return(account);
        }
Exemple #28
0
        public void Log(FacebookAccount account)
        {
            if (account == null)
            {
                return;
            }

            Console.WriteLine($"Facebook User: "******"Account ID: {account.Id}");
            Console.WriteLine($"Full Name: {account.Name}");
            Console.WriteLine("");
        }
Exemple #29
0
 public void Start()
 {
     this.DTSG           = (string)null;
     this.JAZOEST        = (string)null;
     this.Friends        = new List <Friend>();
     this.CurrentAccount = this.Web.DownloadAcc();
     if (this.CurrentAccount.Error)
     {
         return;
     }
     this.CurrentAccount.SetContainer();
     this.CheckAccount();
 }
        /// <summary>
        /// Creates the facebook account.
        /// </summary>
        /// <param name="userProfileId">The user profile identifier.</param>
        /// <param name="facebookAccountId">The facebook account identifier.</param>
        /// <returns></returns>
        public async Task <bool> CreateFacebookAccount(Guid userProfileId, string facebookAccountId)
        {
            var facebookAccount = new FacebookAccount
            {
                UserProfileId     = userProfileId,
                FacebookAccountId = facebookAccountId
            };

            _facebookAccountRepository.Insert(facebookAccount);
            await _unitOfWork.CommitAsync();

            return(true);
        }
 /// <addFacebookUser>
 /// Add new facebok user in  database.
 /// </summary>
 /// <param name="fbaccount">Set Values in a FacebookAccount Class Property and Pass the same Object of FacebookAccount Class.(Domain.FacebookAccount)</param>
 public void addFacebookUser(FacebookAccount fbaccount)
 {
     //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(fbaccount);
             transaction.Commit();
         } //End Transaction
     }     //End session
 }
Exemple #32
0
        public async Task <FacebookAccount> GetAccountAsync(string accessToken)
        {
            var response = await _facebookClient.GetAsync <dynamic>(
                accessToken, "me", "fields=id,name,first_name,last_name");

            if (response == null)
            {
                throw new Exception("FacebookAccount not found. ");
            }

            FacebookAccount facebookAccount = _modelMapper.GetFacebookAccount(response);

            return(facebookAccount);
        }
Exemple #33
0
        public void FacebookGetSnapshot()
        {
            FacebookAccount account = new FacebookAccount { Id = "NHLBruins", FriendlyName = "Boston Bruins" };

            FacebookSnapshot accountSnapshot = FacebookQuery.GetFacebookSnapshot(account);

            Assert.AreEqual(DateTime.UtcNow.Date, accountSnapshot.DateOfSnapshot.Date, "The snapshot is from today");
            Assert.IsTrue(accountSnapshot.TotalLikes > 0, "There are more than 0 likes");
            Assert.IsTrue(accountSnapshot.PeopleTalkingAboutThis > 0, "There are more than 0 people talking about this");
            Assert.IsTrue(accountSnapshot.MostPopularWeek > DateTime.MinValue, "The most popular week is not the default DateTime.MinValue");
            Assert.AreNotEqual(String.Empty, accountSnapshot.MostPopularCity, "The most popular city is not empty");
            Assert.AreNotEqual(String.Empty, accountSnapshot.MostPopularAgeGroup, "The most popular age group is not empty");

            Assert.AreEqual(account.Id, accountSnapshot.FacebookAccountId, "There account name is correct in the snapshot");
            Assert.AreEqual("NHLBruins", accountSnapshot.FacebookAccountId, "There account name is NHLBruins");
        }
		public async Task<AccountData> LoginAsync(FacebookAccess facebookAccess)
		{
			Task<FacebookProfile> facebookProfileTask = _facebookFacade.GetUserProfile(facebookAccess.AccessToken);

			Task<BiketimerAccount> biketimerAccountTask = _biketimerIdentityFacade.GetBiketimerToken(facebookAccess.AccessToken)
															   .ContinueWith(DownloadBiketimerAccountAsync)
															   .Unwrap();

			FacebookProfile facebookProfile = await facebookProfileTask;
			BiketimerAccount biketimerAccount = await biketimerAccountTask;

			FacebookAccount facebookAccount = new FacebookAccount(facebookAccess, facebookProfile);
			AccountData _accountData = new AccountData(facebookAccount, biketimerAccount);

			return _accountData;
		}
        public string AddAllFbPagePost(string userid, string accesstoken, string profileid)
        {
            logger.Error("AddFbPagePost");
            logger.Error(userid + ", " + accesstoken + " , " + profileid);
            string ret = string.Empty;
            Api.Socioboard.Services.FacebookAccount _FacebookAccount = new FacebookAccount();
            Domain.Socioboard.Domain.FacebookAccount _facebookAccount = new Domain.Socioboard.Domain.FacebookAccount();

            try
            {
                string _nextPageDataUrl = string.Empty;
                FacebookClient fb = new FacebookClient();

                if (string.IsNullOrEmpty(accesstoken))
                {
                    try
                    {
                        _facebookAccount = (Domain.Socioboard.Domain.FacebookAccount)(new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(_FacebookAccount.getFacebookAccountDetailsById(userid, profileid), typeof(Domain.Socioboard.Domain.FacebookAccount)));

                        _facebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                        Api.Socioboard.Services.FacebookAccountRepository _FacebookAccountRepository = new FacebookAccountRepository();

                        System.Collections.ArrayList lstFacebookAccounts = _FacebookAccountRepository.getAllFacebookAccounts();

                        Random _random = new Random();
                        var rnum = _random.Next(0, lstFacebookAccounts.Count - 1);
                        _facebookAccount = (Domain.Socioboard.Domain.FacebookAccount)lstFacebookAccounts[rnum];
                        fb.AccessToken = _facebookAccount.AccessToken;
                    }
                    catch { };
                }
                else
                    fb.AccessToken = accesstoken;


                dynamic post = null;
                try
                {
                    post = fb.Get("v2.0/" + profileid + "/posts");
                }
                catch (Exception ex)
                {
                    logger.Error("profileid +posts");
                    logger.Error(ex.Message);
                    logger.Error(ex.StackTrace);
                }
            //dynamic post1 = fb.Get("me/posts");
            _NextPageDataUrl:

                if (!string.IsNullOrEmpty(_nextPageDataUrl))
                {
                    fb = new FacebookClient();
                    post = fb.Get(_nextPageDataUrl);
                    _nextPageDataUrl = string.Empty;
                }
                foreach (var item in post["data"])
                {
                    #region
                    objFbPagePost.Id = Guid.NewGuid();
                    objFbPagePost.UserId = Guid.Parse(userid);
                    objFbPagePost.PageId = profileid;
                    objFbPagePost.PostId = item["id"].ToString();

                    objFbPagePost.PostDate = Convert.ToDateTime(item["created_time"]);
                    objFbPagePost.EntryDate = DateTime.Now;
                    try
                    {
                        objFbPagePost.Post = item["message"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objFbPagePost.PictureUrl = item["picture"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }

                    try
                    {
                        objFbPagePost.LinkUrl = item["link"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objFbPagePost.IconUrl = item["icon"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objFbPagePost.StatusType = item["status_type"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objFbPagePost.Type = item["type"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objFbPagePost.FromId = item["from"]["id"];

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objFbPagePost.FromName = item["from"]["name"];

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    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);
                    }
                    try
                    {
                        if (!objFbPagePostRepository.IsPostExist(objFbPagePost))
                            objFbPagePostRepository.addFbPagePost(objFbPagePost);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        logger.Error(ex.StackTrace);
                    }

                    try
                    {
                        AddAllFbPagePostComments(objFbPagePost.PostId, accesstoken, userid);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        AddAllFbPagePostLiker(objFbPagePost.PostId, accesstoken, userid);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                    #endregion

                }


                try
                {
                    _nextPageDataUrl = post["paging"]["next"];
                    if (!string.IsNullOrEmpty(_nextPageDataUrl))
                        goto _NextPageDataUrl;

                }
                catch { };


            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
                Console.WriteLine(ex.StackTrace);
            }
            return ret;
        }
        public string GetFbPageDetails(string url)
        {
            try
            {
                FacebookClient fb = new FacebookClient();
                FacebookAccount _FacebookAccount = new FacebookAccount();
                //string token = _FacebookAccount.getFbToken();
                //fb.AccessToken = "CAAKYvwDVmnUBACyqUsvADWoAfBYTxi0kbz2gcw0sDWbBVJCXmIUG6rGez4BFSCE4hKV8eNE86eCD2iOwEWADvYuNlYupZCL4WUAGhFmRIZA6nTkdUOFeiUVHuri571QxhZA3YfSk5YkjhYy81pYtPj9FNM2mENtjCWRr5tN9zWZAKpUkw3gzsXRuEH9ZBTBwZD";
                //fb.AccessToken = token;
                // logger.Error(" GetFbPageDetails: " + fb.AccessToken);

                fb.AccessToken = ConfigurationManager.AppSettings["AccessToken1"].ToString();
                dynamic pageinfo = null;
                try
                {
                    pageinfo = fb.Get(url);
                    logger.Error("Token 1");
                }
                catch (Exception ex1)
                {
                    try
                    {
                        //fb.AccessToken = "CAAKYvwDVmnUBAFvCcZCQDL53q82jfR5mvgF2whNsFHgR4NmeSSUeRVpdEUpcVVgK1ERs2GZCNhJAwRHtq6MEWiRtBQnxBmZAML6dnwgpsCbjUmyT7ws6EKZBxuWbxhJqjeNCsxhac00b3L9Bf7LLlYa3PG94Uouj7vXZAZC6djZCme5BuszE3vibNFLKQqaLcgZD";
                        fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString();
                        pageinfo = fb.Get(url);
                        logger.Error("Token 2");
                    }
                    catch (Exception ex2)
                    {
                        try
                        {
                            //fb.AccessToken = "CAAKYvwDVmnUBAAR2O9hxFkHzfNG8H6KbQLaiGFMRshJkbttdzhDeprklcb1yaV0rwtC7N8Xz1rsL1cykiRv2ouXtBUFxvOZCNnpFELnQGFV8jGUWjm1GYsZA40IKAORLGoAcSaa2lJkuuSoLBksB8LFPHI4cqW7VVqxgDwZCRwObxqR4Qp9QEDHxa7j1yoZD";
                            fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString();
                            pageinfo = fb.Get(url);
                            logger.Error("Token 3");
                        }
                        catch (Exception ex3)
                        {
                            try
                            {
                                //fb.AccessToken = "CAAKYvwDVmnUBAFtZB8pvVrqYQonmq7MD90oNdoipDc0Te4onP2XlbZAYT4bzOZAKTr8jdhw0P1PclgLOtVxJ9g2qx4vxZAzh2CXqXAZBZAZBwkgWIVjc2B4rcXAp6O5B3gXqd8Ko5ITL9VCZCMOkMZCPc1hBsp0n8zgPt6e3Dd0vaodPBS8nMz7RD";
                                fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString();
                                pageinfo = fb.Get(url);
                                logger.Error("Token 4");
                            }
                            catch (Exception ex4)
                            {

                                logger.Error("Finally :" + fb.AccessToken);
                                logger.Error(ex4.Message);
                                logger.Error(ex4.Message);

                            }
                        }
                    }

                }

                Domain.Socioboard.Domain.AddFacebookPage objAddFacebookPage = new Domain.Socioboard.Domain.AddFacebookPage();
                objAddFacebookPage.ProfilePageId = pageinfo["id"];
                logger.Error(" pageinfo: " + pageinfo["id"]);
                return new JavaScriptSerializer().Serialize(objAddFacebookPage);
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
                Console.WriteLine(ex.StackTrace);
                return "Something Went Wrong";
            }
        }
        public string AddFacebookPagesByUrl(string userid, string profileId, string groupId, string name)
        {
            logger.Error("AddFacebookPagesByUrllllllll");
            logger.Error(userid + ", " + profileId + ", " + groupId + ", " + name);
            string ret = string.Empty;
            FacebookAccount _FacebookAccount = new FacebookAccount();
            // string token = _FacebookAccount.getFbToken();
            //string token = "CAAKYvwDVmnUBACyqUsvADWoAfBYTxi0kbz2gcw0sDWbBVJCXmIUG6rGez4BFSCE4hKV8eNE86eCD2iOwEWADvYuNlYupZCL4WUAGhFmRIZA6nTkdUOFeiUVHuri571QxhZA3YfSk5YkjhYy81pYtPj9FNM2mENtjCWRr5tN9zWZAKpUkw3gzsXRuEH9ZBTBwZD";
            string token = ConfigurationManager.AppSettings["AccessToken1"].ToString();
            try
            {
                #region fancount
                FacebookClient fb = new FacebookClient();
                fb.AccessToken = token;
                int fancountPage = 0;
                try
                {
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                    //dynamic fancount = fb.Get("fql", new { q = " SELECT fan_count FROM page WHERE page_id =" + profileId });
                    //foreach (var friend in fancount.data)
                    //{
                    //    fancountPage = Convert.ToInt32(friend.fan_count);
                    //}

                    //dynamic friends = fb.Get("v2.0/me/friends");
                    //fancountPage = Convert.ToInt16(friends["summary"]["total_count"].ToString());
                    dynamic friends = fb.Get("v2.0/" + profileId);
                    fancountPage = Convert.ToInt32(friends["likes"].ToString());

                }
                catch (Exception)
                {
                    fancountPage = 0;
                    //fb.AccessToken = "CAAKYvwDVmnUBAFvCcZCQDL53q82jfR5mvgF2whNsFHgR4NmeSSUeRVpdEUpcVVgK1ERs2GZCNhJAwRHtq6MEWiRtBQnxBmZAML6dnwgpsCbjUmyT7ws6EKZBxuWbxhJqjeNCsxhac00b3L9Bf7LLlYa3PG94Uouj7vXZAZC6djZCme5BuszE3vibNFLKQqaLcgZD";
                    fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString();
                    try
                    {
                        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                        //dynamic fancount = fb.Get("fql", new { q = " SELECT fan_count FROM page WHERE page_id =" + profileId });
                        //foreach (var friend in fancount.data)
                        //{
                        //    fancountPage = Convert.ToInt32(friend.fan_count);
                        //}
                        //dynamic friends = fb.Get("v2.0/me/friends");
                        //fancountPage = Convert.ToInt16(friends["summary"]["total_count"].ToString());
                        dynamic friends = fb.Get("v2.0/" + profileId);
                        fancountPage = Convert.ToInt32(friends["likes"].ToString());
                    }
                    catch (Exception ex)
                    {
                        logger.Error("fancount : " + ex.Message);
                    }
                }
                #endregion


                #region Add FacebookAccount
                objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                objFacebookAccount.Id = Guid.NewGuid();
                objFacebookAccount.FbUserId = profileId;
                objFacebookAccount.FbUserName = name;
                objFacebookAccount.AccessToken = "";
                objFacebookAccount.Friends = Convert.ToInt32(fancountPage);
                objFacebookAccount.EmailId = "";
                objFacebookAccount.Type = "Page";
                objFacebookAccount.ProfileUrl = "";
                objFacebookAccount.IsActive = 1;
                objFacebookAccount.UserId = Guid.Parse(userid);
                if (!objFacebookAccountRepository.checkFacebookUserExists(objFacebookAccount.FbUserId, objFacebookAccount.UserId))
                {
                    objFacebookAccountRepository.addFacebookUser(objFacebookAccount);
                }

                #endregion
                #region SocialProfile
                Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                objSocialProfile.Id = Guid.NewGuid();
                objSocialProfile.ProfileType = "facebook_page";
                objSocialProfile.ProfileId = profileId;
                objSocialProfile.UserId = Guid.Parse(userid);
                objSocialProfile.ProfileDate = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                }
                #endregion
                #region Add TeamMemberProfile
                Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(groupId));
                Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                objTeamMemberProfile.Id = Guid.NewGuid();
                objTeamMemberProfile.TeamId = objTeam.Id;
                objTeamMemberProfile.Status = 1;
                objTeamMemberProfile.ProfileType = "facebook_page";
                objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                objTeamMemberProfile.ProfileId = profileId;
                objTeamMemberProfile.ProfilePicUrl = "http://graph.facebook.com/" + objTeamMemberProfile.ProfileId + "/picture?type=small"; ;
                objTeamMemberProfile.ProfileName = name;
                if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeamMemberProfile.TeamId, objTeamMemberProfile.ProfileId))
                {
                    objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                }

                #endregion

                try
                {
                    logger.Error(" Token:" + token);
                    if (token != null)
                    {
                        FacebookClient _FacebookClient = new FacebookClient();
                        _FacebookClient.AccessToken = token;
                        dynamic profile = null;

                        try
                        {
                            profile = fb.Get("v2.0/" + profileId);
                            logger.Error("AddFacebookPagesByUrl Token 1");
                        }
                        catch (Exception ex)
                        {
                            logger.Error("fb.Get(profileId)");
                            logger.Error(ex.StackTrace);
                            Console.WriteLine(ex.StackTrace);
                            try
                            {
                                //fb.AccessToken = "CAAKYvwDVmnUBAFvCcZCQDL53q82jfR5mvgF2whNsFHgR4NmeSSUeRVpdEUpcVVgK1ERs2GZCNhJAwRHtq6MEWiRtBQnxBmZAML6dnwgpsCbjUmyT7ws6EKZBxuWbxhJqjeNCsxhac00b3L9Bf7LLlYa3PG94Uouj7vXZAZC6djZCme5BuszE3vibNFLKQqaLcgZD";
                                fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString();
                                profile = fb.Get("v2.0/" + profileId);
                                logger.Error("AddFacebookPagesByUrl Token 2");
                            }
                            catch (Exception ex2)
                            {
                                try
                                {
                                    //fb.AccessToken = "CAAKYvwDVmnUBAAR2O9hxFkHzfNG8H6KbQLaiGFMRshJkbttdzhDeprklcb1yaV0rwtC7N8Xz1rsL1cykiRv2ouXtBUFxvOZCNnpFELnQGFV8jGUWjm1GYsZA40IKAORLGoAcSaa2lJkuuSoLBksB8LFPHI4cqW7VVqxgDwZCRwObxqR4Qp9QEDHxa7j1yoZD";
                                    fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString();
                                    profile = fb.Get("v2.0/" + profileId);
                                    logger.Error("AddFacebookPagesByUrl Token 3");
                                }
                                catch (Exception ex3)
                                {
                                    try
                                    {
                                        //fb.AccessToken = "CAAKYvwDVmnUBAFtZB8pvVrqYQonmq7MD90oNdoipDc0Te4onP2XlbZAYT4bzOZAKTr8jdhw0P1PclgLOtVxJ9g2qx4vxZAzh2CXqXAZBZAZBwkgWIVjc2B4rcXAp6O5B3gXqd8Ko5ITL9VCZCMOkMZCPc1hBsp0n8zgPt6e3Dd0vaodPBS8nMz7RD";
                                        fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString();
                                        profile = fb.Get("v2.0/" + profileId);
                                        logger.Error("AddFacebookPagesByUrl Token 4");
                                    }
                                    catch (Exception ex4)
                                    {
                                        logger.Error("Finally :" + fb.AccessToken);
                                        logger.Error(ex4.Message);
                                        logger.Error(ex4.Message);

                                    }
                                }
                            }
                        }

                        try
                        {
                            //Edited by Sumit Gupta [10/27/2014]
                            //AddFacebookStats(userid, _FacebookClient, profile);
                            AddFacebookStats(userid, fb, profile);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                            Console.WriteLine(ex.StackTrace);
                        }

                        //Edited by Sumit Gupta [10/29/2014]
                        AddFbPagePost(userid, fb.AccessToken, profileId); // AddFbPagePost(userid, token, profileId);


                    }
                }
                catch (Exception ex)
                {
                    logger.Error("dynamic profile");
                    logger.Error(ex.StackTrace);
                    Console.WriteLine(ex.StackTrace);
                }



            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                Console.WriteLine(ex.StackTrace);
            }
            return ret;
        }
        public string AddFacebookPagesByUrl(string userid, string profileId, string groupId, string name)
        {
            logger.Error(userid + ", " + profileId + ", " + groupId + ", " + name);
            string ret = string.Empty;
            FacebookAccount _FacebookAccount = new FacebookAccount();
            string token = ConfigurationManager.AppSettings["AccessToken1"].ToString();
            try
            {
                #region fancount
                FacebookClient fb = new FacebookClient();
                fb.AccessToken = token;
                int fancountPage = 0;
                try
                {
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                    dynamic friends = fb.Get("v2.0/" + profileId);
                    fancountPage = Convert.ToInt32(friends["likes"].ToString());

                }
                catch (Exception)
                {
                    fancountPage = 0;
                    fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString();
                    try
                    {
                        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                        dynamic friends = fb.Get("v2.0/" + profileId);
                        fancountPage = Convert.ToInt32(friends["likes"].ToString());
                    }
                    catch (Exception ex)
                    {
                        fancountPage = 0;
                        fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString();
                        try
                        {
                            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                            dynamic friends = fb.Get("v2.0/" + profileId);
                            fancountPage = Convert.ToInt32(friends["likes"].ToString());
                        }
                        catch (Exception exx)
                        {
                            fancountPage = 0;
                            fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString();
                            try
                            {
                                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
                                dynamic friends = fb.Get("v2.0/" + profileId);
                                fancountPage = Convert.ToInt32(friends["likes"].ToString());
                            }
                            catch (Exception exxx)
                            {
                                logger.Error("fancount : " + exxx.Message);
                            }
                        }
                    }
                }
                #endregion


                #region Add FacebookAccount
                objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                objFacebookAccount.Id = Guid.NewGuid();
                objFacebookAccount.FbUserId = profileId;
                objFacebookAccount.FbUserName = name;
                objFacebookAccount.AccessToken = "";
                objFacebookAccount.Friends = Convert.ToInt32(fancountPage);
                objFacebookAccount.EmailId = "";
                objFacebookAccount.Type = "Page";
                objFacebookAccount.ProfileUrl = "";
                objFacebookAccount.IsActive = 1;
                objFacebookAccount.UserId = Guid.Parse(userid);
                if (!objFacebookAccountRepository.checkFacebookUserExists(objFacebookAccount.FbUserId, objFacebookAccount.UserId))
                {
                    objFacebookAccountRepository.addFacebookUser(objFacebookAccount);
                }
                if (!string.IsNullOrEmpty(objFacebookAccount.FbUserId))
                {
                    ShareathonRepository shreathonpage = new ShareathonRepository();
                    ShareathonGroupRepository objShareathonGroup = new ShareathonGroupRepository();
                    if (shreathonpage.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId))
                    {
                        shreathonpage.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId);
                    }
                    if (objShareathonGroup.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId))
                    {
                        objShareathonGroup.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId);
                    }
                }
                #endregion
                #region SocialProfile
                Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                objSocialProfile.Id = Guid.NewGuid();
                objSocialProfile.ProfileType = "facebook_page";
                objSocialProfile.ProfileId = profileId;
                objSocialProfile.UserId = Guid.Parse(userid);
                objSocialProfile.ProfileDate = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    #region Add TeamMemberProfile
                    Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                    grpProfile.Id = Guid.NewGuid();
                    grpProfile.GroupId = Guid.Parse(groupId);
                    grpProfile.GroupOwnerId = objFacebookAccount.UserId;
                    grpProfile.ProfileId = objFacebookAccount.FbUserId;
                    grpProfile.ProfileType = "facebook_page";
                    grpProfile.ProfileName = name;
                    grpProfile.EntryDate = DateTime.UtcNow;
                    grpProfileRepo.AddGroupProfile(grpProfile);
                    #endregion
                }
                #endregion


                try
                {
                    logger.Error(" Token:" + token);
                    if (token != null)
                    {
                        FacebookClient _FacebookClient = new FacebookClient();
                        _FacebookClient.AccessToken = token;
                        dynamic profile = null;

                        try
                        {
                            profile = fb.Get("v2.0/" + profileId);
                            logger.Error("AddFacebookPagesByUrl Token 1");
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString();
                                profile = fb.Get("v2.0/" + profileId);
                            }
                            catch (Exception ex2)
                            {
                                try
                                {
                                    //fb.AccessToken = "CAAKYvwDVmnUBAAR2O9hxFkHzfNG8H6KbQLaiGFMRshJkbttdzhDeprklcb1yaV0rwtC7N8Xz1rsL1cykiRv2ouXtBUFxvOZCNnpFELnQGFV8jGUWjm1GYsZA40IKAORLGoAcSaa2lJkuuSoLBksB8LFPHI4cqW7VVqxgDwZCRwObxqR4Qp9QEDHxa7j1yoZD";
                                    fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString();
                                    profile = fb.Get("v2.0/" + profileId);
                                    logger.Error("AddFacebookPagesByUrl Token 3");
                                }
                                catch (Exception ex3)
                                {
                                    try
                                    {
                                        //fb.AccessToken = "CAAKYvwDVmnUBAFtZB8pvVrqYQonmq7MD90oNdoipDc0Te4onP2XlbZAYT4bzOZAKTr8jdhw0P1PclgLOtVxJ9g2qx4vxZAzh2CXqXAZBZAZBwkgWIVjc2B4rcXAp6O5B3gXqd8Ko5ITL9VCZCMOkMZCPc1hBsp0n8zgPt6e3Dd0vaodPBS8nMz7RD";
                                        fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString();
                                        profile = fb.Get("v2.0/" + profileId);
                                        logger.Error("AddFacebookPagesByUrl Token 4");
                                    }
                                    catch (Exception ex4)
                                    {
                                        logger.Error("Finally :" + fb.AccessToken);
                                        logger.Error(ex4.Message);

                                    }
                                }
                            }
                        }
                        new Thread(delegate()
                        {
                            AddFbPagePost(userid, fb.AccessToken, profileId);
                        }).Start();
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
            }
            return ret;
        }
        public string GetFbPageDetails(string url)
        {
            try
            {
                FacebookClient fb = new FacebookClient();
                FacebookAccount _FacebookAccount = new FacebookAccount();

                fb.AccessToken = ConfigurationManager.AppSettings["AccessToken1"].ToString();
                dynamic pageinfo = null;
                try
                {
                    pageinfo = fb.Get(url);
                    logger.Error("Token 1");
                }
                catch (Exception ex1)
                {
                    try
                    {
                        fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString();
                        pageinfo = fb.Get(url);
                        logger.Error("Token 2");
                    }
                    catch (Exception ex2)
                    {
                        try
                        {
                            fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString();
                            pageinfo = fb.Get(url);
                            logger.Error("Token 3");
                        }
                        catch (Exception ex3)
                        {
                            try
                            {
                                fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString();
                                pageinfo = fb.Get(url);
                                logger.Error("Token 4");
                            }
                            catch (Exception ex4)
                            {
                                logger.Error("Finally :" + fb.AccessToken);
                                logger.Error(ex4.Message);
                            }
                        }
                    }

                }

                Domain.Socioboard.Domain.AddFacebookPage objAddFacebookPage = new Domain.Socioboard.Domain.AddFacebookPage();
                objAddFacebookPage.ProfilePageId = pageinfo["id"];
                try
                {
                    objAddFacebookPage.Name = pageinfo["username"];
                }
                catch (Exception)
                {
                    objAddFacebookPage.Name = pageinfo["name"];
                }
                return new JavaScriptSerializer().Serialize(objAddFacebookPage);
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
                return "Something Went Wrong";
            }
        }
Exemple #40
0
 public static FacebookSnapshot GetFacebookSnapshot(FacebookAccount twitterAccount)
 {
     return (new FacebookQuery()).GetSnapshot(twitterAccount) as FacebookSnapshot;
 }