public void AddGoogleAnalyticsReport(Domain.Socioboard.Domain.GoogleAnalyticsReport _GoogleAnalyticsReport) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { bool exist = session.Query <Domain.Socioboard.Domain.GoogleAnalyticsReport>().Any(t => t.GaProfileId == _GoogleAnalyticsReport.GaProfileId); //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { if (!exist) { session.Save(_GoogleAnalyticsReport); transaction.Commit(); } else { try { session.CreateQuery("Update GoogleAnalyticsReport set Visits=:Visits, Views=:Views,TwitterMention=:TwitterMention, Article_Blogs =: Article_Blogs where GaProfileId =: GaProfileId") .SetParameter("Visits", _GoogleAnalyticsReport.Visits) .SetParameter("Views", _GoogleAnalyticsReport.Views) .SetParameter("GaProfileId", _GoogleAnalyticsReport.GaProfileId) .SetParameter("TwitterMention", _GoogleAnalyticsReport.TwitterMention) .SetParameter("Article_Blogs", _GoogleAnalyticsReport.Article_Blogs) .ExecuteUpdate(); transaction.Commit(); } catch (Exception ex) { } } } } }
public string GetGoogleAnalyticsData(string ProfileId) { Domain.Socioboard.Domain.GoogleAnalyticsReport _GoogleAnalyticsReport = new Domain.Socioboard.Domain.GoogleAnalyticsReport(); try { _GoogleAnalyticsReport = objGoogleAnalyticsAccountRepository.GetGoogleAnalyticsReport(ProfileId); } catch (Exception ex) { _GoogleAnalyticsReport = new Domain.Socioboard.Domain.GoogleAnalyticsReport(); } return(new JavaScriptSerializer().Serialize(_GoogleAnalyticsReport)); }
public Domain.Socioboard.Domain.GoogleAnalyticsReport GetGoogleAnalyticsReport(string ProfileId) { Domain.Socioboard.Domain.GoogleAnalyticsReport _GoogleAnalyticsReport; using (NHibernate.ISession session = SessionFactory.GetNewSession()) { try { _GoogleAnalyticsReport = session.Query <Domain.Socioboard.Domain.GoogleAnalyticsReport>().Where(t => t.GaProfileId == ProfileId).FirstOrDefault(); } catch (Exception ex) { _GoogleAnalyticsReport = new Domain.Socioboard.Domain.GoogleAnalyticsReport(); } } return(_GoogleAnalyticsReport); }
public string GetGoogleAnalyticsData(string ProfileId) { Domain.Socioboard.Domain.GoogleAnalyticsReport _GoogleAnalyticsReport = new Domain.Socioboard.Domain.GoogleAnalyticsReport(); try { _GoogleAnalyticsReport = objGoogleAnalyticsAccountRepository.GetGoogleAnalyticsReport(ProfileId); } catch (Exception ex) { _GoogleAnalyticsReport = new Domain.Socioboard.Domain.GoogleAnalyticsReport(); } return new JavaScriptSerializer().Serialize(_GoogleAnalyticsReport); }
public string GetGoogleAnalyticsData(string ProfileId, string AccessToken, string HostName) { try { HostName = HostName.Replace("www.", ""); string arrVisit = string.Empty; string arrViews = string.Empty; string arrTwtMentions = string.Empty; string arrActicleandBlogs = string.Empty; string finalToken = string.Empty; oAuthTokenGa objToken = new oAuthTokenGa(); string finaltoken = objToken.GetAccessToken(AccessToken); try { JObject objArray = JObject.Parse(finaltoken); finalToken = objArray["access_token"].ToString(); } catch (Exception ex) { finalToken = AccessToken; Console.WriteLine(ex.StackTrace); } Analytics _Analytics = new Analytics(); DateTime startDate = DateTime.UtcNow.AddDays(-90); while (startDate.Date < DateTime.UtcNow.Date) { try { string visits = string.Empty; string pageviews = string.Empty; try { string analytics = _Analytics.getAnalyticsData(ProfileId, "ga:visits,ga:pageviews", startDate.ToString("yyyy-MM-dd"), startDate.AddDays(2).ToString("yyyy-MM-dd"), finalToken); JObject JData = JObject.Parse(analytics); visits = JData["totalsForAllResults"]["ga:visits"].ToString(); pageviews = JData["totalsForAllResults"]["ga:pageviews"].ToString(); arrVisit += visits + ","; arrViews += pageviews + ","; } catch (Exception ex) { arrVisit += "0" + ","; arrViews += "0" + ","; } long startUnixTime = startDate.Date.ToUnixTimestamp(); long endUnixTime = startDate.AddDays(3).Date.AddSeconds(-1).ToUnixTimestamp(); var ret = TwtsearchRepo.Find<Domain.Socioboard.MongoDomain.TwitterUrlMentions>(t => t.HostName.Equals(HostName)); var task = Task.Run(async () => { return await ret; }); IList<Domain.Socioboard.MongoDomain.TwitterUrlMentions> lstTwitterUrlMentions = task.Result.ToList(); int twtCount = lstTwitterUrlMentions.Count(t => t.Feeddate > startUnixTime && t.Feeddate <= endUnixTime); arrTwtMentions += twtCount.ToString() + ","; var ret1 = ArticlesAndBlogsRepo.Find<Domain.Socioboard.MongoDomain.ArticlesAndBlogs>(t => t.HostName.Equals(HostName)); var task1 = Task.Run(async () => { return await ret1; }); IList<Domain.Socioboard.MongoDomain.ArticlesAndBlogs> lstArticlesAndBlogs=task1.Result.ToList(); int artucleCount = lstArticlesAndBlogs.Count(t => t.Created_Time > startUnixTime && t.Created_Time <= endUnixTime); arrActicleandBlogs += artucleCount.ToString() + ","; startDate = startDate.AddDays(3); } catch (Exception ex) { logger.Error("GetGoogleAnalyticsData1 => " + ex.Message); } } arrVisit = arrVisit.TrimEnd(','); arrViews = arrViews.TrimEnd(','); arrTwtMentions = arrTwtMentions.TrimEnd(','); arrActicleandBlogs = arrActicleandBlogs.TrimEnd(','); Domain.Socioboard.Domain.GoogleAnalyticsReport _GoogleAnalyticsReport = new Domain.Socioboard.Domain.GoogleAnalyticsReport(); _GoogleAnalyticsReport.GaProfileId = ProfileId; _GoogleAnalyticsReport.Views = arrViews; _GoogleAnalyticsReport.Visits = arrVisit; _GoogleAnalyticsReport.TwitterMention = arrTwtMentions; _GoogleAnalyticsReport.Article_Blogs = arrActicleandBlogs; _GoogleAnalyticsAccountRepository.AddGoogleAnalyticsReport(_GoogleAnalyticsReport); } catch (Exception ex) { logger.Error("GetGoogleAnalyticsData2 => " + ex.Message); } return "Updated Successfuly"; }
public string GetGoogleAnalyticsData(string ProfileId, string AccessToken, string HostName) { try { HostName = HostName.Replace("www.", ""); string arrVisit = string.Empty; string arrViews = string.Empty; string arrTwtMentions = string.Empty; string arrActicleandBlogs = string.Empty; string finalToken = string.Empty; oAuthTokenGa objToken = new oAuthTokenGa(); string finaltoken = objToken.GetAccessToken(AccessToken); try { JObject objArray = JObject.Parse(finaltoken); finalToken = objArray["access_token"].ToString(); } catch (Exception ex) { finalToken = AccessToken; Console.WriteLine(ex.StackTrace); } Analytics _Analytics = new Analytics(); DateTime startDate = DateTime.UtcNow.AddDays(-90); while (startDate.Date < DateTime.UtcNow.Date) { try { string visits = string.Empty; string pageviews = string.Empty; try { string analytics = _Analytics.getAnalyticsData(ProfileId, "ga:visits,ga:pageviews", startDate.ToString("yyyy-MM-dd"), startDate.AddDays(2).ToString("yyyy-MM-dd"), finalToken); JObject JData = JObject.Parse(analytics); visits = JData["totalsForAllResults"]["ga:visits"].ToString(); pageviews = JData["totalsForAllResults"]["ga:pageviews"].ToString(); arrVisit += visits + ","; arrViews += pageviews + ","; } catch (Exception ex) { arrVisit += "0" + ","; arrViews += "0" + ","; } long startUnixTime = startDate.Date.ToUnixTimestamp(); long endUnixTime = startDate.AddDays(3).Date.AddSeconds(-1).ToUnixTimestamp(); var ret = TwtsearchRepo.Find <Domain.Socioboard.MongoDomain.TwitterUrlMentions>(t => t.HostName.Equals(HostName)); var task = Task.Run(async() => { return(await ret); }); IList <Domain.Socioboard.MongoDomain.TwitterUrlMentions> lstTwitterUrlMentions = task.Result.ToList(); int twtCount = lstTwitterUrlMentions.Count(t => t.Feeddate > startUnixTime && t.Feeddate <= endUnixTime); arrTwtMentions += twtCount.ToString() + ","; var ret1 = ArticlesAndBlogsRepo.Find <Domain.Socioboard.MongoDomain.ArticlesAndBlogs>(t => t.HostName.Equals(HostName)); var task1 = Task.Run(async() => { return(await ret1); }); IList <Domain.Socioboard.MongoDomain.ArticlesAndBlogs> lstArticlesAndBlogs = task1.Result.ToList(); int artucleCount = lstArticlesAndBlogs.Count(t => t.Created_Time > startUnixTime && t.Created_Time <= endUnixTime); arrActicleandBlogs += artucleCount.ToString() + ","; startDate = startDate.AddDays(3); } catch (Exception ex) { logger.Error("GetGoogleAnalyticsData1 => " + ex.Message); } } arrVisit = arrVisit.TrimEnd(','); arrViews = arrViews.TrimEnd(','); arrTwtMentions = arrTwtMentions.TrimEnd(','); arrActicleandBlogs = arrActicleandBlogs.TrimEnd(','); Domain.Socioboard.Domain.GoogleAnalyticsReport _GoogleAnalyticsReport = new Domain.Socioboard.Domain.GoogleAnalyticsReport(); _GoogleAnalyticsReport.GaProfileId = ProfileId; _GoogleAnalyticsReport.Views = arrViews; _GoogleAnalyticsReport.Visits = arrVisit; _GoogleAnalyticsReport.TwitterMention = arrTwtMentions; _GoogleAnalyticsReport.Article_Blogs = arrActicleandBlogs; _GoogleAnalyticsAccountRepository.AddGoogleAnalyticsReport(_GoogleAnalyticsReport); } catch (Exception ex) { logger.Error("GetGoogleAnalyticsData2 => " + ex.Message); } return("Updated Successfuly"); }
public Domain.Socioboard.Domain.GoogleAnalyticsReport GetGoogleAnalyticsReport(string ProfileId) { Domain.Socioboard.Domain.GoogleAnalyticsReport _GoogleAnalyticsReport; using (NHibernate.ISession session = SessionFactory.GetNewSession()) { try { _GoogleAnalyticsReport = session.Query<Domain.Socioboard.Domain.GoogleAnalyticsReport>().Where(t => t.GaProfileId == ProfileId).FirstOrDefault(); } catch (Exception ex) { _GoogleAnalyticsReport = new Domain.Socioboard.Domain.GoogleAnalyticsReport(); } } return _GoogleAnalyticsReport; }