Beispiel #1
0
 /// <summary>
 /// Builds the <see cref="EventData"/> from the <paramref name="snapshot"/>.
 /// </summary>
 protected virtual EventData BuildEventData(Snapshot snapshot)
 {
     Logger.LogDebug("Building the snapshot event data", "SnapshotStore\\BuildEventData");
     try
     {
         DateTime  start      = DateTime.Now;
         EventData eventData  = SnapshotBuilder.CreateFrameworkEvent(snapshot);
         string    streamName = GenerateStreamName(snapshot.GetType(), snapshot.Id);
         eventData.AggregateId   = streamName;
         eventData.AggregateRsn  = snapshot.Id;
         eventData.Version       = snapshot.Version;
         eventData.CorrelationId = CorrelationIdHelper.GetCorrelationId();
         DateTime end = DateTime.Now;
         Logger.LogDebug(string.Format("Building the snapshot event data took {0}.", end - start), "SnapshotStore\\BuildEventData");
         return(eventData);
     }
     catch (Exception exception)
     {
         Logger.LogError("There was an issue building the snapshot event data.", exception: exception);
         throw;
     }
     finally
     {
         Logger.LogDebug("Building the snapshot event data... Done", "SnapshotStore\\BuildEventData");
     }
 }
Beispiel #2
0
        public void ThenIsRegistered_WithSnapshot()
        {
            Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1));

            var command = Fixture.Create <ImportTerrainObjectFromCrab>()
                          .WithLifetime(new CrabLifetime(null, null))
                          .WithModification(CrabModification.Insert);

            var parcelId   = new ParcelId(command.CaPaKey.CreateDeterministicId());
            var snapshotId = GetSnapshotIdentifier(parcelId);

            Assert(new Scenario()
                   .GivenNone()
                   .When(command)
                   .Then(new []
            {
                new Fact(parcelId, new ParcelWasRegistered(parcelId, command.CaPaKey)),
                new Fact(parcelId, new ParcelWasRealized(parcelId)),
                new Fact(parcelId, command.ToLegacyEvent()),
                new Fact(snapshotId,
                         SnapshotBuilder.CreateDefaultSnapshot(parcelId)
                         .WithParcelStatus(ParcelStatus.Realized)
                         .Build(2, EventSerializerSettings))
            }));
        }
Beispiel #3
0
 public void SetUp()
 {
     _collection = new SnapshotCollection();
     _collection.DefineTable("Test").CompareKey("Key");
     _snapshot = _collection.NewSnapshot("TestSnapshot");
     _row      = _snapshot.AddNewRow("Test");
 }
 public void SetUp()
 {
     _collection = new SnapshotCollection();
     _collection.DefineTable(TableName).PrimaryKey(IdCol).PrimaryKey(NameCol);
     _tableDef        = _collection.GetTableDefinition(TableName);
     _snapshotBuilder = _collection.NewSnapshot("Test");
 }
        public void AddTerrainObjectHouseNumber_BasedOnSnapshot()
        {
            var command = Fixture.Create <ImportSubaddressFromCrab>()
                          .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null))
                          .WithModification(CrabModification.Insert);

            var terrainObjectHouseNumberWasImportedFromCrab = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                                                              .WithHouseNumberId(command.HouseNumberId)
                                                              .ToLegacyEvent();

            Assert(new Scenario()
                   .Given(_parcelId, Fixture.Create <ParcelWasRegistered>())
                   .Given(_snapshotId,
                          SnapshotBuilder.CreateDefaultSnapshot(_parcelId)
                          .WithAddressIds(new[] { AddressId.CreateFor(command.HouseNumberId) })
                          .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId>()
            {
                { new CrabTerrainObjectHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.TerrainObjectHouseNumberId), new CrabHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.HouseNumberId) }
            })
                          .WithIsRemoved(true)
                          .Build(3, EventSerializerSettings)
                          )
                   .When(command)
                   .Throws(new ParcelRemovedException($"Cannot change removed parcel for parcel id {_parcelId}")));
        }
