public virtual void AddParserItem(FF_FlowInitiation flowInitiation, int gmuId, int appId, IFFParser parser, FFTgtParseBufferHandler action) { using (ILogMethod method = Log.LogMethod("FFParserDictionary", "AddTargetParser")) { try { FFParserItem item = null; if (!this.ContainsKey(gmuId)) { this.Add(gmuId, (item = new FFParserItem())); } else { item = this[gmuId]; } item.GmuId = gmuId; item.AppId = appId; FFParserItemInfo itemInfo = item[flowInitiation]; itemInfo.Parser = parser; itemInfo.Action = action; } catch (Exception ex) { method.Exception(ex); } } }
protected override IFreeformEntity ParseBufferInternal(IFreeformEntity parent, IFreeformEntity rootEntity, ref IFreeformEntity entity, byte[] buffer, int offset, int length) { if (length == 0) { return(null); } int sessionId = -1; if (buffer != null) { if (length < 0) { length = buffer.Length; } bool hasSubTargets = this.HasSubTargets; while (offset < length) { int id = buffer[offset]; int combinedId = id; byte length2 = 0; byte[] buffer2 = null; if (rootEntity != null && rootEntity is IFreeformEntity_Msg) { combinedId = rootEntity.CreateCombinedId(id, false); } if (HasSubTargets) { length2 = buffer[++offset]; // we may get zero length buffer if (length2 > 0) { buffer2 = new byte[length2]; Buffer.BlockCopy(buffer, ++offset, buffer2, 0, buffer2.Length); } else { offset += 1; continue; } } else { buffer2 = new byte[buffer.Length - 1]; Buffer.BlockCopy(buffer, ++offset, buffer2, 0, buffer2.Length); } if (buffer2 != null) { IFreeformEntity_MsgTgt target = null; bool isSecured = false; bool isResponseRequired = false; bool isResponseRequired2 = false; FFParserItem parserItem = this.GetParserItem(rootEntity, id); int appId = id; // not found, then try it with combined id if (parserItem == null) { parserItem = this.GetParserItem(rootEntity, combinedId); } // found if (parserItem != null) { // check if response required id = id.GetRequestResponseId(out isResponseRequired); // check if the packet is secured appId = parserItem.AppId.GetRequestResponseId(out isResponseRequired2); FFTgtParseBufferHandler action = parserItem[this.FlowInitiation].Action; if (action != null) { target = action(parent as IFreeformEntity_MsgTgt, id, length2, buffer2); } else { IFFParser parser = parserItem.GetParser(this.FlowInitiation); if (parser != null) { target = parser.ParseBuffer(rootEntity, appId, buffer2) as IFreeformEntity_MsgTgt; } } } // secured target if (target is FFTgt_B2B_Encrypted) { rootEntity.EncryptedTarget = target; isSecured = true; } entity = target; if (target != null) { target.TargetID = appId; target.TargetLength = length2; target.EntityData = buffer2; target.IsSecured = isSecured; target.IsResponseRequired = isResponseRequired; if (parent != null) { parent.Targets.Add(target); } if (target is IFreeformEntity_MsgTgt_Primary && rootEntity != null) { rootEntity.EntityPrimaryTarget = target; } } } if (hasSubTargets) { offset += length2; } else { break; } } } return(entity); }
public virtual void AddBufferEntityParser(int gmuId, int appId, IFFParser parser, FFTgtParseBufferHandler action) { using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "AddBufferEntityParser")) { try { FF_FlowInitiation flowDirection = this.FlowInitiation; if (_subParsers == null) { _subParsers = new FFParserDictionary(); } if (_parserMappings == null) { _parserMappings = new IntDictionary <int>(); } if (parser != null && parser.FlowInitiation != FF_FlowInitiation.Any) { flowDirection = parser.FlowInitiation; } _subParsers.AddParserItem(flowDirection, gmuId, appId, parser, action); if (appId != -1 && !_parserMappings.ContainsKey(appId)) { _parserMappings.Add(appId, gmuId); } } catch (Exception ex) { method.Exception(ex); } } }
public virtual void AddBufferEntityParser(int gmuId, int appId, FFTgtParseBufferHandler action) { this.AddBufferEntityParser(gmuId, appId, null, action); }
public virtual void AddBufferEntityParser(Type gmuIdEnum, Type appIdEnum, IFFParser parser, FFTgtParseBufferHandler action) { using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "AddBufferEntityParser")) { try { //Array gmuIdValues = Enum.GetValues(gmuIdEnum); //Array appIdValues = Enum.GetValues(appIdEnum); //if (gmuIdValues.Length == appIdValues.Length) //{ // for (int i = 0; i < gmuIdValues.Length; i++) // { // this.AddBufferEntityParser((int)gmuIdValues.GetValue(i), (int)appIdValues.GetValue(i), parser, action); // } //} string[] gmuIdNames = Enum.GetNames(gmuIdEnum); foreach (var gmuIdName in gmuIdNames) { try { object gmuIdValue = Enum.Parse(gmuIdEnum, gmuIdName, true); object appIdValue = Enum.Parse(appIdEnum, gmuIdName, true); this.AddBufferEntityParser((int)gmuIdValue, (int)appIdValue, parser, action); } catch (Exception ex) { method.InfoV("::: ENUM ERROR : Unable to convert from ({0}) to ({1})", gmuIdEnum.FullName, appIdEnum.FullName); } } } catch (Exception ex) { method.Exception(ex); } } }
public virtual void AddBufferEntityParser(Type gmuIdEnum, Type appIdEnum, FFTgtParseBufferHandler action) { this.AddBufferEntityParser(gmuIdEnum, appIdEnum, null, action); }