Пример #1
0
        public string MoveInstagramFeedToMongo()
        {
            InstagramFeedRepository twtfeedrepo = new InstagramFeedRepository();
            string          output    = string.Empty;
            bool            exit      = true;
            int             skip      = 0;
            MongoRepository mongorepo = new MongoRepository("InstagramFeed");

            while (exit)
            {
                List <Domain.Socioboard.Domain.InstagramFeed> fbmsgs = twtfeedrepo.getAllInstagramFeedMongo(skip);
                if (fbmsgs.Count() == 0)
                {
                    exit = false;
                }

                foreach (var item in fbmsgs)
                {
                    Domain.Socioboard.MongoDomain.InstagramFeed mfbmsg = new Domain.Socioboard.MongoDomain.InstagramFeed();
                    mfbmsg.Id = MongoDB.Bson.ObjectId.GenerateNewId();
                    //  mfbmsg.EntryDate = item.EntryDate.ToString();
                    mfbmsg.AdminUser    = item.AdminUser;
                    mfbmsg.CommentCount = item.CommentCount;
                    mfbmsg.Feed         = item.Feed;
                    mfbmsg.FeedId       = item.FeedId;
                    mfbmsg.FeedDate     = item.FeedDate;
                    mfbmsg.FeedId       = item.FeedId;
                    mfbmsg.InstagramId  = item.InstagramId;
                    mfbmsg.strId        = item.Id.ToString();
                    mfbmsg.FeedImageUrl = item.FeedImageUrl;
                    mfbmsg.FeedUrl      = item.FeedUrl;
                    mfbmsg.FromId       = item.FromId;
                    mfbmsg.ImageUrl     = item.ImageUrl;
                    mfbmsg.InstagramId  = item.InstagramId;
                    mfbmsg.IsLike       = item.IsLike;
                    mfbmsg.LikeCount    = item.LikeCount;
                    mfbmsg.strId        = item.Id.ToString();
                    mongorepo.Add <Domain.Socioboard.MongoDomain.InstagramFeed>(mfbmsg);
                }
                skip = skip + 50;
            }

            return(output);
        }
        public string MoveInstagramFeedToMongo()
        {
            InstagramFeedRepository twtfeedrepo = new InstagramFeedRepository();
            string output = string.Empty;
            bool exit = true;
            int skip = 0;
            MongoRepository mongorepo = new MongoRepository("InstagramFeed");

            while (exit)
            {
                List<Domain.Socioboard.Domain.InstagramFeed> fbmsgs = twtfeedrepo.getAllInstagramFeedMongo(skip);
                if (fbmsgs.Count() == 0)
                {
                    exit = false;
                }

                foreach (var item in fbmsgs)
                {
                    Domain.Socioboard.MongoDomain.InstagramFeed mfbmsg = new Domain.Socioboard.MongoDomain.InstagramFeed();
                    mfbmsg.Id = MongoDB.Bson.ObjectId.GenerateNewId();
                    //  mfbmsg.EntryDate = item.EntryDate.ToString();
                    mfbmsg.AdminUser = item.AdminUser;
                    mfbmsg.CommentCount = item.CommentCount;
                    mfbmsg.Feed = item.Feed;
                    mfbmsg.FeedId = item.FeedId;
                    mfbmsg.FeedDate = item.FeedDate;
                    mfbmsg.FeedId = item.FeedId;
                    mfbmsg.InstagramId = item.InstagramId;
                    mfbmsg.strId = item.Id.ToString();
                    mfbmsg.FeedImageUrl = item.FeedImageUrl;
                    mfbmsg.FeedUrl = item.FeedUrl;
                    mfbmsg.FromId = item.FromId;
                    mfbmsg.ImageUrl = item.ImageUrl;
                    mfbmsg.InstagramId = item.InstagramId;
                    mfbmsg.IsLike = item.IsLike;
                    mfbmsg.LikeCount = item.LikeCount;
                    mfbmsg.strId = item.Id.ToString();
                    mongorepo.Add<Domain.Socioboard.MongoDomain.InstagramFeed>(mfbmsg);
                }
                skip = skip + 50;
            }

            return output;
        }
        public string DiscoverySearchinstagram(string Keyword)
        {
            Domain.Socioboard.MongoDomain.InstagramFeed        _InstagramFeed;
            List <Domain.Socioboard.MongoDomain.InstagramFeed> lstInstagramFeed = new List <Domain.Socioboard.MongoDomain.InstagramFeed>();
            //Domain.Socioboard.Domain.InstagramAccount _InstagramAccount = _InstagramAccountRepository.GetInstagramAccount();
            Media  _Media    = new Media();
            string Client_id = ConfigurationManager.AppSettings["InstagramClientKey"].ToString();

            try
            {
                string  ret   = _Media.ActivitySearchByTag(Keyword, "", Client_id);
                JObject Jdata = JObject.Parse(ret);
                foreach (var item in Jdata["data"])
                {
                    try
                    {
                        _InstagramFeed = new Domain.Socioboard.MongoDomain.InstagramFeed();
                        try
                        {
                            _InstagramFeed.Type = item["type"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FeedDate = item["created_time"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FeedUrl = item["link"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.LikeCount = Int32.Parse(item["likes"]["count"].ToString());
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.CommentCount = Int32.Parse(item["comments"]["count"].ToString());
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FeedImageUrl = item["images"]["thumbnail"]["url"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.Feed = item["caption"]["text"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FeedId = item["caption"]["id"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FromId = item["caption"]["from"]["id"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.ImageUrl = item["caption"]["from"]["profile_picture"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.AdminUser = item["caption"]["from"]["username"].ToString();
                        }
                        catch { }
                        if (_InstagramFeed.Type == "video")
                        {
                            try
                            {
                                _InstagramFeed.VideoUrl = item["videos"]["low_resolution"]["url"].ToString();
                            }
                            catch { }
                        }
                        lstInstagramFeed.Add(_InstagramFeed);
                    }
                    catch (Exception ex)
                    {
                    }
                }

                return(new JavaScriptSerializer().Serialize(lstInstagramFeed));
            }
            catch (Exception)
            {
                return(new JavaScriptSerializer().Serialize(lstInstagramFeed));
            }
        }
Пример #4
0
        public void GetInstagramFeeds(Domain.Socioboard.Domain.InstagramAccount objInsAccount)
        {
            MongoRepository instagarmCommentRepo = new MongoRepository("InstagramComment");
            MongoRepository instagramFeedRepo = new MongoRepository("InstagramFeed");
            try
            {
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                InstagramResponse<InstagramMedia[]> userinf2 = userInstagram.CurrentUserFeed("", "", "30", objInsAccount.AccessToken);
                InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>();

                CommentController objComment = new CommentController();
                LikesController objLikes = new LikesController();
                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            objInstagramFeed = new Domain.Socioboard.MongoDomain.InstagramFeed();
                            //objInstagramFeed.EntryDate = DateTime.Now;
                            try
                            {
                                // objInstagramFeed.Id = ObjectId.GenerateNewId();
                                objInstagramFeed.strId = ObjectId.GenerateNewId().ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedId = userinf2.data[j].id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Type = userinf2.data[j].type.ToString();
                                if (objInstagramFeed.Type == "video")
                                {
                                    objInstagramFeed.VideoUrl = userinf2.data[j].videos.standard_resolution.url.ToString();
                                }
                            }
                            catch { } 
                            try
                            {
                                objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.InstagramId = objInsAccount.InstagramId;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.LikeCount = userinf2.data[j].likes.count;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            }
                            catch { }
                            try
                            {
                                string str = userinf2.data[j].user_has_liked.ToString();
                                if (str == "False")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else { objInstagramFeed.IsLike = 1; }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Feed = userinf2.data[j].caption.text;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.ImageUrl = userinf2.data[j].caption.from.profile_picture;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FromId = userinf2.data[j].caption.from.id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedUrl = userinf2.data[j].link;
                            }
                            catch { }
                            //try
                            //{
                            //    objInstagramFeed.UserId = objInsAccount.UserId.;
                            //}
                            //catch { }

                            var ret = instagramFeedRepo.Find<Domain.Socioboard.MongoDomain.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId));
                            var task = Task.Run(async () =>
                            {
                                return await ret;
                            });
                            int count = task.Result.Count;

                            if (count < 1)
                            {
                                instagramFeedRepo.Add(objInstagramFeed);
                            }
                            else
                            {
                                FilterDefinition<BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId);
                                var update = Builders<BsonDocument>.Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl);
                                instagramFeedRepo.Update<Domain.Socioboard.MongoDomain.InstagramFeed>(update, filter);
                            }

                            //if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                            //{
                            //    objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                            //}
                            List<Domain.Socioboard.MongoDomain.InstagramComment> lstInstagramComment = new List<Domain.Socioboard.MongoDomain.InstagramComment>();
                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {

                                    Domain.Socioboard.MongoDomain.InstagramComment objInstagramComment = new Domain.Socioboard.MongoDomain.InstagramComment();

                                    try
                                    {
                                        objInstagramComment.Comment = usercmts.data[cmt].text;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    }
                                    catch { }
                                    //try
                                    //{
                                    //    objInstagramComment.EntryDate = DateTime.UtcNow.ToString();
                                    //}
                                    //catch { }
                                    try
                                    {
                                        objInstagramComment.FeedId = userinf2.data[j].id;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.Id = ObjectId.GenerateNewId();
                                        objInstagramComment.strId = ObjectId.GenerateNewId().ToString();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.InstagramId = objInsAccount.InstagramId;
                                    }
                                    catch { }
                                    try
                                    {
                                        // objInstagramComment.UserId = objInsAccount.UserId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromName = usercmts.data[cmt].from.username;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    }
                                    catch { }

                                    lstInstagramComment.Add(objInstagramComment);
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                }
                            }
                            instagarmCommentRepo.AddList(lstInstagramComment);

                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
Пример #5
0
        public void GetInstagramSelfFeeds(string instagramId, string accessToken)
        {
            MongoRepository instagarmCommentRepo = new MongoRepository("InstagramComment");
            MongoRepository instagramFeedRepo = new MongoRepository("InstagramFeed");
            try
            {
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                GlobusInstagramLib.Instagram.Core.MediaMethods.Media _Media = new GlobusInstagramLib.Instagram.Core.MediaMethods.Media();
                InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>();
                CommentController objComment = new CommentController();
                LikesController objLikes = new LikesController();
                string feeds = _Media.UserResentFeeds(instagramId, accessToken);
                if (feeds != null)
                {
                    JObject feed_data = JObject.Parse(feeds);

                    foreach (var item in feed_data["data"])
                    {
                        try
                        {
                            Domain.Socioboard.MongoDomain.InstagramFeed objInstagramFeed = new Domain.Socioboard.MongoDomain.InstagramFeed();
                            try
                            {
                                objInstagramFeed.FeedDate = item["created_time"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedId = item["id"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Type = item["type"].ToString();
                                if (objInstagramFeed.Type == "video")
                                {
                                    objInstagramFeed.VideoUrl = item["videos"]["standard_resolution"]["url"].ToString();
                                }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedImageUrl = item["images"]["standard_resolution"]["url"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.InstagramId = instagramId;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.LikeCount = Int32.Parse(item["likes"]["count"].ToString());
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.CommentCount = Int32.Parse(item["comments"]["count"].ToString());
                            }
                            catch { }
                            try
                            {
                                string str = item["user_has_liked"].ToString();
                                if (str.ToLower() == "false")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else { objInstagramFeed.IsLike = 1; }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.AdminUser = item["user"]["username"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Feed = item["caption"]["text"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.ImageUrl = item["user"]["profile_picture"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FromId = item["user"]["id"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedUrl = item["link"].ToString();
                            }
                            catch { }

                            var ret = instagramFeedRepo.Find<Domain.Socioboard.MongoDomain.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId));
                            var task = Task.Run(async () =>
                            {
                                return await ret;
                            });
                            int count = task.Result.Count;

                            if (count < 1)
                            {
                                instagramFeedRepo.Add(objInstagramFeed);
                            }
                            else
                            {
                                FilterDefinition<BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId);
                                var update = Builders<BsonDocument>.Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl);
                                instagramFeedRepo.Update<Domain.Socioboard.MongoDomain.InstagramFeed>(update, filter);
                            }
                            List<Domain.Socioboard.MongoDomain.InstagramComment> lstInstagramComment = new List<Domain.Socioboard.MongoDomain.InstagramComment>();
                            usercmts = objComment.GetComment(objInstagramFeed.FeedId, accessToken);
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    Domain.Socioboard.MongoDomain.InstagramComment objInstagramComment = new Domain.Socioboard.MongoDomain.InstagramComment();
                                    try
                                    {
                                        objInstagramComment.Comment = usercmts.data[cmt].text;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    }
                                    catch { }

                                    try
                                    {
                                        objInstagramComment.FeedId = objInstagramFeed.FeedId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.InstagramId = instagramId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromName = usercmts.data[cmt].from.username;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    }
                                    catch { }

                                    lstInstagramComment.Add(objInstagramComment);
                                }
                                catch (Exception ex)
                                {

                                }
                            }
                            instagarmCommentRepo.AddList(lstInstagramComment);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        public string DiscoverySearchinstagram(string Keyword)
        {
            Domain.Socioboard.MongoDomain.InstagramFeed _InstagramFeed;
            List<Domain.Socioboard.MongoDomain.InstagramFeed> lstInstagramFeed = new List<Domain.Socioboard.MongoDomain.InstagramFeed>();
            //Domain.Socioboard.Domain.InstagramAccount _InstagramAccount = _InstagramAccountRepository.GetInstagramAccount();
            Media _Media = new Media();
            string Client_id = ConfigurationManager.AppSettings["InstagramClientKey"].ToString();
            try
            {
                string ret = _Media.ActivitySearchByTag(Keyword, "", Client_id);
                JObject Jdata = JObject.Parse(ret);
                foreach (var item in Jdata["data"])
                {
                    try
                    {
                        _InstagramFeed = new Domain.Socioboard.MongoDomain.InstagramFeed();
                        try
                        {
                            _InstagramFeed.Type = item["type"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FeedDate = item["created_time"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FeedUrl = item["link"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.LikeCount = Int32.Parse(item["likes"]["count"].ToString());
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.CommentCount = Int32.Parse(item["comments"]["count"].ToString());
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FeedImageUrl = item["images"]["thumbnail"]["url"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.Feed = item["caption"]["text"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FeedId = item["caption"]["id"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.FromId = item["caption"]["from"]["id"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.ImageUrl = item["caption"]["from"]["profile_picture"].ToString();
                        }
                        catch { }
                        try
                        {
                            _InstagramFeed.AdminUser = item["caption"]["from"]["username"].ToString();
                        }
                        catch { }
                        if (_InstagramFeed.Type == "video")
                        {
                            try
                            {
                                _InstagramFeed.VideoUrl = item["videos"]["low_resolution"]["url"].ToString();
                            }
                            catch { }
                        }
                        lstInstagramFeed.Add(_InstagramFeed);
                    }
                    catch (Exception ex)
                    {
                    }
                }

                return new JavaScriptSerializer().Serialize(lstInstagramFeed); 
            }
            catch (Exception)
            {

                 return new JavaScriptSerializer().Serialize(lstInstagramFeed); 
            }
        }