コード例 #1
0
ファイル: DemoCommandTests.cs プロジェクト: zeroyou/try
        public async Task Demo_sources_pass_verification()
        {
            var console = new TestConsole();

            var demoSourcesDir = new DirectoryInfo(@"c:\dev\agent\docs\gettingstarted");
            var packageFile    = demoSourcesDir.Subdirectory("Snippets")
                                 .File("Snippets.csproj");

            _output.WriteLine(demoSourcesDir.FullName);
            _output.WriteLine(packageFile.FullName);

            await DemoCommand.Do(new DemoOptions(output : demoSourcesDir), console);

            var resultCode = await VerifyCommand.Do(
                new VerifyOptions(dir : demoSourcesDir),
                console,
                () => new FileSystemDirectoryAccessor(demoSourcesDir),
                new PackageRegistry(),
                new StartupOptions(package : packageFile.FullName));

            _output.WriteLine(console.Out.ToString());
            _output.WriteLine(console.Error.ToString());

            resultCode.Should().Be(0);
        }
コード例 #2
0
        /// <summary>
        /// Parses the tick internally
        /// </summary>
        /// <returns><c>true</c>, if tick was parsed, <c>false</c> otherwise.</returns>
        private bool ParseTick()
        {
            DemoCommand command = (DemoCommand)BitStream.ReadByte();

            BitStream.ReadInt(32);          // tick number
            BitStream.ReadByte();           // player slot

            this.CurrentTick++;             // = TickNum;

            switch (command)
            {
            case DemoCommand.Synctick:
                break;

            case DemoCommand.Stop:
                return(false);

            case DemoCommand.ConsoleCommand:
                BitStream.BeginChunk(BitStream.ReadSignedInt(32) * 8);
                BitStream.EndChunk();
                break;

            case DemoCommand.DataTables:
                BitStream.BeginChunk(BitStream.ReadSignedInt(32) * 8);
                SendTableParser.ParsePacket(BitStream);
                BitStream.EndChunk();

                //Map the weapons in the equipmentMapping-Dictionary.
                MapEquipment();

                //And now we have the entities, we can bind events on them.
                BindEntites();

                break;

            case DemoCommand.StringTables:
                BitStream.BeginChunk(BitStream.ReadSignedInt(32) * 8);
                StringTables.ParsePacket(BitStream, this);
                BitStream.EndChunk();
                break;

            case DemoCommand.UserCommand:
                BitStream.ReadInt(32);
                BitStream.BeginChunk(BitStream.ReadSignedInt(32) * 8);
                BitStream.EndChunk();
                break;

            case DemoCommand.Signon:
            case DemoCommand.Packet:
                ParseDemoPacket();
                break;

            default:
                throw new Exception("Can't handle Demo-Command " + command);
            }

            return(true);
        }
コード例 #3
0
    static async Task Main()
    {
        var endpointConfiguration = new EndpointConfiguration("endpointA");

        endpointConfiguration.EnableInstallers();
        endpointConfiguration.UsePersistence <InMemoryPersistence>();
        endpointConfiguration.SendFailedMessagesTo("error");

        var routingConfig = endpointConfiguration.UseTransport <MsmqTransport>().Routing();

        routingConfig.InstanceMappingFile().FilePath("instance-mapping.xml");
        routingConfig.UseFileBasedRouting();

        var endpoint = await Endpoint.Start(endpointConfiguration)
                       .ConfigureAwait(false);

        Console.WriteLine("Press [c] to send a command. Press [e] to publish an event. Press [Esc] to quit.");

        while (true)
        {
            var key = Console.ReadKey();
            if (key.Key == ConsoleKey.Escape)
            {
                break;
            }

            if (key.Key == ConsoleKey.C)
            {
                var commandId   = Guid.NewGuid();
                var demoCommand = new DemoCommand
                {
                    CommandId = commandId
                };
                await endpoint.Send(demoCommand)
                .ConfigureAwait(false);

                Console.WriteLine();
                Console.WriteLine("Sent command with id: " + commandId);
            }

            if (key.Key == ConsoleKey.E)
            {
                var eventId   = Guid.NewGuid();
                var demoEvent = new DemoEvent
                {
                    EventId = eventId
                };
                await endpoint.Publish(demoEvent)
                .ConfigureAwait(false);

                Console.WriteLine();
                Console.WriteLine("Sent event with id: " + eventId);
            }
        }

        await endpoint.Stop()
        .ConfigureAwait(false);
    }
