/*==========================================================================================================================
        | GET: /SITEMAP
        \-------------------------------------------------------------------------------------------------------------------------*/
        /// <summary>
        ///   Provides the Sitemap.org sitemap for the site.
        /// </summary>
        /// <param name="indent">Optionally enables indentation of XML elements in output for human readability.</param>
        /// <param name="includeMetadata">Optionally enables extended metadata associated with each topic.</param>
        /// <returns>A Sitemap.org sitemap.</returns>
        public virtual ActionResult Index(bool indent = false, bool includeMetadata = false)
        {
            /*------------------------------------------------------------------------------------------------------------------------
            | Ensure topics are loaded
            \-----------------------------------------------------------------------------------------------------------------------*/
            var rootTopic = _topicRepository.Load();

            Contract.Assume(
                rootTopic,
                $"The topic graph could not be successfully loaded from the {nameof(ITopicRepository)} instance. The " +
                $"{nameof(SitemapController)} is unable to establish a local copy to work off of."
                );

            /*------------------------------------------------------------------------------------------------------------------------
            | Establish sitemap
            \-----------------------------------------------------------------------------------------------------------------------*/
            var declaration = new XDeclaration("1.0", "utf-8", "no");
            var sitemap     = GenerateSitemap(rootTopic, includeMetadata);
            var settings    = indent? SaveOptions.None : SaveOptions.DisableFormatting;

            /*------------------------------------------------------------------------------------------------------------------------
            | Return the homepage view
            \-----------------------------------------------------------------------------------------------------------------------*/
            return(Content(declaration.ToString() + sitemap.ToString(settings), "text/xml"));
        }
        protected override async Task <string> CreateStructureAsync(IEnumerable <Sentence> sentences)
        {
            var header = new XDeclaration(version: "1.0", encoding: "utf-8", standalone: "yes");
            var doc    = new XDocument( // xml -> xsd, xmlsoap -> wsdl, xslt (transformata)
                new XElement("text",
                             from sentence in sentences
                             select new XElement("sentence",
                                                 from word in sentence.Words
                                                 select new XElement("word", word)//SecurityElement.Escape(word).Replace("\'", "&apos;"))
                                                 )));

            var text = doc.ToString()
                       .Replace("&amp;", "&amp;amp;")
                       .Replace("&lt;", "&amp;lt;")
                       .Replace("&gt;", "&amp;gt;")
                       .Replace("\'", "&amp;apos;")
                       .Replace("\"", "&amp;quot;");

            var xml = new StringWriterUtf8();
            await xml.WriteAsync(header.ToString() + "\r\n" + text);

            var ooo = xml.ToString();

            return(await Task.FromResult(ooo));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the sitemap XML document for the specified set of nodes.
        /// </summary>
        /// <param name="nodes">The sitemap nodes.</param>
        /// <returns>The sitemap XML document for the specified set of nodes.</returns>
        private string GetSitemapDocument(IEnumerable <XmlSitemapNode> nodes)
        {
            //var languages = _languageService.GetAllLanguages();

            XNamespace ns    = SitemapsNamespace;
            XNamespace xhtml = XhtmlNamespace;

            XElement root = new XElement(
                ns + "urlset",
                new XAttribute(XNamespace.Xmlns + "xhtml", xhtml));

            foreach (var node in nodes)
            {
                // url
                var xel = new XElement
                          (
                    ns + "url",
                    // url/loc
                    new XElement(ns + "loc", node.Loc),
                    // url/lastmod
                    node.LastMod == null ? null : new XElement(
                        ns + "lastmod",
                        node.LastMod.Value.ToLocalTime().ToString("yyyy-MM-ddTHH:mm:sszzz")),
                    // url/changefreq
                    node.ChangeFreq == null ? null : new XElement(
                        ns + "changefreq",
                        node.ChangeFreq.Value.ToString().ToLowerInvariant()),
                    // url/priority
                    node.Priority == null ? null : new XElement(
                        ns + "priority",
                        node.Priority.Value.ToString("F1", CultureInfo.InvariantCulture))
                          );

                if (node.Links != null)
                {
                    foreach (var entry in node.Links)
                    {
                        // url/xhtml:link[culture]
                        xel.Add(new XElement
                                (
                                    xhtml + "link",
                                    new XAttribute("rel", "alternate"),
                                    new XAttribute("hreflang", entry.Lang),
                                    new XAttribute("href", entry.Href)
                                ));
                    }
                }

                root.Add(xel);
            }

            XDeclaration declaration = new XDeclaration("1.0", "UTF-8", "yes");
            XDocument    document    = new XDocument(root);
            var          xml         = declaration.ToString() + document.ToString(SaveOptions.DisableFormatting);

            CheckDocumentSize(xml);

            return(xml);
        }
Exemplo n.º 4
0
        public override string ToString()
        {
            String temp = "";

            if (xmlDeclaration != null || xmlDeclaration.ToString() != "")
            {
                temp = xmlDeclaration + "\n";
            }

            temp += rootElem.ToString();

            return(temp);
        }
Exemplo n.º 5
0
        /// <summary>
        /// I was not able to generate an utf-8 XML string.
        /// This method generates the XML without an xml header and add the
        /// header manually.
        /// </summary>
        /// <param name="document">An XML Document</param>
        /// <returns>Serialized XML as string</returns>
        public static async Task <string> ToFullString(this XDocument document)
        {
            var test = document.Declaration.ToString();

            StringBuilder builder = new StringBuilder();

            builder.AppendLine(xmlDeclaration.ToString());

            using (TextWriter textWriter = new StringWriter(builder))
                using (var xmlWriter = XmlWriter.Create(textWriter, xmlSettings))
                {
                    await document.SaveAsync(xmlWriter, CancellationToken.None);
                }

            return(builder.ToString());
        }
Exemplo n.º 6
0
        public static string SvgObjectToXaml(object obj, bool includeRuntime, XamlWriteOptions options)
        {
            string xamlUntidy = WpfObjToXaml(obj, includeRuntime);

            XDocument doc = XDocument.Parse(xamlUntidy);

            BeautifyDrawingElement(doc.Root, options.Name);
            string xaml = doc.ToString();

            if (options.IncludeXmlDeclaration)
            {
                XDeclaration declaration = new XDeclaration("1.0", "UTF-8", null);
                xaml = declaration.ToString() + Environment.NewLine + xaml;
            }

            if (!options.IncludeNamespaces)
            {
                xaml = RemoveNamespaceDeclarations(xaml);
            }

            return(xaml);
        }
        public string Export(ProductCatalog catalog)
        {
            // Get a list of all the locales that have a value for at least one
            // product, and are valid for Apple export. Order must be preserved
            // throughout this method, so this is converted to a list and then
            // wrapped in a ReadOnlyCollection to prevent mutation.
            var          localesToExport = new ReadOnlyCollection <TranslationLocale>(new List <TranslationLocale>(GetLocalesToExport(catalog)));
            XDeclaration declaration     = new XDeclaration("1.0", "utf-8", "yes");
            XDocument    document        = new XDocument();
            XNamespace   ns      = "http://apple.com/itunes/importer";
            XElement     package = new XElement(ns + "package",
                                                new XAttribute("version", "software5.7"));

            document.Add(package);
            package.Add(new XElement(ns + "provider", catalog.appleTeamID));
            package.Add(new XElement(ns + "team_id", catalog.appleTeamID));
            XElement software = new XElement(ns + "software");

            package.Add(software);
            software.Add(new XElement(ns + "vendor_id", catalog.appleSKU));
            XElement softwareMetadata = new XElement(ns + "software_metadata");

            software.Add(softwareMetadata);
            XElement inAppPurchases = new XElement(ns + "in_app_purchases");

            softwareMetadata.Add(inAppPurchases);

            foreach (var item in catalog.allProducts)
            {
                XElement inAppPurchase = new XElement(ns + "in_app_purchase",
                                                      new XElement(ns + "product_id", item.GetStoreID(AppleAppStore.Name) ?? item.id),
                                                      new XElement(ns + "reference_name", item.id),
                                                      new XElement(ns + "type", ProductTypeString(item)));
                XElement products = new XElement(ns + "products");
                inAppPurchase.Add(products);
                XElement product = new XElement(ns + "product",
                                                new XElement(ns + "cleared_for_sale", true),
                                                new XElement(ns + "wholesale_price_tier", item.applePriceTier));
                products.Add(product);

                XElement locales = new XElement(ns + "locales");
                inAppPurchase.Add(locales);
                // Variable number of localizations, not every product will specify a localization for every language
                // so some of the these descriptions may be missing, in which case we just skip it.
                foreach (var loc in localesToExport)
                {
                    LocalizedProductDescription desc = item.defaultDescription.googleLocale == loc ? item.defaultDescription : item.GetDescription(loc);
                    if (desc != null)
                    {
                        XElement locale = new XElement(ns + "locale",
                                                       new XAttribute("name", LocaleToAppleString(loc)),
                                                       new XElement(ns + "title", desc.Title),
                                                       new XElement(ns + "description", desc.Description));
                        locales.Add(locale);
                    }
                }

                XElement reviewScreenshot = new XElement(ns + "review_screenshot");
                inAppPurchase.Add(reviewScreenshot);
                reviewScreenshot.Add(new XElement(ns + "file_name", Path.GetFileName(item.screenshotPath)));
                FileInfo fileInfo = new FileInfo(item.screenshotPath);
                if (fileInfo.Exists)
                {
                    reviewScreenshot.Add(new XElement(ns + "size", fileInfo.Length));
                    reviewScreenshot.Add(new XElement(ns + "checksum", GetMD5Hash(fileInfo)));
                }

                inAppPurchases.Add(inAppPurchase);
            }
            // Split the declaration and the document because we want UTF-8, not UTF-16.
            return(declaration.ToString() + kNewLine + document.ToString());
        }