示例#1
0
        private XmlDocumentModel CreateArticles()
        {
            TraceVerbose("Retrieving the configurable products...");

            var xmlDocument = new XmlDocumentModel();

            foreach (var configurableProduct in _currentConfigurableProducts)
            {
                TraceVerbose("Processing {0}: {1}", configurableProduct.ProductID, configurableProduct.VendorItemNumber);

                var articleInformation = CreateArticleInformation(configurableProduct);

                var articleXml = ProductExporterHelper.SerializeModel(articleInformation);

                if (UploadRequired(articleXml, configurableProduct.VendorItemNumber))
                {
                    xmlDocument.Articles.Add(articleInformation);

                    TraceVerbose("XML-file '{0}.xml' changed; upload required.", configurableProduct.VendorItemNumber);
                }
                else
                {
                    TraceVerbose("XML-file '{0}.xml' already processed before; upload not required.", configurableProduct.VendorItemNumber);
                }
            }

            return(xmlDocument);
        }
示例#2
0
        private void ExportProducts(IFtpClient ftpClient)
        {
            var document = CreateDocumentModel();

            if (document.Articles.Count > 0)
            {
                TraceVerbose("'{0}' articles are changed; These articles will be uploaded.", document.Articles.Count);

                var xmlProduct = ProductExporterHelper.SerializeModel(document);

                var fileName = String.Format("PIM_AI_{0:yyyyMMddHHmmss}.xml", DateTime.Now);

                try
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        TraceVerbose("Uploading XML-file \"{0}\" to remote server \"{1}\" ...", fileName, NavisionSettings.Server);

                        xmlProduct.Save(memoryStream);

                        memoryStream.Position = 0;

                        ftpClient.UploadFile(fileName, memoryStream);
                    }

                    foreach (var article in document.Articles)
                    {
                        var localProductXmlFilename = GetArchiveFullFileName(article.SupplierItemNumber);

                        var articleXml = ProductExporterHelper.SerializeModel(article);

                        articleXml.Save(localProductXmlFilename);
                    }
                }
                catch (IOException exception)
                {
                    TraceError("Unable to save the file to the ftp directory '{0}'. {1}", NavisionSettings.Server, exception.Message);
                }

                try
                {
                    TraceVerbose("Uploading XML-file '{0}' to local directory '{1}' ...", fileName, NavisionSettings.ArchiveDirectory);

                    xmlProduct.Save(Path.Combine(NavisionSettings.ArchiveDirectory, fileName));
                }
                catch (IOException exception)
                {
                    TraceWarning("Unable to save the file to the archive directory '{0}'. {1}", NavisionSettings.ArchiveDirectory, exception.Message);
                }
            }
            else
            {
                TraceVerbose("Upload not requiered. There is no article change.");
            }
        }