/// <summary> /// Checks relations. /// </summary> /// <param name="lObjectInterface">ObjectInterface.</param> /// <param name="NextElement">Next element we are going to parse.</param> /// <param name="CallCalback">Do we have to call callback?</param> /// <returns>FunctionIO with return parameters like ret value and parse count.</returns> public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { ObjectAttributeEvaluation Evaluation = GetEvaluation(); bool result = false; List<ParserPrimitives> SubPrimitives = cParserObjectRelation.GetSubParserPrimitives(); for (int x = 0; x < SubPrimitives.Count; x++) { FunctionIO ret = SubPrimitives[x].CheckRelations(ref lObjectInterface, x + 1 == SubPrimitives.Count ? null : SubPrimitives[x + 1], CallCalback); if (ret["RetVal"].Value) { result = true; Evaluation.Evaluate((ObjectAttributeEvaluation)ret["ParseCount"]); break;//Proper logic is to break if parser primitives relations are correct, //other logic is to select parser primitive where ParseCount is the biggest. //we use proper logic. } } if (result) return new FunctionIO(Evaluation, RetVal.True); return new FunctionIO(RetVal.False); }
public void moreps(ObjectInterfacePrototipe lObjectInterface) { called = true; }
/// <summary> /// Checks relations. /// </summary> /// <param name="lObjectInterface">ObjectInterface.</param> /// <param name="NextElement">Next element we are going to parse.</param> /// <param name="CallCalback">Do we have to call callback?</param> /// <returns>FunctionIO with return parameters like ret value and parse count.</returns> public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { ObjectAttributeEvaluation Evaluation = GetEvaluation(); bool More = true; int TotalMove = 0; int StartOffset = lObjectInterface.GetOffset(); bool eof = false; while (More) { int Positives = 0; int CurrentMove = 0; if (NextElement != null) { FunctionIO ret = NextElement.CheckRelations(ref lObjectInterface, NextElement.GetNextPrimitive(), false); if (ret["RetVal"].Value) break; } int RecallOffset = lObjectInterface.GetOffset(); List<ParserPrimitives> SubPrimitives = cParserObjectRelation.GetSubParserPrimitives(); for (int x = 0; x < SubPrimitives.Count; x++) { CurrentMove = 0; FunctionIO ret = SubPrimitives[x].CheckRelations(ref lObjectInterface, x + 1 == SubPrimitives.Count ? null : SubPrimitives[x + 1], false); if (ret["RetVal"].Value) { CurrentMove = ((ObjectAttributeEvaluation)ret["ParseCount"]).Value; Positives++; } else//End execution if we fail break; eof = lObjectInterface.MoveByOffset(CurrentMove); TotalMove += CurrentMove; if (eof) break; } if (CallCalback && Positives == SubPrimitives.Count) { lObjectInterface.SetOffset(RecallOffset); for (int x = 0; x < SubPrimitives.Count; x++) { CurrentMove = 0; FunctionIO ret = SubPrimitives[x].CheckRelations(ref lObjectInterface, x + 1 == SubPrimitives.Count ? null : SubPrimitives[x + 1], CallCalback); CurrentMove = ((ObjectAttributeEvaluation)ret["ParseCount"]).Value; eof = lObjectInterface.MoveByOffset(CurrentMove); } } if (eof || Positives != SubPrimitives.Count) { break; } } if (!Evaluation.Evaluate(TotalMove)) return new FunctionIO(RetVal.False); lObjectInterface.SetOffset(StartOffset); return new FunctionIO(Evaluation, RetVal.True); }
public bool Preheader2(ObjectInterfacePrototipe lObjectInterface) { return true; }
public bool Call(ObjectInterfacePrototipe lObjectInterface) { return true; }
public bool NewTable(ObjectInterfacePrototipe lObjectInterface) { ObjectAttributeString lObjectAttribute = (ObjectAttributeString)lObjectInterface.GetCurrentObject().GetAttributeByName("outerHTML"); ExtractedTables.Add(lObjectAttribute.Value); return true; }
public bool Postheader2Description(ObjectInterfacePrototipe lObjectInterface) { return true; }
public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { FunctionIO ret= cRelationFunction.CheckRelations(ref lObjectInterface, NextElement, CallCalback); if (((ObjectAttributeInt)ret.GetFunctionParameterByName("ret")).GetAttributeValue() == 1) if (cCallback != null && CallCalback) cCallback(lObjectInterface); return ret; }
public virtual FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { return null; }
public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { FunctionIO ReturnContainer= new FunctionIO(); ObjectAttributeInt ReturnValue1 = new ObjectAttributeInt("ret",1); ObjectAttributeInt ReturnValue0 = new ObjectAttributeInt("ret",0); ObjectAttributeEvaluation Evaluation = new ObjectAttributeEvaluation(); Evaluation.SetAttributeName("ParseCount"); if (!CheckCurrentObject(ref lObjectInterface)) { ReturnContainer.AddFunctionParameter((ObjectAttribute)ReturnValue0); return ReturnContainer; } if (cParserPrimitives.Count == 0) { if (cCallback != null && CallCalback) cCallback(lObjectInterface); ReturnContainer.AddFunctionParameter((ObjectAttribute)Evaluation); ReturnContainer.AddFunctionParameter((ObjectAttribute)ReturnValue1); return ReturnContainer; } //Here we preset next primitives for (int x = 0; x < cParserPrimitives.Count-1; x++) { cParserPrimitives[x].SetNextPrimitive(cParserPrimitives[x + 1]); } ObjectInterfacePrototipe SubObjects= lObjectInterface.GetSubObjects(); SubObjects.GetFirstObject(); ObjectAttributeEvaluation ParseCountEvaluation = new ObjectAttributeEvaluation( EvaluationMode.Max, 1, 100000000); for( int x=0; x< cParserPrimitives.Count; x++ ) { ParserPrimitives tPrimitives; if (cParserPrimitives.Count == x + 1) tPrimitives = null; else tPrimitives = cParserPrimitives[x + 1]; FunctionIO ret = cParserPrimitives[x].CheckRelations(ref SubObjects, tPrimitives, CallCalback); if (((ObjectAttributeInt)ret.GetFunctionParameterByName("ret")).GetAttributeValue() != 1) { ReturnContainer.AddFunctionParameter((ObjectAttribute)ReturnValue0); return ReturnContainer; } SubObjects.GetOffsetObject(((ObjectAttributeEvaluation)ret.GetFunctionParameterByName("ParseCount")).GetEvaluationValue()); } if (cCallback != null && CallCalback) cCallback(lObjectInterface); ReturnContainer.AddFunctionParameter((ObjectAttribute)Evaluation); ReturnContainer.AddFunctionParameter((ObjectAttribute)ReturnValue1); return ReturnContainer; }
//Singleton check bool CheckCurrentObject(ref ObjectInterfacePrototipe lObjectInterface) { ObjectPrototipe lObjectPrototipe= lObjectInterface.GetCurrentObject(); if (GetAttributeByName("name") != null) { ObjectAttributeString lObjectAttributeString = new ObjectAttributeString(); lObjectAttributeString.SetAttributeName("name"); lObjectAttributeString.SetAttributeValue(lObjectPrototipe.GetObjectName()); if (!GetAttributeByName("name").ComapreAttributes((ObjectAttribute)lObjectAttributeString)) return false; } foreach (ObjectAttribute lObjectAttribute in cObjectAttributes) { if (lObjectAttribute.GetAttributeName() == "name") continue; if(!lObjectAttribute.ComapreAttributes(lObjectPrototipe.GetAttributeByName(lObjectAttribute.GetAttributeName()))) return false; } return true; }
public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { FunctionIO ret= cRelationFunction.CheckRelations(ref lObjectInterface, NextElement, CallCalback); ObjectAttribute RetVal=ret["RetVal"]; if (RetVal.Value) { if (cCallback != null && CallCalback) { if (!cCallback(lObjectInterface)) { RetVal.Value = false; } } } return ret; }
//Singleton check bool CheckCurrentObject(ref ObjectInterfacePrototipe lObjectInterface) { ObjectPrototipe lObjectPrototipe= lObjectInterface.GetCurrentObject(); if (GetAttributeByName("name") != null) { ObjectAttributeString lObjectAttributeString = new ObjectAttributeString("name", lObjectPrototipe.GetObjectName()); if (GetAttributeByName("name")!=lObjectAttributeString) return false; } foreach (ObjectAttribute lObjectAttribute in (from n in cObjectAttributes where n.AttributeName!="name" && n.AttributeName!="negation" select n)) { if(lObjectAttribute!=lObjectPrototipe.GetAttributeByName(lObjectAttribute.AttributeName)) return false; } return true; }
public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { ObjectAttributeEvaluation Evaluation = new ObjectAttributeEvaluation(); Evaluation.AttributeName="ParseCount"; bool negation = GetAttributeByName("negation")==null? false: true; bool Result = CheckCurrentObject(ref lObjectInterface); if (negation) { if (Result) return new FunctionIO(RetVal.False); } else { if (!Result) return new FunctionIO(RetVal.False); } if (cParserPrimitives.Count == 0) { if (cCallback != null && CallCalback) if (!cCallback(lObjectInterface)) return new FunctionIO(Evaluation, RetVal.False); return new FunctionIO(Evaluation, RetVal.True); } //Here we preset next primitives for (int x = 0; x < cParserPrimitives.Count-1; x++) cParserPrimitives[x].SetNextPrimitive(cParserPrimitives[x + 1]); ObjectInterfacePrototipe SubObjects= lObjectInterface.GetSubObjects(); if (SubObjects.GetFirstObject() == null) return new FunctionIO(Evaluation, RetVal.True); ObjectAttributeEvaluation ParseCountEvaluation = new ObjectAttributeEvaluation( EvaluationMode.Max, 1, int.MaxValue); for( int x=0; x< cParserPrimitives.Count; x++ ) { ParserPrimitives tPrimitives; if (cParserPrimitives.Count == x + 1) tPrimitives = null; else tPrimitives = cParserPrimitives[x + 1]; FunctionIO ret = cParserPrimitives[x].CheckRelations(ref SubObjects, tPrimitives, CallCalback); bool tResult= ret["RetVal"].Value; if (!negation) if (!tResult) return new FunctionIO(RetVal.False); else if (tResult) return new FunctionIO(RetVal.False); SubObjects.GetOffsetObject(ret["ParseCount"].Value); } if (cCallback != null && CallCalback) cCallback(lObjectInterface); return new FunctionIO(Evaluation, RetVal.True); }
public bool NewBitfieldDescriptionField(ObjectInterfacePrototipe lObjectInterface) { return true; }
public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { FunctionIO ReturnContainer = new FunctionIO(); ObjectAttributeInt ReturnValue1 = new ObjectAttributeInt("ret", 1); ObjectAttributeInt ReturnValue0 = new ObjectAttributeInt("ret", 0); ObjectAttributeEvaluation Evaluation = null; if (cFunctionParameters == null || cFunctionParameters.GetFunctionParameterByName("ParseCount") == null) { Evaluation = new ObjectAttributeEvaluation(); Evaluation.SetAttributeName("ParseCount"); } else Evaluation = (ObjectAttributeEvaluation)cFunctionParameters.GetFunctionParameterByName("ParseCount"); bool More = true; int TotalMove= 0; int StartOffset = lObjectInterface.GetOffset(); bool eof = false; while (More) { int Positives = 0; int CurrentMove = 0; if (NextElement != null) { FunctionIO ret = NextElement.CheckRelations(ref lObjectInterface, NextElement.GetNextPrimitive(), false); if (((ObjectAttributeInt)ret.GetFunctionParameterByName("ret")).GetAttributeValue() == 1) { break; } } List<ParserPrimitives> SubPrimitives = cParserObjectRelation.GetSubParserPrimitives(); for (int x = 0; x < SubPrimitives.Count; x++) { ParserPrimitives tPrimitives; if (SubPrimitives.Count == x + 1) tPrimitives = null; else tPrimitives = SubPrimitives[x + 1]; FunctionIO ret = SubPrimitives[x].CheckRelations(ref lObjectInterface, tPrimitives, CallCalback); if (((ObjectAttributeInt)ret.GetFunctionParameterByName("ret")).GetAttributeValue() == 1) { CurrentMove += ((ObjectAttributeEvaluation)ret.GetFunctionParameterByName("ParseCount")).GetEvaluationValue(); Positives++; } eof=lObjectInterface.MoveByOffset(CurrentMove); } TotalMove += CurrentMove; if (Positives != SubPrimitives.Count || eof) { More = false; } } if (!Evaluation.EvaluateNext(TotalMove)) { ReturnContainer.AddFunctionParameter((ObjectAttribute)ReturnValue0); return ReturnContainer; } lObjectInterface.SetOffset(StartOffset); ReturnContainer.AddFunctionParameter(Evaluation); ReturnContainer.AddFunctionParameter((ObjectAttribute)ReturnValue1); return ReturnContainer; }
public bool NewBlankBitfield(ObjectInterfacePrototipe lObjectInterface) { return true; }
public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { FunctionIO ReturnContainer = new FunctionIO(); ObjectAttributeInt ReturnValue1 = new ObjectAttributeInt("ret", 1); ObjectAttributeInt ReturnValue0 = new ObjectAttributeInt("ret", 0); ObjectAttributeEvaluation Evaluation= null; if (cFunctionParameters == null || cFunctionParameters.GetFunctionParameterByName("ParseCount") == null) { Evaluation = new ObjectAttributeEvaluation(); Evaluation.SetAttributeName("ParseCount"); } else Evaluation = (ObjectAttributeEvaluation)cFunctionParameters.GetFunctionParameterByName("ParseCount"); bool result = false; List<ParserPrimitives> SubPrimitives = cParserObjectRelation.GetSubParserPrimitives(); for (int x = 0; x < SubPrimitives.Count; x++) { ParserPrimitives tPrimitives; if (SubPrimitives.Count == x + 1) tPrimitives = null; else tPrimitives = SubPrimitives[x + 1]; FunctionIO ret = SubPrimitives[x].CheckRelations(ref lObjectInterface, tPrimitives,CallCalback); if (((ObjectAttributeInt)ret.GetFunctionParameterByName("ret")).GetAttributeValue() == 1) { result = true; Evaluation.SubEvaluate((ObjectAttributeEvaluation)ret.GetFunctionParameterByName("ParseCount")); } } if (result) { ReturnContainer.AddFunctionParameter((ObjectAttribute)Evaluation); ReturnContainer.AddFunctionParameter((ObjectAttribute)ReturnValue1); return ReturnContainer; } ReturnContainer.AddFunctionParameter((ObjectAttribute)ReturnValue0); return ReturnContainer; }
public bool Postheader1Element(ObjectInterfacePrototipe lObjectInterface) { return true; }
/// <summary> /// Checks relations. /// </summary> /// <param name="lObjectInterface">ObjectInterface.</param> /// <param name="NextElement">Next element we are going to parse.</param> /// <param name="CallCalback">Do we have to call callback?</param> /// <returns>FunctionIO with return parameters like ret value and parse count.</returns> public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { ObjectAttributeEvaluation Evaluation = GetEvaluation(); int Positives = 0; List<ParserPrimitives> SubPrimitives = cParserObjectRelation.GetSubParserPrimitives(); for (int x = 0; x < SubPrimitives.Count; x++) { FunctionIO ret = SubPrimitives[x].CheckRelations(ref lObjectInterface, x + 1 == SubPrimitives.Count ? null : SubPrimitives[x + 1], CallCalback); if (ret["RetVal"].Value) { Positives++; if (!Evaluation.Evaluate((ObjectAttributeEvaluation)ret["ParseCount"])) return new FunctionIO(RetVal.False); } } if (Positives == SubPrimitives.Count) return new FunctionIO(Evaluation, RetVal.True); return new FunctionIO(RetVal.False); }
public bool Postheader2Name(ObjectInterfacePrototipe lObjectInterface) { return true; }
/// <summary> /// Recursively check all depths. /// </summary> /// <param name="lObjectInterface">ObjectInterface.</param> /// <param name="CallCallback">Do we have to call callback?</param> /// <param name="depth">Current depth.</param> /// <returns>FunctionIO with return parameters like ret value and parse count.</returns> public FunctionIO CheckDeepRelations(ref ObjectInterfacePrototipe lObjectInterface, bool CallCallback, int depth) { ObjectAttributeEvaluation Evaluation = new ObjectAttributeEvaluation(); Evaluation.AttributeName = "ParseCount"; if (depth > MaxDepth) return new FunctionIO(RetVal.False); bool More = true; int TotalMove = 0; int OccurenciesFound = 0; int StartOffset = lObjectInterface.GetOffset(); bool eof = false; List<ParserPrimitives> SubPrimitives = cParserObjectRelation.GetSubParserPrimitives(); while (More) { int CurrentMove = 0; int Positives = 0; ObjectInterfacePrototipe tInterface = lObjectInterface.GetSubObjects(); FunctionIO ret2 = null; if (tInterface != null) { tInterface.GetFirstObject(); if (tInterface.GetCurrentObject() != null) { ret2 = CheckDeepRelations(ref tInterface, CallCallback, depth + 1); if (ret2["RetVal"].Value) OccurenciesFound += ret2["Occurencies"].Value; } } for (int x = 0; x < SubPrimitives.Count; x++) { CurrentMove = 0; FunctionIO ret = SubPrimitives[x].CheckRelations(ref lObjectInterface, x + 1 == SubPrimitives.Count ? null : SubPrimitives[x + 1], false); if (ret["RetVal"].Value) { CurrentMove = ((ObjectAttributeEvaluation)ret["ParseCount"]).Value; Positives++; } else break;//Stop execution if we fail. eof = lObjectInterface.MoveByOffset(CurrentMove); if (eof) break; } //if (eof) // break; lObjectInterface.SetOffset(StartOffset);//We go back to start offset eof = lObjectInterface.MoveByOffset(TotalMove);//and move for one step and continue checking from there if (Positives == SubPrimitives.Count) { OccurenciesFound++;//We find a new occurency and incrise counter //We recall our callbacks if (CallCallback) { for (int x = 0; x < SubPrimitives.Count; x++) { CurrentMove = 0; FunctionIO ret = SubPrimitives[x].CheckRelations(ref lObjectInterface, x + 1 == SubPrimitives.Count ? null : SubPrimitives[x + 1], CallCallback); CurrentMove = ((ObjectAttributeEvaluation)ret["ParseCount"]).Value; eof = lObjectInterface.MoveByOffset(CurrentMove); } } } TotalMove++;//We incrise move lObjectInterface.SetOffset(StartOffset);//We go back to start offset eof = lObjectInterface.MoveByOffset(TotalMove);//and move for one step and continue checking from there if (eof) break; } if (OccurenciesFound == 0) return new FunctionIO(RetVal.False); Evaluation.Evaluate(TotalMove); lObjectInterface.SetOffset(StartOffset); ObjectAttributeInt ParamOccurrenciesFound = new ObjectAttributeInt("Occurencies", OccurenciesFound); return new FunctionIO(ParamOccurrenciesFound, Evaluation, RetVal.False); }
public bool Preheader2Element(ObjectInterfacePrototipe lObjectInterface) { if (lObjectInterface.GetObjectCount() < 32) return false; return true; }
/// <summary> /// Checks relations. /// </summary> /// <param name="lObjectInterface">ObjectInterface.</param> /// <param name="NextElement">Next element we are going to parse.</param> /// <param name="CallCalback">Do we have to call callback?</param> /// <returns>FunctionIO with return parameters like ret value and parse count.</returns> public override FunctionIO CheckRelations(ref ObjectInterfacePrototipe lObjectInterface, ParserPrimitives NextElement, bool CallCalback) { ObjectAttribute lMaxDepth = null; if (cFunctionParameters != null && (lMaxDepth = cFunctionParameters["MaxDepth"]) != null) MaxDepth = lMaxDepth.Value; FunctionIO ret = CheckDeepRelations(ref lObjectInterface, CallCalback, 1); if (!ret["RetVal"].Value) return new FunctionIO(RetVal.False); int occurencies = ret["Occurencies"].Value; ObjectAttribute MinOccurencies; ObjectAttribute MaxOccurencies; if (cFunctionParameters != null && (MinOccurencies = cFunctionParameters["MinOccurencies"]) != null && (MaxOccurencies = cFunctionParameters["MaxOccurencies"]) != null) if (occurencies < MinOccurencies.Value || occurencies > MaxOccurencies.Value) return new FunctionIO(RetVal.False); return ret; }
public bool moretables(ObjectInterfacePrototipe lObjectInterface) { return true; }
public void Call(ObjectInterfacePrototipe lObjectInterface) { called = true; }