private HttpResponseMessage Invoke <T>(string methodName, params object[] inputs) where T : new() { T instance = new T(); MethodInfo method = typeof(T).GetMethod(methodName); Logger.Current.Informational("Method idenfied: " + method); ResponseXml response = new ResponseXml(string.Empty, methodName);; // Logger.Current.Informational("Request Inputs: \n"+ inputs[0].ToString()); try { response = (ResponseXml)method.Invoke(instance, inputs); } catch (WAException ex) { Logger.Current.Error("A WAException occured while processing " + method, ex); response.RetStatus = ex.Status; response.ErrorString = ex.Message; } catch (Exception ex) { Logger.Current.Error("An exception occured while processing " + method, ex); response.RetStatus = -1; response.ErrorString = ex.Message; } var xml = response.Xml.ToString(); return(new HttpResponseMessage { Content = new StringContent(xml, Encoding.UTF8, "text/xml") }); }
/// <summary> /// Create a new instance of the Response parser /// </summary> /// <param name="responseXml"></param> public GCheckoutResponse(string responseXml) { //to cut down on the number or exceptions, we are going to try to //predetermine the type of message being returned this will allow for //a greater experience on the dev side. If you are not using debug //symbols, it is very difficult to determine if the error is real //or not if you are breaking on all thrown exceptions. _responseXml = responseXml; if (ResponseXml.IndexOf("<request-received") > -1) { _GoodResponse = (AutoGen.RequestReceivedResponse) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.RequestReceivedResponse)); Log.Xml(_GoodResponse.serialnumber, ResponseXml); //_parsed = true; } else if (ResponseXml.IndexOf("<error") > -1) { _ErrorResponse = (AutoGen.ErrorResponse) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.ErrorResponse)); Log.Xml(_ErrorResponse.serialnumber, ResponseXml); //_parsed = true; } else if (ParseMessage()) { //_parsed = true; } else { //What we want to do is determine if there is a type so we //can report it to the user so they can report the error string messageTypeFound = string.Empty; try { var theType = EncodeHelper.Deserialize(ResponseXml); if (theType != null) { messageTypeFound = theType.GetType().Name; } else { messageTypeFound = "Unknown Message Type"; } Log.Xml(Guid.NewGuid().ToString(), ResponseXml); } catch (Exception ex) { Log.Xml(Guid.NewGuid().ToString(), ResponseXml); Log.Err("GCheckoutResponse else check failed:" + ex.Message); } _ErrorResponse = new GCheckout.AutoGen.ErrorResponse(); _ErrorResponse.errormessage = string.Format("Couldn't parse ResponseXml. " + "Message type found was {0}. Please See ResponseXml", messageTypeFound); } }
internal static ResponseXml ToEF(ResponseXmlBO ResponseXmlBO) { ResponseXml ResponseXml = new ResponseXml(); ResponseXml.ResponseId = new Guid(ResponseXmlBO.ResponseId); ResponseXml.Xml = ResponseXmlBO.Xml; ResponseXml.UserId = ResponseXmlBO.User; ResponseXml.IsNewRecord = ResponseXmlBO.IsNewRecord; return(ResponseXml); }
internal static SurveyResponseBO Map(ResponseXml ResponseXml) { SurveyResponseBO SurveyResponseBO = new SurveyResponseBO(); SurveyResponseBO.ResponseId = ResponseXml.ResponseId.ToString(); SurveyResponseBO.XML = ResponseXml.Xml; SurveyResponseBO.UserId = (int)ResponseXml.UserId; SurveyResponseBO.IsNewRecord = (bool)ResponseXml.IsNewRecord; return(SurveyResponseBO); }
/// <summary> /// Parse the Message for a notification data token response message. /// </summary> /// <returns></returns> protected override bool ParseMessage() { try { if (ResponseXml.IndexOf("<notification-history-response") > -1) { _response = (AutoGen.NotificationHistoryResponse) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.NotificationHistoryResponse)); Log.Xml(_response.serialnumber, ResponseXml); return(true); } else { Debug.WriteLine("NotificationHistoryResponse was not expected type: notification-history-response"); /* hack: test against all possible message types and wrap in a response */ var messageTypes = new List <Type> { typeof(AutoGen.NewOrderNotification), typeof(AutoGen.AuthorizationAmountNotification), typeof(AutoGen.ChargeAmountNotification), typeof(AutoGen.OrderStateChangeNotification), typeof(AutoGen.RiskInformationNotification) }; _response = new AutoGen.NotificationHistoryResponse(); _response.notifications = new GCheckout.AutoGen.NotificationHistoryResponseNotifications(); bool found = false; foreach (Type t in messageTypes) { try { Log.Debug("Trying to deserialize message as type:" + t.Name); object o = EncodeHelper.Deserialize(ResponseXml, t); _response.notifications.Items = new object[] { o }; Debug.WriteLine("Message was type:" + t.Name); found = true; break; } catch { //ignore } } Log.Xml(_response.serialnumber, ResponseXml); if (!found) { Log.Err("Unable to determine message type for NotificationHistoryResponse:" + ResponseXml); } return(found); } } catch (Exception ex) { Log.Err("ParseMessage: Error trying to deserialize:" + ex.Message); //let it continue } return(false); }
public String DadosConta(ContaBancaria conta, RequestDadosConta request) { IResponse responseXml = new ResponseXml(); IResponse responseCsv = new ResponseCsv(); IResponse responsePorcento = new ResponsePorcento(); responseXml. SetProximo(responseCsv). SetProximo(responsePorcento); return(responseXml.Retorno(conta, request)); }
/// <summary> /// Parse the Message for a notification data token response message. /// </summary> /// <returns></returns> protected override bool ParseMessage() { try { if (ResponseXml.IndexOf("<notification-data-response") > -1) { _response = (AutoGen.NotificationDataResponse) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.NotificationDataResponse)); Log.Xml(_response.serialnumber, ResponseXml); return(true); } } catch (Exception ex) { Log.Err("NotificationDataResponse ParseResponse:" + ex.Message); } return(false); }
/// <summary> /// Parse the message for a checkout-redirect /// </summary> /// <returns></returns> protected override bool ParseMessage() { //to cut down on the number or exceptions, we are going to try to //predetermine the type of message being returned this will allow for //a greater experience on the dev side. If you are not using debug //symbols, it is very difficult to determine if the error is real //or not if you are breaking on all thrown exceptions. try { if (ResponseXml.IndexOf("<checkout-redirect") > -1) { _CheckoutRedirectResponse = (AutoGen.CheckoutRedirect) EncodeHelper.Deserialize(ResponseXml, typeof(AutoGen.CheckoutRedirect)); Log.Xml(_CheckoutRedirectResponse.serialnumber, ResponseXml); return(true); } } catch (Exception ex) { Log.Err("GCheckoutShoppingCartResponse ParseResponse:" + ex.Message); } return(false); }