Example #1
0
        public void SocialMediaStat_30()
        {
            Api.TwitterAccount.TwitterAccount ApiTwitterAccount = new Api.TwitterAccount.TwitterAccount();
            Api.FacebookAccount.FacebookAccount ApiFacebookAccount = new Api.FacebookAccount.FacebookAccount();
            Api.InstagramAccount.InstagramAccount ApiInstagramAccount = new Api.InstagramAccount.InstagramAccount();
            Api.InboxMessages.InboxMessages ApiInboxMessages = new Api.InboxMessages.InboxMessages();
            Api.ScheduledMessage.ScheduledMessage ApiScheduledMessage = new Api.ScheduledMessage.ScheduledMessage();
            Api.TwitterDirectMessages.TwitterDirectMessages ApiTwitterDirectMessages = new Api.TwitterDirectMessages.TwitterDirectMessages();
            Api.User.User ApiUser = new Api.User.User();
            Api.Team.Team ApiTeam = new Api.Team.Team();
            Api.Groups.Groups ApiGroups = new Api.Groups.Groups();
            Api.GroupReports.GroupReports ApiGroupReports = new Api.GroupReports.GroupReports();
            Api.FacebookGroupReport.FacebookGroupReport ApiFacebookGroupReport = new Api.FacebookGroupReport.FacebookGroupReport();
            Api.InstagramReports.InstagramReports ApiInstagramReports = new Api.InstagramReports.InstagramReports();
            Api.TeamMemberProfile.TeamMemberProfile ApiTeamMemberProfile = new Api.TeamMemberProfile.TeamMemberProfile();
            List<Team> lstTeam = (List<Team>)new JavaScriptSerializer().Deserialize(ApiTeam.GetAllActiveTeam(), typeof(List<Team>));
            foreach (Team item_team in lstTeam)
            {
                SocialStat _SocialStat = new Domain.SocialStat();
                Dictionary<TwitterAccount, List<InboxMessages>> lsttwitterfollower = new Dictionary<TwitterAccount, List<InboxMessages>>();
                FacebookStat _FacebookStat = new Domain.FacebookStat();
                List<FacebookAccount> lstFacebookProfiles = new List<FacebookAccount>();
                List<FacebookAccount> lstFacebookPage = new List<FacebookAccount>();
                List<InstagramAccount> lstInstagramAccount = new List<InstagramAccount>();
                FbPageStat _FbPageStat = new Domain.FbPageStat();
                string InboxMessages = string.Empty;
                string InstagramProfileId = string.Empty;
                string TwitterProfileId = string.Empty;
                Groups _Groups = (Groups)new JavaScriptSerializer().Deserialize(ApiGroups.GetGroupDetailsByGroupId(item_team.GroupId.ToString()), typeof(Groups));
                double days = DateTime.Now.Subtract(_Groups.EntryDate).TotalDays;
                int mod = Convert.ToInt32(days) % 30;
                if (mod == 0)
                {
                    List<TeamMemberProfile> lstTeamMemberProfile = (List<TeamMemberProfile>)new JavaScriptSerializer().Deserialize(ApiTeamMemberProfile.getAllTeamMemberProfilesOfTeam(item_team.Id.ToString()), typeof(List<TeamMemberProfile>));
                    foreach (TeamMemberProfile item_TeamMemberProfile in lstTeamMemberProfile)
                    {
                        if (!string.IsNullOrEmpty(item_TeamMemberProfile.ProfileId) && item_TeamMemberProfile.ProfileType == "twitter")
                        {
                            TwitterAccount _TwitterAccount = (TwitterAccount)new JavaScriptSerializer().Deserialize(ApiTwitterAccount.GetTwitterAccountDetailsById(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId), typeof(TwitterAccount));
                            List<InboxMessages> lstfollowers = (List<InboxMessages>)(new JavaScriptSerializer().Deserialize(ApiInboxMessages.GetTwitterFollowers(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId, "1"), typeof(List<InboxMessages>)));
                            lsttwitterfollower.Add(_TwitterAccount, lstfollowers);
                        }

                        if (!string.IsNullOrEmpty(item_TeamMemberProfile.ProfileId) && item_TeamMemberProfile.ProfileType == "facebook")
                        {
                            FacebookAccount _FacebookAccount = (FacebookAccount)new JavaScriptSerializer().Deserialize(ApiFacebookAccount.getFacebookAccountDetailsById(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId), typeof(FacebookAccount));
                            lstFacebookProfiles.Add(_FacebookAccount);
                        }
                        if (!string.IsNullOrEmpty(item_TeamMemberProfile.ProfileId) && item_TeamMemberProfile.ProfileType == "facebook_page")
                        {
                            FacebookAccount _FacebookAccount = (FacebookAccount)new JavaScriptSerializer().Deserialize(ApiFacebookAccount.getFacebookAccountDetailsById(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId), typeof(FacebookAccount));
                            if (!string.IsNullOrEmpty(_FacebookAccount.AccessToken))
                            {
                                lstFacebookPage.Add(_FacebookAccount);
                            }
                        }
                        if (!string.IsNullOrEmpty(item_TeamMemberProfile.ProfileId) && item_TeamMemberProfile.ProfileType == "instagram")
                        {
                            InstagramAccount _InstagramAccount = (InstagramAccount)new JavaScriptSerializer().Deserialize(ApiInstagramAccount.UserInformation(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId), typeof(InstagramAccount));
                            InstagramProfileId += item_TeamMemberProfile.ProfileId + ",";
                            lstInstagramAccount.Add(_InstagramAccount);
                        }
                        try
                        {
                            InstagramProfileId = InstagramProfileId.TrimEnd(',');
                        }
                        catch (Exception ex)
                        {
                            InstagramProfileId = string.Empty;
                        }
                    }
                    GroupReports _GroupReports = (GroupReports)new JavaScriptSerializer().Deserialize(ApiGroupReports.retrievedata(_Groups.Id.ToString()), typeof(GroupReports));
                    string sexratio = _GroupReports.sexratio;
                    string male = "0";
                    string female = "0";
                    string _male = "0";
                    string _female = "0";
                    try
                    {
                        male = sexratio.Split(',')[0];
                        female = sexratio.Split(',')[1];
                    }
                    catch (Exception ex)
                    {
                        male = "0";
                        female = "0";
                    }
                    try
                    {
                        _male = (Int32.Parse(male) / (Int32.Parse(male) + Int32.Parse(female)) * 100).ToString();
                    }
                    catch (Exception ex)
                    {
                        _male = "0";
                    }
                    try
                    {
                        if (female != "0")
                        {
                            _female = (100 - Int32.Parse(_male)).ToString();
                        }
                        else
                        {
                            _female = "0";
                        }
                    }
                    catch (Exception ex)
                    {
                        _female = "0";
                    }

                    _SocialStat.male = _male;
                    _SocialStat.female = _female;

                    _SocialStat.Mentions = _GroupReports.twtmentions_30.ToString();
                    _SocialStat.Retweets = _GroupReports.twtretweets_30.ToString();
                    _SocialStat.New_Followers = _GroupReports.twitterfollower_30.ToString(); 
                    _SocialStat.Messages_Sent = _GroupReports.sent_30.ToString();
                    _SocialStat.Clicks = ApiScheduledMessage.GetClickCount(_Groups.UserId.ToString(), TwitterProfileId, "30");
                    _SocialStat.Direct_Message = ApiTwitterDirectMessages.GetTwitterDirectMessageRecievedCount(_Groups.UserId.ToString().ToString(), TwitterProfileId, "30");
                    _SocialStat.lsttwitterfollower = lsttwitterfollower;

                    FacebookGroupReport_30 _FacebookGroupReport_30 = (FacebookGroupReport_30)new JavaScriptSerializer().Deserialize(ApiFacebookGroupReport.retrieve_30(_Groups.Id.ToString()), typeof(FacebookGroupReport_30));
                    _FbPageStat.TotalLikes = _FacebookGroupReport_30.TotalLikes;
                    _FbPageStat.TalkingAbout = _FacebookGroupReport_30.TalkingAbout;
                    _FbPageStat.PageLike = _FacebookGroupReport_30.Likes.ToString();
                    _FbPageStat.PageUnlike = _FacebookGroupReport_30.Unlikes.ToString();
                    _FbPageStat.PageImpression = _FacebookGroupReport_30.Impression.ToString();
                    _FbPageStat.lstFacebookAccount = lstFacebookProfiles;
                    _FbPageStat.lstFacebookpage = lstFacebookPage;
                    InstagramStat _InstagramStat = new Domain.InstagramStat();
                    _InstagramStat.NewFollowers = ApiInboxMessages.GetInstagramFollower(_Groups.UserId.ToString(), InstagramProfileId, "30");
                    _InstagramStat.NewFollowings = ApiInboxMessages.GetInstagramFollowing(_Groups.UserId.ToString(), InstagramProfileId, "30");
                    _InstagramStat.ImageCount = ApiInstagramAccount.GetInstagramImageCount(InstagramProfileId, "30");
                    _InstagramStat.VideoCount = ApiInstagramAccount.GetInstagramVideosCount(InstagramProfileId, "30");
                    _InstagramStat.LikesCount = ApiInstagramAccount.GetInstagramLikesCount(InstagramProfileId, "30");
                    _InstagramStat.CommentCount = ApiInstagramAccount.GetInstagramCommentCount(InstagramProfileId, "30");
                    _InstagramStat.lstInstagramAccount = lstInstagramAccount;

                    string ret = MailSender.SendGroupReporsByDay(_Groups.GroupName, "*****@*****.**", _SocialStat, _FbPageStat, _InstagramStat, 30);
                }
            }

        }