Beispiel #6
0
        public void WhenLifetimeIsFinite_BasedOnSnapshot()
        {
            var command = Fixture.Create <ImportSubaddressFromCrab>()
                          .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), Fixture.Create <LocalDateTime>()));

            var terrainObjectHouseNumberWasImportedFromCrab = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                                                              .WithHouseNumberId(command.HouseNumberId)
                                                              .ToLegacyEvent();

            Assert(new Scenario()
                   .Given(_parcelId, Fixture.Create <ParcelWasRegistered>())
                   .Given(_snapshotId,
                          SnapshotBuilder
                          .CreateDefaultSnapshot(_parcelId)
                          .WithParcelStatus(ParcelStatus.Retired)
                          .WithAddressIds(new List <AddressId>())
                          .WithLastModificationBasedOnCrab(Modification.Update)
                          .WithImportedSubaddressFromCrab(new List <AddressSubaddressWasImportedFromCrab> {
                command.ToLegacyEvent()
            })
                          .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId>
            {
                { new CrabTerrainObjectHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) }
            })
                          .Build(5, EventSerializerSettings))
                   .When(command)
                   .Then(new[]
            {
                new Fact(_parcelId, command.ToLegacyEvent()),
            }));
        }
Beispiel #7
0
        public void WhenDeleteAndInfiniteLifetimeWithAddress_WithSnapshot()
        {
            Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1));

            var command = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                          .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null))
                          .WithModification(CrabModification.Insert);

            var deleteCommand = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                                .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null))
                                .WithTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId)
                                .WithHouseNumberId(command.HouseNumberId)
                                .WithModification(CrabModification.Delete);

            var addressId = AddressId.CreateFor(command.HouseNumberId);

            Assert(new Scenario()
                   .Given(_parcelId,
                          Fixture.Create <ParcelWasRegistered>(),
                          Fixture.Create <ParcelAddressWasAttached>()
                          .WithAddressId(addressId),
                          command.ToLegacyEvent())
                   .When(deleteCommand)
                   .Then(new[]
            {
                new Fact(_parcelId, new ParcelAddressWasDetached(_parcelId, addressId)),
                new Fact(_parcelId, deleteCommand.ToLegacyEvent()),
                new Fact(_snapshotId,
                         SnapshotBuilder.CreateDefaultSnapshot(_parcelId)
                         .WithLastModificationBasedOnCrab(Modification.Update)
                         .Build(4, EventSerializerSettings))
            }));
        }
Beispiel #8
0
        SessionSnapshot ISessionSnapshotProvider.GetSnapshot()
        {
            var builder = new SnapshotBuilder();
            var visitor = new SessionSnapshotVisitor(_workingMemory);

            _network.Visit(builder, visitor);
            return(builder.Build());
        }
Beispiel #9
0
        public override T SnapshotItem <T>(int id)
        {
            Debug.Assert(id >= 0 && id <= 65535, "incorrect id");

            return(id < 0
                ? null
                : SnapshotBuilder.NewItem <T>(id));
        }
 internal TestData()
 {
     _collection = new SnapshotCollection();
     Definer     = _collection.DefineTable(TableName);
     Builder     = _collection.NewSnapshot("Test");
     Snapshot    = _collection.GetSnapshot("Test");
     NewRow();
 }
