Ejemplo n.º 1
0
 protected virtual void CheckFileSize(SitemapIndexInfo info, string path)
 {
     if (new FileInfo(path).Length > SitemapIndexInfo.MAX_FILE_SIZE)
     {
         throw new ArgumentOutOfRangeException("info", string.Format("size of a sitemap index file greater than {0}.", SitemapIndexInfo.MAX_FILE_SIZE));
     }
 }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public virtual void Serialize(SitemapIndexInfo info, string path)
        {
            this.CheckArguments(info, path);

            XmlSerializer           serializer = new XmlSerializer(typeof(SitemapIndexInfo));
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add(string.Empty, "http://www.sitemaps.org/schemas/sitemap/0.9");
            using (TextWriter writer = new StreamWriter(path, false, Encoding.UTF8)) {
                serializer.Serialize(writer, info, namespaces);
            }

            this.CheckFileSize(info, path);
        }
Ejemplo n.º 3
0
        protected virtual void CheckArguments(SitemapIndexInfo info, string path)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("path is null or empty.", "path");
            }
            if (info.Items.Count > SitemapIndexInfo.MAX_ITEMS_COUNT)
            {
                throw new ArgumentOutOfRangeException("info", string.Format("number of items in a sitemap index file greater than {0}.", SitemapIndexInfo.MAX_ITEMS_COUNT));
            }

            FileUtility.CreateFolder(path);
        }