Пример #1
0
        public static AmazonStateTask <TInput, TClient, TRequest, TResponse> SetParameters <TInput, TClient, TRequest,
                                                                                            TResponse>(
            this AmazonStateTask <TInput, TClient, TRequest, TResponse> task,
            Expression <Func <TInput, TRequest> > mapping)
            where TClient : AmazonServiceClient
            where TResponse : AmazonWebServiceResponse
            where TRequest : AmazonWebServiceRequest
        {
            task.Mapping = mapping.Compile();

            var parameter = mapping.Parameters.Single();


            var nodeType = mapping.Body.NodeType;

            switch (nodeType)
            {
            case ExpressionType.Parameter:
                var parameterExpression = (ParameterExpression)mapping.Body;

                break;

            case ExpressionType.MemberInit:
                foreach (var binding in ((MemberInitExpression)mapping.Body).Bindings)
                {
                    task.Parameters.Add(binding.Member.Name, "x.something");
                }
                break;

            default: throw new NotImplementedException(Convert.ToString(nodeType));
            }


            return(task);
        }
Пример #2
0
 public static AmazonStateTask <TInput, TClient, TRequest, TResponse> SetName <TInput, TClient, TRequest,
                                                                               TResponse>(
     this AmazonStateTask <TInput, TClient, TRequest, TResponse> task, string name)
     where TClient : AmazonServiceClient
     where TResponse : AmazonWebServiceResponse
     where TRequest : AmazonWebServiceRequest
 {
     task.Name = name;
     return(task);
 }
Пример #3
0
 public static AmazonStateTask <TInput, TClient, TRequest, TResponse> AddErrorHandler <TInput, TClient, TRequest,
                                                                                       TResponse>(
     this AmazonStateTask <TInput, TClient, TRequest, TResponse> task,
     Type errorType,
     ErrorHandler errorHandler)
     where TClient : AmazonServiceClient
     where TResponse : AmazonWebServiceResponse
     where TRequest : AmazonWebServiceRequest
 {
     task.ErrorHandlers.Add(errorType, errorHandler);
     return(task);
 }
Пример #4
0
        Catch <TInput, TClient, TRequest, TResponse>(
            this AmazonStateTask <TInput, TClient, TRequest, TResponse> task, Type exceptionType, IState fallbackState)
        //  where TException : Exception
            where TClient : AmazonServiceClient
            where TResponse : AmazonWebServiceResponse
            where TRequest : AmazonWebServiceRequest
        {
            //TODO: register the error fallback mapping.

            // WOrk in progress.
            return(task);
        }
Пример #5
0
        public object GetStartState()
        {
            var createCollection =
                new AmazonStateTask <IndexAllFacesRequest, AmazonRekognitionClient, CreateCollectionRequest,
                                     CreateCollectionResponse>()
                .SetParameters(i => new CreateCollectionRequest
            {
                CollectionId = i.Collection,
                Tags         = new Dictionary <string, string>
                {
                    { "App", "Test" }
                }
            }
                               );

            var waitState = new WaitState();



            var getCollection =
                new AmazonStateTask <IndexAllFacesRequest, AmazonRekognitionClient, DescribeCollectionRequest,
                                     DescribeCollectionResponse>()
                .SetParameters(i => new DescribeCollectionRequest
            {
                CollectionId = i.Collection
            })
                .AddErrorHandler(typeof(ResourceNotFoundException), new ErrorHandler
            {
                FallbackState = createCollection
            });

            var getObject = new AmazonStateTask <GetObjectRequest, AmazonS3Client, GetObjectRequest, GetObjectResponse>()
                            .SetParameters(i => i)
                            .Catch(typeof(Amazon.DynamoDBv2.Model.ResourceNotFoundException), createCollection)
                            .SetNextState(new SuccessState {
                Name = "Done"
            });

            var getAllObjects = new MapState <ListObjectsV2Response, S3Object, GetObjectRequest>(getObject)
                                .SetIterator(i => i.S3Objects)
                                .SetMapping(i => new GetObjectRequest
            {
                BucketName = i.BucketName,
                Key        = i.Key
            });

            var listObjects =
                new AmazonStateTask <IndexAllFacesRequest, AmazonS3Client, ListObjectsV2Request, ListObjectsV2Response>()
                .SetParameters(i => new ListObjectsV2Request
            {
                BucketName = i.Bucket
            })
                .AddErrorHandler(typeof(AmazonS3Exception), new ErrorHandler())
                .SetNextState(getAllObjects);


            var getItem =
                new AmazonStateTask <IndexAllFacesRequest, AmazonDynamoDBClient, GetItemRequest, GetItemResponse>()
                .SetParameters(i => new GetItemRequest
            {
                TableName = i.TableName,
                Key       = new Dictionary <string, AttributeValue>
                {
                    { "Partition", new AttributeValue(i.Bucket) }
                }
            }).AddErrorHandler(typeof(Amazon.DynamoDBv2.Model.ResourceNotFoundException), new ErrorHandler {
                FallbackState = new FailState()
            });


            var passState = new PassState(getItem)
            {
            };

            var choiceState = new ChoiceSate <IndexAllFacesRequest>(passState)
                              .AddRule(i => i.Bucket.StartsWith("node") ||
                                       i.TableName != "Something", waitState)
                              .AddRule(i => i.Collection == null, getItem);

            var parallelTask = new ParallelState()
                               .AddState(getCollection)
                               .AddState(listObjects)
                               .AddState(getItem)
                               .SetNextState(new SuccessState());

            return(choiceState);

            return(parallelTask);
        }