public static Tuple <bool, string> EvaluateTests(Guid testingMetaOpID, string filterPattern) { try { var result = new Tuple <bool, string>(false, ""); var testingMetaOp = MetaManager.Instance.GetMetaOperator(testingMetaOpID); using (var mainOp = Utilities.CreateEmptyOperator()) { mainOp.Definition.Name = "Main"; MetaManager.Instance.AddMetaOperator(mainOp.Definition.ID, mainOp.Definition); var addOpCmd = new AddOperatorCommand(mainOp, testingMetaOpID); addOpCmd.Do(); var testingOp = testingMetaOp.GetOperatorInstance(addOpCmd.AddedInstanceID); result = EvaluateTests(testingOp, filterPattern); var deleteOperatorCmd = new DeleteOperatorsCommand(mainOp, new List <Operator>() { testingOp }); deleteOperatorCmd.Do(); MetaManager.Instance.RemoveMetaOperator(mainOp.Definition.ID); } return(result); } catch (Exception ex) { Logger.Error("Failed to evaluate operator definition {0}: {1}", testingMetaOpID, ex.ToString()); return(new Tuple <bool, string>(false, "")); } }
public void testCmdSerialization() { var parentMetaID = Guid.NewGuid(); var parentMetaOp = CreateCombinedMetaOperator(parentMetaID); MetaManager.Instance.AddMetaOperator(parentMetaID, parentMetaOp); var opToDelete = parentMetaOp.Operators.First().Value.Item1; MetaManager.Instance.AddMetaOperator(opToDelete.ID, opToDelete); var parentOp = parentMetaOp.CreateOperator(Guid.NewGuid()); var cmd = new DeleteOperatorsCommand(parentOp, new List <Operator>() { parentOp.InternalOps[0] }); cmd.Do(); var serializedCmd = JsonConvert.SerializeObject(cmd, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple }); var cmdType = cmd.GetType().AssemblyQualifiedName; var cmdID = Guid.NewGuid().ToString(); var jsonCommand = new JObject( new JProperty("Type", "Command"), new JProperty("CommandType", cmdType), new JProperty("Command", serializedCmd)); // store in db _couchDB.StoreDocument(_dbName, cmdID, jsonCommand.ToString()); // read from db var response = _couchDB.GetDocument(_dbName, cmdID, string.Empty); var obj = JObject.Parse(response); var typeName = obj["CommandType"].Value <string>(); var commandType = Type.GetType(typeName); var commandJson = obj["Command"].Value <string>(); var command = (ICommand)JsonConvert.DeserializeObject(commandJson, commandType, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects }); Assert.AreEqual("Delete Operators", command.Name); Assert.AreEqual(0, parentMetaOp.Operators.Count); command.Undo(); Assert.AreEqual(1, parentMetaOp.Operators.Count); }
public static Tuple <bool, string> EvaluateTests(Operator testingOp, string filterPattern) { try { //connect it to a testsevaluator var compositionOp = testingOp.Parent; var evaluatorMetaOpID = Guid.Parse("0316356c-b1fe-490a-89ce-73c8f67ebccc"); var evaluatorMetaOp = MetaManager.Instance.GetMetaOperator(evaluatorMetaOpID); var addOpCmd = new AddOperatorCommand(compositionOp, evaluatorMetaOpID); addOpCmd.Do(); var evaluatorOp = evaluatorMetaOp.GetOperatorInstance(addOpCmd.AddedInstanceID); var connection = new MetaConnection(testingOp.ID, testingOp.Outputs[0].ID, evaluatorOp.ID, evaluatorOp.Inputs[0].ID); var addConnectionCmd = new InsertConnectionCommand(compositionOp.Definition, connection, 0); addConnectionCmd.Do(); //configure the testsevaluator op and start testing var startTestsTriggerOpPart = evaluatorOp.Inputs[1]; var filterOpPart = evaluatorOp.Inputs[3]; //we must create a down flank for the startTestsTrigger value to start the tests properly var updateStartTestsCmd = new UpdateOperatorPartValueFunctionCommand(startTestsTriggerOpPart, new Float(1.0f)); updateStartTestsCmd.Do(); var updateFilterCmd = new UpdateOperatorPartValueFunctionCommand(filterOpPart, new Text(filterPattern)); updateFilterCmd.Do(); evaluatorOp.Outputs[0].Eval(new OperatorPartContext()); updateStartTestsCmd.Value = new Float(0.0f); updateStartTestsCmd.Do(); var resultLog = evaluatorOp.Outputs[0].Eval(new OperatorPartContext()).Text; var result = new Tuple <bool, string>(resultLog.StartsWith(compositionOp.Definition.Name + " : passed"), resultLog); var deleteOperatorCmd = new DeleteOperatorsCommand(compositionOp, new List <Operator>() { evaluatorOp }); deleteOperatorCmd.Do(); return(result); } catch (Exception ex) { Logger.Error("Failed to evaluate operator definition {0}: {1}", testingOp.Name, ex.ToString()); return(new Tuple <bool, string>(false, "")); } }