コード例 #4
0
        public void SyncTest()
        {
            DemoCommand command = new DemoCommand();

            command.Execute();
            // 说明同步调用的情况下,只触发一次同步事件
            Assert.AreEqual <int>(1, command.Log.Count);
            Assert.AreEqual <string>("OnCompleted", command.Log[0]);
        }
コード例 #5
0
        private void ReadCommandHeader(out DemoCommand cmd, out int tick, out int playerSlot)
        {
            cmd = (DemoCommand)_reader.ReadByte();

            Debug.Assert((int)cmd >= 1 && cmd <= DemoCommand.LastCmd);

            tick       = _reader.ReadInt32();
            playerSlot = _reader.ReadByte();
        }
コード例 #6
0
        public void AsyncTest()
        {
            DemoCommand command = new DemoCommand();

            command.AsyncExecute();
            Thread.Sleep(200); // 给异步调用留出可以触发的时间
            // 说明异步调用的情况下,同时触发同步和异步事件
            Assert.AreEqual <int>(2, command.Log.Count);
            Assert.AreEqual <string>("OnCompleted", command.Log[0]);
            Assert.AreEqual <string>("OnAsyncCompleted", command.Log[1]);
        }
コード例 #7
0
        private DemoReader(Stream input)
        {
            Header = new DemoHeader(input);

            List <DemoCommand> commands = new List <DemoCommand>();

            Commands = commands;

            DemoCommand cmd = null;

            while ((cmd = ParseCommand(input)) != null)
            {
                commands.Add(cmd);
            }
        }
コード例 #8
0
        public async Task Demo_creates_the_output_directory_if_it_does_not_exist()
        {
            var console = new TestConsole();

            var outputDirectory = new DirectoryInfo(
                Path.Combine(
                    Create.EmptyWorkspace().Directory.FullName,
                    Guid.NewGuid().ToString("N")));

            await DemoCommand.Do(
                new DemoOptions(output : outputDirectory),
                console,
                startServer : (options, context) => { });

            outputDirectory.Refresh();

            outputDirectory.Exists.Should().BeTrue();
        }
コード例 #9
0
        public async Task Demo_returns_an_error_if_the_output_directory_is_not_empty()
        {
            var console = new TestConsole();

            var outputDirectory = Create.EmptyWorkspace().Directory;

            File.WriteAllText(Path.Combine(outputDirectory.FullName, "a file.txt"), "");

            await DemoCommand.Do(
                new DemoOptions(output : outputDirectory),
                console,
                startServer : (options, context) => { });

            var resultCode = await VerifyCommand.Do(
                new VerifyOptions(new FileSystemDirectoryAccessor(outputDirectory)),
                console);

            resultCode.Should().NotBe(0);
        }
コード例 #10
0
        public async Task Demo_project_passes_verification()
        {
            var console = new TestConsole();

            var outputDirectory = Create.EmptyWorkspace().Directory;
            var packageFile     = outputDirectory.Subdirectory("Snippets")
                                  .File("Snippets.csproj");

            await DemoCommand.Do(new DemoOptions(output : outputDirectory), console);

            var resultCode = await VerifyCommand.Do(
                new VerifyOptions(new FileSystemDirectoryAccessor(outputDirectory)),
                console,
                startupOptions : new StartupOptions(package: packageFile.FullName));

            _output.WriteLine(console.Out.ToString());
            _output.WriteLine(console.Error.ToString());

            resultCode.Should().Be(0);
        }
コード例 #11
0
        public async Task Demo_starts_the_server_if_there_are_no_errors()
        {
            var console = new TestConsole();

            var outputDirectory = Create.EmptyWorkspace().Directory;

            StartupOptions startupOptions = null;
            await DemoCommand.Do(
                new DemoOptions(output : outputDirectory),
                console,
                (options, context) => startupOptions = options);

            await VerifyCommand.Do(
                new VerifyOptions(new FileSystemDirectoryAccessor(outputDirectory)),
                console);

            _output.WriteLine(console.Out.ToString());
            _output.WriteLine(console.Error.ToString());

            startupOptions.Uri.Should().Be(new Uri("QuickStart.md", UriKind.Relative));
        }
