public List<GeoSystem> getGeoSystemData(DateTime fromDate, DateTime toDate, Site site) { List<GeoSystem> geoSystems = new List<GeoSystem>(); int startIndex = 1; Boolean isMore; DataFeed feed = null; do { isMore = false; try { feed = getGADataFeed(site, fromDate, toDate, "ga:city,ga:country,ga:isMobile,ga:language,ga:transactionId", "ga:transactions", "", "", startIndex); if (feed != null) { foreach (DataEntry singleEntry in feed.Entries) { GeoSystem geoSystem = new GeoSystem(singleEntry); geoSystems.Add(geoSystem); isMore = true; } } } catch (Exception rEx) { log.Error("Error in getGeoSystemData", rEx); } if (isMore) startIndex += numberOfGARecordsToRetrievePerRequest; } while (isMore); return geoSystems; }
public void recordAnalyticsGeoSystem(GeoSystem geoSystem) { SqlConnection conn = new SqlConnection(connectionAnalytics); try { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = @"IF NOT EXISTS(SELECT (1) FROM Analytics_Geo_System (nolock) WHERE TransactionID = @TransactionID) INSERT INTO Analytics_Geo_System (City, Country, Language, TransactionID, isMobile) VALUES (@City, @Country, @Language, @TransactionID, @IsMobile) ELSE UPDATE Analytics_Geo_System SET City = @City, Country = @Country, Language = @Language, IsMobile = @IsMobile WHERE TransactionID = @TransactionID"; cmd.Parameters.Add("@City", SqlDbType.NVarChar); cmd.Parameters["@City"].Value = truncate(geoSystem.city, 255); cmd.Parameters.Add("@Country", SqlDbType.NVarChar); cmd.Parameters["@Country"].Value = truncate(geoSystem.country, 255); cmd.Parameters.Add("@Language", SqlDbType.NVarChar); cmd.Parameters["@Language"].Value = truncate(geoSystem.language, 255); cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar); cmd.Parameters["@TransactionID"].Value = truncate(geoSystem.orderNumber, 255); cmd.Parameters.Add("@IsMobile", SqlDbType.Bit); cmd.Parameters["@IsMobile"].Value = geoSystem.isMobile; cmd.ExecuteNonQuery(); cmd.Dispose(); } catch (SqlException sqle) { log.Error("Error in recordAnalyticsGeoSystem", sqle); } finally { if (conn != null) { if (conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } } }