Example #1
0
        public static void updateMongoDbYtGroupsChildComments(Domain.Socioboard.Models.Mongo.MongoYoutubeComments item)
        {
            try
            {
                Helper.DatabaseRepository     dbr               = new Helper.DatabaseRepository();
                Domain.Socioboard.Models.User _SBGrpMember      = dbr.Single <Domain.Socioboard.Models.User>(t => t.Id == Convert.ToInt64(item.sbGrpMemberUserid));
                Domain.Socioboard.Models.User _CmntReviewedById = dbr.Single <Domain.Socioboard.Models.User>(t => t.Id == Convert.ToInt64(item.reviewedBysbUserId));

                if (_SBGrpMember != null)
                {
                    item.sbGrpMemberName  = _SBGrpMember.FirstName + " " + _SBGrpMember.LastName;
                    item.sbGrpMemberEmail = _SBGrpMember.EmailId;
                }
                if (_CmntReviewedById != null)
                {
                    item.reviewedBy = _CmntReviewedById.FirstName + " " + _CmntReviewedById.LastName;
                }

                MongoRepository mongorepo = new MongoRepository("YoutubeVideosCommentsReply");
                try
                {
                    FilterDefinition <BsonDocument> filter = new BsonDocument("commentId", item.commentId);
                    var update = Builders <BsonDocument> .Update.Set("sbGrpMemberName", item.sbGrpMemberName).Set("sbGrpMemberEmail", item.sbGrpMemberEmail).Set("reviewedBy", item.reviewedBy);

                    mongorepo.Update <MongoYoutubeComments>(update, filter);
                }
                catch
                {
                }
            }
            catch
            {
            }
            Console.WriteLine(count++);
        }
 public void UpdateTwitterAccount()
 {
     while (true)
     {
         try
         {
             Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();
             oAuthTwitter OAuth            = new oAuthTwitter(Helper.AppSettings.twitterConsumerKey, Helper.AppSettings.twitterConsumerScreatKey, Helper.AppSettings.twitterRedirectionUrl);
             List <Domain.Socioboard.Models.TwitterAccount> lstTwtAccounts = dbr.Find <Domain.Socioboard.Models.TwitterAccount>(t => t.isActive).ToList();
             foreach (var item in lstTwtAccounts)
             {
                 try
                 {
                     OAuth.AccessToken       = item.oAuthToken;
                     OAuth.AccessTokenSecret = item.oAuthSecret;
                     OAuth.TwitterScreenName = item.twitterScreenName;
                     Console.WriteLine(item.twitterScreenName + "Updating Started");
                     TwtFeeds.updateTwitterFeeds(item, OAuth);
                     Console.WriteLine(item.twitterScreenName + "Updated");
                 }
                 catch (Exception ex)
                 {
                     Thread.Sleep(600000);
                 }
             }
             Thread.Sleep(600000);
         }
         catch (Exception ex)
         {
             Console.WriteLine("issue in web api calling" + ex.StackTrace);
             Thread.Sleep(600000);
         }
     }
 }
Example #3
0
        public static void UpdateSQLYtGrp(Domain.Socioboard.Models.YoutubeGroupInvite item)
        {
            Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();
            if (item.Owner)
            {
                Domain.Socioboard.Models.User _SBUser = dbr.Single <Domain.Socioboard.Models.User>(t => t.Id == item.UserId);
                if (_SBUser != null)
                {
                    item.OwnerName    = _SBUser.FirstName + " " + _SBUser.LastName;
                    item.OwnerEmailid = _SBUser.EmailId;
                    item.SBUserName   = _SBUser.FirstName + " " + _SBUser.LastName;
                    item.SBEmailId    = _SBUser.EmailId;
                    if (_SBUser.ProfilePicUrl == "" || _SBUser.ProfilePicUrl == null)
                    {
                        item.SBProfilePic = "https://i.imgur.com/zqN47Qp.png";
                    }
                    else
                    {
                        item.SBProfilePic = _SBUser.ProfilePicUrl;
                    }

                    dbr.Update(item);
                }
            }
            else
            {
                Domain.Socioboard.Models.User _SBUserOwner = dbr.Single <Domain.Socioboard.Models.User>(t => t.Id == item.AccessSBUserId);
                Domain.Socioboard.Models.User _SBUserMmbr  = dbr.Single <Domain.Socioboard.Models.User>(t => t.Id == item.UserId);
                if (_SBUserOwner != null)
                {
                    item.OwnerName    = _SBUserOwner.FirstName + " " + _SBUserOwner.LastName;
                    item.OwnerEmailid = _SBUserOwner.EmailId;

                    if (_SBUserMmbr != null)
                    {
                        item.SBUserName = _SBUserMmbr.FirstName + " " + _SBUserMmbr.LastName;
                        item.SBEmailId  = _SBUserMmbr.EmailId;
                        if (_SBUserMmbr.ProfilePicUrl == "" || _SBUserMmbr.ProfilePicUrl == null)
                        {
                            item.SBProfilePic = "https://i.imgur.com/zqN47Qp.png";
                        }
                        else
                        {
                            item.SBProfilePic = _SBUserMmbr.ProfilePicUrl;
                        }
                    }

                    dbr.Update(item);
                }
            }
            Console.WriteLine(count++);
        }
