public void GetUserActivities(string UserId, string ProfileId, string AcessToken, int status) { oAuthTokenGPlus ObjoAuthTokenGPlus = new oAuthTokenGPlus(); try { //Domain.Socioboard.Domain.GooglePlusActivities _GooglePlusActivities = null; Domain.Socioboard.MongoDomain.GoogleplusFeed _GooglePlusActivities; string _Activities = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetActivitiesList.Replace("[ProfileId]", ProfileId) + "?key=" + ConfigurationManager.AppSettings["Api_Key"].ToString(), AcessToken); JObject J_Activities = JObject.Parse(_Activities); foreach (var item in J_Activities["items"]) { _GooglePlusActivities = new Domain.Socioboard.MongoDomain.GoogleplusFeed(); _GooglePlusActivities.Id = ObjectId.GenerateNewId(); //_GooglePlusActivities.UserId = Guid.Parse(UserId); _GooglePlusActivities.GpUserId = ProfileId; try { _GooglePlusActivities.FromUserName = item["actor"]["displayName"].ToString(); } catch { } try { _GooglePlusActivities.FromId = item["actor"]["id"].ToString(); } catch { } try { _GooglePlusActivities.ActivityId = item["id"].ToString(); } catch { } try { _GooglePlusActivities.ActivityUrl = item["url"].ToString(); } catch { } try { _GooglePlusActivities.Title = item["title"].ToString(); } catch { } try { _GooglePlusActivities.FromProfileImage = item["actor"]["image"]["url"].ToString(); } catch { } try { _GooglePlusActivities.Content = item["object"]["content"].ToString(); } catch { } try { _GooglePlusActivities.PublishedDate = Convert.ToDateTime(item["published"].ToString()).ToString("yyyy/MM/dd HH:mm:ss"); } catch { } try { _GooglePlusActivities.PlusonersCount = Convert.ToInt32(item["object"]["plusoners"]["totalItems"].ToString()); } catch { } try { _GooglePlusActivities.RepliesCount = Convert.ToInt32(item["object"]["replies"]["totalItems"].ToString()); } catch { } try { _GooglePlusActivities.ResharersCount = Convert.ToInt32(item["object"]["resharers"]["totalItems"].ToString()); } catch { } try { _GooglePlusActivities.AttachmentType = item["object"]["attachments"][0]["objectType"].ToString(); if (_GooglePlusActivities.AttachmentType == "video") { _GooglePlusActivities.Attachment = item["object"]["attachments"][0]["embed"]["url"].ToString(); } else if (_GooglePlusActivities.AttachmentType == "photo") { _GooglePlusActivities.Attachment = item["object"]["attachments"][0]["image"]["url"].ToString(); } else if (_GooglePlusActivities.AttachmentType == "album") { _GooglePlusActivities.Attachment = item["object"]["attachments"][0]["thumbnails"][0]["image"]["url"].ToString(); } else if (_GooglePlusActivities.AttachmentType == "article") { try { _GooglePlusActivities.Attachment = item["object"]["attachments"][0]["image"]["url"].ToString(); } catch { } try { _GooglePlusActivities.ArticleDisplayname = item["object"]["attachments"][0]["displayName"].ToString(); } catch { } try { _GooglePlusActivities.ArticleContent = item["object"]["attachments"][0]["content"].ToString(); } catch { } try { _GooglePlusActivities.Link = item["object"]["attachments"][0]["url"].ToString(); } catch { } } } catch (Exception ex) { _GooglePlusActivities.AttachmentType = "note"; _GooglePlusActivities.Attachment = ""; } //if (!objGooglePlusActivitiesRepository.checkgoogleplusActivityExists(_GooglePlusActivities.ActivityId, Guid.Parse(UserId))) //{ // objGooglePlusActivitiesRepository.addgoogleplusActivity(_GooglePlusActivities); //} var ret = gplusFeedRepo.Find<Domain.Socioboard.MongoDomain.GoogleplusFeed>(t => t.ActivityId.Equals(_GooglePlusActivities.ActivityId)); var task = Task.Run(async () => { return await ret; }); int count = task.Result.Count; if (count < 1) { gplusFeedRepo.Add(_GooglePlusActivities); } else { FilterDefinition<BsonDocument> filter = new BsonDocument("ActivityId", _GooglePlusActivities.ActivityId); var update = Builders<BsonDocument>.Update.Set("PlusonersCount", _GooglePlusActivities.PlusonersCount).Set("RepliesCount", _GooglePlusActivities.RepliesCount).Set("ResharersCount", _GooglePlusActivities.ResharersCount); gplusFeedRepo.Update<Domain.Socioboard.MongoDomain.GoogleplusFeed>(update, filter); } new Thread(delegate(){ GetGooglePlusComments(_GooglePlusActivities.ActivityId, AcessToken, ProfileId); }).Start(); new Thread(delegate() { GetGooglePlusLikes(_GooglePlusActivities.ActivityId, AcessToken, ProfileId, status); }).Start(); } } catch (Exception ex) { logger.Error("GetUserActivities => " + ex.Message); } }
public void GetUserActivities(string UserId, string ProfileId, string AcessToken, int status) { oAuthTokenGPlus ObjoAuthTokenGPlus = new oAuthTokenGPlus(); try { //Domain.Socioboard.Domain.GooglePlusActivities _GooglePlusActivities = null; Domain.Socioboard.MongoDomain.GoogleplusFeed _GooglePlusActivities; string _Activities = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetActivitiesList.Replace("[ProfileId]", ProfileId) + "?key=" + ConfigurationManager.AppSettings["Api_Key"].ToString(), AcessToken); JObject J_Activities = JObject.Parse(_Activities); foreach (var item in J_Activities["items"]) { _GooglePlusActivities = new Domain.Socioboard.MongoDomain.GoogleplusFeed(); _GooglePlusActivities.Id = ObjectId.GenerateNewId(); //_GooglePlusActivities.UserId = Guid.Parse(UserId); _GooglePlusActivities.GpUserId = ProfileId; try { _GooglePlusActivities.FromUserName = item["actor"]["displayName"].ToString(); } catch { } try { _GooglePlusActivities.FromId = item["actor"]["id"].ToString(); } catch { } try { _GooglePlusActivities.ActivityId = item["id"].ToString(); } catch { } try { _GooglePlusActivities.ActivityUrl = item["url"].ToString(); } catch { } try { _GooglePlusActivities.Title = item["title"].ToString(); } catch { } try { _GooglePlusActivities.FromProfileImage = item["actor"]["image"]["url"].ToString(); } catch { } try { _GooglePlusActivities.Content = item["object"]["content"].ToString(); } catch { } try { _GooglePlusActivities.PublishedDate = Convert.ToDateTime(item["published"].ToString()).ToString("yyyy/MM/dd HH:mm:ss"); } catch { } try { _GooglePlusActivities.PlusonersCount = Convert.ToInt32(item["object"]["plusoners"]["totalItems"].ToString()); } catch { } try { _GooglePlusActivities.RepliesCount = Convert.ToInt32(item["object"]["replies"]["totalItems"].ToString()); } catch { } try { _GooglePlusActivities.ResharersCount = Convert.ToInt32(item["object"]["resharers"]["totalItems"].ToString()); } catch { } try { _GooglePlusActivities.AttachmentType = item["object"]["attachments"][0]["objectType"].ToString(); if (_GooglePlusActivities.AttachmentType == "video") { _GooglePlusActivities.Attachment = item["object"]["attachments"][0]["embed"]["url"].ToString(); } else if (_GooglePlusActivities.AttachmentType == "photo") { _GooglePlusActivities.Attachment = item["object"]["attachments"][0]["image"]["url"].ToString(); } else if (_GooglePlusActivities.AttachmentType == "album") { _GooglePlusActivities.Attachment = item["object"]["attachments"][0]["thumbnails"][0]["image"]["url"].ToString(); } else if (_GooglePlusActivities.AttachmentType == "article") { try { _GooglePlusActivities.Attachment = item["object"]["attachments"][0]["image"]["url"].ToString(); } catch { } try { _GooglePlusActivities.ArticleDisplayname = item["object"]["attachments"][0]["displayName"].ToString(); } catch { } try { _GooglePlusActivities.ArticleContent = item["object"]["attachments"][0]["content"].ToString(); } catch { } try { _GooglePlusActivities.Link = item["object"]["attachments"][0]["url"].ToString(); } catch { } } } catch (Exception ex) { _GooglePlusActivities.AttachmentType = "note"; _GooglePlusActivities.Attachment = ""; } //if (!objGooglePlusActivitiesRepository.checkgoogleplusActivityExists(_GooglePlusActivities.ActivityId, Guid.Parse(UserId))) //{ // objGooglePlusActivitiesRepository.addgoogleplusActivity(_GooglePlusActivities); //} var ret = gplusFeedRepo.Find <Domain.Socioboard.MongoDomain.GoogleplusFeed>(t => t.ActivityId.Equals(_GooglePlusActivities.ActivityId)); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { gplusFeedRepo.Add(_GooglePlusActivities); } else { FilterDefinition <BsonDocument> filter = new BsonDocument("ActivityId", _GooglePlusActivities.ActivityId); var update = Builders <BsonDocument> .Update.Set("PlusonersCount", _GooglePlusActivities.PlusonersCount).Set("RepliesCount", _GooglePlusActivities.RepliesCount).Set("ResharersCount", _GooglePlusActivities.ResharersCount); gplusFeedRepo.Update <Domain.Socioboard.MongoDomain.GoogleplusFeed>(update, filter); } GetGooglePlusComments(_GooglePlusActivities.ActivityId, AcessToken, ProfileId); GetGooglePlusLikes(_GooglePlusActivities.ActivityId, AcessToken, ProfileId, status); } } catch (Exception ex) { logger.Error("GetUserActivities => " + ex.Message); } }