/// <summary> /// Creates a new message of the given type. If there is a template /// for the message type, then it is used to set all the values in the /// new message (the values will be copied from the original messages, /// not referred to directly, to avoid affecting the templates if a value /// in a message created this way is modified). If the factory has an /// ITraceGenerator set, it uses it to assign a new trace number as a /// NUMERIC value of length 6 in field 11; if AssignDate is true, /// then the current DateTime is stored in field 7 as a DATE10 type. /// </summary> /// <param name="type"></param> /// <returns></returns> //public IsoMessage NewTemplateMessage(Int32 type) //{ // IsoMessage m = (ConfigParser.ISOHeaders.ContainsKey(type)) ? new IsoMessage(ConfigParser.ISOHeaders[type]) : new IsoMessage(null); // m.Type = type; // m.Etx = Etx; // if (ConfigParser.ISOTypeTemplates.ContainsKey(type)) // { // IsoMessage templ = ConfigParser.ISOTypeTemplates[type]; // for (Int32 i = 2; i < 128; i++) // { // if (templ.HasField(i)) // m.SetField(i, (IsoValue)templ.GetField(i).Clone()); // } // } // if (TraceGenerator != null) // { // m.SetValue(11, TraceGenerator.NextTrace(), IsoType.NUMERIC, 6, TypeElement.Field); // } // if (ConfigParser.ISOAssignDate) // { // m.SetValue(7, DateTime.Now, IsoType.DATE10, 10, TypeElement.Field); // } // return m; //} /// <summary> /// Creates a new message of the given type. If there is a template /// for the message type, then it is used to set all the values in the /// new message (the values will be copied from the original messages, /// not referred to directly, to avoid affecting the templates if a value /// in a message created this way is modified). If the factory has an /// ITraceGenerator set, it uses it to assign a new trace number as a /// NUMERIC value of length 6 in field 11; if AssignDate is true, /// then the current DateTime is stored in field 7 as a DATE10 type. /// </summary> /// <param name="type"></param> /// <returns></returns> //public IsoMessage NewParseMessage(Int32 type) //{ // IsoMessage m = (ConfigParser.ISOHeaders.ContainsKey(type)) ? new IsoMessage(ConfigParser.ISOHeaders[type]) : new IsoMessage(null); // m.Type = type; // m.Etx = Etx; // if (ConfigParser.ISOParseMap.ContainsKey(type)) // { // Dictionary<Int32, FieldParseInfo> guide = ConfigParser.ISOParseMap[type]; // List<Int32> index = ConfigParser.ISOParseOrder[type]; // foreach (Int32 i in index) // { // FieldParseInfo fpi = guide[i]; // if (fpi.SubData.Count > 0) // { // Dictionary<Int32, IsoValue> subFieldList = new Dictionary<int, IsoValue>(); // IsoValue subField = null; // foreach (KeyValuePair<Int32, FieldParseInfo> fpiSub in fpi.SubData) // { // switch (fpiSub.Value.Type) // { // case IsoType.NUMERIC: // subField = new IsoValue(fpiSub.Value.Type, "0".PadRight(fpiSub.Value.Length, '0'), fpiSub.Value.Length, "0".PadRight(fpiSub.Value.Length, '0'), fpiSub.Value.TypeElement); // break; // case IsoType.ALPHA: // subField = new IsoValue(fpiSub.Value.Type, "0".PadRight(fpiSub.Value.Length, '0'), fpiSub.Value.Length, "0".PadRight(fpiSub.Value.Length, '0'), fpiSub.Value.TypeElement); // break; // case IsoType.LLVAR: // subField = new IsoValue(fpiSub.Value.Type, "00", "00"); // break; // case IsoType.LLLVAR: // subField = new IsoValue(fpiSub.Value.Type, "000", "000"); // break; // case IsoType.DATE10: // subField = new IsoValue(fpiSub.Value.Type, DateTime.Now, DateTime.Now.ToString("MMddHHmmss")); // break; // case IsoType.DATE12: // subField = new IsoValue(fpiSub.Value.Type, DateTime.Now, DateTime.Now.ToString("yyMMddHHmmss")); // break; // case IsoType.DATE6: // subField = new IsoValue(fpiSub.Value.Type, DateTime.Now, DateTime.Now.ToString("yyMMdd")); // break; // case IsoType.DATE4: // subField = new IsoValue(fpiSub.Value.Type, DateTime.Now, DateTime.Now.ToString("MMdd")); // break; // case IsoType.DATE_EXP: // subField = new IsoValue(fpiSub.Value.Type, DateTime.Now, DateTime.Now.ToString("YYmm")); // break; // case IsoType.TIME: // subField = new IsoValue(fpiSub.Value.Type, DateTime.Now, DateTime.Now.ToString("HHmmss")); // break; // case IsoType.AMOUNT: // subField = new IsoValue(fpiSub.Value.Type, "000000000000", "000000000000"); // break; // } // subFieldList.Add(fpiSub.Key, subField); // } // m.SetField(i, new IsoValue(fpi.Type, "0".PadRight(fpi.Length, '0'), fpi.Length, "0".PadRight(fpi.Length, '0'), "", subFieldList)); // } // else // { // switch (fpi.Type) // { // case IsoType.NUMERIC: // m.SetField(i, new IsoValue(fpi.Type, "0".PadRight(fpi.Length, '0'), fpi.Length, "0".PadRight(fpi.Length, '0'), fpi.TypeElement)); // break; // case IsoType.ALPHA: // m.SetField(i, new IsoValue(fpi.Type, "0".PadRight(fpi.Length, '0'), fpi.Length, "0".PadRight(fpi.Length, '0'), fpi.TypeElement)); // break; // case IsoType.LLVAR: // m.SetField(i, new IsoValue(fpi.Type, "00", "00")); // break; // case IsoType.LLLVAR: // m.SetField(i, new IsoValue(fpi.Type, "000", "000")); // break; // case IsoType.DATE10: // m.SetField(i, new IsoValue(fpi.Type, DateTime.Now, DateTime.Now.ToString("MMddHHmmss"))); // break; // case IsoType.DATE12: // m.SetField(i, new IsoValue(fpi.Type, DateTime.Now, DateTime.Now.ToString("yyMMddHHmmss"))); // break; // case IsoType.DATE6: // m.SetField(i, new IsoValue(fpi.Type, DateTime.Now, DateTime.Now.ToString("yyMMdd"))); // break; // case IsoType.DATE4: // m.SetField(i, new IsoValue(fpi.Type, DateTime.Now, DateTime.Now.ToString("MMdd"))); // break; // case IsoType.DATE_EXP: // m.SetField(i, new IsoValue(fpi.Type, DateTime.Now, DateTime.Now.ToString("YYmm"))); // break; // case IsoType.TIME: // m.SetField(i, new IsoValue(fpi.Type, DateTime.Now, DateTime.Now.ToString("HHmmss"))); // break; // case IsoType.AMOUNT: // m.SetField(i, new IsoValue(fpi.Type, "000000000000", "000000000000")); // break; // } // } // } // } // if (TraceGenerator != null) // { // m.SetValue(11, TraceGenerator.NextTrace(), IsoType.NUMERIC, 6, TypeElement.Field); // } // if (ConfigParser.ISOAssignDate) // { // m.SetValue(7, DateTime.Now, IsoType.DATE10, 10, TypeElement.Field); // } // return m; //} /// <summary> /// Creates a response for the specified request, by creating a new /// message with a message type of the original request type plus 16. /// If there is a template for the resulting type, its values are copied /// onto the new message; after that, all the values from the original /// request that are not already in the response are copied to it. /// </summary> /// <param name="request">An ISO8583 request.</param> /// <returns>A new ISO8583 message with the corresponding response /// type for the request and with values already copied from its /// template (if any) and the request.</returns> public IsoMessage CreateResponse(CaseBusiness.CC.Global.MensagemInterfaceDados interfaceDados, IsoMessage request) { Int32 responseType = request.Type + 16; IsoMessage resp = (ConfigParser.ISOHeaders.ContainsKey(responseType)) ? new IsoMessage(interfaceDados.MensagemInterfaceHeader.TipoCodificacao, ConfigParser.ISOHeaders[responseType]) : new IsoMessage(); IsoMessage templ = null; resp.Type = responseType; resp.Etx = etx; if (ConfigParser.ISOTypeTemplates.ContainsKey(resp.Type)) { templ = ConfigParser.ISOTypeTemplates[resp.Type]; } if (templ != null) { for (Int32 i = 2; i < 128; i++) { if (templ.Has(i)) { resp.SetField(i, (IsoValue)templ.Get(i).Clone()); if (request.Has(i)) { IsoValue field = request.Get(i); if (field.SubData != null) { if (field.SubData.Count > 0) { foreach (KeyValuePair <Int32, IsoValue> subValue in field.SubData) { if (templ.Has(i, subValue.Key)) { IsoValue v = (IsoValue)templ.Get(i, subValue.Key).Clone(); resp.SetSubData(i, subValue.Key, new IsoValue(v.Type, field.Base, subValue.Value, subValue.Value.ToString().Length, subValue.Value.ToString(), v.Requirements, v.TypeElement, v.SubElementIDLength, v.LengthOfLengthSubElement)); } } } else { resp.SetField(i, field); } } else { resp.SetField(i, field); } } else { if (templ.Get(i).Requirements == "CE") { resp.SetField(i, null); } } } } } else { resp = new IsoMessage(); } return(resp); }