private void WriteFeedFile(XmlWriter xmlWriter, FeedGenerationFileInstruction fileInstruction)
        {
            var countRec = new Tuple <int, int, int>(0, 0, 0);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteDocType("product_catalog_data", null, DocTypeSystemId, null);
            xmlWriter.WriteStartElement("product_catalog_data");
            var header = new XE("header");

            header.Add(new XE("cid", Cid));
            header.Add(new XE("subid", SubId));
            //header.Add(new XE("datefmt", DateFormatString));
            header.Add(new XE("processtype", (_isIncrementalRun) ? "UPDATE" : "OVERWRITE"));
            header.Add(new XE("aid", fileInstruction.Aid));

            header.WriteTo(xmlWriter);

            //<feedGenerationFileLineItem isIncluded="true" catalog="books" storedProcedureName="uspCJFeedBooks" catalogattributesection="booksattributes" ranges="00-04;05-09" />
            foreach (var fileComponent in fileInstruction.LineItems)
            {
                WriteFileComponent(xmlWriter, fileComponent, ref countRec);
            }

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
        }
        /// <summary>
        /// creates feed file name based on supplied identifier. creates folder if does not exist
        /// </summary>
        /// <param name="fileInstruction"></param>
        /// <returns>feed file path</returns>
        private static string GetFeedFileName(FeedGenerationFileInstruction fileInstruction)
        {
            //feed file name
            var fileName = String.Format(FileNameFormat, fileInstruction.Key);

            if (!Directory.Exists(OutputFolderPath))
            {
                Directory.CreateDirectory(OutputFolderPath);
            }
            return(Path.Combine(OutputFolderPath, fileName));
        }
示例#3
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            var result = new FeedGenerationFileInstructionsConfigurationSection {
                FeedGenerationFileInstructions = new List <FeedGenerationFileInstruction>()
            };

            if (section.ChildNodes.Count == 0)
            {
                return(result);
            }

            foreach (XmlNode childNode in section.ChildNodes)
            {
                if (childNode.Attributes == null || childNode.Attributes["key"] == null)
                {
                    continue;
                }

                var fileInstruction = new FeedGenerationFileInstruction {
                    Key = childNode.Attributes["key"].Value, Aid = childNode.Attributes["aid"].Value, LineItems = new List <FeedGenerationFileLineItem>()
                };
                foreach (XmlNode childNodeChild in childNode.ChildNodes)
                {
                    if (childNodeChild == null || childNodeChild.Attributes == null)
                    {
                        continue;
                    }

                    var lineItem = new FeedGenerationFileLineItem
                    {
                        Catalog = childNodeChild.Attributes["catalog"].Value,
                        Catalogattributesection = childNodeChild.Attributes["catalogattributesection"].Value,
                        IsIncluded          = bool.Parse(childNodeChild.Attributes["isIncluded"].Value),
                        RangeDatas          = childNodeChild.Attributes["ranges"].Value,
                        StoredProcedureName = childNodeChild.Attributes["storedProcedureName"].Value
                    };

                    fileInstruction.LineItems.Add(lineItem);
                }

                result.FeedGenerationFileInstructions.Add(fileInstruction);
            }
            return(result);
        }
        private void GenerateFeedFile(FeedGenerationFileInstruction fileInstruction)
        {
            var feedFilePath = GetFeedFileName(fileInstruction);

            try
            {
                Log.DebugFormat("[WriteFeedFile] {0} start", feedFilePath);
                //create gzip archive stream
                if (GzipFiles)
                {
                    using (var gzipOut = new GZipStream(File.Create(feedFilePath + ".gz"), CompressionMode.Compress))
                    {
                        using (var xmlWriter = XmlWriter.Create(gzipOut, new XmlWriterSettings {
                            Indent = true
                        }))
                        {
                            WriteFeedFile(xmlWriter, fileInstruction);
                        } //end using
                    }
                }
                else
                {
                    using (var xmlWriter = XmlWriter.Create(feedFilePath, new XmlWriterSettings {
                        Indent = true
                    }))
                    {
                        WriteFeedFile(xmlWriter, fileInstruction);
                    } //end using
                }
                _executionLogLogger.AddFileGenerationUpdate(feedFilePath, true);
            }
            catch (Exception ex)
            {
                Log.Error("Error generating a feed file.", ex);
                _executionLogLogger.AddFileGenerationUpdate(feedFilePath, false);
                _hasError = true;
            }
        }