private static async Task <OperationResult> ReadAllAsync(InMemoryStore store) { var context = new QueryContext(QueryContext.QUERY_ALL, QueryTypes.AllValues, store); OperationResult result = await Factory.RunOperationAsync(context); printCallback("in memory count: " + store._store.Count); var coll = result.Result as ConfigCollection; printCallback("ConfigEntityResult items from all: " + coll.WrappedConfigEntities.Count()); return(result); }
private static async Task <OperationResult> CreateInMemory(InMemoryStore store, string other = null) { var changeRequest = new ConfigChangeRequest { Name = other == null ? "ConnectionString" : other, Value = "/Users/timoheiten/my-db.db" }; var context = new CommandContext(CommandTypes.Create, changeRequest, store); OperationResult result = await Factory.RunOperationAsync(context); return(result); }
private static async Task <OperationResult> UpdateValueInMemory(InMemoryStore store) { var changeRequest = new ConfigChangeRequest { Name = "ConnectionString", Value = "/Users/timoheiten/my-db-2.db" }; var context = new CommandContext(CommandTypes.UpdateValue, changeRequest, store); var result = await Factory.RunOperationAsync(context); return(result); }
public static async Task Run(Action <object> _printCallback) { printCallback = _printCallback; var memory = new InMemoryStore(); OperationResult Aresult = await CreateInMemory(memory); printCallback(ToStringOpResult(Aresult)); var exists = await ReadConfigEntityInMemory("ConnectionString", memory); printCallback(ToStringOpResult(exists)); StepIn("now update --> press any key"); Aresult = await UpdateValueInMemory(memory); printCallback(ToStringOpResult(Aresult)); StepIn("Read works--> press any key"); var read1 = await ReadConfigEntityInMemory("ConnectionString", memory); printCallback(ToStringOpResult(read1)); StepIn("now query fail in try catch! --> press any key"); try { OperationResult read = await ReadConfigEntityInMemory("Not found", memory); printCallback(ToStringOpResult(read)); } catch (System.Exception ex) { printCallback("failed with:\n" + ex); } StepIn("Create another one and query all"); var r2 = CreateInMemory(memory).Result; printCallback(ToStringOpResult(r2)); var readAll = await ReadAllAsync(memory); printCallback(ToStringOpResult(readAll)); StepIn("now Delete ConnectionString Value and catch exception! --> press any key"); Aresult = await DeleteAndQueryAfter(memory); printCallback(ToStringOpResult(Aresult)); }
///<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); }
///<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 }); }
private static async Task <OperationResult> DeleteAndQueryAfter(InMemoryStore store) { var changeRequest = new ConfigChangeRequest { Name = "ConnectionString", Value = "null" }; var context = new CommandContext(CommandTypes.Delete, changeRequest, store); OperationResult result = await Factory.RunOperationAsync(context); var queryResult = await ReadConfigEntityInMemory("ConnectionString", store); if (queryResult.IsSuccess == false) { printCallback("now after delete it was not found!"); } else { printCallback("could still find --> error in test"); } return(result); }
private static async Task <OperationResult> ReadConfigEntityInMemory(string queryName, InMemoryStore store) { var context = new QueryContext(queryName, QueryTypes.ValueRequest, store); var result = await Factory.RunOperationAsync(context); printCallback("in memory count: " + store._store.Count); printCallback("ConfigEntityResult Name: " + result.Result?.Name); printCallback("ConfigEntityResult Value: " + result.Result?.Value); return(result); }