public async Task <Dictionary <string, GeoEntityCount> > GetGeoCount(CloudTable geoTable) { Dictionary <string, int> _geoCount = JsonConvert.DeserializeObject <Dictionary <string, int> >(this.GeoCount ??= "{}");; Dictionary <string, GeoEntityCount> response = new Dictionary <string, GeoEntityCount>(); foreach (string key in _geoCount.Keys) { response.Add(key, new GeoEntityCount(await GeoEntity.get(geoTable, key), _geoCount[key])); } return(response); }
public GeoEntityCount(GeoEntity geoEntity, int clickCount) { this.City = geoEntity.City; this.CountryCode = geoEntity.CountryCode; this.CountryName = geoEntity.CountryName; this.Latitude = geoEntity.Latitude; this.Longitude = geoEntity.Longitude; this.RegionCode = geoEntity.RegionCode; this.RowKey = geoEntity.RowKey; this.TimeZone = geoEntity.TimeZone; this.ZipCode = geoEntity.ZipCode; this.ClickCount = clickCount; }
public static async Task <bool> put(CloudTable geoTable, GeoEntity entityToInsert) { await geoTable.CreateIfNotExistsAsync(); try { GeoEntity entity = await GeoEntity.get(geoTable, entityToInsert.RowKey); if (entity != null) { return(true); } TableOperation insertGeoOperation = TableOperation.InsertOrMerge(entityToInsert); await geoTable.ExecuteAsync(insertGeoOperation); } catch { return(false); } return(true); }
public static async Task <GeoEntity> get(CloudTable geoTable, string key) { await geoTable.CreateIfNotExistsAsync(); TableQuery <GeoEntity> rangeQuery = new TableQuery <GeoEntity>().Where( TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, $"{string.Empty}"), TableOperators.And, TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, $"{key}"))); var sessionRedirectFound = await geoTable.ExecuteQuerySegmentedAsync(rangeQuery, null); if (sessionRedirectFound.Results.Count > 0) { GeoEntity entity = sessionRedirectFound.Results.ToArray()[0]; return(entity); } else { return(null); } }