コード例 #1
0
 public PutPointResult(PutItemResult putItemResult)
 {
     if (putItemResult == null)
     {
         throw new ArgumentNullException("putItemResult");
     }
     PutItemResult = putItemResult;
 }
コード例 #2
0
        public async Task <PutPointResult> PutPointAsync(PutPointRequest putPointRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (putPointRequest == null)
            {
                throw new ArgumentNullException("putPointRequest");
            }

            var geohash = S2Manager.GenerateGeohash(putPointRequest.GeoPoint);
            var hashKey = S2Manager.GenerateHashKey(geohash, _config.HashKeyLength);
            var geoJson = GeoJsonMapper.StringFromGeoObject(putPointRequest.GeoPoint);

            var putItemRequest = putPointRequest.PutItemRequest;

            putItemRequest.TableName = _config.TableName;

            var hashKeyValue = new AttributeValue
            {
                N = hashKey.ToString(CultureInfo.InvariantCulture)
            };

            putItemRequest.Item[_config.HashKeyAttributeName]  = hashKeyValue;
            putItemRequest.Item[_config.RangeKeyAttributeName] = putPointRequest.RangeKeyValue;


            var geohashValue = new AttributeValue
            {
                N = geohash.ToString(CultureInfo.InvariantCulture)
            };

            putItemRequest.Item[_config.GeohashAttributeName] = geohashValue;

            var geoJsonValue = new AttributeValue
            {
                S = geoJson
            };

            putItemRequest.Item[_config.GeoJsonAttributeName] = geoJsonValue;

            PutItemResult putItemResult = await _config.DynamoDBClient.PutItemAsync(putItemRequest, cancellationToken).ConfigureAwait(false);

            var putPointResult = new PutPointResult(putItemResult);

            return(putPointResult);
        }