//All Data
        //channels
        public static List <Domain.Socioboard.Models.YoutubeChannel> GetYtAllChaData(long groupIds, Helper.Cache _redisCache, Helper.AppSettings settings, Model.DatabaseRepository dbr)
        {
            List <Domain.Socioboard.Models.YoutubeReports_all> lstReportsAll = new List <Domain.Socioboard.Models.YoutubeReports_all>();

            List <Domain.Socioboard.Models.Groupprofiles>  lstGroupprofiles  = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.groupId == groupIds).Where(t => t.profileType == Domain.Socioboard.Enum.SocialProfileType.YouTube).ToList();
            List <Domain.Socioboard.Models.YoutubeChannel> lstYoutubeChannel = new List <Domain.Socioboard.Models.YoutubeChannel>();


            foreach (var item in lstGroupprofiles)
            {
                Domain.Socioboard.Models.YoutubeChannel YTChnl = Repositories.YoutubeReportsRepository.GetYtChannelLsts(item.profileId, _redisCache, dbr);
                if (YTChnl != null)
                {
                    lstYoutubeChannel.Add(YTChnl);
                }
            }

            return(lstYoutubeChannel);
        }
        //
        //videos
        public static List <Domain.Socioboard.Models.Mongo.YoutubeVideoDetailsList> GetYtAllVdoData(long groupIds, Helper.Cache _redisCache, Helper.AppSettings settings, Model.DatabaseRepository dbr)
        {
            List <Domain.Socioboard.Models.Groupprofiles>  lstGroupprofiles  = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.groupId == groupIds).Where(t => t.profileType == Domain.Socioboard.Enum.SocialProfileType.YouTube).ToList();
            List <Domain.Socioboard.Models.YoutubeChannel> lstYoutubeChannel = new List <Domain.Socioboard.Models.YoutubeChannel>();

            List <string> lstChannelIds = new List <string>();

            foreach (var item in lstGroupprofiles)
            {
                Domain.Socioboard.Models.YoutubeChannel YTChnl = Repositories.YoutubeReportsRepository.GetYtChannelLsts(item.profileId, _redisCache, dbr);
                if (YTChnl != null)
                {
                    lstYoutubeChannel.Add(YTChnl);
                    lstChannelIds.Add(YTChnl.YtubeChannelId);
                }
            }


            MongoRepository mongorepo = new MongoRepository("YoutubeVideosDetailedList", settings);

            var result = mongorepo.Find <Domain.Socioboard.Models.Mongo.YoutubeVideoDetailsList>(t => lstChannelIds.Contains(t.channelId));
            var task   = Task.Run(async() =>
            {
                return(await result);
            });
            IList <Domain.Socioboard.Models.Mongo.YoutubeVideoDetailsList> lstVideos = task.Result;

            try
            {
                var lstVideos_sorted = lstVideos.OrderBy(t => Convert.ToDateTime(t.publishedAt)).ToList();
                return(lstVideos_sorted.ToList());
            }
            catch
            {
                var lstVideos_sorted = lstVideos;
                return(lstVideos_sorted.ToList());
            }
        }
        //
        public static Domain.Socioboard.Models.YoutubeChannel GetYtChannelLsts(string YtChannelId, Helper.Cache _redisCache, Model.DatabaseRepository dbr)
        {
            try
            {
                Domain.Socioboard.Models.YoutubeChannel inMemYTChannel = _redisCache.Get <Domain.Socioboard.Models.YoutubeChannel>(Domain.Socioboard.Consatants.SocioboardConsts.CacheYTChannel + YtChannelId);
                if (inMemYTChannel != null)
                {
                    return(inMemYTChannel);
                }
            }
            catch { }

            List <Domain.Socioboard.Models.YoutubeChannel> lstYTChannel = dbr.Find <Domain.Socioboard.Models.YoutubeChannel>(t => t.YtubeChannelId.Equals(YtChannelId)).ToList();

            if (lstYTChannel != null && lstYTChannel.Count() > 0)
            {
                _redisCache.Set(Domain.Socioboard.Consatants.SocioboardConsts.CacheYTChannel + YtChannelId, lstYTChannel.First());
                return(lstYTChannel.First());
            }
            else
            {
                return(null);
            }
        }
        public static List <Domain.Socioboard.Models.Mongo.YoutubeReports> GetYoutubeBulkReports(long groupId, Helper.Cache _redisCache, Helper.AppSettings settings, Model.DatabaseRepository dbr)
        {
            List <Domain.Socioboard.Models.Mongo.YoutubeReports> lstReports = new List <Domain.Socioboard.Models.Mongo.YoutubeReports>();

            List <Domain.Socioboard.Models.Groupprofiles>  lstGroupprofiles  = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.groupId == groupId).Where(t => t.profileType == Domain.Socioboard.Enum.SocialProfileType.YouTube).ToList();
            List <Domain.Socioboard.Models.YoutubeChannel> lstYoutubeChannel = new List <Domain.Socioboard.Models.YoutubeChannel>();


            foreach (var item in lstGroupprofiles)
            {
                Domain.Socioboard.Models.YoutubeChannel YTChnl = Repositories.YoutubeReportsRepository.GetYtChannelLsts(item.profileId, _redisCache, dbr);
                if (YTChnl != null)
                {
                    lstYoutubeChannel.Add(YTChnl);
                }
            }

            MongoRepository mongorepo_channel = new MongoRepository("YoutubeReportsData", settings);
            var             result_channel    = mongorepo_channel.Find <Domain.Socioboard.Models.Mongo.YoutubeReports>(t => t.datetime_unix < UnixTimeNows(DateTime.UtcNow) && t.datetime_unix >= UnixTimeNows(DateTime.UtcNow.AddDays(-90)) && t.channelId.Contains(lstYoutubeChannel.First().YtubeChannelId));
            var             task_channel      = Task.Run(async() =>
            {
                return(await result_channel);
            });
            IList <Domain.Socioboard.Models.Mongo.YoutubeReports> lstYtReports_channel = task_channel.Result;

            try
            {
                var lstYtReports_channel_sorted = lstYtReports_channel.OrderBy(t => t.datetime_unix);
            }
            catch
            {
                var lstYtReports_channel_sorted = lstYtReports_channel.ToList();
            }

            foreach (var channel_Items in lstYoutubeChannel)
            {
                if (channel_Items != lstYoutubeChannel.First())
                {
                    var result_channels = mongorepo_channel.Find <Domain.Socioboard.Models.Mongo.YoutubeReports>(t => t.datetime_unix < UnixTimeNows(DateTime.UtcNow) && t.datetime_unix >= UnixTimeNows(DateTime.UtcNow.AddDays(-90)) && t.channelId.Contains(channel_Items.YtubeChannelId));
                    var task_channels   = Task.Run(async() =>
                    {
                        return(await result_channels);
                    });
                    IList <Domain.Socioboard.Models.Mongo.YoutubeReports> lstYtReports_channel_new = task_channels.Result;

                    foreach (var new_item in lstYtReports_channel_new)
                    {
                        foreach (var main_list in lstYtReports_channel)
                        {
                            if (main_list.datetime_unix == new_item.datetime_unix)
                            {
                                main_list.views    = main_list.views + new_item.views;
                                main_list.likes    = main_list.likes + new_item.likes;
                                main_list.comments = main_list.comments + new_item.comments;
                            }
                        }
                    }
                }
            }

            try
            {
                var lstYtReports_channel_sorted = lstYtReports_channel.OrderBy(t => t.datetime_unix);
                return(lstYtReports_channel_sorted.ToList());
            }
            catch
            {
                var lstYtReports_channel_sorted = lstYtReports_channel.ToList();
                return(lstYtReports_channel_sorted.ToList());
            }
        }