Example #4
0
        public void UpadateGoogleAnalyticsAccount()
        {
            while (true)
            {
                try
                {
                    Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();
                    oAuthTokenGPlus           ObjoAuthTokenGPlus = new oAuthTokenGPlus(AppSettings.GoogleConsumerKey, AppSettings.GoogleConsumerSecret, AppSettings.GoogleRedirectUri);
                    Analytics _Analytics = new Analytics(AppSettings.GoogleConsumerKey, AppSettings.GoogleConsumerSecret, AppSettings.GoogleRedirectUri);
                    List <Domain.Socioboard.Models.GoogleAnalyticsAccount> lstTwtAccounts = dbr.Find <Domain.Socioboard.Models.GoogleAnalyticsAccount>(t => t.IsActive).ToList();

                    foreach (var item in lstTwtAccounts)
                    {
                        try
                        {
                            if (item.LastUpdate.AddHours(1) <= DateTime.UtcNow)
                            {
                                if (item.IsActive)
                                {
                                    try
                                    {
                                        string  objRefresh     = ObjoAuthTokenGPlus.GetAccessToken(item.RefreshToken);
                                        JObject objaccesstoken = JObject.Parse(objRefresh);
                                        string  access_token   = objaccesstoken["access_token"].ToString();
                                        string  analytics      = _Analytics.getAnalyticsData(item.GaProfileId, "ga:visits,ga:pageviews", DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-dd"), DateTime.UtcNow.ToString("yyyy-MM-dd"), access_token);
                                        JObject JData          = JObject.Parse(analytics);
                                        string  visits         = JData["totalsForAllResults"]["ga:visits"].ToString();
                                        string  pageviews      = JData["totalsForAllResults"]["ga:pageviews"].ToString();
                                        item.Views      = Double.Parse(pageviews);
                                        item.Visits     = Double.Parse(visits);
                                        item.LastUpdate = DateTime.UtcNow;
                                        dbr.Update <Domain.Socioboard.Models.GoogleAnalyticsAccount>(item);
                                    }
                                    catch (Exception ex)
                                    {
                                        Thread.Sleep(600000);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            Thread.Sleep(600000);
                        }
                        Thread.Sleep(600000);
                    }
                }
                catch
                {
                }
            }
        }
        public void UpadateGoogleAnalyticsAccount()
        {
            while (true)
            {
                try
                {
                    Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();
                    oAuthTokenGPlus           ObjoAuthTokenGPlus = new oAuthTokenGPlus("246221405801-5sg3n6bfpj329ie7tiqfdnb404pc78ea.apps.googleusercontent.com", "S5B4EtNKIe-1yHq4xEtXHCHK", "https://www.socioboard.com/GoogleManager/Google");
                    Analytics _Analytics = new Analytics("246221405801-5sg3n6bfpj329ie7tiqfdnb404pc78ea.apps.googleusercontent.com", "S5B4EtNKIe-1yHq4xEtXHCHK", "https://www.socioboard.com/GoogleManager/Google");
                    List <Domain.Socioboard.Models.GoogleAnalyticsAccount> lstTwtAccounts = dbr.Find <Domain.Socioboard.Models.GoogleAnalyticsAccount>(t => t.IsActive).ToList();

                    foreach (var item in lstTwtAccounts)
                    {
                        try
                        {
                            if (item.LastUpdate.AddHours(1) <= DateTime.UtcNow)
                            {
                                if (item.IsActive)
                                {
                                    try
                                    {
                                        string  objRefresh     = ObjoAuthTokenGPlus.GetAccessToken(item.RefreshToken);
                                        JObject objaccesstoken = JObject.Parse(objRefresh);
                                        string  access_token   = objaccesstoken["access_token"].ToString();
                                        string  analytics      = _Analytics.getAnalyticsData(item.GaProfileId, "ga:visits,ga:pageviews", DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-dd"), DateTime.UtcNow.ToString("yyyy-MM-dd"), access_token);
                                        JObject JData          = JObject.Parse(analytics);
                                        string  visits         = JData["totalsForAllResults"]["ga:visits"].ToString();
                                        string  pageviews      = JData["totalsForAllResults"]["ga:pageviews"].ToString();
                                        item.Views      = Double.Parse(pageviews);
                                        item.Visits     = Double.Parse(visits);
                                        item.LastUpdate = DateTime.UtcNow;
                                        dbr.Update <Domain.Socioboard.Models.GoogleAnalyticsAccount>(item);
                                    }
                                    catch (Exception ex)
                                    {
                                        Thread.Sleep(600000);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            Thread.Sleep(600000);
                        }
                        Thread.Sleep(600000);
                    }
                }
                catch
                {
                }
            }
        }
Example #6
0
        public static void FetchSQLYtGrp()
        {
            Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();
            List <Domain.Socioboard.Models.YoutubeGroupInvite> lstYtChannels = dbr.Find <Domain.Socioboard.Models.YoutubeGroupInvite>(t => t.Active).ToList();

            Parallel.ForEach(
                lstYtChannels,
                new ParallelOptions {
                MaxDegreeOfParallelism = 21
            },
                items => { UpdateSQLYtGrp(items); }
                );
        }
Example #7
0
 public void UpdateTwitterAccount()
 {
     while (true)
     {
         try
         {
             int count = 1;
             Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();
             oAuthTwitter OAuth            = new oAuthTwitter(AppSettings.twitterConsumerKey, AppSettings.twitterConsumerSecret, AppSettings.twitterRedirectionUrl);
             List <Domain.Socioboard.Models.TwitterAccount> lstTwtAccounts = dbr.Find <Domain.Socioboard.Models.TwitterAccount>(t => t.isActive).ToList();
             //lstTwtAccounts = lstTwtAccounts.Where(t => t.twitterUserId.Equals("758233674978426880")).ToList();
             foreach (var item in lstTwtAccounts)
             {
                 try
                 {
                     OAuth.AccessToken       = item.oAuthToken;
                     OAuth.AccessTokenSecret = item.oAuthSecret;
                     OAuth.TwitterScreenName = item.twitterScreenName;
                     Console.WriteLine(item.twitterScreenName + "Updating Started");
                     Thread thread_twitter = new Thread(() => TwtFeeds.updateTwitterFeeds(item, OAuth));
                     thread_twitter.Name = "twitter service thread :" + noOfthreadRunning;
                     thread_twitter.Start();
                     //TwtFeeds.updateTwitterFeeds(item, OAuth);
                     Console.WriteLine(item.twitterScreenName + "Updated");
                     Console.WriteLine(count++);
                     Thread.Sleep(1000);
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.StackTrace);
                     //Thread.Sleep(600000);
                     Thread.Sleep(TimeSpan.FromMinutes(1));
                 }
             }
             //Thread.Sleep(600000);
             Thread.Sleep(TimeSpan.FromMinutes(60));
         }
         catch (Exception ex)
         {
             Console.WriteLine("issue in web api calling" + ex.StackTrace);
             // Thread.Sleep(600000);
             Thread.Sleep(TimeSpan.FromMinutes(1));
         }
     }
 }
        public static string TwitterFollowerCount(string userId, long groupId, Helper.DatabaseRepository dbr)
        {
            string[] profileids    = null;
            string   FollowerCount = string.Empty;
            // List<Domain.Socioboard.Models.Groupprofiles> iMmemGroupprofiles = _redisCache.Get<List<Domain.Socioboard.Models.Groupprofiles>>(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
            List <Domain.Socioboard.Models.Groupprofiles> lstGroupprofiles = new List <Domain.Socioboard.Models.Groupprofiles>();

            //if (iMmemGroupprofiles != null && iMmemGroupprofiles.Count > 0)
            //{
            //    lstGroupprofiles = iMmemGroupprofiles.Where(t => t.profileType == Domain.Socioboard.Enum.SocialProfileType.Twitter).ToList();
            //}
            //else
            //{
            //    lstGroupprofiles = dbr.Find<Domain.Socioboard.Models.Groupprofiles>(t => t.groupId == groupId && t.profileType == Domain.Socioboard.Enum.SocialProfileType.Twitter).ToList();
            //}

            profileids = lstGroupprofiles.Select(t => t.profileId).ToArray();
            long TwitterFollowerCount = dbr.Find <Domain.Socioboard.Models.TwitterAccount>(t => profileids.Contains(t.twitterUserId) && t.isActive).Sum(t => t.followersCount);

            if (TwitterFollowerCount > 1000000)
            {
                long r = TwitterFollowerCount % 1000000;
                long t = TwitterFollowerCount / 1000000;
                FollowerCount = t.ToString() + "." + (r / 10000).ToString() + "M";
            }
            else if (TwitterFollowerCount > 1000)
            {
                long r = TwitterFollowerCount % 1000;
                long t = TwitterFollowerCount / 1000;
                FollowerCount = t.ToString() + "." + (r / 100).ToString() + "K";
            }
            else
            {
                FollowerCount = TwitterFollowerCount.ToString();
            }
            return(FollowerCount);
        }
Example #9
0
        public void UpdateYtAccount()
        {
            {
                while (true)
                {
                    try
                    {
                        Helper.DatabaseRepository dbr         = new Helper.DatabaseRepository();
                        string            apiKey              = AppSettings.googleApiKey;
                        oAuthTokenYoutube ObjoAuthTokenYtubes = new oAuthTokenYoutube(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);
                        oAuthToken        objToken            = new oAuthToken(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);
                        Video             ObjVideo            = new Video(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);

                        JObject userinfo = new JObject();
                        List <Domain.Socioboard.Models.YoutubeChannel> lstYtChannels = dbr.Find <Domain.Socioboard.Models.YoutubeChannel>(t => t.IsActive).ToList();
                        long count = 0;
                        Console.WriteLine("---------------- Youtube Dataservices Started ----------------");
                        foreach (var item in lstYtChannels)
                        {
                            List <Domain.Socioboard.Models.Groupprofiles> _grpProfile = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.profileId.Contains(item.YtubeChannelId)).ToList();
                            try
                            {
                                if (item.LastUpdate.AddHours(1) <= DateTime.UtcNow)
                                {
                                    if (item.IsActive)
                                    {
                                        try
                                        {
                                            //string objRefresh = ObjoAuthTokenYtubes.GetAccessToken(item.RefreshToken);
                                            //JObject objaccesstoken = JObject.Parse(objRefresh);
                                            //string access_token = objaccesstoken["access_token"].ToString();

                                            string  ChannelInfo  = ObjVideo.GetChannelInfo(apiKey, item.YtubeChannelId);
                                            JObject JChannelInfo = JObject.Parse(ChannelInfo);

                                            try
                                            {
                                                string  cmntsCount  = ObjVideo.GetChannelCmntCount(apiKey, item.YtubeChannelId);
                                                JObject JcmntsCount = JObject.Parse(cmntsCount);

                                                try
                                                {
                                                    item.CommentsCount = Convert.ToDouble(JcmntsCount["pageInfo"]["totalResults"]);
                                                }
                                                catch
                                                {
                                                }
                                            }
                                            catch { }

                                            foreach (var ittem in JChannelInfo["items"])
                                            {
                                                try
                                                {
                                                    item.YtubeChannelName = ittem["snippet"]["title"].ToString();
                                                    _grpProfile.Select(s => { s.profileName = ittem["snippet"]["title"].ToString(); return(s); }).ToList();
                                                }
                                                catch
                                                {
                                                }
                                                try
                                                {
                                                    item.ChannelpicUrl = Convert.ToString(ittem["snippet"]["thumbnails"]["default"]["url"]).Replace(".jpg", "");
                                                    _grpProfile.Select(s => { s.profilePic = Convert.ToString(ittem["snippet"]["thumbnails"]["default"]["url"]).Replace(".jpg", ""); return(s); }).ToList();
                                                }
                                                catch
                                                {
                                                }
                                                try
                                                {
                                                    item.YtubeChannelDescription = Convert.ToString(ittem["snippet"]["description"]);
                                                    if (item.YtubeChannelDescription == "")
                                                    {
                                                        item.YtubeChannelDescription = "No Description";
                                                    }
                                                }
                                                catch
                                                {
                                                }
                                                //try
                                                //{
                                                //    item.CommentsCount = Convert.ToDouble(ittem["statistics"]["commentCount"]);
                                                //}
                                                //catch
                                                //{

                                                //}
                                                try
                                                {
                                                    item.SubscribersCount = Convert.ToDouble(ittem["statistics"]["subscriberCount"]);
                                                }
                                                catch
                                                {
                                                }
                                                try
                                                {
                                                    item.VideosCount = Convert.ToDouble(ittem["statistics"]["videoCount"]);
                                                }
                                                catch
                                                {
                                                }
                                                try
                                                {
                                                    item.ViewsCount = Convert.ToDouble(ittem["statistics"]["viewCount"]);
                                                }
                                                catch
                                                {
                                                }

                                                dbr.Update <Domain.Socioboard.Models.YoutubeChannel>(item);
                                                foreach (var item_grpProfile in _grpProfile)
                                                {
                                                    dbr.Update <Domain.Socioboard.Models.Groupprofiles>(item_grpProfile);
                                                }

                                                Youtube.YtFeeds.GetYtFeeds(item.YtubeChannelId, "");

                                                item.LastUpdate = DateTime.UtcNow;
                                                dbr.Update <Domain.Socioboard.Models.YoutubeChannel>(item);
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            Thread.Sleep(600000);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Thread.Sleep(600000);
                            }


                            long oldcount = count;
                            count++;
                            long newcount      = count;
                            long totalcount    = lstYtChannels.Count();
                            long percentagenew = (newcount * 100) / totalcount;
                            long percentageold = (oldcount * 100) / totalcount;
                            if (percentagenew != percentageold)
                            {
                                Console.WriteLine("---------------- {0}% Completed ----------------", percentagenew);
                            }
                        }
                        Thread.Sleep(600000);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("issue in web api calling" + ex.StackTrace);
                        Thread.Sleep(600000);
                    }
                }
            }
        }
Example #10
0
        public void UpdateYAnalyticsReports()
        {
            while (true)
            {
                try
                {
                    Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();

                    string            apiKey = AppSettings.googleApiKey;
                    oAuthTokenYoutube ObjoAuthTokenYtubes = new oAuthTokenYoutube(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);
                    oAuthToken        objToken            = new oAuthToken(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);
                    YAnalytics        ObjYAnalytics       = new YAnalytics(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);

                    List <Domain.Socioboard.Models.YoutubeChannel> lstYtChannels = dbr.Find <Domain.Socioboard.Models.YoutubeChannel>(t => t.IsActive).ToList();
                    long count = 0;
                    Console.WriteLine("---------------- Youtube Analytics Dataservices Started ----------------");
                    foreach (var item in lstYtChannels)
                    {
                        #region count for mongo data
                        MongoRepository mongoreposs = new MongoRepository("YoutubeReportsData");
                        var             result      = mongoreposs.Find <Domain.Socioboard.Models.Mongo.YoutubeReports>(t => t.channelId.Equals(item.YtubeChannelId));
                        var             task        = Task.Run(async() =>
                        {
                            return(await result);
                        });
                        IList <Domain.Socioboard.Models.Mongo.YoutubeReports> lstYanalytics = task.Result;
                        int count90AnalyticsUpdated = lstYanalytics.Count();
                        #endregion

                        try
                        {
                            if (!item.Days90Update || count90AnalyticsUpdated < 90)
                            {
                                if (item.IsActive)
                                {
                                    try
                                    {
                                        ////////code of reports here///////////////////////

                                        DateTime to_Date = DateTime.UtcNow;
                                        string   to_dd   = "0" + Convert.ToString(to_Date.Day);
                                        to_dd = to_dd.Substring(to_dd.Length - 2);
                                        string to_mm = "0" + Convert.ToString(to_Date.Month);
                                        to_mm = to_mm.Substring(to_mm.Length - 2);
                                        string   to_yyyy   = Convert.ToString(to_Date.Year);
                                        DateTime from_Date = DateTime.UtcNow.AddDays(-90);
                                        string   from_dd   = "0" + Convert.ToString(from_Date.Day);
                                        from_dd = from_dd.Substring(from_dd.Length - 2);
                                        string from_mm = "0" + Convert.ToString(from_Date.Month);
                                        from_mm = from_mm.Substring(from_mm.Length - 2);
                                        string from_yyyy = Convert.ToString(from_Date.Year);

                                        string YaFrom_Date = from_yyyy + "-" + from_mm + "-" + from_dd;
                                        string YaTo_Date   = to_yyyy + "-" + to_mm + "-" + to_dd;


                                        MongoRepository mongorepo = new MongoRepository("YoutubeReportsData");


                                        string  AnalyticData  = ObjYAnalytics.Get_YAnalytics_ChannelId(item.YtubeChannelId, item.RefreshToken, YaFrom_Date, YaTo_Date);
                                        JObject JAnalyticData = JObject.Parse(AnalyticData);

                                        JArray dataArray = (JArray)JAnalyticData["rows"];

                                        List <string> datesJdata = new List <string>();
                                        if (dataArray != null)
                                        {
                                            foreach (var rows in dataArray)
                                            {
                                                datesJdata.Add(rows[0].ToString());
                                            }

                                            foreach (var items in dataArray)
                                            {
                                                YoutubeReports _YReports = new YoutubeReports();

                                                string date                       = items[0].ToString();
                                                string channelIdd                 = items[1].ToString();
                                                int    SubscribersGained          = Convert.ToInt32(items[2]);
                                                int    views                      = Convert.ToInt32(items[3]);
                                                int    likes                      = Convert.ToInt32(items[4]);
                                                int    comments                   = Convert.ToInt32(items[5]);
                                                int    shares                     = Convert.ToInt32(items[6]);
                                                int    dislikes                   = Convert.ToInt32(items[7]);
                                                int    subscribersLost            = Convert.ToInt32(items[8]);
                                                double averageViewDuration        = Convert.ToInt64(items[9]);
                                                double estimatedMinutesWatched    = Convert.ToInt64(items[10]);
                                                double annotationClickThroughRate = Convert.ToInt64(items[11]);
                                                double annotationCloseRate        = Convert.ToInt64(items[12]);
                                                string uniqueIdentifier           = item.YtubeChannelId + "_" + date;
                                                double datetime_unix              = Convert.ToDouble(UnixTimeNows(Convert.ToDateTime(date)));

                                                _YReports.Id                         = ObjectId.GenerateNewId();
                                                _YReports.date                       = date;
                                                _YReports.channelId                  = channelIdd;
                                                _YReports.SubscribersGained          = SubscribersGained;
                                                _YReports.views                      = views;
                                                _YReports.likes                      = likes;
                                                _YReports.comments                   = comments;
                                                _YReports.dislikes                   = dislikes;
                                                _YReports.subscribersLost            = subscribersLost;
                                                _YReports.averageViewDuration        = averageViewDuration;
                                                _YReports.estimatedMinutesWatched    = estimatedMinutesWatched;
                                                _YReports.annotationClickThroughRate = annotationClickThroughRate;
                                                _YReports.annotationCloseRate        = annotationCloseRate;
                                                _YReports.uniqueIdentifier           = uniqueIdentifier;
                                                _YReports.datetime_unix              = datetime_unix;

                                                mongorepo.Add(_YReports);
                                            }
                                        }
                                        else
                                        {
                                            datesJdata.Add("Null");
                                        }

                                        for (int i = 1; i <= 90; i++)
                                        {
                                            YoutubeReports _YReports    = new YoutubeReports();
                                            DateTime       dateTimeTemp = DateTime.UtcNow.AddDays(-i);

                                            string now_dd = "0" + Convert.ToString(dateTimeTemp.Day);
                                            now_dd = now_dd.Substring(now_dd.Length - 2);
                                            string now_mm = "0" + Convert.ToString(dateTimeTemp.Month);
                                            now_mm = now_mm.Substring(now_mm.Length - 2);
                                            string now_yyyy  = Convert.ToString(dateTimeTemp.Year);
                                            string Ynow_Date = now_yyyy + "-" + now_mm + "-" + now_dd;

                                            if (!(datesJdata.Contains(Ynow_Date)))
                                            {
                                                _YReports.Id                         = ObjectId.GenerateNewId();
                                                _YReports.date                       = Ynow_Date;
                                                _YReports.channelId                  = item.YtubeChannelId;
                                                _YReports.SubscribersGained          = 0;
                                                _YReports.views                      = 0;
                                                _YReports.likes                      = 0;
                                                _YReports.comments                   = 0;
                                                _YReports.dislikes                   = 0;
                                                _YReports.subscribersLost            = 0;
                                                _YReports.averageViewDuration        = 0;
                                                _YReports.estimatedMinutesWatched    = 0;
                                                _YReports.annotationClickThroughRate = 0;
                                                _YReports.annotationCloseRate        = 0;
                                                _YReports.uniqueIdentifier           = item.YtubeChannelId + "_" + Ynow_Date;
                                                _YReports.datetime_unix              = Convert.ToDouble(UnixTimeNows(Convert.ToDateTime(Ynow_Date)));

                                                mongorepo.Add(_YReports);
                                            }
                                        }

                                        item.Days90Update      = true;
                                        item.LastReport_Update = DateTime.UtcNow;
                                        dbr.Update <Domain.Socioboard.Models.YoutubeChannel>(item);
                                    }
                                    catch (Exception)
                                    {
                                        Thread.Sleep(600000);
                                    }
                                }
                            }
                            else
                            {
                                if (item.LastReport_Update.AddHours(24) < DateTime.UtcNow)
                                {
                                    //dailyReport Code here//

                                    if (item.IsActive)
                                    {
                                        try
                                        {
                                            //code of reports here//
                                            DateTime to_Date = DateTime.UtcNow;
                                            string   to_dd   = "0" + Convert.ToString(to_Date.Day);
                                            to_dd = to_dd.Substring(to_dd.Length - 2);
                                            string to_mm = "0" + Convert.ToString(to_Date.Month);
                                            to_mm = to_mm.Substring(to_mm.Length - 2);
                                            string   to_yyyy   = Convert.ToString(to_Date.Year);
                                            DateTime from_Date = DateTime.UtcNow.AddDays(-4);
                                            string   from_dd   = "0" + Convert.ToString(from_Date.Day);
                                            from_dd = from_dd.Substring(from_dd.Length - 2);
                                            string from_mm = "0" + Convert.ToString(from_Date.Month);
                                            from_mm = from_mm.Substring(from_mm.Length - 2);
                                            string from_yyyy = Convert.ToString(from_Date.Year);

                                            string YaFrom_Date = from_yyyy + "-" + from_mm + "-" + from_dd;
                                            string YaTo_Date   = to_yyyy + "-" + to_mm + "-" + to_dd;



                                            string  AnalyticData  = ObjYAnalytics.Get_YAnalytics_ChannelId(item.YtubeChannelId, item.RefreshToken, YaFrom_Date, YaTo_Date);
                                            JObject JAnalyticData = JObject.Parse(AnalyticData);

                                            JArray dataArray = (JArray)JAnalyticData["rows"];

                                            List <string> datesJdata = new List <string>();
                                            if (dataArray != null)
                                            {
                                                foreach (var rows in dataArray)
                                                {
                                                    datesJdata.Add(rows[0].ToString());
                                                }

                                                foreach (var items in dataArray)
                                                {
                                                    YoutubeReports _YReports = new YoutubeReports();

                                                    string date                       = items[0].ToString();
                                                    string channelIdd                 = items[1].ToString();
                                                    int    SubscribersGained          = Convert.ToInt32(items[2]);
                                                    int    views                      = Convert.ToInt32(items[3]);
                                                    int    likes                      = Convert.ToInt32(items[4]);
                                                    int    comments                   = Convert.ToInt32(items[5]);
                                                    int    shares                     = Convert.ToInt32(items[6]);
                                                    int    dislikes                   = Convert.ToInt32(items[7]);
                                                    int    subscribersLost            = Convert.ToInt32(items[8]);
                                                    double averageViewDuration        = Convert.ToInt64(items[9]);
                                                    double estimatedMinutesWatched    = Convert.ToInt64(items[10]);
                                                    double annotationClickThroughRate = Convert.ToInt64(items[11]);
                                                    double annotationCloseRate        = Convert.ToInt64(items[12]);
                                                    string uniqueIdentifier           = item.YtubeChannelId + "_" + date;
                                                    double datetime_unix              = Convert.ToDouble(UnixTimeNows(Convert.ToDateTime(date)));

                                                    _YReports.Id                         = ObjectId.GenerateNewId();
                                                    _YReports.date                       = date;
                                                    _YReports.channelId                  = channelIdd;
                                                    _YReports.SubscribersGained          = SubscribersGained;
                                                    _YReports.views                      = views;
                                                    _YReports.likes                      = likes;
                                                    _YReports.comments                   = comments;
                                                    _YReports.dislikes                   = dislikes;
                                                    _YReports.subscribersLost            = subscribersLost;
                                                    _YReports.averageViewDuration        = averageViewDuration;
                                                    _YReports.estimatedMinutesWatched    = estimatedMinutesWatched;
                                                    _YReports.annotationClickThroughRate = annotationClickThroughRate;
                                                    _YReports.annotationCloseRate        = annotationCloseRate;
                                                    _YReports.uniqueIdentifier           = uniqueIdentifier;
                                                    _YReports.datetime_unix              = datetime_unix;


                                                    try
                                                    {
                                                        MongoRepository mongoRepotsRepo = new MongoRepository("YoutubeReportsData");
                                                        var             ret             = mongoRepotsRepo.Find <YoutubeReports>(t => t.uniqueIdentifier.Equals(_YReports.uniqueIdentifier));
                                                        var             task_Reports    = Task.Run(async() =>
                                                        {
                                                            return(await ret);
                                                        });
                                                        int count_Reports = task_Reports.Result.Count;
                                                        if (count_Reports < 1)
                                                        {
                                                            try
                                                            {
                                                                mongoRepotsRepo.Add(_YReports);
                                                            }
                                                            catch { }
                                                        }
                                                        else
                                                        {
                                                            try
                                                            {
                                                                FilterDefinition <BsonDocument> filter = new BsonDocument("uniqueIdentifier", _YReports.uniqueIdentifier);
                                                                var update = Builders <BsonDocument> .Update.Set("SubscribersGained", _YReports.SubscribersGained).Set("views", _YReports.views).Set("likes", _YReports.likes).Set("comments", _YReports.comments).Set("dislikes", _YReports.dislikes).Set("subscribersLost", _YReports.subscribersLost).Set("averageViewDuration", _YReports.averageViewDuration).Set("estimatedMinutesWatched", _YReports.estimatedMinutesWatched).Set("annotationClickThroughRate", _YReports.annotationClickThroughRate).Set("annotationCloseRate", _YReports.annotationCloseRate);

                                                                mongoRepotsRepo.Update <YoutubeReports>(update, filter);
                                                            }
                                                            catch { }
                                                        }
                                                    }
                                                    catch { }
                                                }
                                            }
                                            else
                                            {
                                                datesJdata.Add("Null");
                                            }

                                            for (int i = 1; i <= 4; i++)
                                            {
                                                YoutubeReports _YReports    = new YoutubeReports();
                                                DateTime       dateTimeTemp = DateTime.UtcNow.AddDays(-i);

                                                string now_dd = "0" + Convert.ToString(dateTimeTemp.Day);
                                                now_dd = now_dd.Substring(now_dd.Length - 2);
                                                string now_mm = "0" + Convert.ToString(dateTimeTemp.Month);
                                                now_mm = now_mm.Substring(now_mm.Length - 2);
                                                string now_yyyy  = Convert.ToString(dateTimeTemp.Year);
                                                string Ynow_Date = now_yyyy + "-" + now_mm + "-" + now_dd;

                                                if (!(datesJdata.Contains(Ynow_Date)))
                                                {
                                                    _YReports.Id                         = ObjectId.GenerateNewId();
                                                    _YReports.date                       = Ynow_Date;
                                                    _YReports.channelId                  = item.YtubeChannelId;
                                                    _YReports.SubscribersGained          = 0;
                                                    _YReports.views                      = 0;
                                                    _YReports.likes                      = 0;
                                                    _YReports.comments                   = 0;
                                                    _YReports.dislikes                   = 0;
                                                    _YReports.subscribersLost            = 0;
                                                    _YReports.averageViewDuration        = 0;
                                                    _YReports.estimatedMinutesWatched    = 0;
                                                    _YReports.annotationClickThroughRate = 0;
                                                    _YReports.annotationCloseRate        = 0;
                                                    _YReports.uniqueIdentifier           = item.YtubeChannelId + "_" + Ynow_Date;
                                                    _YReports.datetime_unix              = Convert.ToDouble(UnixTimeNows(Convert.ToDateTime(Ynow_Date)));

                                                    MongoRepository mongoRepotsRepo = new MongoRepository("YoutubeReportsData");
                                                    mongoRepotsRepo.Add(_YReports);
                                                }
                                            }

                                            item.LastReport_Update = DateTime.UtcNow;
                                            dbr.Update <Domain.Socioboard.Models.YoutubeChannel>(item);
                                        }
                                        catch (Exception)
                                        {
                                            Thread.Sleep(600000);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Thread.Sleep(600000);
                        }


                        long oldcount = count;
                        count++;
                        long newcount      = count;
                        long totalcount    = lstYtChannels.Count();
                        long percentagenew = (newcount * 100) / totalcount;
                        long percentageold = (oldcount * 100) / totalcount;
                        if (percentagenew != percentageold)
                        {
                            Console.WriteLine("---------------- {0}% Completed ----------------", percentagenew);
                        }
                    }
                    Thread.Sleep(600000);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("issue in web api calling" + ex.StackTrace);
                    Thread.Sleep(600000);
                }
            }
        }
        public static List <Domain.Socioboard.Models.Groupprofiles> getGroupProfiles(long groupId, Helper.Cache _redisCache, Helper.DatabaseRepository dbr)
        {
            try
            {
                List <Domain.Socioboard.Models.Groupprofiles> inMemGroupProfiles = _redisCache.Get <List <Domain.Socioboard.Models.Groupprofiles> >(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                if (inMemGroupProfiles != null)
                {
                    return(inMemGroupProfiles);
                }
            }
            catch { }

            List <Domain.Socioboard.Models.Groupprofiles> groupProfiles = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.groupId == groupId).ToList();

            _redisCache.Set(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId, groupProfiles);
            return(groupProfiles);
        }
 //services for delete free user all feeds data
 // * keep only  3months data only
 public void deleteTwitterfeeds()
 {
     try
     {
         Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();
         oAuthTwitter OAuth            = new oAuthTwitter(AppSettings.twitterConsumerKey, AppSettings.twitterConsumerSecret, AppSettings.twitterRedirectionUrl);
         List <Domain.Socioboard.Models.TwitterAccount> lstTwtAccounts = dbr.Find <Domain.Socioboard.Models.TwitterAccount>(t => t.isActive).ToList();
         foreach (var item in lstTwtAccounts)
         {
             try
             {
                 var id = item.userId;
                 List <Domain.Socioboard.Models.User> userdetails = dbr.Find <Domain.Socioboard.Models.User>(t => t.Id == id).ToList();
                 if (userdetails != null)
                 {
                     if (userdetails.First().AccountType == Domain.Socioboard.Enum.SBAccountType.Free)
                     {
                         MongoRepository mongorepo = new MongoRepository("MongoTwitterFeed");
                         var             builder   = Builders <Domain.Socioboard.Models.Mongo.MongoTwitterFeed> .Sort;
                         var             sort      = builder.Descending(t => t.feedDate);
                         var             result    = mongorepo.Find <Domain.Socioboard.Models.Mongo.MongoTwitterFeed>(t => t.profileId.Equals(item.twitterUserId));
                         var             task      = Task.Run(async() =>
                         {
                             return(await result);
                         });
                         IList <Domain.Socioboard.Models.Mongo.MongoTwitterFeed> allTwitterFeeds = task.Result;
                         allTwitterFeeds = allTwitterFeeds.OrderByDescending(t => t.feedTimeStamp).ToList();
                         DateTime lstfeed = Convert.ToDateTime(allTwitterFeeds.First().feedDate);
                         foreach (var iteme in allTwitterFeeds)
                         {
                             DateTime latestFeedDate = Convert.ToDateTime(iteme.feedDate);
                             DateTime FeedDate       = lstfeed.AddMonths(-3);//constant date value
                             if (latestFeedDate.Date <= FeedDate.Date)
                             {
                                 try
                                 {
                                     var             idd             = iteme.messageId;
                                     MongoRepository _DeleteTwtFeeds = new MongoRepository("MongoTwitterFeed");
                                     var             builders        = Builders <Domain.Socioboard.Models.Mongo.MongoTwitterFeed> .Filter;
                                     FilterDefinition <Domain.Socioboard.Models.Mongo.MongoTwitterFeed> filter = builders.Eq("messageId", idd);
                                     _DeleteTwtFeeds.Delete <Domain.Socioboard.Models.Mongo.MongoTwitterFeed>(filter);
                                 }
                                 catch (Exception ex)
                                 {
                                 }
                             }
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
                 Thread.Sleep(600000);
             }
         }
         Thread.Sleep(600000);
     }
     catch (Exception ex)
     {
         Console.WriteLine("issue in web api calling" + ex.StackTrace);
         Thread.Sleep(600000);
     }
 }
Example #13
0
        public void UpdateVideoDetailsList()
        {
            while (true)
            {
                try
                {
                    Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();

                    string            apiKey = AppSettings.googleApiKey;
                    oAuthTokenYoutube ObjoAuthTokenYtubes = new oAuthTokenYoutube(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);
                    oAuthToken        objToken            = new oAuthToken(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);
                    Video             objVideo            = new Video(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);

                    List <Domain.Socioboard.Models.YoutubeChannel> lstYtChannels = dbr.Find <Domain.Socioboard.Models.YoutubeChannel>(t => t.IsActive).ToList();
                    long count = 0;
                    Console.WriteLine("---------------- Youtube Videos List Dataservices Started ----------------");
                    foreach (var item in lstYtChannels)
                    {
                        try
                        {
                            if (item.LastVideoListDetails_Update.AddMinutes(60) < DateTime.UtcNow)
                            {
                                MongoRepository mongoreposs = new MongoRepository("YoutubeVideos");
                                var             result      = mongoreposs.Find <Domain.Socioboard.Models.Mongo.MongoYoutubeFeeds>(t => t.YtChannelId.Equals(item.YtubeChannelId));
                                var             task        = Task.Run(async() =>
                                {
                                    return(await result);
                                });
                                IList <Domain.Socioboard.Models.Mongo.MongoYoutubeFeeds> lstChannelVideos = task.Result;
                                List <string> videoIds = new List <string>();

                                foreach (var items in lstChannelVideos)
                                {
                                    videoIds.Add(items.YtVideoId);
                                }

                                foreach (string videoId in videoIds)
                                {
                                    try
                                    {
                                        string  VideoList  = objVideo.GetYTVideoDetailList(apiKey, videoId);
                                        JObject JVideoList = JObject.Parse(VideoList);

                                        foreach (var itemVideo in JVideoList["items"])
                                        {
                                            YoutubeVideoDetailsList _YVideoDetails = new YoutubeVideoDetailsList();


                                            _YVideoDetails.Id = ObjectId.GenerateNewId();
                                            try
                                            {
                                                _YVideoDetails.YtvideoId  = itemVideo["id"].ToString();
                                                _YVideoDetails.watchUrl   = "https://www.youtube.com/watch?v=" + _YVideoDetails.YtvideoId;
                                                _YVideoDetails.embedVideo = "https://www.youtube.com/embed/" + _YVideoDetails.YtvideoId;
                                            }
                                            catch
                                            {
                                                _YVideoDetails.YtvideoId  = "";
                                                _YVideoDetails.watchUrl   = "N/A";
                                                _YVideoDetails.embedVideo = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.publishedAt = itemVideo["snippet"]["publishedAt"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.publishedAt = "0001-01-01";
                                            }
                                            try
                                            {
                                                _YVideoDetails.publishDateUnix = UnixTimeNows(Convert.ToDateTime(_YVideoDetails.publishedAt));
                                            }
                                            catch
                                            {
                                                _YVideoDetails.publishDateUnix = UnixTimeNows(Convert.ToDateTime("0001-01-01"));
                                            }
                                            try
                                            {
                                                _YVideoDetails.channelId = itemVideo["snippet"]["channelId"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.channelId = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.title = itemVideo["snippet"]["title"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.title = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.description = itemVideo["snippet"]["description"].ToString();
                                                if (_YVideoDetails.description == "")
                                                {
                                                    _YVideoDetails.description = "No Description";
                                                }
                                            }
                                            catch
                                            {
                                                _YVideoDetails.description = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.vdoImageUrl = itemVideo["snippet"]["thumbnails"]["default"]["url"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.vdoImageUrl = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.channelTitle = itemVideo["snippet"]["channelTitle"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.channelTitle = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.categoryId = itemVideo["snippet"]["categoryId"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.categoryId = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.liveBroadcastContent = itemVideo["snippet"]["liveBroadcastContent"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.liveBroadcastContent = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.duration    = itemVideo["contentDetails"]["duration"].ToString();
                                                _YVideoDetails.videoLength = _YVideoDetails.duration.Replace("PT", "").Replace("H", "h:").Replace("M", "m:").Replace("S", "s");
                                            }
                                            catch
                                            {
                                                _YVideoDetails.duration    = "N/A";
                                                _YVideoDetails.videoLength = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.dimension = itemVideo["contentDetails"]["dimension"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.dimension = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.definition = itemVideo["contentDetails"]["definition"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.definition = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.caption = itemVideo["contentDetails"]["caption"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.caption = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.licensedContent = itemVideo["contentDetails"]["licensedContent"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.licensedContent = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.projection = itemVideo["contentDetails"]["projection"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.projection = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.uploadStatus = itemVideo["status"]["uploadStatus"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.uploadStatus = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.privacyStatus = itemVideo["status"]["privacyStatus"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.privacyStatus = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.license = itemVideo["status"]["license"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.license = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.embeddable = itemVideo["status"]["embeddable"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.embeddable = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.publicStatsViewable = itemVideo["status"]["publicStatsViewable"].ToString();
                                            }
                                            catch
                                            {
                                                _YVideoDetails.publicStatsViewable = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.viewCount = Convert.ToInt32(itemVideo["statistics"]["viewCount"]);
                                            }
                                            catch
                                            {
                                                _YVideoDetails.viewCount = 0;
                                            }
                                            try
                                            {
                                                _YVideoDetails.likeCount = Convert.ToInt32(itemVideo["statistics"]["likeCount"].ToString());
                                            }
                                            catch
                                            {
                                                _YVideoDetails.likeCount = 0;
                                            }
                                            try
                                            {
                                                _YVideoDetails.dislikeCount = Convert.ToInt32(itemVideo["statistics"]["dislikeCount"].ToString());
                                            }
                                            catch
                                            {
                                                _YVideoDetails.dislikeCount = 0;
                                            }
                                            try
                                            {
                                                _YVideoDetails.favoriteCount = Convert.ToInt32(itemVideo["statistics"]["favoriteCount"].ToString());
                                            }
                                            catch
                                            {
                                                _YVideoDetails.favoriteCount = 0;
                                            }
                                            try
                                            {
                                                _YVideoDetails.commentCount = Convert.ToInt32(itemVideo["statistics"]["commentCount"].ToString());
                                            }
                                            catch
                                            {
                                                _YVideoDetails.commentCount = 0;
                                            }
                                            try
                                            {
                                                _YVideoDetails.channelProfilePic = item.ChannelpicUrl;
                                            }
                                            catch
                                            {
                                                _YVideoDetails.channelProfilePic = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.channelEmailId = item.Channel_EmailId;
                                            }
                                            catch
                                            {
                                                _YVideoDetails.channelEmailId = "N/A";
                                            }
                                            try
                                            {
                                                _YVideoDetails.channelUrl = item.WebsiteUrl;
                                            }
                                            catch
                                            {
                                                _YVideoDetails.channelUrl = "N/A";
                                            }

                                            try
                                            {
                                                MongoRepository mongoRepotsRepo = new MongoRepository("YoutubeVideosDetailedList");
                                                var             ret             = mongoRepotsRepo.Find <YoutubeVideoDetailsList>(t => t.YtvideoId.Equals(_YVideoDetails.YtvideoId));
                                                var             task_Reports    = Task.Run(async() =>
                                                {
                                                    return(await ret);
                                                });
                                                int count_Reports = task_Reports.Result.Count;
                                                if (count_Reports < 1)
                                                {
                                                    try
                                                    {
                                                        mongoRepotsRepo.Add(_YVideoDetails);
                                                    }
                                                    catch { }
                                                }
                                                else
                                                {
                                                    try
                                                    {
                                                        FilterDefinition <BsonDocument> filter = new BsonDocument("YtvideoId", _YVideoDetails.YtvideoId);
                                                        var update = Builders <BsonDocument> .Update.Set("title", _YVideoDetails.title).Set("description", _YVideoDetails.description).Set("vdoImageUrl", _YVideoDetails.vdoImageUrl).Set("channelTitle", _YVideoDetails.channelTitle).Set("uploadStatus", _YVideoDetails.uploadStatus).Set("categoryId", _YVideoDetails.categoryId).Set("privacyStatus", _YVideoDetails.privacyStatus).Set("viewCount", _YVideoDetails.viewCount).Set("likeCount", _YVideoDetails.likeCount).Set("dislikeCount", _YVideoDetails.dislikeCount).Set("favoriteCount", _YVideoDetails.favoriteCount).Set("commentCount", _YVideoDetails.commentCount).Set("publishDateUnix", _YVideoDetails.publishDateUnix).Set("videoLength", _YVideoDetails.videoLength).Set("channelProfilePic", _YVideoDetails.channelProfilePic).Set("channelEmailId", _YVideoDetails.channelEmailId).Set("channelUrl", _YVideoDetails.channelUrl);

                                                        mongoRepotsRepo.Update <YoutubeReports>(update, filter);
                                                    }
                                                    catch { }
                                                }
                                            }
                                            catch { }

                                            Console.Write(".");
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }

                                item.LastVideoListDetails_Update = DateTime.UtcNow;
                                dbr.Update <Domain.Socioboard.Models.YoutubeChannel>(item);
                            }
                        }
                        catch
                        {
                        }


                        long oldcount = count;
                        count++;
                        long newcount      = count;
                        long totalcount    = lstYtChannels.Count();
                        long percentagenew = (newcount * 100) / totalcount;
                        long percentageold = (oldcount * 100) / totalcount;
                        if (percentagenew != percentageold)
                        {
                            Console.WriteLine("---------------- {0}% Completed ----------------", percentagenew);
                        }
                    }
                    Thread.Sleep(600000);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("issue in web api calling" + ex.StackTrace);
                    Thread.Sleep(600000);
                }
            }
        }
        public static Domain.Socioboard.Models.TwitterAccount getTwitterAccount(string twitterUserId, Helper.Cache _redisCache, Helper.DatabaseRepository dbr)
        {
            try
            {
                Domain.Socioboard.Models.TwitterAccount inMemTwitterAcc = _redisCache.Get <Domain.Socioboard.Models.TwitterAccount>(Domain.Socioboard.Consatants.SocioboardConsts.CacheTwitterAccount + twitterUserId);
                if (inMemTwitterAcc != null)
                {
                    return(inMemTwitterAcc);
                }
            }
            catch { }

            List <Domain.Socioboard.Models.TwitterAccount> lstTwitterAcc = dbr.Find <Domain.Socioboard.Models.TwitterAccount>(t => t.twitterUserId.Equals(twitterUserId)).ToList();

            if (lstTwitterAcc != null && lstTwitterAcc.Count() > 0)
            {
                _redisCache.Set(Domain.Socioboard.Consatants.SocioboardConsts.CacheTwitterAccount + twitterUserId, lstTwitterAcc.First());
                return(lstTwitterAcc.First());
            }
            else
            {
                return(null);
            }
        }
Example #15
0
        public void UpdateGooglePlusAccount()
        {
            while (true)
            {
                try
                {
                    Helper.DatabaseRepository dbr = new Helper.DatabaseRepository();
                    oAuthTokenGPlus           ObjoAuthTokenGPlus = new oAuthTokenGPlus(AppSettings.GoogleConsumerKey, AppSettings.GoogleConsumerSecret, AppSettings.GoogleRedirectUri);
                    oAuthToken objToken = new oAuthToken(AppSettings.GoogleConsumerKey, AppSettings.GoogleConsumerSecret, AppSettings.GoogleRedirectUri);
                    JObject    userinfo = new JObject();
                    List <Domain.Socioboard.Models.Googleplusaccounts> lstTwtAccounts = dbr.Find <Domain.Socioboard.Models.Googleplusaccounts>(t => t.IsActive).ToList();
                    // lstTwtAccounts = lstTwtAccounts.Where(t => t.GpUserName.Contains("Avinash Verma")).ToList();
                    foreach (var item in lstTwtAccounts)
                    {
                        List <Domain.Socioboard.Models.Groupprofiles> _grpProfile = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.profileId.Contains(item.GpUserId)).ToList();
                        try
                        {
                            if (item.LastUpdate.AddHours(1) <= DateTime.UtcNow)
                            {
                                if (item.IsActive)
                                {
                                    try
                                    {
                                        string  objRefresh     = ObjoAuthTokenGPlus.GetAccessToken(item.RefreshToken);
                                        JObject objaccesstoken = JObject.Parse(objRefresh);
                                        string  access_token   = objaccesstoken["access_token"].ToString();
                                        string  user           = objToken.GetUserInfo("self", access_token);
                                        userinfo = JObject.Parse(JArray.Parse(user)[0].ToString());
                                        string people = objToken.GetPeopleInfo("self", access_token, item.GpUserId);
                                        userinfo = JObject.Parse(JArray.Parse(people)[0].ToString());

                                        try
                                        {
                                            item.GpUserName = userinfo["displayName"].ToString();
                                        }
                                        catch
                                        {
                                            try
                                            {
                                                item.GpUserName = userinfo["name"].ToString();
                                            }
                                            catch { }
                                        }
                                        try
                                        {
                                            item.GpProfileImage = Convert.ToString(userinfo["image"]["url"]);
                                            _grpProfile.Select(s => { s.profilePic = Convert.ToString(userinfo["image"]["url"]); return(s); }).ToList();
                                        }
                                        catch
                                        {
                                            try
                                            {
                                                item.GpProfileImage = Convert.ToString(userinfo["picture"]);
                                                _grpProfile.Select(s => { s.profilePic = Convert.ToString(userinfo["picture"]); return(s); }).ToList();
                                            }
                                            catch { }
                                        }
                                        try
                                        {
                                            item.about = Convert.ToString(userinfo["tagline"]);
                                        }
                                        catch
                                        {
                                            item.about = item.about;
                                        }
                                        try
                                        {
                                            item.college = Convert.ToString(userinfo["organizations"][0]["name"]);
                                        }
                                        catch
                                        {
                                            item.college = item.college;
                                        }
                                        try
                                        {
                                            item.coverPic = Convert.ToString(userinfo["cover"]["coverPhoto"]["url"]);
                                        }
                                        catch
                                        {
                                            item.coverPic = item.coverPic;
                                        }
                                        try
                                        {
                                            item.education = Convert.ToString(userinfo["organizations"][0]["type"]);
                                        }
                                        catch
                                        {
                                            item.education = item.education;
                                        }
                                        try
                                        {
                                            item.EmailId = Convert.ToString(userinfo["emails"][0]["value"]);
                                        }
                                        catch
                                        {
                                            item.EmailId = item.EmailId;
                                        }
                                        try
                                        {
                                            item.gender = Convert.ToString(userinfo["gender"]);
                                        }
                                        catch
                                        {
                                            item.gender = item.gender;
                                        }
                                        try
                                        {
                                            item.workPosition = Convert.ToString(userinfo["occupation"]);
                                        }
                                        catch
                                        {
                                            item.workPosition = item.workPosition;
                                        }

                                        #region Get_InYourCircles
                                        try
                                        {
                                            string  _InyourCircles  = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetPeopleList.Replace("[userId]", item.GpUserId).Replace("[collection]", "visible") + "?key=" + AppSettings.GoogleApiKey, item.AccessToken);
                                            JObject J_InyourCircles = JObject.Parse(_InyourCircles);
                                            item.InYourCircles = Convert.ToInt32(J_InyourCircles["totalItems"].ToString());
                                        }
                                        catch (Exception ex)
                                        {
                                            item.InYourCircles = item.InYourCircles;
                                        }
                                        #endregion

                                        #region Get_HaveYouInCircles
                                        try
                                        {
                                            string  _HaveYouInCircles  = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetPeopleProfile + item.GpUserId + "?key=" + AppSettings.GoogleApiKey, item.AccessToken);
                                            JObject J_HaveYouInCircles = JObject.Parse(_HaveYouInCircles);
                                            item.HaveYouInCircles = Convert.ToInt32(J_HaveYouInCircles["circledByCount"].ToString());
                                        }
                                        catch (Exception ex)
                                        {
                                            item.HaveYouInCircles = item.HaveYouInCircles;
                                        }
                                        #endregion

                                        dbr.Update <Domain.Socioboard.Models.Googleplusaccounts>(item);
                                        foreach (var item_grpProfile in _grpProfile)
                                        {
                                            dbr.Update <Domain.Socioboard.Models.Groupprofiles>(item_grpProfile);
                                        }
                                        GooglePlusFeed.GetUserActivities(item.GpUserId, access_token);

                                        item.LastUpdate = DateTime.UtcNow;
                                        dbr.Update <Domain.Socioboard.Models.Googleplusaccounts>(item);
                                    }
                                    catch (Exception)
                                    {
                                        Thread.Sleep(600000);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Thread.Sleep(600000);
                        }
                    }
                    Thread.Sleep(600000);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("issue in web api calling" + ex.StackTrace);
                    Thread.Sleep(600000);
                }
            }
        }