public void Groupshreathon(object o) { try { var arr = o as object[]; var shareathon = (GroupShareathon)arr[0]; var dbr = (DatabaseRepository)arr[1]; var shareathonRepository = (MongoRepository)arr[2]; var ids = shareathon.Facebookpageid.Split(','); foreach (var id in ids) { try { var groupApiHitsCountNew = 0; var fbAcc = dbr.Single <Facebookaccounts>(t => t.FbUserId == shareathon.Facebookaccountid); //var lstFbAcc = dbr.Single<Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == id); if (fbAcc != null) { if (groupApiHitsCountNew < GroupMaxapiHitsCount) { var feeds = string.Empty; if (fbAcc.GroupShareathonUpdate.AddHours(1) <= DateTime.UtcNow) { feeds = Fbpages.getFacebookRecentPost(fbAcc.AccessToken, id); var feedId = string.Empty; if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]")) { var fbpageNotes = JObject.Parse(feeds); foreach (var obj in JArray.Parse(fbpageNotes["data"].ToString())) { try { var feedid = obj["id"].ToString(); feedid = feedid.Split('_')[1]; feedId = feedid + "," + feedId; } catch (Exception ex) { Console.WriteLine(ex.Message); } } try { var dt = SBHelper.ConvertFromUnixTimestamp(shareathon.Lastsharetimestamp); dt = dt.AddMinutes(shareathon.Timeintervalminutes); if (shareathon.Lastpostid == null || !shareathon.Lastpostid.Equals(feedId) && SBHelper.ConvertToUnixTimestamp(dt) <= SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow)) { ShareFeedonGroup(fbAcc.AccessToken, feedId, id, "", shareathon.Facebookgroupid, shareathon.Timeintervalminutes, shareathon.Facebookaccountid, shareathon.Lastsharetimestamp, shareathon.Facebooknameid); } fbAcc.GroupShareathonUpdate = DateTime.UtcNow; dbr.Update(fbAcc); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { FilterDefinition <BsonDocument> filter = new BsonDocument("strId", shareathon.strId); var update = Builders <BsonDocument> .Update.Set("FacebookStatus", 0); shareathonRepository.Update <GroupShareathon>(update, filter); GroupapiHitsCount = GroupMaxapiHitsCount; } } else { GroupapiHitsCount = 0; } } } } catch { GroupapiHitsCount = GroupMaxapiHitsCount; } } } catch (Exception e) { GroupapiHitsCount = GroupMaxapiHitsCount; Console.WriteLine(e.Message); } finally { NoOfthreadGroupshreathonRunning--; } }
public void PageShreathon(object o) { try { var arr = o as object[]; var shareathon = (PageShareathon)arr[0]; var dbr = (DatabaseRepository)arr[1]; var shareathonRepository = (MongoRepository)arr[2]; var ids = shareathon.Facebookpageid.Split(','); GlobalVariable.pageShareathonIdsRunning.Add(shareathon.strId); foreach (var id in ids) { try { PageapiHitsCount = 0; var fbAcc = dbr.Single <Facebookaccounts>(t => t.FbUserId == shareathon.Facebookaccountid); Facebookaccounts facebookPage = null; var lstFbAcc = dbr.Single <Facebookaccounts>(t => t.FbUserId == id); if (lstFbAcc != null) { facebookPage = lstFbAcc; } if (facebookPage != null) { if (PageapiHitsCount < PageMaxapiHitsCount) { var feeds = string.Empty; if (facebookPage.PageShareathonUpdate.AddHours(1) <= DateTime.UtcNow) { feeds = Fbpages.getFacebookRecentPost(fbAcc.AccessToken, facebookPage.FbUserId); var feedId = string.Empty; if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]")) { PageapiHitsCount++; var fbpageNotes = JObject.Parse(feeds); foreach (var obj in JArray.Parse(fbpageNotes["data"].ToString())) { try { feedId = obj["id"].ToString(); feedId = feedId.Split('_')[1]; var dt = SBHelper.ConvertFromUnixTimestamp( shareathon.Lastsharetimestamp); dt = dt.AddMinutes(shareathon.Timeintervalminutes); if (!shareathon.Lastpostid.Equals(feedId) && SBHelper.ConvertToUnixTimestamp(dt) <= SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow)) { var ret = ShareFeed(fbAcc.AccessToken, feedId, facebookPage.FbUserId, "", fbAcc.FbUserId, facebookPage.FbUserName); if (!string.IsNullOrEmpty(ret)) { Thread.Sleep(1000 * 60 * shareathon.Timeintervalminutes); } } } catch { PageapiHitsCount = PageMaxapiHitsCount; } } fbAcc.PageShareathonUpdate = DateTime.UtcNow; facebookPage.PageShareathonUpdate = DateTime.UtcNow; dbr.Update(fbAcc); dbr.Update(facebookPage); } else { FilterDefinition <BsonDocument> filter = new BsonDocument("strId", shareathon.strId); var update = Builders <BsonDocument> .Update.Set("FacebookStatus", 0); shareathonRepository.Update <PageShareathon>(update, filter); } } else { PageapiHitsCount = 0; } } } } catch { PageapiHitsCount = PageMaxapiHitsCount; } } try { if (!string.IsNullOrEmpty(shareathon.FacebookPageUrlId)) { var urlsIds = shareathon.FacebookPageUrlId.Split(','); foreach (var idUrl in urlsIds) { try { PageapiHitsCount = 0; var fbAcc = dbr.Single <Facebookaccounts>( t => t.FbUserId == shareathon.Facebookaccountid); var pagename = Fbpages.GetFbPageName(fbAcc.AccessToken, idUrl); if (PageapiHitsCount < PageMaxapiHitsCount) { var feeds = string.Empty; feeds = Fbpages.getFacebookRecentPost(fbAcc.AccessToken, idUrl); var feedId = string.Empty; if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]")) { PageapiHitsCount++; var fbpageNotes = JObject.Parse(feeds); foreach (var obj in JArray.Parse(fbpageNotes["data"].ToString())) { try { feedId = obj["id"].ToString(); feedId = feedId.Split('_')[1]; var dt = SBHelper.ConvertFromUnixTimestamp( shareathon.Lastsharetimestamp); dt = dt.AddMinutes(shareathon.Timeintervalminutes); if (!shareathon.Lastpostid.Equals(feedId) && SBHelper.ConvertToUnixTimestamp(dt) <= SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow)) { var ret = ShareFeed(fbAcc.AccessToken, feedId, idUrl, "", fbAcc.FbUserId, pagename); if (!string.IsNullOrEmpty(ret)) { Thread.Sleep(1000 * 60 * shareathon.Timeintervalminutes); } } } catch { PageapiHitsCount = PageMaxapiHitsCount; } } fbAcc.PageShareathonUpdate = DateTime.UtcNow; dbr.Update(fbAcc); } else { FilterDefinition <BsonDocument> filter = new BsonDocument("strId", shareathon.strId); var update = Builders <BsonDocument> .Update.Set("FacebookStatus", 1); shareathonRepository.Update <PageShareathon>(update, filter); } } } catch { PageapiHitsCount = PageMaxapiHitsCount; } } } } catch (Exception) { } GlobalVariable.pageShareathonIdsRunning.Remove(shareathon.strId); } catch (Exception e) { PageapiHitsCount = PageMaxapiHitsCount; Console.WriteLine(e.Message); } finally { NoOfthreadPageshreathonRunning--; } }