コード例 #12
0
        public async Task Demo_sources_pass_verification()
        {
            var console = new TestConsole();

            var demoSourcesDir = Create.EmptyWorkspace().Directory;
            var packageFile    = demoSourcesDir.Subdirectory("Snippets")
                                 .File("Snippets.csproj");

            _output.WriteLine(demoSourcesDir.FullName);
            _output.WriteLine(packageFile.FullName);

            await DemoCommand.Do(new DemoOptions(output : demoSourcesDir), console);

            var resultCode = await VerifyCommand.Do(
                new VerifyOptions(new FileSystemDirectoryAccessor(demoSourcesDir)),
                console);

            _output.WriteLine(console.Out.ToString());
            _output.WriteLine(console.Error.ToString());

            resultCode.Should().Be(0);
        }
コード例 #13
0
        private bool ParseTick()
        {
            DemoCommand command = (DemoCommand)BitStream.ReadByte();

            BitStream.ReadInt(32);          // tick number
            BitStream.ReadByte();           // player slot

            this.CurrentTick++;             // = TickNum;

            switch (command)
            {
            case DemoCommand.Synctick:
                break;

            case DemoCommand.Stop:
                return(false);

            case DemoCommand.ConsoleCommand:
                BitStream.BeginChunk(BitStream.ReadSignedInt(32) * 8);
                BitStream.EndChunk();
                break;

            case DemoCommand.DataTables:
                BitStream.BeginChunk(BitStream.ReadSignedInt(32) * 8);
                SendTableParser.ParsePacket(BitStream);
                BitStream.EndChunk();

                for (int i = 0; i < SendTableParser.ServerClasses.Count; i++)
                {
                    var sc = SendTableParser.ServerClasses[i];

                    if (sc.BaseClasses.Count > 6 && sc.BaseClasses [6].Name == "CWeaponCSBase")
                    {
                        //It is a "weapon" (Gun, C4, ... (...is the cz still a "weapon" after the nerf?))
                        if (sc.BaseClasses.Count > 7)
                        {
                            if (sc.BaseClasses [7].Name == "CWeaponCSBaseGun")
                            {
                                //it is a ratatatata-weapon.
                                var s = sc.DTName.Substring(9).ToLower();
                                equipmentMapping.Add(sc, Equipment.MapEquipment(s));
                            }
                            else if (sc.BaseClasses [7].Name == "CBaseCSGrenade")
                            {
                                //"boom"-weapon.
                                equipmentMapping.Add(sc, Equipment.MapEquipment(sc.DTName.Substring(3).ToLower()));
                            }
                        }
                        else if (sc.Name == "CC4")
                        {
                            //Bomb is neither "ratatata" nor "boom", its "booooooom".
                            equipmentMapping.Add(sc, EquipmentElement.Bomb);
                        }
                        else if (sc.Name == "CKnife" || (sc.BaseClasses.Count > 6 && sc.BaseClasses [6].Name == "CKnife"))
                        {
                            //tsching weapon
                            equipmentMapping.Add(sc, EquipmentElement.Knife);
                        }
                        else if (sc.Name == "CWeaponNOVA" || sc.Name == "CWeaponSawedoff" || sc.Name == "CWeaponXM1014")
                        {
                            equipmentMapping.Add(sc, Equipment.MapEquipment(sc.Name.Substring(7).ToLower()));
                        }
                    }
                }

                BindEntites();

                break;

            case DemoCommand.StringTables:
                BitStream.BeginChunk(BitStream.ReadSignedInt(32) * 8);
                StringTables.ParsePacket(BitStream, this);
                BitStream.EndChunk();
                break;

            case DemoCommand.UserCommand:
                BitStream.ReadInt(32);
                BitStream.BeginChunk(BitStream.ReadSignedInt(32) * 8);
                BitStream.EndChunk();
                break;

            case DemoCommand.Signon:
            case DemoCommand.Packet:
                ParseDemoPacket();
                break;

            default:
                throw new Exception("Can't handle Demo-Command " + command);
            }

            return(true);
        }
コード例 #14
0
        public void Test1()
        {
            var errors = DemoCommand.ParseUShort("--port -9000");

            errors.First().Message.Should().Contain("--port");
        }