示例#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());
                }
        }
示例#2
0
 public void CopySite(
     [Argument("site", "s", Description = "The root http address of the website to copy.")]
     string original,
     [Argument("target", "t", Description = "The root http address of the destination website.")]
     string target,
     [Argument("overwrite", "y", DefaultValue = false, Description = "True to overwrite any existing content.")]
     bool overwrite)
 {
     using (SiteConverter index = new SiteConverter(StoragePath(original), original))
     using (ContentStorage writer = new ContentStorage(StoragePath(target), false))
     {
         index.Overwrite = overwrite;
         index.ConvertTo(target, writer);
     }
 }