Пример #1
0
    public Status ProcessRequest(ResolverRequest request)
    {
        Status status = new Status();

        status.Id       = request.Id;
        status.ActionId = request.ActionId;

        try
        {
            String         cueId  = request.CueId;
            Config         config = JsonTools.Convert <Config>(request.Signal.Cues[cueId].Resolver.Config);
            LambdaArn      arn    = new LambdaArn(config.Arn);
            RegionEndpoint region = RegionEndpoint.GetBySystemName(System.Environment.GetEnvironmentVariable("AWS_REGION"));
            if (!String.IsNullOrEmpty(arn.Region))
            {
                region = RegionEndpoint.GetBySystemName(arn.Region);
            }

            AmazonLambdaClient client = new AmazonLambdaClient(region);   // Set Region

            InvokeResponse response = AWSUtilities.CallLambdaMethod(client, arn.Arn, JsonTools.Serialize(request));
            status.NewStatus = StatusType.SentToResolver;
            status.Message   = $"Request Sent To Lambda Function [{arn.Name}].";
        }
        catch (Exception e)
        {
            status.NewStatus = StatusType.Error;
            status.Message   = e.Message;
        }

        return(status);
    }
Пример #2
0
    public Status ProcessRequest(ResolverRequest request)
    {
        Status status = new Status();

        status.Id       = request.Id;
        status.ActionId = request.ActionId;

        Dictionary <object, object> data = new Dictionary <object, object>();
        StringBuilder sb = new StringBuilder();

        try
        {
            ActionType action = request.Actions[request.ActionId];
            foreach (MultiValueVariable variable in action.Variables)
            {
                data[variable.Name] = variable.Values;
                if (sb.Length > 0)
                {
                    sb.AppendLine();
                }
                sb.Append($"{variable.Name} = {String.Join(',', variable.Values)}");
            }

            status.Message     = sb.ToString();
            status.Data        = data;
            status.NewStatus   = StatusType.Completed;
            status.CloseSignal = false;
        }
        catch (Exception e)
        {
            status.NewStatus = StatusType.Error;
            status.Message   = e.Message;
        }

        return(status);
    }
Пример #3
0
    public Status ProcessRequest(ResolverRequest request)
    {
        Status status = new Status();

        status.Id       = request.Id;
        status.ActionId = request.ActionId;

        try
        {
            String          cueId  = request.CueId;
            Config          config = JsonTools.Convert <Config>(request.Signal.Cues[cueId].Resolver.Config);
            StepFunctionArn arn    = new StepFunctionArn(config.Arn);
            RegionEndpoint  region = RegionEndpoint.GetBySystemName(System.Environment.GetEnvironmentVariable("AWS_REGION"));
            if (!String.IsNullOrEmpty(arn.Region))
            {
                region = RegionEndpoint.GetBySystemName(arn.Region);
            }

            AmazonStepFunctionsClient client = new AmazonStepFunctionsClient(region);   // Set Region

            StartExecutionRequest exeRequest = new StartExecutionRequest
            {
                StateMachineArn = config.Arn,
                Input           = JsonTools.Serialize(request)
            };

            if (config.UseDefaultName == false)
            {
                if (String.IsNullOrWhiteSpace(config.ExecutionName))
                {
                    exeRequest.Name = $"syntinel-{request.Id}-{request.ActionId}";
                }
                else
                {
                    exeRequest.Name = config.ExecutionName;
                }
            }

            Task <StartExecutionResponse> t = client.StartExecutionAsync(exeRequest);
            t.Wait(30000);
            StartExecutionResponse response = t.Result;

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                StepFunctionArn eArn = new StepFunctionArn(response.ExecutionArn);
                status.NewStatus = StatusType.SentToResolver;
                status.Message   = $"Request Sent To Step Function [{eArn.Name}].  Execution Name [{eArn.ExecutionName}].";
            }
            else
            {
                status.NewStatus = StatusType.Error;
                status.Message   = $"Error Sending To Step Function [{arn.Name}].  {response.HttpStatusCode}";
            }
        }
        catch (Exception e)
        {
            status.NewStatus = StatusType.Error;
            status.Message   = e.Message;
        }

        return(status);
    }