Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string oldText = @"<p><i>This is</i> some sample text to <strong>demonstrate</strong> the capability of the <strong>HTML diff tool</strong>.</p>
                                <p>It is based on the <b>Ruby</b> implementation found <a href='http://github.com/myobie/htmldiff'>here</a>. Note how the link has no tooltip</p>
                                <p>What about a number change: 123456?</p>
                                <table cellpadding='0' cellspacing='0'>
                                <tr><td>Some sample text</td><td>Some sample value</td></tr>
                                <tr><td>Data 1 (this row will be removed)</td><td>Data 2</td></tr>
                                </table>
                                Here is a number 2 32";

            string newText = @"<p>This is some sample <strong>text to</strong> demonstrate the awesome capabilities of the <strong>HTML <u>diff</u> tool</strong>.</p><br/><br/>Extra spacing here that was not here before.
                                <p>It is <i>based</i> on the Ruby implementation found <a title='Cool tooltip' href='http://github.com/myobie/htmldiff'>here</a>. Note how the link has a tooltip now and the HTML diff algorithm has preserved formatting.</p>
                                <p>What about a number change: 123356?</p>
                                <table cellpadding='0' cellspacing='0'>
                                <tr><td>Some sample <strong>bold text</strong></td><td>Some sample value</td></tr>
                                </table>
                                Here is a number 2 <sup>32</sup>";

            HtmlDiff diffHelper = new HtmlDiff(oldText, newText);
            litOldText.Text = oldText;
            litNewText.Text = newText;
            litDiffText.Text = diffHelper.Build();
        }
Ejemplo n.º 2
0
        private void ShowVsHistory()
        {
            HtmlContent html = repository.Fetch(moduleId);
            ContentHistory history = new ContentHistory(historyGuid);
            if (history.ContentGuid != html.ModuleGuid) { return; }

            litCurrentHeading.Text = string.Format(Resource.CurrentVersionHeadingFormat,
                DateTimeHelper.Format(html.LastModUtc, timeZone, "g", timeOffset));

            if ((HtmlConfiguration.UseHtmlDiff)&&(highlightDiff))
            {
                HtmlDiff diffHelper = new HtmlDiff(history.ContentText, html.Body);
                litCurrentVersion.Text = diffHelper.Build();
            }
            else
            {
                litCurrentVersion.Text = html.Body;
            }

            litHistoryHead.Text = string.Format(Resource.VersionAsOfHeadingFormat,
                DateTimeHelper.Format(history.CreatedUtc, timeZone, "g", timeOffset));

            litHistoryVersion.Text = history.ContentText;

            string onClick = "top.window.LoadHistoryInEditor('" + historyGuid.ToString() + "');  return false;";
            btnRestore.Attributes.Add("onclick", onClick);
        }
Ejemplo n.º 3
0
        private void ShowVsDraft()
        {
            HtmlContent html = repository.Fetch(moduleId);

            if (html == null) { return; }

            ContentWorkflow draftContent = ContentWorkflow.GetWorkInProgress(html.ModuleGuid);

            if (draftContent.Guid != workflowGuid) { return; }

            if ((HtmlConfiguration.UseHtmlDiff)&&(highlightDiff))
            {
                HtmlDiff diffHelper = new HtmlDiff(html.Body, draftContent.ContentText);
                litCurrentVersion.Text = diffHelper.Build();
            }
            else
            {
                litCurrentVersion.Text = draftContent.ContentText;
            }

            litCurrentHeading.Text = string.Format(Resource.CurrentDraftHeadingFormat,
                DateTimeHelper.Format(draftContent.RecentActionOn, timeZone, "g", timeOffset));

            litHistoryHead.Text = string.Format(Resource.CurrentVersionHeadingFormat,
                DateTimeHelper.Format(html.LastModUtc, timeZone, "g", timeOffset));

            litHistoryVersion.Text = html.Body;

            //string onClick = "top.window.LoadHistoryInEditor('" + historyGuid.ToString() + "');  return false;";
            //btnRestore.Attributes.Add("onclick", onClick);
            btnRestore.Visible = false;
        }