Beispiel #11
0
        public override void Init(string[] args)
        {
            Tick      = 0;
            StartTime = 0;
            SendRconCommandsClients = new Queue <int>();
            GameTypes       = new Dictionary <string, Type>();
            SnapshotIdPool  = new SnapshotIdPool();
            SnapshotBuilder = new SnapshotBuilder();

            Config        = Kernel.Get <BaseConfig>();
            GameContext   = Kernel.Get <BaseGameContext>();
            Storage       = Kernel.Get <BaseStorage>();
            NetworkServer = Kernel.Get <BaseNetworkServer>();
            Console       = Kernel.Get <BaseGameConsole>();
            Register      = Kernel.Get <BaseRegister>();
            NetworkBan    = Kernel.Get <BaseNetworkBan>();

            if (Config == null ||
                GameContext == null ||
                Storage == null ||
                NetworkServer == null ||
                Console == null)
            {
                throw new Exception("Register components fail");
            }

            Clients = new BaseServerClient[MaxClients];
            for (var i = 0; i < Clients.Length; i++)
            {
                Clients[i] = Kernel.Get <BaseServerClient>();
            }

            Storage.Init("TeeSharp", StorageType.Server);
            Config.Init(ConfigFlags.Server | ConfigFlags.Econ);
            Console.CommandAdded += ConsoleOnCommandAdded;
            Console.Init();
            PrintCallbackInfo = Console.RegisterPrintCallback(
                (OutputLevel)Config["ConsoleOutputLevel"].AsInt(), OnConsolePrint);
            NetworkServer.Init();

            GameContext.BeforeInit();

            var useDefaultConfig = args.Any(a => a == "--default" || a == "-d");

            if (useDefaultConfig)
            {
            }
            else
            {
                RegisterConsoleCommands();
                Console.ExecuteFile("autoexec.cfg");
                Console.ParseArguments(args);
            }

            Config.RestoreString();
        }
            public async Task<ChecksumScope> CreateChecksumAsync(Solution solution, CancellationToken cancellationToken)
            {
                // TODO: add logging mechanism
                var cache = _caches.CreateRootTreeNodeCache(solution);

                var builder = new SnapshotBuilder(cache);
                var snapshot = new ChecksumScope(_caches, cache, await builder.BuildAsync(solution, cancellationToken).ConfigureAwait(false));

                return snapshot;
            }
            public async Task<ChecksumScope> CreateChecksumAsync(Solution solution, CancellationToken cancellationToken)
            {
                using (Logger.LogBlock(FunctionId.SolutionChecksumServiceFactory_CreateChecksumAsync, cancellationToken))
                {
                    var cache = _caches.CreateRootTreeNodeCache(solution);

                    var builder = new SnapshotBuilder(cache);
                    var snapshot = new ChecksumScope(_caches, cache, await builder.BuildAsync(solution, cancellationToken).ConfigureAwait(false));

                    return snapshot;
                }
            }
Beispiel #14
0
        public void WhenLifetimeIsFinite_BasedOnSnapshot()
        {
            var command = Fixture.Create <ImportTerrainObjectFromCrab>()
                          .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), Fixture.Create <LocalDateTime>()));

            Assert(new Scenario()
                   .Given(_parcelId, Fixture.Create <ParcelWasRegistered>())
                   .Given(_snapshotId, SnapshotBuilder.CreateDefaultSnapshot(_parcelId).Build(0, EventSerializerSettings))
                   .When(command)
                   .Then(new[]
            {
                new Fact(_parcelId, new ParcelWasRetired(_parcelId)),
                new Fact(_parcelId, command.ToLegacyEvent())
            }));
        }
Beispiel #15
0
 private static void SnapshotData(string connectionString, SnapshotBuilder builder, TableStructure table,
                                  TableDefinition definition)
 {
     using (var conn = new SqlConnection(connectionString))
         using (var command = new SqlCommand(SnapshotTableSelectBuilder.Build(table, definition)))
         {
             command.Connection = conn;
             conn.Open();
             Dictionary <string, int> columnIndex = null;
             using (var reader = command.ExecuteReader())
             {
                 SnapshotRows(builder, table, reader, columnIndex);
             }
         }
 }
        public void SetUp()
        {
            _collection = new SnapshotCollection();
            _collection.DefineTable(TestTableName).CompareKey("Id");
            _table    = _collection.GetTableDefinition(TestTableName);
            _snapshot = _collection.NewSnapshot("Test");

            //Borrow a column config so that we can test with it.
            void ExtractColumnDefForTest(ColumnConfig config)
            {
                _cc = config;
            }

            var report = new[] { "T" }.AsReport(rep => rep.AddColumn(t => t, ExtractColumnDefForTest));
        }
        public void WithNoDeleteAndInfiniteLifetime_WithSnapshot()
        {
            Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1));

            var command = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                          .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null));

            var subaddress1 = Fixture.Create <ImportSubaddressFromCrab>()
                              .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null))
                              .WithHouseNumberId(command.HouseNumberId);

            var subaddress2 = Fixture.Create <ImportSubaddressFromCrab>()
                              .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null))
                              .WithHouseNumberId(command.HouseNumberId);

            Assert(new Scenario()
                   .Given(_parcelId,
                          Fixture.Create <ParcelWasRegistered>(),
                          subaddress1.ToLegacyEvent(),
                          subaddress2.ToLegacyEvent())
                   .When(command)
                   .Then(new []
            {
                new Fact(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(command.HouseNumberId))),
                new Fact(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(subaddress1.SubaddressId))),
                new Fact(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(subaddress2.SubaddressId))),
                new Fact(_parcelId, command.ToLegacyEvent()),
                new Fact(_snapshotId,
                         SnapshotBuilder.CreateDefaultSnapshot(_parcelId)
                         .WithLastModificationBasedOnCrab(Modification.Update)
                         .WithImportedSubaddressFromCrab(new List <AddressSubaddressWasImportedFromCrab>
                {
                    subaddress1.ToLegacyEvent(),
                    subaddress2.ToLegacyEvent()
                })
                         .WithAddressIds(new List <AddressId>
                {
                    AddressId.CreateFor(command.HouseNumberId),
                    AddressId.CreateFor(subaddress1.SubaddressId),
                    AddressId.CreateFor(subaddress2.SubaddressId)
                })
                         .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId>
                {
                    { new CrabTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) }
                })
                         .Build(6, EventSerializerSettings))
            }));
        }
        public static SnapshotJsonFile Load1(string sourceFilePath)
        {
            using (StreamReader streamReader = File.OpenText(sourceFilePath))
                using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader))
                {
                    SnapshotBuilder snapshotBuilder = new SnapshotBuilder();

                    JsonSerializer serializer   = new JsonSerializer();
                    JsonSnapshot   jsonSnapshot = (JsonSnapshot)serializer.Deserialize(jsonTextReader, typeof(JsonSnapshot));

                    return(new SnapshotJsonFile
                    {
                        Snapshot = jsonSnapshot.ToSnapshot()
                    });
                }
        }
