コード例 #1
0
        internal async Task <Document> PutItemHelperAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken)
        {
            var currentConfig = config ?? new PutItemOperationConfig();

            PutItemRequest req = new PutItemRequest
            {
                TableName = TableName,
                Item      = this.ToAttributeMap(doc)
            };

            this.AddRequestHandler(req, isAsync: true);

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues);
            }

            ValidateConditional(currentConfig);


            if (currentConfig.Expected != null)
            {
                req.Expected = this.ToExpectedAttributeMap(currentConfig.Expected);
            }
            else if (currentConfig.ExpectedState != null &&
                     currentConfig.ExpectedState.ExpectedValues != null &&
                     currentConfig.ExpectedState.ExpectedValues.Count > 0)
            {
                req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(this);
                if (req.Expected.Count > 1)
                {
                    req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator);
                }
            }
            else if (currentConfig.ConditionalExpression != null && currentConfig.ConditionalExpression.IsSet)
            {
                currentConfig.ConditionalExpression.ApplyExpression(req, this);
            }

            var resp = await DDBClient.PutItemAsync(req, cancellationToken).ConfigureAwait(false);

            doc.CommitChanges();

            Document ret = null;

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                ret = this.FromAttributeMap(resp.Attributes);
            }
            return(ret);
        }
コード例 #2
0
ファイル: Functions.cs プロジェクト: aws/aws-lambda-dotnet
        public async Task <APIGatewayProxyResponse> OnConnectHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            try
            {
                var connectionId = request.RequestContext.ConnectionId;
                context.Logger.LogLine($"ConnectionId: {connectionId}");

                var ddbRequest = new PutItemRequest
                {
                    TableName = ConnectionMappingTable,
                    Item      = new Dictionary <string, AttributeValue>
                    {
                        { ConnectionIdField, new AttributeValue {
                              S = connectionId
                          } }
                    }
                };

                await DDBClient.PutItemAsync(ddbRequest);

                return(new APIGatewayProxyResponse
                {
                    StatusCode = 200,
                    Body = "Connected."
                });
            }
            catch (Exception e)
            {
                context.Logger.LogLine("Error connecting: " + e.Message);
                context.Logger.LogLine(e.StackTrace);
                return(new APIGatewayProxyResponse
                {
                    StatusCode = 500,
                    Body = $"Failed to connect: {e.Message}"
                });
            }
        }
コード例 #3
0
ファイル: Functions.cs プロジェクト: rottenmonday/CHMURY
        public async Task <APIGatewayProxyResponse> LoginHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            try
            {
                var connectionId = request.RequestContext.ConnectionId;
                var options      = new JsonSerializerOptions
                {
                    PropertyNameCaseInsensitive = true,
                };
                LoginRequest logRequest = JsonSerializer.Deserialize <LoginRequest>(request.Body, options);
                var          ddbRequest = new PutItemRequest
                {
                    TableName = UsersRoomsTable,
                    Item      = new Dictionary <string, AttributeValue>
                    {
                        { "NodeId", new AttributeValue {
                              S = "user-" + logRequest.UserID
                          } },
                        { "TargetId", new AttributeValue {
                              S = "user-" + logRequest.UserID
                          } },
                        { "UserId", new AttributeValue {
                              S = logRequest.UserID
                          } }
                    }
                };

                await DDBUtils.AddUserToHisRooms(logRequest.UserID, connectionId);

                await DDBClient.PutItemAsync(ddbRequest);

                var customRoomsInfo = await DDBUtils.GetUserCustomRooms(logRequest.UserID);

                LoginResponse responseMsg = new LoginResponse()
                {
                    Success          = true,
                    Users            = await DDBUtils.GetAllUsers(),
                    CustomRoomsNames = customRoomsInfo.Item1,
                    CustomRoomsIds   = customRoomsInfo.Item2
                };

                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.OK,
                    Body = JsonSerializer.Serialize(responseMsg)
                });
            }
            catch (Exception e)
            {
                context.Logger.LogLine("Error logging in: " + e.Message);
                context.Logger.LogLine(e.StackTrace);
                LoginResponse responseMsg = new LoginResponse()
                {
                    Success = false
                };
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError,
                    Body = JsonSerializer.Serialize(responseMsg)
                });
            }
        }