/// <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); }
/// <summary> /// Add an additional response. /// </summary> /// <remarks>This is used when processing the nextpagetoken. /// We are able to combine multiple messages together.</remarks> /// <param name="response">The response to add to this message</param> public void AddAdditionalResponse(NotificationHistoryResponse response) { AutoGen.NotificationHistoryResponse theResponse = response.Response as AutoGen.NotificationHistoryResponse; if (theResponse != null) { _additionalResponses.Add(theResponse); _notificationResponses = null; } else { //TODO wrap the error in a specific error to allow people to obtain the message that blew up. throw new NotificationHistoryException(response, response.NextPageToken, null); } }