private FunctionHelper SetupHelper(IInterpreterFunction parent) { FunctionHelper setHelper = new FunctionHelper(); setHelper.FunctionInterpreter(parent); return(setHelper); }
public static void AddToLibrary(IInterpreterFunction f) { //если функция с таким именем есть - заменяем var oldFunc = AdditionalLibrary.Find(curF => curF.Name == f.Name); if (oldFunc != null) { AdditionalLibrary.Remove(oldFunc); } AdditionalLibrary.Add(f); }
public void SrcField_SrcGraphFieldAndListOfObjects_ReturnsCorrectReference() { IdentifierExpression identifier = new IdentifierExpression("test", 0, 0); SrcGraphField input1 = new SrcGraphField(identifier, 0, 0); List <Object> list = new List <Object>(); Function expected = new Function(1); Graph graph = new Graph(null, null, expected, null); IInterpreterFunction parent = Substitute.For <IInterpreterFunction>(); parent.DispatchGraph(identifier, Arg.Any <List <object> >()).Returns(graph); FunctionHelper functionHelper = SetupHelper(parent); Function res = functionHelper.SrcField(input1, list); Assert.AreEqual(expected.Reference, res.Reference); }
public void DstField_DstGraphFieldAndListOfObjects_ReturnsCorrectResult() { IdentifierExpression identifier = new IdentifierExpression("test", 0, 0); DstGraphField input1 = new DstGraphField(identifier, 0, 0); List <Object> list = new List <Object>(); Function expected = new Function(1); Graph graph = new Graph(null, null, null, expected); IInterpreterFunction parent = Substitute.For <IInterpreterFunction>(); parent.DispatchGraph(identifier, Arg.Any <List <object> >()).Returns(graph); FunctionHelper functionHelper = SetupHelper(parent); Function res = functionHelper.DstField(input1, list); res.Should().BeEquivalentTo(expected); }
public void FunctionInterpreter(IInterpreterFunction interpreter) { _interpreter = interpreter; }
private void AddToGroups(IInterpreterFunction f) { AddToGroups(f.GroupName, f.Description); }
public static object ExecuteCommand(string cmdString, InterpretationData data) { if (data.Stopper.IsStopped) { throw new StopException(); } CommandModel cmd = new CommandModel(cmdString.Trim()); Task <object> commandTask = null; if (Converter.CanConvertToSimpleType(cmd.Command))//берём простой тип { commandTask = Converter.ToSimpleType(cmd.Command); } if (commandTask == null) { SyntacticConstructionsManager.TryExecute(cmd, data, out commandTask); } if (commandTask == null) { //ищем функцию по имени во всей библиотеке, начинаем с функций этой интерпретации IInterpreterFunction func = data.InterpretationFuncs.FirstOrDefault(Func => Func.Name == cmd.KeyWord); if (func == null) { func = AdditionalLibrary.FirstOrDefault(Func => Func.Name == cmd.KeyWord); } if (func == null) { func = MainLibrary.FirstOrDefault(Func => Func.Name == cmd.KeyWord); } if (func != null) { var stringParameters = cmd.GetParameters(); object[] parameters = new object[stringParameters.Length]; for (int i = 0; i < parameters.Length; i++) { parameters[i] = ExecuteCommand(stringParameters[i], data); } commandTask = func.GetResult(parameters, data); } } if (commandTask == null)//если ничего не удалось, возвращаем входную команду, как строку { commandTask = Task.FromResult <object>(cmdString); } if (commandTask.Status == TaskStatus.Created)//если задача создана, но не запущена { commandTask.Start(); } if (cmd.IsAsync)//если асинхронно, на всё пофиг { return(null); } else { try { return(commandTask.Result); }//если что то не так, прокидываем исключение выше catch { throw commandTask.Exception.InnerException; }; } }
public static bool RemoveFromLibrary(IInterpreterFunction f) { bool result = AdditionalLibrary.Remove(f); return(result); }