Ejemplo n.º 4
0
        private void PopulateControls()
        {
            if (moduleId == -1) { return; }
            if (itemId == -1) { return; }
            //if (module == null) { return; }
            if (historyGuid == Guid.Empty) { return; }

            Blog blog = new Blog(itemId);
            if (blog.ModuleId != moduleId)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }

            ContentHistory history = new ContentHistory(historyGuid);
            if (history.ContentGuid != blog.BlogGuid) { return; }

            litCurrentHeading.Text = string.Format(BlogResources.CurrentVersionHeadingFormat,
                DateTimeHelper.Format(blog.LastModUtc, timeZone, "g", timeOffset));

            if (BlogConfiguration.UseHtmlDiff)
            {
                HtmlDiff diffHelper = new HtmlDiff(history.ContentText, blog.Description);
                litCurrentVersion.Text = diffHelper.Build();
            }
            else
            {
                litCurrentVersion.Text = blog.Description;
            }

            litHistoryHead.Text = string.Format(BlogResources.VersionAsOfHeadingFormat,
                DateTimeHelper.Format(history.CreatedUtc, timeZone, "g", timeOffset));

            litHistoryVersion.Text = history.ContentText;

            string onClick = "top.window.LoadHistoryInEditor('" + historyGuid.ToString() + "');  return false;";
            btnRestore.Attributes.Add("onclick", onClick);
        }
Ejemplo n.º 5
0
        public ActionResult Compare(string path, int first, int second)
        {
            var page = _repository.Get(new PagePath(path));

            var id1 = Math.Min(first, second);
            var id2 = Math.Max(first, second);

            var diff1 = page.Revisions.First(k => k.Id == id1).HtmlBody;
            var diff2 = page.Revisions.First(k => k.Id == id2).HtmlBody;

            var differ = new HtmlDiff(diff1, diff2);
            return Json(new
                            {
                                success = true,
                                content = differ.Build()
                            }, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 6
-3
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .ReadFrom.AppSettings()
                .CreateLogger();
            var log = Log.Logger.ForContext<Crufty.CruftyConsole>();

            // get list of all courts to process
            var client = new MongoClient(ConfigurationManager.AppSettings["MongoServer"]);
            var database = client.GetDatabase("CourtCruft");
            var collection = database.GetCollection<CourtWebsite>("CourtWebsites");
            List<CourtWebsite> documents = new List<CourtWebsite>();
            Task.Run(async () =>
            {
                documents = await collection.Find(new BsonDocument()).ToListAsync();
            }).Wait();

            // loop over list of courts and scrape them.
            foreach (var courtWebsite in documents)
            {
                try
                {
                    // wrap in error handling so we catch 404s and "network down"
                    ScrapingBrowser browser = new ScrapingBrowser();
                    WebPage homePage = browser.NavigateToPage(new Uri(courtWebsite.Url));

                    //PageWebForm form = homePage.FindFormById("sb_form");
                    //form["q"] = "scrapysharp";
                    //form.Method = HttpVerb.Get;
                    //WebPage resultsPage = form.Submit();

                    // if no xpath filter, just grab the whole page
                    var currentPage = (String.IsNullOrEmpty(courtWebsite.SelectionXPathString)) ?
                        homePage.Html.InnerHtml
                        :homePage.Html.SelectSingleNode(courtWebsite.SelectionXPathString).InnerHtml;

                    if (String.IsNullOrWhiteSpace(currentPage))
                    {
                        log.Error("Unable to find {XPath} in {Url}", courtWebsite.SelectionXPathString, courtWebsite.Url);
                        continue;
                    }

                    if (courtWebsite.NewPageHtml != currentPage)
                    {
                        HtmlDiff diffHelper = new HtmlDiff(courtWebsite.NewPageHtml, currentPage);
                        courtWebsite.DiffedHtml = diffHelper.Build().Insert(0, "<style>ins {background-color: #cfc;text-decoration: none;} del {    color: #999;    background-color:#FEC8C8;</style>");
                        courtWebsite.OldPageHtml = courtWebsite.NewPageHtml;
                        courtWebsite.NewPageHtml = currentPage;
                        courtWebsite.LastChangedDateTime = DateTime.Now;
                        courtWebsite.Checked = false;

                        log.Information("Changes found for {CourtName}", courtWebsite.CourtName);
                    }

                    courtWebsite.LastRunDateTime = DateTime.Now;

                    var filter = Builders<CourtWebsite>.Filter.Eq(s => s.Id, courtWebsite.Id);
                    Task.Run(async () =>
                    {
                        await collection.ReplaceOneAsync(filter, courtWebsite);
                    }).Wait();

                    log.Verbose("Successfully scraped site {CourtName}", courtWebsite.CourtName);
                }
                catch (WebException exception)
                {
                    log.Error(exception, "Web Exception for {CourtName} (check the url) {ExceptionMessage} {url}", courtWebsite.CourtName, exception.Message, courtWebsite.Url);
                }
                catch (Exception exception)
                {
                    log.With("CourtWebsite", courtWebsite)
                        .Error(exception, "General Exception for {CourtName} {ExceptionMessage}", courtWebsite.CourtName, exception.Message);
                }
            }
        }