Пример #1
0
        public async Task <string> FunctionHandler(ResponseSourse json, ILambdaContext context)
        {
            context.Logger.LogLine($"Beginning to process {context.FunctionName} records...");
            var photoJsonData = json;

            using (var dbContext = new DynamoDBContext(_dbClient))
            {
                context.Logger.LogLine($"Create context {context.FunctionName}...");

                var items = photoJsonData.response.items.ToList();
                for (int i = 0; i < items.Count; i++)
                {
                    var item     = items.ElementAt(i);
                    var largSize = item.sizes.FirstOrDefault(x => x.type == "w");
                    if (largSize == null)
                    {
                        continue;
                    }

                    await dbContext.SaveAsync <Photo>(new Photo()
                    {
                        id     = item.id,
                        imgUrl = largSize.url,
                        lat    = item.lat.ToString(),
                        lng    = [email protected](),
                    });
                }

                context.Logger.LogLine("Stream processing complete.");

                return(true.ToString());
            }
        }
Пример #2
0
        public async Task <string> FunctionHandler(ResponseSourse json, ILambdaContext context)
        {
            context.Logger.LogLine($"Beginning to process {context.FunctionName} records...");
            var photoJsonData = json;

            //return "";
            context.Logger.LogLine($"Create context {context.FunctionName}...");

            var config = new GeoDataManagerConfiguration(new AmazonDynamoDBClient(), _tableName);
            var ddb    = new AmazonDynamoDBClient();

            _config         = new GeoDataManagerConfiguration(ddb, _tableName);
            _geoDataManager = new GeoDataManager(_config);

            var items = photoJsonData.response.items.ToList();

            for (int i = 0; i < items.Count; i++)
            {
                var item        = items.ElementAt(i);
                var imgUrl      = item.sizes.FirstOrDefault(x => x.type == "p")?.url;
                var imgUrlLarge = item.sizes.FirstOrDefault(x => x.type == "w")?.url;

                if (String.IsNullOrEmpty(imgUrl) || String.IsNullOrEmpty(imgUrlLarge))
                {
                    continue;
                }

                var guid      = Guid.NewGuid();
                var latitude  = item.lat;
                var longitude = item.@long;

                var point = new GeoPoint(latitude, longitude);

                var rangeKeyVal = new AttributeValue {
                    S = guid.ToString()
                };
                var imgUrlVal = new AttributeValue {
                    S = imgUrl
                };
                var imgUrlLargeVal = new AttributeValue {
                    S = imgUrlLarge
                };

                var req = new PutPointRequest(point, rangeKeyVal);
                req.PutItemRequest.Item["imgUrl"]      = imgUrlVal;
                req.PutItemRequest.Item["imgUrlLarge"] = imgUrlLargeVal;

                await _geoDataManager.PutPointAsync(req);
            }

            context.Logger.LogLine("Stream processing complete.");
            return(true.ToString());
        }