Example #5
0
        public static int AddYoutubeChannels(string profiledata, long userId, long groupId, Helper.Cache _redisCache, Helper.AppSettings _appSettings, Model.DatabaseRepository dbr, IHostingEnvironment _appEnv)
        {
            int      isSaved   = 0;
            Channels _Channels = new Channels("575089347457-74q0u81gj88ve5bfdmbklcf2dnc0353q.apps.googleusercontent.com", "JRtS_TaeYpKOJWBCqt9h8-iG", "http://localhost:9821/GoogleManager/Google");

            Domain.Socioboard.Models.YoutubeChannel _YoutubeChannel;
            string[] YTdata = Regex.Split(profiledata, "<:>");
            _YoutubeChannel = Repositories.GplusRepository.getYTChannel(YTdata[2], _redisCache, dbr);


            if (_YoutubeChannel != null)
            {
                try
                {
                    _YoutubeChannel.UserId                  = userId;
                    _YoutubeChannel.YtubeChannelId          = YTdata[2];
                    _YoutubeChannel.YtubeChannelName        = YTdata[3];
                    _YoutubeChannel.ChannelpicUrl           = YTdata[9];
                    _YoutubeChannel.WebsiteUrl              = "https://www.youtube.com/channel/" + YTdata[2];
                    _YoutubeChannel.EntryDate               = DateTime.UtcNow;
                    _YoutubeChannel.YtubeChannelDescription = YTdata[4];
                    _YoutubeChannel.IsActive                = true;
                    _YoutubeChannel.AccessToken             = YTdata[0];
                    _YoutubeChannel.RefreshToken            = YTdata[1];
                    _YoutubeChannel.PublishingDate          = Convert.ToDateTime(YTdata[5]);
                    _YoutubeChannel.VideosCount             = Convert.ToDouble(YTdata[8]);
                    _YoutubeChannel.CommentsCount           = Convert.ToDouble(YTdata[7]);
                    _YoutubeChannel.SubscribersCount        = Convert.ToDouble(YTdata[10]);
                    _YoutubeChannel.ViewsCount              = Convert.ToDouble(YTdata[6]);
                }
                catch (Exception ex)
                {
                }
                isSaved = dbr.Update <Domain.Socioboard.Models.YoutubeChannel>(_YoutubeChannel);
            }
            else
            {
                _YoutubeChannel = new Domain.Socioboard.Models.YoutubeChannel();
                try
                {
                    _YoutubeChannel.UserId                  = userId;
                    _YoutubeChannel.YtubeChannelId          = YTdata[2];
                    _YoutubeChannel.YtubeChannelName        = YTdata[3];
                    _YoutubeChannel.ChannelpicUrl           = YTdata[9];
                    _YoutubeChannel.WebsiteUrl              = "https://www.youtube.com/channel/" + YTdata[2];
                    _YoutubeChannel.EntryDate               = DateTime.UtcNow;
                    _YoutubeChannel.YtubeChannelDescription = YTdata[4];
                    _YoutubeChannel.IsActive                = true;
                    _YoutubeChannel.AccessToken             = YTdata[0];
                    _YoutubeChannel.RefreshToken            = YTdata[1];
                    _YoutubeChannel.PublishingDate          = Convert.ToDateTime(YTdata[5]);
                    _YoutubeChannel.VideosCount             = Convert.ToDouble(YTdata[8]);
                    _YoutubeChannel.CommentsCount           = Convert.ToDouble(YTdata[7]);
                    _YoutubeChannel.SubscribersCount        = Convert.ToDouble(YTdata[10]);
                    _YoutubeChannel.ViewsCount              = Convert.ToDouble(YTdata[6]);
                }
                catch (Exception ex)
                {
                }
                isSaved = dbr.Add <Domain.Socioboard.Models.YoutubeChannel>(_YoutubeChannel);
            }

            if (isSaved == 1)
            {
                List <Domain.Socioboard.Models.YoutubeChannel> lstytChannel = dbr.Find <Domain.Socioboard.Models.YoutubeChannel>(t => t.YtubeChannelId.Equals(_YoutubeChannel.YtubeChannelId)).ToList();
                if (lstytChannel != null && lstytChannel.Count() > 0)
                {
                    isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstytChannel.First().YtubeChannelId, lstytChannel.First().YtubeChannelName, userId, lstytChannel.First().ChannelpicUrl, Domain.Socioboard.Enum.SocialProfileType.YouTube, dbr);
                    //codes to delete cache
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                }
            }
            return(isSaved);
        }