protected SocketMessage SortSocketMessage(SocketMessage request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.Headers.BodyType == typeof(ServiceGroupModel)) { using (var op = new ServiceOperator(request)) { return(op.Operate()); } } if (request.Headers.BodyType == typeof(ScriptModel)) { using (var op = new ScriptOperator(request)) { return(op.Operate()); } } throw new ArgumentException("Unknown Message Type!", nameof(request.Headers.BodyType)); }
public static ScriptStatement Parse( string statement, object left = null, object right = null, ScriptOperator operat = ScriptOperator.None, string func = null, bool isChild = false) { ScriptStatement scriptStatement1 = new ScriptStatement(); scriptStatement1.leftObject = left; scriptStatement1.rightObject = right; scriptStatement1.op = operat; scriptStatement1.functionName = func; int num = 1; if (!isChild) { ++num; } string str = ""; ScriptOperator operat1 = ScriptOperator.None; bool flag1 = false; bool flag2 = false; bool flag3 = false; bool flag4 = false; bool flag5 = false; while (statement.Length > 0) { char c = statement[0]; statement = statement.Remove(0, 1); if (!flag3 && char.IsNumber(c)) { if (str.Length > 0 && !flag1) { if (flag4 && str == "-") { flag4 = false; } else { scriptStatement1.error = "Found unexpected number."; break; } } flag1 = true; } else if (c == '.' && !flag3) { if (str.Length > 0 && !flag1) { scriptStatement1.error = "Found unexpected Period."; break; } flag2 = true; } else if (c == ' ' || c == '(' || c == ')') { flag5 = true; if (flag3 && (str == "and" || str == "or")) { flag3 = false; flag4 = true; } if (scriptStatement1.data == null) { if (flag3) { scriptStatement1.data = (object)str; } else if (flag2) { scriptStatement1.data = (object)Change.ToSingle((object)str); } else if (flag1) { scriptStatement1.data = (object)Convert.ToInt32(str); } } if (flag4) { if (str == "+") { operat1 = ScriptOperator.Plus; } else if (str == "-") { operat1 = ScriptOperator.Minus; } else if (str == "*") { operat1 = ScriptOperator.Multiply; } else if (str == "/") { operat1 = ScriptOperator.Divide; } else if (str == "==") { operat1 = ScriptOperator.IsEqual; } else if (str == "!=") { operat1 = ScriptOperator.IsNotEqual; } else if (str == ">") { operat1 = ScriptOperator.GreaterThan; } else if (str == "<") { operat1 = ScriptOperator.LessThan; } else if (str == "&&") { operat1 = ScriptOperator.And; } else if (str == "and") { operat1 = ScriptOperator.And; } else if (str == "or") { operat1 = ScriptOperator.Or; } if (scriptStatement1.op == ScriptOperator.None) { scriptStatement1.op = operat1; } } switch (c) { case '(': ScriptStatement scriptStatement2 = ScriptStatement.Parse(statement, func: (flag3 ? str : (string)null), isChild: true); statement = scriptStatement2.remainingStatementString; if (scriptStatement2.error != null) { scriptStatement1.error = scriptStatement2.error; goto label_76; } else { scriptStatement1.data = (object)scriptStatement2; break; } case ')': --num; break; } if (scriptStatement1.data != null) { object obj = scriptStatement1.data; scriptStatement1.data = (object)null; if (operat1 > ScriptOperator.COMPARATORS) { ScriptStatement scriptStatement3 = ScriptStatement.Parse(statement, obj, isChild: true); obj = (object)scriptStatement3; statement = scriptStatement3.remainingStatementString; } if (scriptStatement1.leftObject == null) { scriptStatement1.leftObject = obj; } else { if (scriptStatement1.rightObject != null) { return(ScriptStatement.Parse(statement, (object)scriptStatement1, obj, operat1, isChild: true)); } scriptStatement1.rightObject = obj; } } str = ""; flag3 = false; flag2 = false; flag1 = false; flag4 = false; if (num <= 0) { break; } } else if (!flag3 && c == '+' || (c == '-' || c == '*') || (c == '/' || c == '=' || (c == '<' || c == '!')) || (c == '>' || c == '&')) { if (str.Length > 0 && !flag4) { scriptStatement1.error = "Found unexpected operator."; break; } flag4 = true; } else if (c == '"') { flag5 = true; flag3 = true; } else { if (str.Length > 0 && !flag3) { scriptStatement1.error = "Found unexpected letter."; break; } flag3 = true; } if (!flag5) { str += (string)(object)c; } flag5 = false; } label_76: scriptStatement1.remainingStatementString = statement; return(scriptStatement1); }