コード例 #1
0
        /** -------------------------------------------------------------------- **/

        private void CallbackSaveGeneratorSitemapTextPerHost(object sender, EventArgs e)
        {
            SaveFileDialog Dialog = new SaveFileDialog();

            Dialog.Filter           = "Sitemap Text files (*.txt)|*.txt|All files (*.*)|*.*";
            Dialog.FilterIndex      = 2;
            Dialog.RestoreDirectory = true;
            Dialog.DefaultExt       = "txt";
            Dialog.AddExtension     = true;
            Dialog.FileName         = "Macroscope-Sitemap.txt";

            MacroscopeSitemapGenerator SitemapGenerator;

            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                string Pathname = Dialog.FileName;

                SitemapGenerator = new MacroscopeSitemapGenerator(
                    NewDocCollection: this.JobMaster.GetDocCollection()
                    );

                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    SitemapGenerator.WriteSitemapTextPerHost(NewPath: Pathname);
                    Cursor.Current = Cursors.Default;
                }
                catch (Exception ex)
                {
                    this.DialogueBoxError("Error saving Sitemap Text", ex.Message);
                }
            }

            Dialog.Dispose();
        }
コード例 #2
0
        /** -------------------------------------------------------------------- **/

        private void CallbackSaveGeneratorSitemapXmlPerHost(object sender, EventArgs e)
        {
            SaveFileDialog Dialog = new SaveFileDialog();

            Dialog.Filter           = "Sitemap XML files (*.xml)|*.xml|All files (*.*)|*.*";
            Dialog.FilterIndex      = 2;
            Dialog.RestoreDirectory = true;
            Dialog.DefaultExt       = "xml";
            Dialog.AddExtension     = true;
            Dialog.FileName         = "Macroscope-Sitemap.xml";

            MacroscopeSitemapGenerator SitemapGenerator;

            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                string Pathname = Dialog.FileName;

                Cursor.Current = Cursors.WaitCursor;

                SitemapGenerator = new MacroscopeSitemapGenerator(
                    NewDocCollection: this.JobMaster.GetDocCollection()
                    );

                try
                {
                    SitemapGenerator.WriteSitemapXmlPerHost(NewPath: Pathname);
                }
                catch (XmlException ex)
                {
                    this.DialogueBoxError("Error saving Sitemap XML for one or more hosts", ex.Message);
                }
                catch (MacroscopeSitemapException ex)
                {
                    this.DialogueBoxError("Error saving Sitemap XML", ex.Message);
                }
                catch (Exception ex)
                {
                    this.DialogueBoxError("Error saving Sitemap XML for one or more hosts", ex.Message);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
            else
            {
                this.DialogueBoxError("Error saving Sitemap XML", "Could not open file.");
            }

            if (Dialog != null)
            {
                Dialog.Dispose();
            }
        }
コード例 #3
0
 public void TestGenerateXmlSitemap()
 {
     foreach (string Url in this.Urls)
     {
         MacroscopeJobMaster          JobMaster        = new MacroscopeJobMaster(MacroscopeConstants.RunTimeMode.LIVE);
         MacroscopeDocumentCollection DocCollection    = new MacroscopeDocumentCollection(JobMaster: JobMaster);
         MacroscopeSitemapGenerator   SitemapGenerator = new MacroscopeSitemapGenerator(NewDocCollection: DocCollection);
         DocCollection.AddDocument(new MacroscopeDocument(JobMaster.SetStartUrl(Url: Url)));
         XmlDocument SitemapXML = SitemapGenerator.GenerateXmlSitemap(Host: new Uri(Url).Host);
         Assert.AreEqual("urlset", SitemapXML.DocumentElement.LocalName);
     }
 }
コード例 #4
0
        /** -------------------------------------------------------------------- **/

        private void CallbackSaveGeneratorSitemapXmlPerHost(object sender, EventArgs e)
        {
            SaveFileDialog Dialog = new SaveFileDialog();

            Dialog.Filter           = "Sitemap XML files (*.xml)|*.xml|All files (*.*)|*.*";
            Dialog.FilterIndex      = 2;
            Dialog.RestoreDirectory = true;
            Dialog.DefaultExt       = "xml";
            Dialog.AddExtension     = true;
            Dialog.FileName         = "Macroscope-Sitemap.xml";

            MacroscopeSitemapGenerator SitemapGenerator;

            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                string Pathname = Dialog.FileName;

                SitemapGenerator = new MacroscopeSitemapGenerator(
                    NewDocCollection: this.JobMaster.GetDocCollection()
                    );

                try
                {
                    if (Macroscope.MemoryGuard(RequiredMegabytes: 256))
                    {
                        Cursor.Current = Cursors.WaitCursor;
                        SitemapGenerator.WriteSitemapXmlPerHost(NewPath: Pathname);
                        Cursor.Current = Cursors.Default;
                    }
                }
                catch (MacroscopeInsufficientMemoryException ex)
                {
                    this.DialogueBoxError("Error saving Sitemap XML", ex.Message);
                    GC.Collect();
                }
                catch (XmlException ex)
                {
                    this.DialogueBoxError("Error saving Sitemap XML", ex.Message);
                    GC.Collect();
                }
                catch (Exception ex)
                {
                    this.DialogueBoxError("Error saving Sitemap XML", ex.Message);
                    GC.Collect();
                }
            }

            GC.Collect();

            Dialog.Dispose();
        }
コード例 #5
0
 public void TestWriteSitemapXml()
 {
     foreach (string Url in this.Urls)
     {
         MacroscopeJobMaster          JobMaster        = new MacroscopeJobMaster(MacroscopeConstants.RunTimeMode.LIVE);
         MacroscopeDocumentCollection DocCollection    = new MacroscopeDocumentCollection(JobMaster: JobMaster);
         MacroscopeSitemapGenerator   SitemapGenerator = new MacroscopeSitemapGenerator(NewDocCollection: DocCollection);
         DocCollection.AddDocument(new MacroscopeDocument(JobMaster.SetStartUrl(Url: Url)));
         string Filename = string.Join(".", Path.GetTempFileName(), ".xml");
         SitemapGenerator.WriteSitemapXml(NewPath: Filename);
         Assert.IsTrue(File.Exists(Filename));
         if (File.Exists(Filename))
         {
             File.Delete(Filename);
         }
     }
 }
コード例 #6
0
        public void TestWriteSitemapXmlWithEmptyDocCollection()
        {
            MacroscopeJobMaster          JobMaster        = new MacroscopeJobMaster(MacroscopeConstants.RunTimeMode.LIVE);
            MacroscopeDocumentCollection DocCollection    = new MacroscopeDocumentCollection(JobMaster: JobMaster);
            MacroscopeSitemapGenerator   SitemapGenerator = new MacroscopeSitemapGenerator(NewDocCollection: DocCollection);
            string Filename = string.Join(".", Path.GetTempFileName(), ".xml");

            try
            {
                SitemapGenerator.WriteSitemapXml(NewPath: Filename);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.GetType(), new MacroscopeSitemapException().GetType());
            }
            Assert.IsFalse(File.Exists(Filename));
            if (File.Exists(Filename))
            {
                File.Delete(Filename);
            }
        }