Exemplo n.º 1
0
        internal static void PivotizeTag(Tag tag, IEnumerable <StreamReader> streamReaders, Stream destination, string siteDomain)
        {
            XDocument           doc;
            XmlNamespaceManager namespaceManager;

            using (var stream = AssemblyExtensions.OpenScopedResourceStream <Program> ("Template.cxml"))
                using (var reader = XmlReader.Create(stream, ReaderSettings))
                {
                    doc = XDocument.Load(reader);
                    namespaceManager = new XmlNamespaceManager(reader.NameTable);
                    namespaceManager.AddNamespace("c", CollectionNamespace.NamespaceName);
                    namespaceManager.AddNamespace("p", PivotNamespace.NamespaceName);
                }
            var collectionNode = doc.Root;

            Debug.Assert(collectionNode != null);
            collectionNode.SetAttributeValue("Name", "Tagged Questions: {0}".FormatInvariant(tag.Name));
            // TODO: do we want to strip hyphens from tag for AdditionalSearchText?
            collectionNode.SetAttributeValue(PivotNamespace + "AdditionalSearchText", tag.Name);

            var itemsNode = collectionNode.XPathSelectElement("c:Items", namespaceManager);

            itemsNode.SetAttributeValue("HrefBase", "http://{0}/questions/".FormatInvariant(siteDomain));
            itemsNode.SetAttributeValue("ImgBase", Path.ChangeExtension(tag.Name, ".dzc"));
            using (var writer = new CollectionWriter(destination, WriterSettings, futureCw =>
            {
                futureCw.Flush();
                var sw = new StreamWriter(destination);
                foreach (var sr in streamReaders)
                {
                    foreach (var line in sr.Lines())
                    {
#if DEBUG
                        sw.WriteLine(line);
#else
                        sw.Write(line);
#endif
                    }
                    sr.Close();
                }
                sw.Flush();
            })
                   )
            {
                doc.Save(writer);
            }
        }
        public void PivotizeTag (Tag tag, IEnumerable<StreamReader> streamReaders, Stream destination)
        {
            XDocument doc;
            XmlNamespaceManager namespaceManager;
            using (var stream = AssemblyExtensions.OpenScopedResourceStream<DeepZoomCollection> ("Template.cxml"))
            using (var reader = XmlReader.Create (stream, _settings.XmlReaderSettings))
            {
                doc = XDocument.Load (reader);
                namespaceManager = new XmlNamespaceManager(reader.NameTable);
                namespaceManager.AddNamespace("c", Namespaces.Collection.NamespaceName);
                namespaceManager.AddNamespace("p", Namespaces.Pivot.NamespaceName);
            }
            var collectionNode = doc.Root;
            Debug.Assert(collectionNode != null);
            collectionNode.SetAttributeValue ("Name", "Tagged Questions: {0}".FormatInvariant (tag.Name));
            // TODO: do we want to strip hyphens from tag for AdditionalSearchText?
            collectionNode.SetAttributeValue (Namespaces.Pivot + "AdditionalSearchText", tag.Name);

            var itemsNode = collectionNode.XPathSelectElement ("c:Items", namespaceManager);
            itemsNode.SetAttributeValue ("HrefBase", "http://{0}/questions/".FormatInvariant (_settings.SiteDomain));
            itemsNode.SetAttributeValue ("ImgBase", Path.ChangeExtension (tag.Name, ".dzc"));
            using (var writer = new CollectionWriter (destination, _settings.XmlWriterSettings, futureCw =>
                {
                    futureCw.Flush ();
                    var sw = new StreamWriter (destination);
                    foreach (var sr in streamReaders)
                    {
                        foreach (var line in sr.Lines())
                        {
#if DEBUG
                            sw.WriteLine (line);
#else
                            sw.Write (line);
#endif
                        }
                        sr.Close ();
                    }
                    sw.Flush ();
                })
            )
            {
                doc.Save (writer);
            }
        }