public string GetRealDataToString() { IfType x = FactoryType.CreateType(GetDataType());//(m_packet.getDataType()); string res = x.ToStringRealData(m_packet.getData()); return(res); }
public async Task <bool> SaveRealDataToDbAsync(string adress) { Packet.DataType type = GetDataType(); IfType x = FactoryType.CreateType(type); return(await x.SaveToDbAsync(m_packet.getData(), "127.0.0.1")); }
public object GetRealData() { IfType x = FactoryType.CreateType(GetDataType());//(m_packet.getDataType()); object res = x.getRealData(m_packet.getData()); return(res); }
// <summary> // check length of date with length // </summary> public bool checkLengthOfData() { byte[] data = GetData(); IfType x = FactoryType.CreateType((Packet.DataType)GetDataType()); int type_len = x.getFieldLength(); return(type_len == data.Length); }
public override Packet.PacketType createWrite(byte[] hexAddress, Packet.DataType type, string strData) { //byte[] addr = Packet.HexNiblleToAsciiByte(hexAddress); int lenRaw = strData.Length / 2; IfType x = FactoryType.CreateType(type); byte[] type_ascii = x.setFieldType(); byte[] data_ascii = x.setFieldData(strData); //m_packet = new Packet(Packet.PacketType.Read, Packet.DataType.Merenja, data_ascii, 0x01); return(Packet.PacketType.Write); }
public override Packet.PacketType createRead(byte idDest, Packet.DataType command) { IfType x = FactoryType.CreateType(command); byte[] command_data = x.setFieldType(); byte[] data = x.setFieldData("0"); // m_packet = new Packet(Packet.PacketType.Read, command_data, data, idDest); return(Packet.PacketType.Read); }
public override Packet.PacketType createWrite(byte[] hexAddress, Packet.DataType type, byte[] hexData) { // byte[] addr = Packet.HexNiblleToAsciiByte(hexAddress); //byte[] data = Packet.HexNiblleToAsciiByte(hexData); IfType x = FactoryType.CreateType(type); byte[] type_ascii = x.setFieldType(); // m_packet = new Packet(Packet.PacketType.Read, Packet.DataType.Merenja, data, 0x01); return(Packet.PacketType.Write); }
internal void PromiseTruthyCheck(Context contextToCheck, IfType ifType = IfType.If) { contextToCheck.Truthy = ifType == IfType.If; TruthyStack.Push(contextToCheck); }
public IfStatement(IfType iftype) { trueStmts = new StatementCollection(this); falseStmts = new StatementCollection(this); this.iftype = iftype; }
protected bool IfCommon(out string output, IfType iftype, bool test) { if (iftype == IfType.Empty || iftype == IfType.True || iftype == IfType.Zero) // these, insert a dummy entry to normalise - we don't have a comparitor { paras.Insert(1, new Parameter() { value = "", isstring = true }); } // p0 = value, p1 = comparitor, p2 = true expansion, p3 = false expansion, p4 = empty expansion string value = (paras[0].isstring) ? paras[0].value : vars[paras[0].value]; string comparitor = (paras[1].isstring) ? paras[1].value : vars[paras[1].value]; int pexp = 0; // 0 = blank, else parameter to expand if (paras.Count >= 5 && value.Length == 0) // if we have an empty, and string is empty. { pexp = 4; } else { bool tres; if (iftype == IfType.True) { int nres; bool ok = value.InvariantParse(out nres); if (!ok) { output = "Condition value is not an integer"; return(false); } tres = (nres != 0) == test; } else if (iftype == IfType.Contains) { tres = (value.IndexOf(comparitor, StringComparison.InvariantCultureIgnoreCase) != -1) == test; } else if (iftype == IfType.StrEquals) { tres = value.Equals(comparitor, StringComparison.InvariantCultureIgnoreCase) == test; } else if (iftype == IfType.Empty) // 2 parameters { tres = (value.Length == 0) == test; } else if (iftype == IfType.Zero) { double nres; bool ok = value.InvariantParse(out nres); if (!ok) { output = "Condition value is not an fractional or integer"; return(false); } tres = (Math.Abs(nres) < 0.000001) == test; } else { double nleft, nright = 0; bool ok = value.InvariantParse(out nleft) && comparitor.InvariantParse(out nright); if (!ok) { output = "Condition value is not an fractional or integer on one or both sides"; return(false); } if (iftype == IfType.Greater) { tres = nleft > nright; } else if (iftype == IfType.GreaterEqual) { tres = nleft >= nright; } else if (iftype == IfType.Less) { tres = nleft < nright; } else if (iftype == IfType.LessEqual) { tres = nleft < nright; } else { tres = (Math.Abs(nleft - nright) < 0.000001) == test; } } if (tres) { pexp = 2; } else if (paras.Count >= 4) // if we don't have p4, then use 0, which is empty { pexp = 3; } } if (pexp == 0) { output = ""; } else if (paras[pexp].isstring) // string.. already been expanded, don't do it again { output = paras[pexp].value; } else { return(caller.ExpandStringFull(vars[paras[pexp].value], out output, recdepth + 1) != ConditionFunctions.ExpandResult.Failed); } return(true); }
public IfTag(string mtext, IfType type, int Deep, TagConfig config, int no_) : base(mtext, mtext, Deep, config, no_) { this.Type = type; }
/// <summary> /// /// </summary> /// <param name="tokens"></param> /// <exception cref="ArgumentException"></exception> public If(IEnumerable <string> tokens) : base(tokens) { InverseEval = false; Type = IfType.Unknown; Consume(); switch (Peek()) { case Tokens.TokenType.BooleanFalse: case Tokens.TokenType.BooleanTrue: { var(_, s) = Consume(); Type = s == Tokens.TokenType.BooleanFalse ? IfType.EvaluatedToFalse : IfType.EvaluatedToTrue; Ensure(0); return; } } if (Peek() == Tokens.TokenType.NotOperator) { InverseEval = true; Consume(); } (Lhs, LhsType) = Consume(); var _ = LhsType switch { Tokens.TokenType.Variable => true, Tokens.TokenType.Numeric => true, Tokens.TokenType.StringLiteral => true, _ => throw new ArgumentException("parse: invalid LHS for if") }; if (Empty()) { Type = IfType.VariableLookup; return; } // ==, !=, <, <=, >, >= // is, is not // consume the first part of the operator var(c, compType) = Consume(); var comp = (string)c; if (compType == Tokens.TokenType.Is) { // is -> == comp = "=="; // is not -> != if (Peek() == Tokens.TokenType.Not) { comp = "!="; Consume(); // not } } else { // <=, >= if (Peek() == Tokens.TokenType.EqualTo) { var(t, _) = Consume(); comp += (string)t; } } ComparisonOperator = Tokens.GetTokenType(comp); var isValid = ComparisonOperator switch { Tokens.TokenType.LessThan => true, Tokens.TokenType.LessThanEq => true, Tokens.TokenType.GreaterThan => true, Tokens.TokenType.GreaterThanEq => true, Tokens.TokenType.CompEq => true, Tokens.TokenType.NotEqual => true, _ => false }; if (!isValid) { throw new ArgumentException($"fatal: invalid comparison operator {comp}"); } (Rhs, RhsType) = Consume(); _ = RhsType switch { Tokens.TokenType.Variable => true, Tokens.TokenType.Numeric => true, Tokens.TokenType.StringLiteral => true, _ => throw new ArgumentException("parse: invalid RHS for if") }; Ensure(0); if (Type == IfType.Unknown) { Type = IfType.SimpleComparison; } } } }
internal IfBlock(Expression member, IfType type, IList <ASTElementBase> children, int line, int column) : base(children, line, column) { QueryType = type; Expr = member; }
public bool checkPattern(Packet.DataType type, string text) { IfType x = FactoryType.CreateType(type); return(x.checkStringPattern(text)); }
public bool checkMinMax(Packet.DataType type, string input, string min, string max) { IfType x = FactoryType.CreateType(type); return(x.checkMinMax(input, min, max)); }
internal IfBlock(Expression expr, IfType type, IList <ASTElementBase> elseBlock, IList <ASTElementBase> children, int line, int column) : base(children, elseBlock, line, column) { QueryType = type; Expr = expr; }
public bool ExecuteTest(ChatContext context) { //convert variables var value1 = context.ConvertVariables(Value1); var value2 = context.ConvertVariables(Value2); //determine case sensitivity if (!(CaseSensitiveTest)) { value1 = value1.ToLower(); value2 = value2.ToLower(); } //perform comparison switch (IfType) { case IfTestType.ContextVariableExists: return(context.ContextVariables.ContainsKey(value2)); case IfTestType.EqualTo: return(value1 == value2); case IfTestType.NotEqual: return(value1 != value2); case IfTestType.Contains: return(value1.Contains(value2)); case IfTestType.DoesNotContain: return(!(value1.Contains(value2))); case IfTestType.LessThan: { var cValue1 = int.Parse(value1); var cValue2 = int.Parse(value2); return(cValue1 < cValue2); } case IfTestType.GreaterThan: { var cValue1 = int.Parse(value1); var cValue2 = int.Parse(value2); return(cValue1 > cValue2); } case IfTestType.GreaterThanOrEqualTo: { var cValue1 = int.Parse(value1); var cValue2 = int.Parse(value2); return(cValue1 >= cValue2); } case IfTestType.LessThanOrEqualTo: { var cValue1 = int.Parse(value1); var cValue2 = int.Parse(value2); return(cValue1 <= cValue2); } default: throw new NotImplementedException("If Type '" + IfType.ToString() + "' not implememented."); } }