internal void ReadXml(XmlTextReader reader, string nodeName) { while (reader.Read()) { // End of invoice element, get out of here if (reader.Name == nodeName && reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.NodeType != XmlNodeType.Element) { continue; } DateTime dt; int m; switch (reader.Name) { case "account": var accountHref = reader.GetAttribute("href"); AccountCode = Uri.UnescapeDataString(accountHref.Substring(accountHref.LastIndexOf("/") + 1)); break; case "original_invoice": var originalInvoiceHref = reader.GetAttribute("href"); var invoiceNumber = Uri.UnescapeDataString(originalInvoiceHref.Substring(originalInvoiceHref.LastIndexOf("/") + 1)); MatchCollection matches = Regex.Matches(invoiceNumber, "([^\\d]{2})(\\d+)"); if (matches.Count == 1) { OriginalInvoiceNumberPrefix = matches[0].Groups[1].Value; OriginalInvoiceNumber = int.Parse(matches[0].Groups[2].Value); } else { OriginalInvoiceNumber = int.Parse(invoiceNumber); } break; case "uuid": Uuid = reader.ReadElementContentAsString(); break; case "state": var state = reader.ReadElementContentAsString(); if (!state.IsNullOrEmpty()) { State = state.ParseAsEnum <InvoiceState>(); } break; case "invoice_number": if (Int32.TryParse(reader.ReadElementContentAsString(), out m)) { InvoiceNumber = m; } break; case "invoice_number_prefix": InvoiceNumberPrefix = reader.ReadElementContentAsString(); break; case "po_number": PoNumber = reader.ReadElementContentAsString(); break; case "vat_number": VatNumber = reader.ReadElementContentAsString(); break; case "subtotal_in_cents": SubtotalInCents = reader.ReadElementContentAsInt(); break; case "tax_in_cents": TaxInCents = reader.ReadElementContentAsInt(); break; case "total_in_cents": TotalInCents = reader.ReadElementContentAsInt(); break; case "currency": Currency = reader.ReadElementContentAsString(); break; case "created_at": if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt)) { CreatedAt = dt; } break; case "updated_at": if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt)) { UpdatedAt = dt; } break; case "closed_at": if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt)) { ClosedAt = dt; } break; case "tax_type": TaxType = reader.ReadElementContentAsString(); break; case "tax_rate": TaxRate = reader.ReadElementContentAsDecimal(); break; case "tax_region": TaxRegion = reader.ReadElementContentAsString(); break; case "net_terms": if (int.TryParse(reader.ReadElementContentAsString(), out m)) { _netTerms = m; } break; case "collection_method": var method = reader.ReadElementContentAsString(); if (!method.IsNullOrEmpty()) { CollectionMethod = method.ParseAsEnum <Collection>(); } break; case "customer_notes": CustomerNotes = reader.ReadElementContentAsString(); break; case "terms_and_conditions": TermsAndConditions = reader.ReadElementContentAsString(); break; case "vat_reverse_charge_notes": VatReverseChargeNotes = reader.ReadElementContentAsString(); break; case "gateway_code": GatewayCode = reader.ReadElementContentAsString(); break; case "line_items": // overrite existing value with the Recurly API response Adjustments = new AdjustmentList(); Adjustments.ReadXml(reader); break; case "transactions": // overrite existing value with the Recurly API response Transactions = new TransactionList(); Transactions.ReadXml(reader); break; case "address": Address = new Address(reader); _referenceAddress = (Address)Address.Clone(); break; case "shipping_address": ShippingAddress = new ShippingAddress(reader); break; case "subtotal_before_discount_in_cents": if (int.TryParse(reader.ReadElementContentAsString(), out m)) { SubtotalBeforeDiscountInCents = m; } break; case "discount_in_cents": if (int.TryParse(reader.ReadElementContentAsString(), out m)) { DiscountInCents = m; } break; case "balance_in_cents": if (int.TryParse(reader.ReadElementContentAsString(), out m)) { BalanceInCents = m; } break; case "due_on": if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt)) { DueOn = dt; } break; case "type": Type = reader.ReadElementContentAsString(); break; case "origin": Origin = reader.ReadElementContentAsString(); break; case "attempt_next_collection_at": if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt)) { AttemptNextCollectionAt = dt; } break; case "recovery_reason": RecoveryReason = reader.ReadElementContentAsString(); break; case "all_line_items": AllLineItemsLink = reader.ReadElementContentAsString(); break; } } }
internal override void ReadXml(XmlTextReader reader) { while (reader.Read()) { // End of account element, get out of here if (reader.Name == "adjustment" && reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.NodeType != XmlNodeType.Element) { continue; } switch (reader.Name) { case "account": var href = reader.GetAttribute("href"); AccountCode = Uri.UnescapeDataString(href.Substring(href.LastIndexOf("/") + 1)); break; case "uuid": Uuid = reader.ReadElementContentAsString(); break; case "description": Description = reader.ReadElementContentAsString(); break; case "accounting_code": AccountingCode = reader.ReadElementContentAsString(); break; case "product_code": ProductCode = reader.ReadElementContentAsString(); break; case "origin": Origin = reader.ReadElementContentAsString(); break; case "unit_amount_in_cents": UnitAmountInCents = reader.ReadElementContentAsInt(); break; case "quantity": Quantity = reader.ReadElementContentAsInt(); break; case "discount_in_cents": DiscountInCents = reader.ReadElementContentAsInt(); break; case "tax_in_cents": TaxInCents = reader.ReadElementContentAsInt(); break; case "total_in_cents": TotalInCents = reader.ReadElementContentAsInt(); break; case "currency": Currency = reader.ReadElementContentAsString(); break; case "tax_exempt": TaxExempt = reader.ReadElementContentAsBoolean(); break; case "tax_code": TaxCode = reader.ReadElementContentAsString(); break; case "tax_type": TaxType = reader.ReadElementContentAsString(); break; case "tax_rate": TaxRate = reader.ReadElementContentAsDecimal(); break; case "tax_region": TaxRegion = reader.ReadElementContentAsString(); break; case "credit_reason_code": CreditReasonCode = reader.ReadElementContentAsString(); break; case "original_adjustment_uuid": OriginalAjustmentUuid = reader.ReadElementContentAsString(); break; case "start_date": DateTime startDate; if (DateTime.TryParse(reader.ReadElementContentAsString(), out startDate)) { StartDate = startDate; } break; case "end_date": DateTime endDate; if (DateTime.TryParse(reader.ReadElementContentAsString(), out endDate)) { EndDate = endDate; } break; case "created_at": DateTime createdAt; if (DateTime.TryParse(reader.ReadElementContentAsString(), out createdAt)) { CreatedAt = createdAt; } break; case "updated_at": DateTime updatedAt; if (DateTime.TryParse(reader.ReadElementContentAsString(), out updatedAt)) { UpdatedAt = updatedAt; } break; case "state": State = reader.ReadElementContentAsString().ParseAsEnum <AdjustmentState>(); break; case "revenue_schedule_type": var revenueScheduleType = reader.ReadElementContentAsString(); if (!revenueScheduleType.IsNullOrEmpty()) { RevenueScheduleType = revenueScheduleType.ParseAsEnum <Adjustment.RevenueSchedule>(); } break; case "shipping_address": ShippingAddress = new ShippingAddress(); ShippingAddress.ReadXml(reader); break; } } }