Example #2
0
        public void SocialMediaStat_7()
        {
            Api.User.User ApiUser = new Api.User.User();
            Api.AdminUserDetails.AdminUserDetails ApiAdminUserDetails = new Api.AdminUserDetails.AdminUserDetails();
            Api.TwitterAccount.TwitterAccount ApiTwitterAccount = new Api.TwitterAccount.TwitterAccount();
            Api.FacebookAccount.FacebookAccount ApiFacebookAccount = new Api.FacebookAccount.FacebookAccount();
            Api.InboxMessages.InboxMessages ApiInboxMessages = new Api.InboxMessages.InboxMessages();
            Api.TwitterDirectMessages.TwitterDirectMessages ApiTwitterDirectMessages = new Api.TwitterDirectMessages.TwitterDirectMessages();
            Api.ScheduledMessage.ScheduledMessage ApiScheduledMessage = new Api.ScheduledMessage.ScheduledMessage();
            Api.TeamMemberProfile.TeamMemberProfile ApiTeamMemberProfile = new Api.TeamMemberProfile.TeamMemberProfile();
            Api.Team.Team ApiTeam = new Api.Team.Team();
            Api.Groups.Groups ApiGroups = new Api.Groups.Groups();
            Api.InstagramAccount.InstagramAccount ApiInstagramAccount = new Api.InstagramAccount.InstagramAccount();
            Api.GroupReports.GroupReports ApiGroupReports = new Api.GroupReports.GroupReports();
            string email = string.Empty;

            List<Team> lstTeam = (List<Team>)new JavaScriptSerializer().Deserialize(ApiTeam.GetAllActiveTeam(), typeof(List<Team>));
            foreach (Team item_team in lstTeam)
            {
                string TwitterProfileId = string.Empty;
                string FacebookProfileId = string.Empty;
                string FacebookPageProfileId = string.Empty;
                string InstagramProfileId = string.Empty;
                int TotalLikes = 0;
                int TalkingAbout = 0;
                int PageLike = 0;
                int PageUnlike = 0;
                int PageImpression = 0;
                int objFacebookAccount = 0;
                SocialStat _SocialStat = new Domain.SocialStat();
                //List<TwitterAccount> lstTwitterAccount =(List<TwitterAccount>)new JavaScriptSerializer().Deserialize(ApiTwitterAccount.getAllTwitterAccountsOfUser(item_user.Id.ToString()), typeof(List<TwitterAccount>));
                Groups _Groups = (Groups)new JavaScriptSerializer().Deserialize(ApiGroups.GetGroupDetailsByGroupId(item_team.GroupId.ToString()), typeof(Groups));
                double days = DateTime.Now.Subtract(_Groups.EntryDate).TotalDays;
                int mod = Convert.ToInt32(days) % 7;
                if (mod == 0)
                {
                    List<TeamMemberProfile> lstTeamMemberProfile = (List<TeamMemberProfile>)new JavaScriptSerializer().Deserialize(ApiTeamMemberProfile.getAllTeamMemberProfilesOfTeam(item_team.Id.ToString()), typeof(List<TeamMemberProfile>));

                    Dictionary<TwitterAccount, List<InboxMessages>> lsttwitterfollower = new Dictionary<TwitterAccount, List<InboxMessages>>();
                    //Dictionary<FacebookAccount, FbPageStat> lstFacebookStats = new Dictionary<FacebookAccount, Domain.FbPageStat>();
                    //List<FbPageStat> lstFacebookStats = new List<Domain.FbPageStat>();
                    FacebookStat _FacebookStat = new Domain.FacebookStat();
                    List<FacebookAccount> lstFacebookProfiles = new List<FacebookAccount>();
                    List<FacebookAccount> lastFacebookPage = new List<FacebookAccount>();
                    List<InstagramAccount> lstInstagramAccount = new List<InstagramAccount>();
                    FbPageStat _FbPageStat = new Domain.FbPageStat();
                    string FollowerIds = string.Empty;

                    foreach (TeamMemberProfile item_TeamMemberProfile in lstTeamMemberProfile)
                    {
                        if (!string.IsNullOrEmpty(item_TeamMemberProfile.ProfileId) && item_TeamMemberProfile.ProfileType == "twitter")
                        {
                            TwitterProfileId += item_TeamMemberProfile.ProfileId + ",";
                            TwitterAccount _TwitterAccount = (TwitterAccount)new JavaScriptSerializer().Deserialize(ApiTwitterAccount.GetTwitterAccountDetailsById(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId), typeof(TwitterAccount));
                            List<InboxMessages> lstfollowers = (List<InboxMessages>)(new JavaScriptSerializer().Deserialize(ApiInboxMessages.GetTwitterFollowers(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId, "1"), typeof(List<InboxMessages>)));
                            foreach (InboxMessages item in lstfollowers)
                            {
                                FollowerIds += item.FromId + ",";
                            }
                            lsttwitterfollower.Add(_TwitterAccount, lstfollowers);
                        }

                        if (!string.IsNullOrEmpty(item_TeamMemberProfile.ProfileId) && item_TeamMemberProfile.ProfileType == "facebook")
                        {
                            FacebookAccount _FacebookAccount = (FacebookAccount)new JavaScriptSerializer().Deserialize(ApiFacebookAccount.getFacebookAccountDetailsById(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId), typeof(FacebookAccount));
                            lstFacebookProfiles.Add(_FacebookAccount);
                        }

                        if (!string.IsNullOrEmpty(item_TeamMemberProfile.ProfileId) && item_TeamMemberProfile.ProfileType == "facebook_page")
                        {
                            FacebookAccount _FacebookAccount = (FacebookAccount)new JavaScriptSerializer().Deserialize(ApiFacebookAccount.getFacebookAccountDetailsById(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId), typeof(FacebookAccount));
                            if (!string.IsNullOrEmpty(_FacebookAccount.AccessToken))
                            {

                                JObject fbaccountdetails = _FacebookStat.GetFacebookPageDetails(_FacebookAccount.FbUserId, _FacebookAccount.AccessToken);
                                string totalLikes = fbaccountdetails["likes"].ToString();
                                string talkingAbout = fbaccountdetails["talking_about_count"].ToString();
                                int fblikers = _FacebookStat.GetFacebookNewLiker(_FacebookAccount.FbUserId, _FacebookAccount.AccessToken, 7);
                                int fbunliker = _FacebookStat.GetFacebookUnliker(_FacebookAccount.FbUserId, _FacebookAccount.AccessToken, 7);
                                int fbimpression = _FacebookStat.GetFacebookImpression(_FacebookAccount.FbUserId, _FacebookAccount.AccessToken, 7);

                                lastFacebookPage.Add(_FacebookAccount);
                                TotalLikes += Int32.Parse(totalLikes);
                                TalkingAbout += Int32.Parse(talkingAbout);
                                PageLike += fblikers;
                                PageUnlike += fbunliker;
                                PageImpression += fbimpression;

                            }
                        }


                        if (!string.IsNullOrEmpty(item_TeamMemberProfile.ProfileId) && item_TeamMemberProfile.ProfileType == "instagram")
                        {
                            InstagramAccount _InstagramAccount = (InstagramAccount)new JavaScriptSerializer().Deserialize(ApiInstagramAccount.UserInformation(_Groups.UserId.ToString(), item_TeamMemberProfile.ProfileId), typeof(InstagramAccount));
                            InstagramProfileId += item_TeamMemberProfile.ProfileId + ",";
                            lstInstagramAccount.Add(_InstagramAccount);
                        }

                    }
                    try
                    {
                        TwitterProfileId = TwitterProfileId.Substring(0, TwitterProfileId.Length - 1);
                    }
                    catch (Exception e)
                    {
                        TwitterProfileId = string.Empty;
                        Console.WriteLine(e.Message);
                    }

                    try
                    {
                        InstagramProfileId = InstagramProfileId.Substring(0, InstagramProfileId.Length - 1);
                    }
                    catch (Exception e)
                    {
                        InstagramProfileId = string.Empty;
                        Console.WriteLine(e.Message);
                    }

                    try
                    {
                        FollowerIds = FollowerIds.Substring(0, FollowerIds.Length - 1);
                    }
                    catch (Exception ex)
                    {
                        FollowerIds = string.Empty;
                    }
                    string sexratio = ApiGroupReports.GetSexRatio(FollowerIds);
                    string male = "0";
                    string female = "0";
                    string _male = "0";
                    string _female = "0";
                    try
                    {
                        male = sexratio.Split(',')[0];
                        female = sexratio.Split(',')[1];
                    }
                    catch (Exception ex)
                    {
                        male = "0";
                        female = "0";
                    }
                    try
                    {
                        _male = (Int32.Parse(male) / (Int32.Parse(male) + Int32.Parse(female)) * 100).ToString();
                    }
                    catch (Exception ex)
                    {
                        _male = "0";
                    }
                    try
                    {
                        _female = (Int32.Parse(female) / (Int32.Parse(male) + Int32.Parse(female)) * 100).ToString();
                    }
                    catch (Exception ex)
                    {
                        _female = "0";
                    }
                    _FbPageStat.TotalLikes = TotalLikes.ToString();
                    _FbPageStat.TalkingAbout = TalkingAbout.ToString();
                    _FbPageStat.PageLike = PageLike.ToString();
                    _FbPageStat.PageUnlike = PageUnlike.ToString();
                    _FbPageStat.PageImpression = PageImpression.ToString();
                    _FbPageStat.lstFacebookAccount = lstFacebookProfiles;
                    _FbPageStat.lstFacebookpage = lastFacebookPage;

                    _SocialStat.male = _male;
                    _SocialStat.female = _female;

                    _SocialStat.Mentions = ApiInboxMessages.GetTwitterMentionCount(_Groups.UserId.ToString(), TwitterProfileId, "7");
                    _SocialStat.Retweets = ApiInboxMessages.GetTwitterRetweetCount(_Groups.UserId.ToString(), TwitterProfileId, "7");
                    _SocialStat.New_Followers = ApiInboxMessages.GetTwitterFollowersCount(_Groups.UserId.ToString(), TwitterProfileId, "7");
                    _SocialStat.Messages_Sent = (Int32.Parse(ApiScheduledMessage.GetSentMessageCount(_Groups.UserId.ToString(), TwitterProfileId, "7")) + Int32.Parse(ApiTwitterDirectMessages.GetTwitterDirectMessageSentCount(_Groups.UserId.ToString(), TwitterProfileId, "7"))).ToString();
                    _SocialStat.Clicks = ApiScheduledMessage.GetClickCount(_Groups.UserId.ToString(), TwitterProfileId, "7");
                    _SocialStat.Direct_Message = ApiTwitterDirectMessages.GetTwitterDirectMessageRecievedCount(_Groups.UserId.ToString().ToString(), TwitterProfileId, "7");
                    _SocialStat.lsttwitterfollower = lsttwitterfollower;

                    InstagramStat _InstagramStat = new Domain.InstagramStat();
                    _InstagramStat.NewFollowers = ApiInboxMessages.GetInstagramFollower(_Groups.UserId.ToString(), InstagramProfileId, "7");
                    _InstagramStat.NewFollowings = ApiInboxMessages.GetInstagramFollowing(_Groups.UserId.ToString(), InstagramProfileId, "7");
                    _InstagramStat.ImageCount = ApiInstagramAccount.GetInstagramImageCount(InstagramProfileId, "7");
                    _InstagramStat.VideoCount = ApiInstagramAccount.GetInstagramVideosCount(InstagramProfileId, "7");
                    _InstagramStat.LikesCount = ApiInstagramAccount.GetInstagramLikesCount(InstagramProfileId, "7");
                    _InstagramStat.CommentCount = ApiInstagramAccount.GetInstagramCommentCount(InstagramProfileId, "7");
                    _InstagramStat.lstInstagramAccount = lstInstagramAccount;


                    string ret = MailSender.SendGroupReporsByDay(_Groups.GroupName, "*****@*****.**", _SocialStat, _FbPageStat, _InstagramStat, 7);
                }

            }


        }