Beispiel #19
0
        public void WhenLifetimeIsFinite_WithSnapshot()
        {
            Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1));

            var command = Fixture.Create <ImportSubaddressFromCrab>()
                          .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), Fixture.Create <LocalDateTime>()));

            var terrainObjectHouseNumberWasImportedFromCrab = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                                                              .WithHouseNumberId(command.HouseNumberId)
                                                              .ToLegacyEvent();

            Assert(new Scenario()
                   .Given(_parcelId,
                          Fixture.Create <ParcelWasRegistered>(),
                          Fixture.Create <ParcelWasRealized>(),
                          Fixture.Create <ParcelAddressWasAttached>()
                          .WithAddressId(AddressId.CreateFor(command.HouseNumberId)),
                          terrainObjectHouseNumberWasImportedFromCrab,
                          Fixture.Create <ParcelAddressWasDetached>()
                          .WithAddressId(AddressId.CreateFor(command.HouseNumberId)),
                          Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                          .WithHouseNumberId(command.HouseNumberId)
                          .WithLifetime(command.Lifetime)
                          .WithTerrainObjectHouseNumberId(new CrabTerrainObjectHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.TerrainObjectHouseNumberId))
                          .WithModification(CrabModification.Historize)
                          .ToLegacyEvent())
                   .When(command)
                   .Then(new []
            {
                new Fact(_parcelId, command.ToLegacyEvent()),
                new Fact(_snapshotId,
                         SnapshotBuilder
                         .CreateDefaultSnapshot(_parcelId)
                         .WithParcelStatus(ParcelStatus.Realized)
                         .WithAddressIds(new List <AddressId>())
                         .WithLastModificationBasedOnCrab(Modification.Update)
                         .WithImportedSubaddressFromCrab(new List <AddressSubaddressWasImportedFromCrab> {
                    command.ToLegacyEvent()
                })
                         .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId>
                {
                    { new CrabTerrainObjectHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) }
                })
                         .Build(6, EventSerializerSettings))
            }));
        }
Beispiel #20
0
        public static void Make(string connectionString, SnapshotBuilder builder, IEnumerable <SchemaStructure> schemas,
                                SnapshotCollection snapshotCollection)
        {
            var schemasOrdered = schemas.OrderBy(s => s.Name);

            foreach (var schema in schemasOrdered)
            {
                foreach (var table in schema.Tables)
                {
                    var definition = snapshotCollection.GetTableDefinition(table.Name);
                    if (definition?.ExcludeFromComparison ?? false)
                    {
                        continue;
                    }

                    SnapshotData(connectionString, builder, table, definition);
                }
            }
        }
Beispiel #21
0
        public void WhenModificationIsInsertThenParcelWasRecovered_BasedOnSnapshot()
        {
            var command = Fixture.Create <ImportTerrainObjectFromCrab>()
                          .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null))
                          .WithModification(CrabModification.Insert);

            Assert(new Scenario()
                   .Given(_parcelId, Fixture.Create <ParcelWasRegistered>())
                   .Given(_snapshotId,
                          SnapshotBuilder.CreateDefaultSnapshot(_parcelId)
                          .WithIsRemoved(true)
                          .Build(0, EventSerializerSettings))
                   .When(command)
                   .Then(new[]
            {
                new Fact(_parcelId, new ParcelWasRecovered(_parcelId)),
                new Fact(_parcelId, new ParcelWasRealized(_parcelId)),
                new Fact(_parcelId, command.ToLegacyEvent())
            }));
        }
