private Task <object> Execute(CommandModel cmd, InterpretationData data) { return(Task.Run(new Func <object>(() => { return data.Vars[cmd.Command]; }))); }
public Task <object> GetResult(object[] parameters, InterpretationData data) { return(Task.Run(() => { return meth.Invoke(ScriptTools.GetParametersFromArray(parameters)); })); }
private Task <object> Execute(CommandModel cmd, InterpretationData data, Operator generalOperator) { return(Task.Run(new Func <object>(() => { string expression = cmd.Command; object leftValue = Interpreter.ExecuteCommand(generalOperator.StringLeft, data); object rightValue = Interpreter.ExecuteCommand(generalOperator.StringRight, data); switch (generalOperator.StringOperator) { case "+": return Operators.UniversalSum(leftValue, rightValue); case "-": return Operators.UniversalMinus(leftValue, rightValue); case "*": return Operators.UniversalMult(leftValue, rightValue); case "^": return Operators.UniversalPow(leftValue, rightValue); case "/": return Operators.UniversalDiv(leftValue, rightValue); case "%": return Operators.UniversalRemainder(leftValue, rightValue); case "==": return Operators.UniversalEqual(leftValue, rightValue); case "!=": return Operators.UniversalUnEqual(leftValue, rightValue); case "<": return Operators.UniversalLess(leftValue, rightValue); case "<=": return Operators.UniversalLess(leftValue, rightValue) || Operators.UniversalEqual(leftValue, rightValue); case ">=": return Operators.UniversalMore(leftValue, rightValue) || Operators.UniversalEqual(leftValue, rightValue); case ">": return Operators.UniversalMore(leftValue, rightValue); case "||": return (bool)rightValue || (bool)leftValue; case "&&": return (bool)rightValue && (bool)leftValue; case "!": return !((bool)rightValue); default: throw new InvalidCastException(); } }))); }
private Task <object> Execute(CommandModel cmd, InterpretationData data) { return(Task.Run(new Func <object>(() => { List <ConditionAction> conditions = GetConditionsAndActions(cmd); foreach (ConditionAction ca in conditions) { if (ca.Condition.Length == 0)//если это "else" без условия { Interpreter.ExecuteScript(ca.Action, data); break; } object value = Interpreter.ExecuteCommand(ca.Condition, data); if (value is bool boolValue) { if (boolValue) { Interpreter.ExecuteScript(ca.Action, data); break; } } else { throw new ConversionFailedException("Can not convert " + value.GetType().Name + " to Bool."); } } return null; }))); }
public static void ExecuteScript(string script, IInterpreterFunction[] additionalFunctions) { var data = new InterpretationData(); data.InterpretationFuncs.AddRange(additionalFunctions); ExecuteScript(script, data); }
private Task <object> Execute(CommandModel cmd, InterpretationData data) { return(Task.Run(new Func <object>(() => { var parameters = cmd.GetParameters(); if (parameters.Length != 1) { throw new WrongNumberOfParametersException(parameters.Length, 1); } object num = Interpreter.ExecuteCommand(parameters[0], data); if (!(num is int)) { throw new ConversionFailedException("Не удаётся конвертировать " + parameters[0] + " в int."); } int numberRepetitions = (int)num; string script = cmd.Command; int bracerIndex = script.IndexOf('{'); script = script.Substring(bracerIndex + 1, (script.Length - 1) - bracerIndex - 1).Trim(); while (numberRepetitions-- > 0) { try { Interpreter.ExecuteScript(script, data); } catch (BreakException) { break; } catch (Exception e) { throw e; }//прокидываем выше } return null; }))); }
private Task <object> Execute(CommandModel cmd, InterpretationData data) { return(Task.Factory.StartNew <object>(() => { int milliseconds = (int)Interpreter.ExecuteCommand(cmd.GetParameters()[0], data); Stopwatch sw = new Stopwatch(); sw.Start(); while (sw.ElapsedMilliseconds < milliseconds) { if (data.Stopper.IsStopped) { throw new StopException(); } if (milliseconds - sw.ElapsedMilliseconds > 1100) { Thread.Sleep(1000); } if (milliseconds - sw.ElapsedMilliseconds > 50) { Task.Delay(1).Wait(); } } sw.Stop(); return milliseconds; }, TaskCreationOptions.LongRunning)); }
public Task <object> GetResult(object[] parameters, InterpretationData data) { return(Task.Run(new Func <object>(() => { string text = parameters[0].ToString(); int volume = (int)parameters[1]; volume = volume < 0 ? 0 : volume > 100 ? 100 : volume; int rate = (int)parameters[2]; rate = rate < -10 ? -10 : rate > 10 ? 10 : rate; SpeechSynthesizer ss = new SpeechSynthesizer() { Volume = volume, Rate = rate }; if (parameters.Length > 3) { ss.SetOutputToWaveFile(parameters[3].ToString()); } var t = ss.SpeakAsync(text); while (!t.IsCompleted && !data.Stopper.IsStopped) { Thread.Sleep(50); } ss.Dispose(); return parameters; }))); }
private Task <object> Execute(CommandModel cmd, InterpretationData data) { return(Task.Factory.StartNew(new Func <object>(() => { Interpreter.ExecuteScript(cmd.Command.Substring(1, cmd.Command.Length - 2), data); return null; }), TaskCreationOptions.AttachedToParent)); }
public Task <object> TryExecute(CommandModel cmd, InterpretationData data) { if (cmd.KeyWord == "CheckVar" && cmd.GetParameters().Length == 1) { return(Execute(cmd, data)); } return(null); }
public Task <object> TryExecute(CommandModel cmd, InterpretationData data) { if (IsValidConstruction(cmd, data)) { return(Execute(cmd, data)); } return(null); }
public void Invoke(MouseEventArgs e) { var data = new InterpretationData(); data.Vars["X"] = e.X; data.Vars["Y"] = e.Y; data.Vars["Button"] = e.Button; base.Invoke(new TriggeredEventArgs(Name, Script, data)); }
public static Task UdpateLibraryFromGlobalScript() { return(Task.Run(() => { InterpretationData data = new InterpretationData(); ExecuteScript(ProgramSettings.RuntimeSettings.InterpreterSettings.DefaultGlobalScript, data); data.InterpretationFuncs.ForEach(f => AddToLibrary(f)); })); }
public TriggeredEventArgs(string name, string script, InterpretationData _data = null) { TriggerName = name; TriggerScript = script; triggerData = _data != null ? _data : new InterpretationData(); triggerData.Vars["TriggerName"] = name; triggerData.Vars["TriggerScript"] = script; }
public Task <object> TryExecute(CommandModel cmd, InterpretationData data) { var generalOperator = GetGeneralOperator(cmd.Command); if (generalOperator.PriorityLevel < 7) { return(Execute(cmd, data, generalOperator)); } return(null); }
public void Invoke(PressedKeysEventArgs key) { var data = new InterpretationData(); data.Vars["Key"] = key.Key.ToString(); base.Invoke(new TriggeredEventArgs(Name, Script, data)); if (Exclusive && EnableTrigger && EnableAllTriggers)//блочим только в том случае, если сработали { key.Handled = true; } }
private Task <object> Execute(CommandModel cmd, InterpretationData data) { return(Task.Run(new Func <object>(() => { var pars = cmd.GetParameters(); if (pars.Length == 1) { return data.Vars.HasVar(Interpreter.ExecuteCommand(pars[0].Trim(), data).ToString()); } return false; }))); }
public Task <object> GetResult(object[] parameters, InterpretationData data) { return(Task.Run(new Func <object>(() => { bool deleted = false; foreach (var param in parameters) { deleted = deleted || data.Vars.RemoveVar(param.ToString()); } return deleted; }))); }
public static bool TryExecute(CommandModel command, InterpretationData data, out Task <object> result) { foreach (var sc in syntacticConstructs) { result = sc.TryExecute(command, data); if (result != null) { return(true); } } result = null; return(false); }
private Task <object> Execute(CommandModel cmd, InterpretationData data) { return(Task.Run(new Func <object>(() => { string script = cmd.Command; int assignmentIndex = ScriptTools.GetCharIndexOutsideBrackets(script, '='); string varName = script.Substring(0, assignmentIndex).Trim(); string valueString = script.Substring(assignmentIndex + 1, (script.Length - 1) - assignmentIndex).Trim(); object value = Interpreter.ExecuteCommand(valueString, data); data.Vars[varName] = value; return value; }))); }
public Task <object> GetResult(object[] parameters, InterpretationData data) { return(Task.Run(new Func <object>(() => { for (int i = 0; i < funcsParamsNames.Length; i++) { data.Vars[funcsParamsNames[i]] = parameters[i]; } try { Interpreter.ExecuteScript(Script, data); } catch (ReturnException e) { return e.ReturnValue; } catch (Exception) { return null; } return null; }))); }
public Task <object> GetResult(object[] parameters, InterpretationData data) { return(Task.Run(new Func <object>(() => { if (parameters.Length > 0) { if (parameters[0] is InterpretationData newData) { return newData.ToString(); } } return data.ToString(); }))); }
private bool IsValidConstruction(CommandModel cmd, InterpretationData data) { int index = ScriptTools.GetCharIndexOutsideBrackets(cmd.Command, '='); if (index == 0 || index == cmd.Command.Length - 1 || index == -1) { return(false); } if (cmd.Command[index - 1] == '=' || cmd.Command[index + 1] == '=' || cmd.Command[index - 1] == '!') { return(false); } return(ScriptTools.GetCharIndexOutsideBrackets(cmd.Command, '.') == -1); }
public Task <object> TryExecute(CommandModel cmd, InterpretationData data) { var colonIndex = Script.ScriptTools.GetCharIndexOutsideBrackets(cmd.Command, ':');//глобально if (colonIndex != -1) { string newDataName = cmd.Command.Substring(0, colonIndex); if (!IsValidName(newDataName)) { return(null); } if (!Vault.InterpretationDatas.ContainsKey(newDataName)) { Vault.InterpretationDatas.Add(newDataName, new InterpretationData()); } return(Task.Run(() => Interpreter.ExecuteCommand(cmd.Command.Substring(colonIndex + 1), Vault.InterpretationDatas[newDataName]))); } colonIndex = Script.ScriptTools.GetCharIndexOutsideBrackets(cmd.Command, '.');//локально if (colonIndex != -1) { string newDataName = cmd.Command.Substring(0, colonIndex); if (!IsValidName(newDataName)) { return(null); } InterpretationData dataToExecute = null; if (!data.Vars.HasVar(newDataName) || !(data.Vars[newDataName] is InterpretationData)) { var newData = Interpreter.ExecuteCommand(newDataName, data); if (newData is InterpretationData newDataCasted) { dataToExecute = newDataCasted; } else { data.Vars[newDataName] = new InterpretationData(); dataToExecute = (InterpretationData)data.Vars[newDataName]; } } else { dataToExecute = (InterpretationData)data.Vars[newDataName]; } return(Task.Run(() => Interpreter.ExecuteCommand(cmd.Command.Substring(colonIndex + 1), dataToExecute))); } return(null); }
public Task <object> GetResult(object[] parameters, InterpretationData data) { return(Task.Run(new Func <object>(() => { InterpretationData nowDateTime = new InterpretationData() { Stopper = data.Stopper }; DateTime d = DateTime.Now; nowDateTime.Vars["Year"] = d.Year; nowDateTime.Vars["Month"] = d.Month; nowDateTime.Vars["Day"] = d.Day; nowDateTime.Vars["Hour"] = d.Hour; nowDateTime.Vars["Minute"] = d.Minute; nowDateTime.Vars["Second"] = d.Second; nowDateTime.Vars["Millisecond"] = d.Millisecond; return nowDateTime; }))); }
private Task <object> Execute(CommandModel cmd, InterpretationData data) { return(Task.Factory.StartNew(new Func <object>(() => { string description = ""; if (cmd.Command.StartsWith("[")) { description = cmd.Command.Substring(0, cmd.Command.IndexOf("func") - 1).Trim(); description = description.Remove(description.Length - 1, 1).Remove(0, 1); } CommandModel newModel = new CommandModel(cmd.Command.Substring(cmd.Command.IndexOf("func") + 4).Trim()); string name = newModel.KeyWord; string script = cmd.Command; int bracerIndex = script.IndexOf('{'); script = script.Substring(bracerIndex + 1, (script.Length - 1) - bracerIndex - 1).Trim(); var buf = new UserFunc(name, newModel.GetParameters(), script, description); data.InterpretationFuncs.RemoveAll(func => func.Name == buf.Name); data.InterpretationFuncs.Add(buf); return null; }), TaskCreationOptions.AttachedToParent)); }
public static void ExecuteScript(string script, InterpretationData data) { try { data.Stopper.RegisterStopper(stopSender); string[] commands = ScriptTools.GetCommands(script); foreach (var cmd in commands) { ExecuteCommand(cmd, data); } } catch (Exception e) when(!(e is ReturnException) && !(e is BreakException)) { if (!data.Stopper.IsStopped) { MessageBox.Show(e.ToString(), "Ошибка"); } } finally { data.Stopper.UnRegisterStopper(stopSender); } }
private bool IsValidConstruction(CommandModel cmd, InterpretationData data) { return(cmd.KeyWord.StartsWith("Delay") && cmd.GetParameters().Length == 1); }
private bool IsValidConstruction(CommandModel cmd, InterpretationData data) { return(cmd.Command.StartsWith("repeat")); }
private bool IsValidConstruction(CommandModel cmd, InterpretationData data) { return(data.Vars.HasVar(cmd.Command.Trim())); }