Exemplo n.º 1
0
        //public static string addtwitterContentfeedsdata(string keyword, string userId, Helper.AppSettings _appSettings )
        //{
        //    //MongoRepository mongorepo = new MongoRepository("ContentFeeds", _appSettings);
        //    MongoRepository mongorepo = new MongoRepository("RssNewsContentsFeeds", _appSettings);
        //    bool output = false;

        //    string timeline = TwitterHashTag.TwitterBoardHashTagSearch(keyword, null);
        //    int i = 0;
        //    if (!string.IsNullOrEmpty(timeline) && !timeline.Equals("[]"))
        //    {
        //        foreach (JObject obj in JArray.Parse(timeline))
        //        {
        //            RssNewsContentsFeeds contentFeedsDet = new RssNewsContentsFeeds();
        //            // Domain.Socioboard.Models.Mongo.ContentFeeds contentFeedsDet = new Domain.Socioboard.Models.Mongo.ContentFeeds();
        //            contentFeedsDet.Id = ObjectId.GenerateNewId();

        //            i++;
        //            try
        //            {
        //                contentFeedsDet.Link = JArray.Parse(obj["entities"]["expanded_url"].ToString())[0]["url"].ToString();
        //                //contentFeedsDet = JArray.Parse(obj["entities"]["expanded_url"].ToString())[0]["url"].ToString();
        //            }
        //            catch
        //            {
        //                try
        //                {
        //                    //contentFeedsDet.Link = JArray.Parse(obj["entities"]["urls"].ToString())[0]["expanded_url"].ToString();
        //                    contentFeedsDet.Link = JArray.Parse(obj["entities"]["urls"].ToString())[0]["expanded_url"].ToString();
        //                }
        //                catch (Exception e)
        //                {

        //                }
        //            }
        //            try
        //            {
        //                //contentFeedsDet.Image = JArray.Parse(obj["extended_entities"]["media"].ToString())[0]["media_url"].ToString();
        //                contentFeedsDet.Image = JArray.Parse(obj["extended_entities"]["media"].ToString())[0]["media_url"].ToString();
        //            }
        //            catch
        //            {
        //                try
        //                {
        //                    contentFeedsDet.Image = JArray.Parse(obj["entities"]["media"].ToString())[0]["media_url"].ToString();
        //                }
        //                catch (Exception e)
        //                {

        //                }
        //            }

        //            try
        //            {
        //                contentFeedsDet.Title = obj["text"].ToString();
        //                //contentFeedsDet.Title = obj["text"].ToString();
        //            }
        //            catch (Exception e)
        //            {

        //            }

        //            try
        //            {
        //                string Const_TwitterDateTemplate = "ddd MMM dd HH:mm:ss +ffff yyyy";
        //                contentFeedsDet.PublishingDate = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(DateTime.ParseExact((string)obj["created_at"], Const_TwitterDateTemplate, new System.Globalization.CultureInfo("en-US"))).ToString();
        //                //contentFeedsDet.CreatedDate = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(DateTime.ParseExact((string)obj["created_at"], Const_TwitterDateTemplate, new System.Globalization.CultureInfo("en-US")));
        //            }
        //            catch (Exception e)
        //            {

        //            }
        //            contentFeedsDet.UserId = userId;
        //            contentFeedsDet.keywords = keyword;
        //            // var ret = mongorepo.Find<RssNewsContentsFeeds>(t => t.FeedId == contentFeedsDet.FeedId);

        //            var ret = mongorepo.Find<RssNewsContentsFeeds>(t => t.UserId == userId && t.Image == contentFeedsDet.Image);
        //            var task = Task.Run(async () =>
        //            {
        //                return await ret;
        //            });
        //            int count = task.Result.Count;
        //            if (count < 1)
        //            {
        //                try
        //                {
        //                    //mongorepo.Add<RssNewsContentsFeeds>(contentFeedsDet);ContentFeeds
        //                    mongorepo.Add<RssNewsContentsFeeds>(contentFeedsDet);
        //                }
        //                catch (Exception e) { }

        //            }
        //            else
        //            {
        //                //return "already data present";
        //            }
        //        }
        //        return "data successfully added";
        //    }
        //    output = true;
        //    return output.ToString();
        //}

        public static bool addGplusContentfeedsdata(string keywords, string userId, Helper.AppSettings _appSettings)
        {
            MongoRepository mongorepo = new MongoRepository("RssNewsContentsFeeds", _appSettings);

            bool output = false;

            try
            {
                var discoveryResponse = GplusDiscoverySearchHelper.GooglePlus(keywords, _appSettings.GoogleApiKeyForRssFeed);

                JObject GplusActivities = JObject.Parse(discoveryResponse);

                foreach (JObject obj in JArray.Parse(GplusActivities["items"].ToString()))
                {
                    RssNewsContentsFeeds contentGFeedsDet = new RssNewsContentsFeeds();
                    contentGFeedsDet.Id = ObjectId.GenerateNewId();

                    try
                    {
                        foreach (JObject att in JArray.Parse(obj["object"]["attachments"].ToString()))
                        {
                            contentGFeedsDet.Image = att["fullImage"]["url"].ToString();

                            contentGFeedsDet.Link = att["url"].ToString();

                            contentGFeedsDet.Title = att["displayName"].ToString();
                        }
                    }
                    catch { }
                    try
                    {
                        contentGFeedsDet.PublishingDate = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(DateTime.Parse(obj["published"].ToString())).ToString();
                    }
                    catch { }


                    contentGFeedsDet.UserId   = userId;
                    contentGFeedsDet.keywords = keywords;
                    var ret  = mongorepo.Find <RssNewsContentsFeeds>(t => t.Title == contentGFeedsDet.Title);
                    var task = Task.Run(async() =>
                    {
                        return(await ret);
                    });
                    int count = task.Result.Count;
                    if (count < 1)
                    {
                        try
                        {
                            mongorepo.Add(contentGFeedsDet);
                            output = true;
                        }
                        catch { }
                    }
                }
                return(output);
            }
            catch { }

            return(output);
        }
        public string DiscoverySearchGplus(string UserId, string keyword)
        {
            List <Domain.Socioboard.Domain.DiscoverySearch> GplusDiscoverySearch = new List <Domain.Socioboard.Domain.DiscoverySearch>();
            string profileid = string.Empty;

            try
            {
                string searchResultObj = GplusDiscoverySearchHelper.GooglePlus(keyword);
                GooglePlusAccountRepository gplusAccRepo = new GooglePlusAccountRepository();
                ArrayList alst = gplusAccRepo.getAllGooglePlusAccounts();

                GlobusGooglePlusLib.Authentication.oAuthToken oauth = new GlobusGooglePlusLib.Authentication.oAuthToken();
                GooglePlusActivities obj = new GooglePlusActivities();

                JObject GplusActivities = JObject.Parse(GplusDiscoverySearchHelper.GooglePlus(keyword));

                foreach (JObject gobj in JArray.Parse(GplusActivities["items"].ToString()))
                {
                    Domain.Socioboard.Domain.DiscoverySearch gpfeed = new Domain.Socioboard.Domain.DiscoverySearch();
                    gpfeed.Id = Guid.NewGuid();

                    try
                    {
                        gpfeed.MessageId       = gobj["url"].ToString();
                        gpfeed.CreatedTime     = DateTime.Parse(gobj["published"].ToString());
                        gpfeed.Message         = gobj["title"].ToString();
                        gpfeed.FromId          = gobj["actor"]["id"].ToString();
                        gpfeed.FromName        = gobj["actor"]["displayName"].ToString();
                        gpfeed.ProfileImageUrl = gobj["actor"]["image"]["url"].ToString();
                    }
                    catch { }

                    GplusDiscoverySearch.Add(gpfeed);
                }
            }
            catch { }
            return(new JavaScriptSerializer().Serialize(GplusDiscoverySearch));
        }