-
Notifications
You must be signed in to change notification settings - Fork 104
Async version, remove depenency on RazorLight, implemented IDisposable #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mikaelliljedahl
wants to merge
9
commits into
SimpleBrowserDotNet:master
Choose a base branch
from
mikaelliljedahl:PreparePRToMainProject
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
44d97a2
Remove calls to HtmlLogFormatter depending on RazorLight.
mikaelliljedahl d39fc3f
Merge pull request #1 from mikaelliljedahl/NoLogging
mikaelliljedahl 1686069
Added Async versions of all calls
mikaelliljedahl 7648b63
Merge pull request #2 from mikaelliljedahl/NoLogging
mikaelliljedahl 202aa2f
rewritten tests. Unfortunately not all of them pass
mikaelliljedahl f8d0f3e
Update readme.md
mikaelliljedahl 907346d
reverted some changes in csproj and set version 0.7.0 in nuspec
mikaelliljedahl 4bd9715
Fixes for failed tests including getting back commented code in Frame…
mikaelliljedahl 9f2b045
moved MaxRedirects to be a property with default value according to R…
mikaelliljedahl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,15 @@ namespace Sample | |
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using RazorEngine.Templating; | ||
using SimpleBrowser; | ||
|
||
internal class Program | ||
{ | ||
private static void Main(string[] args) | ||
private static async Task Main(string[] args) | ||
{ | ||
Browser browser = new Browser(); | ||
using Browser browser = new Browser(); | ||
try | ||
{ | ||
// log the browser request/response data to files so we can interrogate them in case of an issue with our scraping | ||
|
@@ -27,7 +29,7 @@ private static void Main(string[] args) | |
browser.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10"; | ||
|
||
// browse to GitHub | ||
browser.Navigate("http://github.com/"); | ||
await browser.NavigateAsync("http://github.com/"); | ||
if (LastRequestFailed(browser)) | ||
{ | ||
// always check the last request in case the page failed to load | ||
|
@@ -43,7 +45,7 @@ private static void Main(string[] args) | |
} | ||
else | ||
{ | ||
loginLink.Click(); | ||
await loginLink.ClickAsync(); | ||
if (LastRequestFailed(browser)) | ||
{ | ||
return; | ||
|
@@ -52,7 +54,7 @@ private static void Main(string[] args) | |
// fill in the form and click the login button - the fields are easy to locate because they have ID attributes | ||
browser.Find("login_field").Value = "[email protected]"; | ||
browser.Find("password").Value = "yourpassword"; | ||
browser.Find(ElementType.Button, "name", "commit").Click(); | ||
await browser.Find(ElementType.Button, "name", "commit").ClickAsync(); | ||
if (LastRequestFailed(browser)) | ||
{ | ||
return; | ||
|
@@ -89,7 +91,9 @@ private static void Main(string[] args) | |
} | ||
finally | ||
{ | ||
string path = WriteFile("log-" + DateTime.UtcNow.Ticks + ".html", browser.RenderHtmlLogFile("SimpleBrowser Sample - Request Log")); | ||
RenderService rsvc = new RenderService(); | ||
|
||
string path = WriteFile("log-" + DateTime.UtcNow.Ticks + ".html", browser.RenderHtmlLogFile( rsvc, "SimpleBrowser Sample - Request Log")); | ||
|
||
Console.WriteLine("Log file published to:"); | ||
Console.WriteLine(path); | ||
|
@@ -135,4 +139,13 @@ private static string WriteFile(string filename, string text) | |
return path; | ||
} | ||
} | ||
|
||
public class RenderService : HtmlLogFormatter.IViewRenderService | ||
{ | ||
public string RenderToString<TModel>(string template, string title, TModel model) | ||
{ | ||
|
||
return RazorEngine.Engine.Razor.RunCompile(template, title, model.GetType(), model); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand this solution. It looks like RazorLight has simply been replaced by RazorEngine. Was that the intention? I thought you wanted to be able to create a production library that didn't include a dependency on Razor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention was to remove the dependency from the library, so I used a dependency injection pattern (using the IViewRenderService interface that only implements this method). In the sample program (which is not part of the nuget) I just show that RazorEngine could be used to render the log to string, but anything that implements the interface can be used. And if you like to use RazorLight, go ahead. The Interface doesn't care.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this as a step to move forward. I removed the dependency on RazorLight from SimpleBrowser and put all of the rendering stuff into a separate library by implementing the interface and setting the renderer in SimpleBrowser. This way, any renderer can be implemented - razor, json, email, etc.