Beispiel #22
0
        public void Test()
        {
            string json = @"{
  ""serializer-id"": ""9e93055d-7bde-4f55-b340-dd5a4880d96e"",
  ""original-path"": ""c:\\aaa"",
  ""creation-time"": ""2019-05-08T19:17:00Z""
}";

            using (StringReader stringReader = new StringReader(json))
                using (JsonTextReader jsonTextReader = new JsonTextReader(stringReader))
                {
                    SnapshotBuilder    snapshotBuilder = new SnapshotBuilder();
                    JsonSnapshotReader reader          = new JsonSnapshotReader(jsonTextReader, snapshotBuilder);

                    reader.Read();

                    Assert.AreEqual("c:\\aaa", snapshotBuilder.Snapshot.OriginalPath);
                    Assert.AreEqual(DateTime.Parse("2019-05-08T19:17:00Z", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal), snapshotBuilder.Snapshot.CreationTime);
                }
        }
Beispiel #23
0
        public void WhenLifetimeIsFinite_WithSnapshot()
        {
            Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1));

            var command = Fixture.Create <ImportTerrainObjectFromCrab>()
                          .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), Fixture.Create <LocalDateTime>()));

            Assert(new Scenario()
                   .Given(_parcelId,
                          Fixture.Create <ParcelWasRegistered>())
                   .When(command)
                   .Then(new []
            {
                new Fact(_parcelId, new ParcelWasRetired(_parcelId)),
                new Fact(_parcelId, command.ToLegacyEvent()),
                new Fact(_snapshotId,
                         SnapshotBuilder.CreateDefaultSnapshot(_parcelId)
                         .WithParcelStatus(ParcelStatus.Retired)
                         .Build(2, EventSerializerSettings))
            }));
        }
Beispiel #24
0
        public void WithDifferentHouseNumberId_WithSnapshot()
        {
            Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1));

            var oldHouseNumberId = new CrabHouseNumberId(-1);
            var oldCommand       = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                                   .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null))
                                   .WithModification(CrabModification.Insert)
                                   .WithHouseNumberId(oldHouseNumberId);

            var command = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                          .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null))
                          .WithModification(CrabModification.Correction)
                          .WithTerrainObjectHouseNumberId(oldCommand.TerrainObjectHouseNumberId);

            Assert(new Scenario()
                   .Given(_parcelId,
                          Fixture.Create <ParcelWasRegistered>(),
                          Fixture.Create <ParcelAddressWasAttached>()
                          .WithAddressId(AddressId.CreateFor(oldHouseNumberId)),
                          oldCommand.ToLegacyEvent())
                   .When(command)
                   .Then(new[]
            {
                new Fact(_parcelId, new ParcelAddressWasDetached(_parcelId, AddressId.CreateFor(oldHouseNumberId))),
                new Fact(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(command.HouseNumberId))),
                new Fact(_parcelId, command.ToLegacyEvent()),
                new Fact(_snapshotId,
                         SnapshotBuilder.CreateDefaultSnapshot(_parcelId)
                         .WithLastModificationBasedOnCrab(Modification.Update)
                         .WithAddressIds(new List <AddressId> {
                    AddressId.CreateFor(command.HouseNumberId)
                })
                         .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId>
                {
                    { new CrabTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) }
                })
                         .Build(5, EventSerializerSettings))
            }));
        }
