static void Main(string[] args) { Log = new LegacyLog(); var app = new GoogleAnalytics(Log); Environment = new EzEnv(Log); string thumb = System.Configuration.ConfigurationManager.AppSettings["gaCertThumb"]; m_oReportDate = DateTime.Today.AddDays(-1); if (Environment.Name == Name.Dev) { Log = new ConsoleLog(); if ((args.Length > 1) && (args[0] == "--date")) { DateTime.TryParseExact(args[1], "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out m_oReportDate); } if (app.Init(m_oReportDate, thumb)) { Run(app); } Done(); } else { try { if (app.Init(m_oReportDate, thumb)) { if ((args.Length > 1) && (args[0] == "--backfill")) { RunBackfill(app, args[1], args[2]); } else { Run(app); } } Done(); } catch (Exception ex) { app.Log.Error("Error Occured!\n\nStatement: {0}\n\nDescription: {1}", ex.Message, ex.ToString()); app.Log.Error("\nPress enter to exit"); } // try } // if dev/non-dev env }
/// <returns>Item1 = todayVisitors, Item2 = monthVisitors</returns> private Tuple <int, int> GetAnalyticsData(string profileID, DateTime firstOfMonth) { int todayVisitors = 0; int monthVisitors = 0; var ga = new GoogleAnalytics(); ga.Init(DateTime.UtcNow, GaCertThumb, profileID); var todayAnalytics = ga.FetchByCountry(DateTime.Today, LastChanged); var monthToDateAnalytics = ga.FetchByCountry(firstOfMonth, LastChanged); if (todayAnalytics.ContainsKey("United Kingdom")) { todayVisitors = todayAnalytics["United Kingdom"].Users; } if (monthToDateAnalytics.ContainsKey("United Kingdom")) { monthVisitors = monthToDateAnalytics["United Kingdom"].Users; } return(new Tuple <int, int>(todayVisitors, monthVisitors)); }