public override void Interprete(ARCPO_Packet pPacket) { //is it a known custom command? if (this.CommandRunDict.ContainsKey(this.GetPacketKey(pPacket).ToString())) { CommandRun vCR = this.CommandRunDict[this.GetPacketKey(pPacket).ToString()]; //Idea: use name (dictionnary of known values) and fallback interpretes ... later. this.SendWMAppCommand(Convert.ToInt32(vCR.mCommand)); } }
/// <summary> /// Runs a custom command (dispatch to submethods according packet type) /// </summary> /// <param name="commandRun"></param> private void RunCustom(ARCPO_Packet pPacket) { CommandRun vCR = this.CommandRunDict[this.GetPacketKey(pPacket).ToString()]; if (vCR.IsExtended) { this.RunExtendedCommand(vCR, pPacket); } else { this.RunCustom(vCR); } }
/// <summary> /// Runs an extended command, where the action is not defined only by the command type, but by also other data within the packet /// </summary> /// <param name="pPacket"></param> private void RunExtendedCommand(CommandRun pCR, ARCPO_Packet pPacket) { //search for the matching commandExt CommandRunExt vCRE = null; foreach (CommandRunExt vIter in pCR.mSubCommands) { if ( (string.IsNullOrEmpty(vIter.mPacketSubtype) || vIter.mPacketSubtype[0] == (char)pPacket.mSubType) && (string.IsNullOrEmpty(vIter.mPacketBody) || vIter.mPacketBody == pPacket.ContentString) ) { //found vCRE = vIter; break; } } if (vCRE != null) { RunCustom(vCRE); } }