Beispiel #25
0
        protected override void DoSnapshot()
        {
            GameContext.OnBeforeSnapshots();

            for (var i = 0; i < Clients.Length; i++)
            {
                // client must be ingame to recive snapshots
                if (Clients[i].State != ServerClientState.IN_GAME)
                {
                    continue;
                }

                // this client is trying to recover, don't spam snapshots
                if (Clients[i].SnapRate == SnapRate.RECOVER && Tick % TickSpeed != 0)
                {
                    continue;
                }

                // this client is trying to recover, don't spam snapshots
                if (Clients[i].SnapRate == SnapRate.INIT && Tick % 10 != 0)
                {
                    continue;
                }

                SnapshotBuilder.StartBuild();
                GameContext.OnSnapshot(i);
                var now      = Time.Get();
                var snapshot = SnapshotBuilder.EndBuild();
                var crc      = snapshot.Crc();

                Clients[i].SnapshotStorage.PurgeUntil(Tick - TickSpeed * 3);
                Clients[i].SnapshotStorage.Add(Tick, now, snapshot);

                var deltaTick = -1;

                if (Clients[i].SnapshotStorage.Get(Clients[i].LastAckedSnapshot,
                                                   out var _, out var deltaSnapshot))
                {
                    deltaTick = Clients[i].LastAckedSnapshot;
                }
Beispiel #26
0
        public void WhenModificationDelete_WithSnapshot()
        {
            Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1));

            var command = Fixture.Create <ImportTerrainObjectFromCrab>()
                          .WithModification(CrabModification.Delete);

            Assert(new Scenario()
                   .Given(_parcelId,
                          Fixture.Create <ParcelWasRegistered>())
                   .When(command)
                   .Then(new []
            {
                new Fact(_parcelId, new ParcelWasRemoved(_parcelId)),
                new Fact(_parcelId, command.ToLegacyEvent()),
                new Fact(_snapshotId,
                         SnapshotBuilder.CreateDefaultSnapshot(_parcelId)
                         .WithIsRemoved(true)
                         .WithLastModificationBasedOnCrab(Modification.Delete)
                         .Build(2, EventSerializerSettings))
            }));
        }
Beispiel #27
0
        public override void Init(string[] args)
        {
            Tick      = 0;
            StartTime = 0;

            SnapshotIdPool  = new SnapshotIdPool();
            SnapshotBuilder = new SnapshotBuilder();

            Config        = Kernel.Get <BaseConfig>();
            GameContext   = Kernel.Get <BaseGameContext>();
            Storage       = Kernel.Get <BaseStorage>();
            NetworkServer = Kernel.Get <BaseNetworkServer>();
            Console       = Kernel.Get <BaseGameConsole>();
            Register      = Kernel.Get <BaseRegister>();
            NetworkBan    = Kernel.Get <BaseNetworkBan>();

            if (Config == null ||
                GameContext == null ||
                Storage == null ||
                NetworkServer == null ||
                Console == null)
            {
                throw new Exception("Register components fail");
            }

            Storage.Init("TeeSharp", StorageType.SERVER);

            Console.Init();
            Console.RegisterPrintCallback((OutputLevel)Config["ConsoleOutputLevel"].AsInt(), SendRconLineAuthed);

            NetworkServer.Init();

            RegisterConsoleCommands();
            GameContext.RegisterConsoleCommands();

            Console.ExecuteFile("autoexec.cfg");
            Console.ParseArguments(args);
        }
Beispiel #28
0
        public void WhenDeleteAndInfiniteLifetimeWithAddress_BasedOnSnapshot()
        {
            var command = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                          .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null))
                          .WithModification(CrabModification.Insert);

            var deleteCommand = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>()
                                .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null))
                                .WithTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId)
                                .WithHouseNumberId(command.HouseNumberId)
                                .WithModification(CrabModification.Delete);

            var addressId = AddressId.CreateFor(command.HouseNumberId);

            Assert(new Scenario()
                   .Given(_parcelId,
                          Fixture.Create <ParcelWasRegistered>(),
                          Fixture.Create <ParcelAddressWasAttached>()
                          .WithAddressId(addressId),
                          command.ToLegacyEvent())
                   .Given(_snapshotId,
                          SnapshotBuilder.CreateDefaultSnapshot(_parcelId)
                          .WithLastModificationBasedOnCrab(Modification.Insert)
                          .WithAddressIds(new List <AddressId> {
                addressId
            })
                          .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId>
            {
                { new CrabTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) }
            })
                          .Build(2, EventSerializerSettings))
                   .When(deleteCommand)
                   .Then(_parcelId,
                         new ParcelAddressWasDetached(_parcelId, addressId),
                         deleteCommand.ToLegacyEvent()));
        }
