예제 #1
0
    public void CommandBatch_Execute_Success()
    {
        // Arrange
        Command.Counter = 0;
        var command1 = new Command(2);
        var command2 = new Command(1);
        var command3 = new Command(3);

        // Act
        var batch = new CommandBatch();

        batch.Add(command3)
        .Add(command2)
        .Add(command1)
        .Execute();

        var task = Task.Run(async() =>
        {
            while (batch.IsDone == false)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(20));
            }

            return(1);
        });

        var unused = task.Result;

        //Assert
        Assert.AreEqual(1, command2.Count);
        Assert.AreEqual(2, command1.Count);
        Assert.AreEqual(3, command3.Count);
    }
예제 #2
0
        //
        public override void SendBatch(CommandBatch commandBatch)
        {
            // Extract serialisation from cache
            CommandHttpClientCache serialisedCache = (CommandHttpClientCache)commandBatch.SerialisedCache;
            string batchUrl = serialisedCache.BatchUrl;
            string postData = serialisedCache.PostData;
            Dictionary <string, string> headers = serialisedCache.Headers;

            // Send HTTP request
            SendRequest(batchUrl, postData, headers, responseArray => {
                // Process each command response
                try
                {
                    for (var batchId = 0; batchId < responseArray.Count; batchId += 1)
                    {
                        var commandResponse = responseArray[batchId] as JArray;
                        if (commandResponse == null)
                        {
                            throw new Exception("Response item " + batchId + " is not an Array:" + responseArray);
                        }

                        CommandBatchItem commandItem         = commandBatch.BatchItems[batchId];
                        string commandName                   = commandItem.CommandName;
                        Action <Exception, JToken> commandCb = commandItem.Cb;

                        // Check if there are any events attached to this request
                        if (commandResponse.Count >= 3)
                        {
                            Logger.Verbose("[" + commandName + "] processing events");
                            Mage.EventManager.EmitEventList((JArray)commandResponse[2]);
                        }

                        // Check if the response was an error
                        if (commandResponse[0].Type != JTokenType.Null)
                        {
                            Logger.Verbose("[" + commandName + "] server error");
                            commandCb(new Exception(commandResponse[0].ToString()), null);
                            continue;
                        }

                        // Pull off call result object, if it doesn't exist
                        Logger.Verbose("[" + commandName + "] call response");

                        try
                        {
                            commandCb(null, commandResponse[1]);
                        }
                        catch (Exception error)
                        {
                            Logger.Data(error).Error("Error during command callback");
                        }
                    }
                }
                catch (Exception error)
                {
                    Logger.Data(error).Error("Error when processing command batch responses");
                }
            });
        }
예제 #3
0
        public void ShouldAddACommandToTheCommandBatch(Type fixtureType)
        {
            var fixture               = Activator.CreateInstance(fixtureType) as CommandBatchFixtureBase;
            var commandBatch          = new CommandBatch(fixture.Connector);
            var commandBuilderFactory = fixture.Connector.GetCommandBuilderFactory();
            var tableTypeDescriptor   = DescriptorCache.Instance.GetTableTypeDescriptor(typeof(BatchMock));
            var valueProvider         = new ClassValueProvider(fixture.Connector, new List <object> {
                fixture.CreateMock(), fixture.CreateMock()
            });

            commandBatch.Add(new CommandBatchStep(commandBuilderFactory.CreateInsertCommandBuilder(tableTypeDescriptor).GetCommand(valueProvider)));
            commandBatch.Add(new CommandBatchStep(commandBuilderFactory.CreateInsertCommandBuilder(tableTypeDescriptor).GetCommand(valueProvider)));

            commandBatch.GetCommand().CommandText.Should().Be(fixture.CommandBatchText);
        }
예제 #4
0
        public ComposerBatch(
            CommandSequence root,
            IModesController modesController,
            Composer composer)
        {
            Requires.NotNull(root, nameof(root));
            Requires.NotNull(modesController, nameof(modesController));
            Requires.NotNull(composer, nameof(composer));

            this.root            = root;
            this.modesController = modesController;
            this.composer        = composer;
            batch = new CommandBatch();
            root.Add(batch);
        }
예제 #5
0
 //
 public override void SerialiseBatch(CommandBatch commandBatch)
 {
     Logger.Verbose("THIS TRANSPORT CLIENT IS NOT IMPLEMENTED");
     throw new Exception("THIS TRANSPORT CLIENT IS NOT IMPLEMENTED");
 }
예제 #6
0
 public abstract void SendBatch(CommandBatch batch);
예제 #7
0
 public abstract void SerialiseBatch(CommandBatch commandBatch);