public void LoadJsonAsyncWithObjectAndArray() { string json = @" { ""Simple"" : ""Value"", ""RabbitMQ"" : { ""Host"" : ""localhost"", ""Port"" : ""5672"" }, ""Connections"" : [ 1, 2, 3, 4] } "; var transform = new JsonTransform(); var result = transform.Parse(json); var collection = (result.Result as ConfigCollection).WrappedConfigEntities; Assertion(collection, "Simple", "Value", 0); Assertion(collection, "RabbitMQ:Host", "localhost", 1); Assertion(collection, "RabbitMQ:Port", "5672", 2); Assertion(collection, "Connections:0", "1", 3); Assertion(collection, "Connections:1", "2", 4); Assertion(collection, "Connections:2", "3", 5); Assertion(collection, "Connections:3", "4", 6); }
public void LoadJsonAndTransformBack() { string json = @" { ""Simple"" : ""Value"", ""RabbitMQ"" : { ""Host"" : ""localhost"", ""Port"" : ""5672"" }, ""Connections"" : [ 1, 2, 3, 4] } "; var transform = new JsonTransform(); var result = transform.Parse(json); var collection = (result.Result as ConfigCollection).WrappedConfigEntities; OperationResult opResult = transform.Format(collection); var jsonEntity = opResult.Result as ConfigEntityJson; Assert.NotNull(jsonEntity); var token = jsonEntity.Json; Assert.Equal(token["Simple"], "Value"); Assert.Equal(token["RabbitMQ:Host"], "localhost"); Assert.Equal(token["RabbitMQ:Port"], "5672"); Assert.Equal(token["Connections"], "1,2,3,4"); }
public void ArrayWithObjectWithArray() { string json = @" { ""Array"" : [ { ""Key-1"" : [ 1, 2, 3, 4 ], }, { ""Nested"" : { ""NestedKey"" : ""NestedValue"" } } ] } "; var transform = new JsonTransform(); var result = transform.Parse(json); var collection = (result.Result as ConfigCollection).WrappedConfigEntities; Assertion(collection, "Array:0:Key-1:0", "1", 0); Assertion(collection, "Array:0:Key-1:1", "2", 1); Assertion(collection, "Array:0:Key-1:2", "3", 2); Assertion(collection, "Array:0:Key-1:3", "4", 3); Assertion(collection, "Array:1:Nested:NestedKey", "NestedValue", 4); }
public void NestedObjectAndArray() { string json = @" { ""Object"" : { ""Nested"" : { ""Array"" : [ 1,2,3,4 ], ""Key"" : ""Value"" }, ""Nested2"" : { ""Nested3"" : { ""N-Key"" : ""N-Value"" } } } } "; var transform = new JsonTransform(); var result = transform.Parse(json); var collection = (result.Result as ConfigCollection).WrappedConfigEntities; Assertion(collection, "Object:Nested:Array:0", "1", 0); Assertion(collection, "Object:Nested:Array:1", "2", 1); Assertion(collection, "Object:Nested:Array:2", "3", 2); Assertion(collection, "Object:Nested:Array:3", "4", 3); Assertion(collection, "Object:Nested:Key", "Value", 4); Assertion(collection, "Object:Nested2:Nested3:N-Key", "N-Value", 5); }
///<summary> /// load simple json file /// save to in Memory store /// and load all and print to console ///</summary> public static async Task Run(Action <object> printCallback) { var store = new InMemoryStore(); // upload file from the current directory string json = JsonFromConfigFile(); ITransform transform = new JsonTransform(); OperationResult result = transform.Parse(json); if (result.Result is ConfigCollection collection) { foreach (var item in collection.WrappedConfigEntities) { var request = new ConfigChangeRequest { Name = item.Name, Value = item.Value }; var context = new CommandContext(CommandTypes.Create, request, store); await Factory.RunOperationAsync(context); } } else { throw new InvalidCastException("should have been ConfigCollection yet is " + result.Result.GetType().Name); } foreach (var item in await store.AllEntitesAsync()) { printCallback($"next one is [{item.Name}] - [{item.Value}]"); } printCallback("also find RabbitMQ:Port and change it to 5674"); ConfigEntity port = await QueryRabbitPortAsync(store); printCallback(port.Name + " - " + port.Value); var updateRq = new ConfigChangeRequest { Name = port.Name, Value = "5674" }; var update = new CommandContext(CommandTypes.UpdateValue, updateRq, store); OperationResult rs = await Factory.RunOperationAsync(update); printCallback("after the update:"); port = await QueryRabbitPortAsync(store); printCallback(port.Name + " - " + port.Value); }
public void LoadJsonAsyncSimpleOnes() { string json = @" { ""Simple"" : ""Value"", ""RabbitMQ"" : ""simple-2"" } "; var transform = new JsonTransform(); var result = transform.Parse(json); var collection = (result.Result as ConfigCollection).WrappedConfigEntities; Assertion(collection, "Simple", "Value", 0); Assertion(collection, "RabbitMQ", "simple-2", 1); System.Console.WriteLine(); }
public void LoadJsonAsyncWithObject() { string json = @" { ""Simple"" : ""Value"", ""RabbitMQ"" : { ""Host"" : ""localhost"", ""Port"" : ""5672"" } } "; var transform = new JsonTransform(); var result = transform.Parse(json); var collection = (result.Result as ConfigCollection).WrappedConfigEntities; Assertion(collection, "Simple", "Value", 0); Assertion(collection, "RabbitMQ:Host", "localhost", 1); Assertion(collection, "RabbitMQ:Port", "5672", 2); System.Console.WriteLine(); }
///<summary> ///setup communcation with the CLI or any other client via ZeroMQ ///</summary> public static Communication GetCommunication(string tcpConnection) { var store = new InMemoryStore(); // upload file from the current directory string json = JsonFromConfigFile(); ITransform transform = new JsonTransform(); OperationResult result = transform.Parse(json); var socket = new RequestBus(tcpConnection); socket.Connect(); return(new Communication { Storage = store, Socket = socket, JsonString = json, Transform = transform, ConfigEntities = result.Result as ConfigCollection }); }
public void ArrayWithObjects() { string json = @" { ""Array"" : [ { ""Key-1"" : ""Value-1"", }, { ""Key-2"" : ""Value-2"", }, 42 ] } "; var transform = new JsonTransform(); var result = transform.Parse(json); var collection = (result.Result as ConfigCollection).WrappedConfigEntities; Assertion(collection, "Array:0:Key-1", "Value-1", 0); Assertion(collection, "Array:1:Key-2", "Value-2", 1); }