Example #1
0
        public void Import(
            [Argument("page", "p", Description = "The full http address of the page to save the source content to.")]
            string targetLink,
            [Argument("source", "s", Description = "The full http address of the page you want to import.")]
            string sourceLink,
            [Argument("recursive", "r", DefaultValue = false, Description = "True to recursivly import all links within the same domain.")]
            bool recursive,
            [Argument("noprompt", "q", DefaultValue = false, Description = "True to stop prompt for confirmation before overwriting content.")]
            bool noPrompt
            )
        {
            Uri targetUri = new Uri(targetLink, UriKind.Absolute);

            using (TempDirectory tempFolder = new TempDirectory())
                using (ContentStorage writer = new ContentStorage(StoragePath(targetLink), false))
                {
                    bool exists = writer.ContainsKey(targetUri.NormalizedPathAndQuery());
                    if (exists)
                    {
                        if (!noPrompt && !new ConfirmPrompt().Continue("Overwrite " + targetUri.NormalizedPathAndQuery()))
                        {
                            return;
                        }
                    }

                    Uri sourceUri = new Uri(sourceLink, UriKind.Absolute);
                    using (SiteCollector index = new SiteCollector(tempFolder.TempPath, sourceLink))
                    {
                        index.NoDefaultPages       = true;
                        index.UpdateSearchTemplate = false;
                        if (recursive)
                        {
                            index.CrawlSite();
                        }
                        else
                        {
                            index.AddUrlsFound = false;
                            index.CrawlPage(sourceUri.NormalizedPathAndQuery());
                        }
                    }

                    using (SiteConverter index = new SiteConverter(tempFolder.TempPath, sourceLink))
                    {
                        index.Overwrite = true;
                        index.ConvertTo(targetLink, writer);
                    }

                    if (exists)
                    {
                        writer.Remove(targetUri.NormalizedPathAndQuery());
                    }
                    writer.Rename(sourceUri.NormalizedPathAndQuery(), targetUri.NormalizedPathAndQuery());
                }
        }
Example #2
0
 public void CrawlSite(
     [Argument("site", "s", Description = "The root http address of the website copy.")]
     string site)
 {
     using (SiteCollector index = new SiteCollector(StoragePath(site), site))
     {
         index.MaxCrawlAge = TimeSpan.FromMinutes(1);
         if (!index.CrawlSite())
         {
             Console.Error.WriteLine("Not Modified.");
             Environment.ExitCode = 1;
         }
     }
 }