示例#1
0
 public static void Generate(YmlCatalog catalog, string outputFileName)
 {
     var serializer = new XmlSerializer(typeof(YmlCatalog), "");
     File.Delete(outputFileName);
     using (Stream textWriter = File.OpenWrite(outputFileName))
     {
         using (var writer = new XmlTextWriter(textWriter, null))
         {
             var ns = new XmlSerializerNamespaces();
             ns.Add("", "");
             writer.Formatting = Formatting.Indented;
             writer.WriteStartDocument();
             writer.WriteDocType("yml_catalog", null, "shops.dtd", null);
             serializer.Serialize(writer, catalog, ns);
         }
     }
 }
        public void GenerateYml()
        {
            var catalog = new YmlCatalog
            {
                Date = DateTime.Now
            };
            var shop = new Shop();
            catalog.Shop = shop;

            const String netpingRu = "Netping.ru";
            shop.Name = netpingRu;
            shop.Company = netpingRu;
            shop.Url = "http://www.netping.ru";
            shop.Currencies.Add(new Currency
            {
                Id = "RUR",
                Rate = 1,
                Plus = 0
            });

            var tree = new DevicesTree(_dataRepository.Devices);

            foreach (var categoryNode in tree.Nodes)
            {
                shop.Categories.Add(new Category
                {
                    Id = categoryNode.Id,
                    Name = categoryNode.Name,
                    ParentId = categoryNode.Parent == null ? (Int32?)null : categoryNode.Parent.Id
                });

                foreach (var childCategoryNode in categoryNode.Nodes)
                {
                    AddOffers(childCategoryNode, shop, categoryNode);
                }
            }

            shop.LocalDeliveryCost = 0;

            YmlGenerator.Generate(catalog, StaticFilePaths.CatalogFilePath);
        }