Beispiel #29
0
        private static void SnapshotRows(SnapshotBuilder builder, TableStructure table, SqlDataReader reader, Dictionary <string, int> columnIndex)
        {
            while (reader.Read())
            {
                RowBuilder rowBuilder = null;
                foreach (var tableColumn in table.Columns)
                {
                    if (columnIndex == null)
                    {
                        columnIndex = LoadColumnIndex(reader);
                    }

                    if (columnIndex.TryGetValue(tableColumn.Name, out var currentIx))
                    {
                        if (rowBuilder == null)
                        {
                            rowBuilder = builder.AddNewRow(table.Name);
                        }

                        rowBuilder[tableColumn.Name] = reader[currentIx];
                    }
                }
            }
        }
Beispiel #30
0
        protected override void DoSnapshot()
        {
            GameContext.OnBeforeSnapshot();
            // TODO demo recorder

            for (var i = 0; i < Clients.Length; i++)
            {
                if (Clients[i].State != ServerClientState.InGame)
                {
                    continue;
                }

                if (Clients[i].SnapshotRate == SnapshotRate.Recover && Tick % TickSpeed != 0)
                {
                    continue;
                }

                if (Clients[i].SnapshotRate == SnapshotRate.Init && Tick % 10 != 0)
                {
                    continue;
                }

                SnapshotBuilder.Start();
                GameContext.OnSnapshot(i);

                var now      = Time.Get();
                var snapshot = SnapshotBuilder.Finish();
                var crc      = snapshot.Crc();

                Clients[i].SnapshotStorage.PurgeUntil(Tick - TickSpeed * 3);
                Clients[i].SnapshotStorage.Add(Tick, now, snapshot);

                var deltaTick = -1;

                if (Clients[i].SnapshotStorage.Get(Clients[i].LastAckedSnapshot,
                                                   out _, out var deltaSnapshot))
                {
                    deltaTick = Clients[i].LastAckedSnapshot;
                }
                else
                {
                    deltaSnapshot = new Snapshot(new SnapshotItem[0], 0);
                    if (Clients[i].SnapshotRate == SnapshotRate.Full)
                    {
                        Clients[i].SnapshotRate = SnapshotRate.Recover;
                    }
                }

                var deltaData = new int[Snapshot.MaxSize / sizeof(int)];
                var deltaSize = SnapshotDelta.CreateDelta(deltaSnapshot, snapshot, deltaData);

                if (deltaSize == 0)
                {
                    var msg = new MsgPacker((int)NetworkMessages.ServerSnapEmpty, true);
                    msg.AddInt(Tick);
                    msg.AddInt(Tick - deltaTick);
                    SendMsg(msg, MsgFlags.Flush, i);
                    continue;
                }

                var snapData     = new byte[Snapshot.MaxSize];
                var snapshotSize = IntCompression.Compress(deltaData, 0, deltaSize, snapData, 0);
                var numPackets   = (snapshotSize + Snapshot.MaxPacketSize - 1) / Snapshot.MaxPacketSize;

                for (int n = 0, left = snapshotSize; left != 0; n++)
                {
                    var chunk = left < Snapshot.MaxPacketSize ? left : Snapshot.MaxPacketSize;
                    left -= chunk;

                    if (numPackets == 1)
                    {
                        var msg = new MsgPacker((int)NetworkMessages.ServerSnapSingle, true);
                        msg.AddInt(Tick);
                        msg.AddInt(Tick - deltaTick);
                        msg.AddInt(crc);
                        msg.AddInt(chunk);
                        msg.AddRaw(snapData, n * Snapshot.MaxPacketSize, chunk);
                        SendMsg(msg, MsgFlags.Flush, i);
                    }
                    else
                    {
                        var msg = new MsgPacker((int)NetworkMessages.ServerSnap, true);
                        msg.AddInt(Tick);
                        msg.AddInt(Tick - deltaTick);
                        msg.AddInt(numPackets);
                        msg.AddInt(n);
                        msg.AddInt(crc);
                        msg.AddInt(chunk);
                        msg.AddRaw(snapData, n * Snapshot.MaxPacketSize, chunk);
                        SendMsg(msg, MsgFlags.Flush, i);
                    }
                }
            }

            GameContext.OnAfterSnapshots();
        }
Beispiel #31
0
 public override bool SnapshotItem <T>(T item, int id)
 {
     Debug.Assert(id >= 0 && id <= 65535, "incorrect id");
     return(id >= 0 && SnapshotBuilder.AddItem(item, id));
 }
Beispiel #32
0
 public void SetUp()
 {
     _sutBuilder = SnapshotBuilder.Default;
 }