public BaseContract LoadContract(Address address) { if (address == this.integration.contractRegistryAddress) { throw new ArgumentOutOfRangeException(address + " is a magic address which cannot be used for contracts."); } var data = this.LoadData(address); this.integration.logger.LogTrace("Received contract data: " + data.Length + " bytes for " + address); if (data.Length == 0) { if (address == KitContract.DefaultAddress) { data = this.integration.initialKitFallback; } else { return(new NonexistentContract()); } } return((BaseContract)StrongForceSerialization.DeserializeStatefulObject(data)); }
public void Serializes_And_Deserializes_Messages() { var targets = new Address[] { new Address(new byte[] { 10, 20, 127, 54, 51 }), null }; var type = "NotARealActionType"; var payload = new Dictionary <string, object>() { { "isTest", true }, }; var serializedMessage = StrongForceSerialization.SerializeMessage(targets, type, payload); var deserializedMessage = StrongForceSerialization.DeserializeMessage(serializedMessage); Assert.Equal(targets, deserializedMessage.Item1); Assert.Equal(type, deserializedMessage.Item2); Assert.Equal(payload, deserializedMessage.Item3); }
public void SaveContract(BaseContract contract) { if (contract.Address == this.integration.contractRegistryAddress) { throw new ArgumentOutOfRangeException(contract.Address + " is a magic address which cannot be used for contracts."); } if (contract is NonexistentContract) { return; } var data = StrongForceSerialization.SerializeStatefulObject(contract); var typeName = Encoding.ASCII.GetBytes(contract.GetType().Name); this.SaveData(contract.Address, data, typeName); this.integration.logger.LogTrace("Saved contract data: " + data.Length + " bytes for " + contract.Address); }
public void Serializes_And_Deserializes_Contracts() { var address = new Address(new byte[] { 10, 20, 127, 54, 51 }); var adminAddress = new Address(new byte[] { 10, 20, 4 }); var contract = StatefulObject.Create <FavoriteNumberContract>(new Dictionary <string, object> { { "Admin", adminAddress.ToString() }, { "Number", 15 } }); contract.RegisterWithRegistry(new InMemoryIntegration.FakeContractContext(address)); var serializedContract = StrongForceSerialization.SerializeStatefulObject(contract); var deserializedContract = (FavoriteNumberContract)StrongForceSerialization.DeserializeStatefulObject(serializedContract); deserializedContract.RegisterWithRegistry(new InMemoryIntegration.FakeContractContext(address)); Assert.Equal(contract.GetState(), deserializedContract.GetState()); Assert.Equal(contract.Address, deserializedContract.Address); Assert.Equal(contract.Number, deserializedContract.Number); }
public (Address Sender, Address[] Targets, string Type, IDictionary <string, object> Payload) ReadMessage() { var message = this.ReadFromStream(); if (message.Action == null) { throw new InvalidOperationException("Expected an Action message"); } var sender = new Address(message.Action.Address.ToByteArray()); var data = message.Action.Data.ToByteArray(); this.integration.logger.LogTrace("Received message data: " + data.Length + " bytes from " + sender); var(targets, messageType, messagePayload) = StrongForceSerialization.DeserializeMessage(data); this.integration.logger.LogInformation("Received an action with type: " + messageType); return(sender, targets, messageType, messagePayload); }
public Task StartAsync(CancellationToken cancellationToken) { var initialKit = (KitContract)StatefulObject.Create( this.settings.InitialKitType, this.settings.InitialKitPayload); initialKit.RegisterWithRegistry( new InMemoryIntegration.FakeContractContext( KitContract.DefaultAddress)); var facade = new CosmosIntegration( this.logger, StrongForceSerialization.SerializeStatefulObject(initialKit)); this.server = new Server { Services = { Strongforce.StrongForce.BindService(facade) }, Ports = { new ServerPort(this.settings.Hostname, this.settings.Port, ServerCredentials.Insecure) }, }; this.server.Start(); return(Task.CompletedTask); }