Ejemplo n.º 1
0
        private List <QBDInventorySite> SyncInventorySites(QuickBooksService service, string ticket, RequestProcessor2 req)
        {
            // Requests to the QuickBooks API are made in QBXML format.
            var doc = new XmlDocument();

            // Add the prolog processing instructions.
            doc.AppendChild(doc.CreateXmlDeclaration("1.0", null, null));
            doc.AppendChild(doc.CreateProcessingInstruction("qbxml", "version=\"14.0\""));

            XmlElement outer = doc.CreateElement("QBXML");

            doc.AppendChild(outer);

            XmlElement inner = doc.CreateElement("QBXMLMsgsRq");

            outer.AppendChild(inner);
            inner.SetAttribute("onError", "stopOnError");

            // Build the request to get inventory sites.
            service.BuildInventorySiteQueryRq(doc, inner);

            try
            {
                Logger.Debug(doc.OuterXml);

                var response = req.ProcessRequest(ticket, doc.OuterXml);

                Logger.Debug(response);

                if (string.IsNullOrEmpty(response))
                {
                    return(new List <QBDInventorySite>());
                }

                // Then walk the response.
                var walkReponse = service.WalkInventorySiteQueryRs(response);

                if (SaveErrorCount > 0)
                {
                    StatusText += string.Format("{0} - Sync failed. Please correct the {1} errors first.\r\n", DateTime.Now.ToString(), SaveErrorCount);
                    OnPropertyChanged("StatusText");

                    return(new List <QBDInventorySite>());
                }
                else
                {
                    return(walkReponse.Item3);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                return(new List <QBDInventorySite>());
            }
        }