Skip to content
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

Retarget to latest VS SDK/Platform #6

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
9 changes: 3 additions & 6 deletions Example.Wpf/Example.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="LiteHtmlSharp.WPF">
<HintPath>..\LiteHtmlSharp.Wpf\bin\Debug\net45\LiteHtmlSharp.WPF.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -95,12 +98,6 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LiteHtmlSharp.Wpf\LiteHtmlSharp.Wpf.csproj">
<Project>{e1b78fe5-a0b8-4250-bfb5-f604f22550e2}</Project>
<Name>LiteHtmlSharp.Wpf</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
25 changes: 25 additions & 0 deletions Example.Wpf/Example.Wpf.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29521.150
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Wpf", "Example.Wpf.csproj", "{33B4D9F4-0DFE-4A85-9289-227BFC64ACBF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{33B4D9F4-0DFE-4A85-9289-227BFC64ACBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33B4D9F4-0DFE-4A85-9289-227BFC64ACBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33B4D9F4-0DFE-4A85-9289-227BFC64ACBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33B4D9F4-0DFE-4A85-9289-227BFC64ACBF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {10B2808D-C8D0-4058-9720-CE2AB6F32503}
EndGlobalSection
EndGlobal
249 changes: 128 additions & 121 deletions Example.Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using LiteHtmlSharp.Wpf;
using LiteHtmlSharp.Wpf;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
Expand All @@ -18,136 +19,142 @@

namespace Example.Wpf
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
WpfContainer _litehtmlContainer;
LiteHtmlPanel _liteHtmlPanel;
HttpClient _httpClient;
string _lastUrl;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
WpfContainer _litehtmlContainer;
LiteHtmlPanel _liteHtmlPanel;
HttpClient _httpClient;
string _lastUrl;

public MainWindow()
{
InitializeComponent();
var masterCss = IncludedMasterCss.CssString;
public MainWindow()
{
InitializeComponent();
var masterCss = IncludedMasterCss.CssString;

_httpClient = new HttpClient();
_httpClient = new HttpClient();

_litehtmlContainer = new WpfContainer(masterCss, GetResourceString, GetResourceBytes);
_liteHtmlPanel = new LiteHtmlPanel(ScrollViewer, _litehtmlContainer);
_liteHtmlPanel.LinkClicked += LiteHtmlPanel_LinkClicked;
_liteHtmlPanel.LoadHtml(@"
<html>
<head></head>
<body>
<div><a href='http://www.google.com'>google.com</a></div>
<div><a href='http://www.pingplotter.com'>pingplotter.com</a></div>
<br />
<div style='width:100px; height:100px; background-color:red'></div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam auctor nisi quis ultrices scelerisque.
Mauris imperdiet vehicula metus quis bibendum. Maecenas non erat quis est imperdiet vehicula. Proin
scelerisque mauris purus, elementum sodales tellus imperdiet id. Vivamus luctus lorem nec augue
porttitor, eu mattis nisl laoreet. Cras fringilla vel purus ut imperdiet. Donec luctus finibus elit,
eu elementum purus cursus a. Suspendisse mollis tristique leo a auctor. Vivamus pulvinar pretium
elementum. Donec purus sapien, consequat laoreet eros viverra, laoreet pulvinar ligula. Sed faucibus
nisl odio, sed facilisis odio scelerisque ut.
</p>
<p>
Nullam dapibus enim vel tortor luctus molestie. Vestibulum non sagittis leo, non vulputate magna.
Aliquam erat volutpat. Nulla hendrerit vel metus nec condimentum. Sed aliquet purus id ipsum interdum
ullamcorper. Nullam congue luctus urna eu bibendum. Morbi non tellus turpis. Mauris nec dui in massa
facilisis imperdiet. Proin metus purus, imperdiet ac laoreet vel, elementum ac nulla. Vivamus dolor
tellus, blandit auctor elementum id, mattis consequat tellus. Vivamus id maximus felis. Praesent
aliquet augue id metus rutrum maximus. Etiam et nulla eu lectus efficitur elementum. Integer porttitor
quis erat sit amet feugiat. In id magna mollis, viverra nibh at, sollicitudin leo.
</p>
</body>
</html>
");
}
_litehtmlContainer = new WpfContainer(masterCss, GetResourceString, GetResourceBytes);
_liteHtmlPanel = new LiteHtmlPanel(ScrollViewer, _litehtmlContainer);
_liteHtmlPanel.LinkClicked += LiteHtmlPanel_LinkClicked;
using (var reader = new StreamReader(@"C:\Users\ckindel\source\winprint\tests\Home.html", Encoding.UTF8))
{
_liteHtmlPanel.LoadHtml(reader.ReadToEnd());
}
// _liteHtmlPanel.LoadHtml(@"
// <html>
// <head></head>
// <body>
// <div><a href='http://www.google.com'>google.com</a></div>
// <div><a href='http://www.pingplotter.com'>pingplotter.com</a></div>
// <br />
// <div style='width:100px; height:100px; background-color:red'></div>
// <p>
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam auctor nisi quis ultrices scelerisque.
// Mauris imperdiet vehicula metus quis bibendum. Maecenas non erat quis est imperdiet vehicula. Proin
// scelerisque mauris purus, elementum sodales tellus imperdiet id. Vivamus luctus lorem nec augue
// porttitor, eu mattis nisl laoreet. Cras fringilla vel purus ut imperdiet. Donec luctus finibus elit,
// eu elementum purus cursus a. Suspendisse mollis tristique leo a auctor. Vivamus pulvinar pretium
// elementum. Donec purus sapien, consequat laoreet eros viverra, laoreet pulvinar ligula. Sed faucibus
// nisl odio, sed facilisis odio scelerisque ut.
// </p>
// <p>
// Nullam dapibus enim vel tortor luctus molestie. Vestibulum non sagittis leo, non vulputate magna.
// Aliquam erat volutpat. Nulla hendrerit vel metus nec condimentum. Sed aliquet purus id ipsum interdum
// ullamcorper. Nullam congue luctus urna eu bibendum. Morbi non tellus turpis. Mauris nec dui in massa
// facilisis imperdiet. Proin metus purus, imperdiet ac laoreet vel, elementum ac nulla. Vivamus dolor
// tellus, blandit auctor elementum id, mattis consequat tellus. Vivamus id maximus felis. Praesent
// aliquet augue id metus rutrum maximus. Etiam et nulla eu lectus efficitur elementum. Integer porttitor
// quis erat sit amet feugiat. In id magna mollis, viverra nibh at, sollicitudin leo.
// </p>
// </body>
// </html>
//");
}

private void LiteHtmlPanel_LinkClicked(string url)
{
if (url.StartsWith("http:") || url.StartsWith("https:"))
{
_lastUrl = url;
}
else
{
var builder = new UriBuilder(_lastUrl);
builder.Path = url;
_lastUrl = builder.ToString();
}
try
{
var pageContent = _httpClient.GetStringAsync(_lastUrl).Result;
_liteHtmlPanel.LoadHtml(pageContent);
}
catch (Exception ex)
{
MessageBox.Show("Error loading page. " + (ex.InnerException ?? ex).Message);
}
}
private void LiteHtmlPanel_LinkClicked(string url)
{
if (url.StartsWith("http:") || url.StartsWith("https:"))
{
_lastUrl = url;
}
else
{
var builder = new UriBuilder(_lastUrl);
builder.Path = url;
_lastUrl = builder.ToString();
}
try
{
var pageContent = _httpClient.GetStringAsync(_lastUrl).Result;
_liteHtmlPanel.LoadHtml(pageContent);
}
catch (Exception ex)
{
MessageBox.Show("Error loading page. " + (ex.InnerException ?? ex).Message);
}
}

public byte[] GetResourceBytes(string resource)
{
if (string.IsNullOrWhiteSpace(resource))
{
return new byte[0];
}
public byte[] GetResourceBytes(string resource)
{
if (string.IsNullOrWhiteSpace(resource))
{
return new byte[0];
}

try
{
var url = GetUrlForRequest(resource);
return _httpClient.GetByteArrayAsync(url).Result;
}
catch
{
return null;
}
}
try
{
var url = GetUrlForRequest(resource);
return _httpClient.GetByteArrayAsync(url).Result;
}
catch
{
return null;
}
}

public string GetResourceString(string resource)
{
if (string.IsNullOrWhiteSpace(resource))
{
return string.Empty;
}
try
{
var url = GetUrlForRequest(resource);
return _httpClient.GetStringAsync(url).Result;
}
catch
{
return null;
}
}
public string GetResourceString(string resource)
{
if (string.IsNullOrWhiteSpace(resource))
{
return string.Empty;
}
try
{
var url = GetUrlForRequest(resource);
string data = _httpClient.GetStringAsync(url).Result;
return data;
}
catch (Exception e)
{
Debug.WriteLine($"GetResourceString({resource} - {e.Message}");
return null;
}
}

string GetUrlForRequest(string resource)
{
try
{
UriBuilder urlBuilder;
if (resource.StartsWith("//") || resource.StartsWith("http:") || resource.StartsWith("https:"))
string GetUrlForRequest(string resource)
{
try
{
urlBuilder = new UriBuilder(resource.TrimStart(new char[] { '/' }));
UriBuilder urlBuilder;
if (resource.StartsWith("//") || resource.StartsWith("http:") || resource.StartsWith("https:"))
{
urlBuilder = new UriBuilder(resource.TrimStart(new char[] { '/' }));
}
else
{
urlBuilder = new UriBuilder(_lastUrl);
urlBuilder.Path = resource;
}
var requestUrl = urlBuilder.ToString();
return requestUrl;
}
else
catch
{
urlBuilder = new UriBuilder(_lastUrl);
urlBuilder.Path = resource;
return null;
}
var requestUrl = urlBuilder.ToString();
return requestUrl;
}
catch
{
return null;
}
}
}
}
}
}
31 changes: 31 additions & 0 deletions LiteHtmlLib/LiteHtmlLib.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29521.150
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LiteHtmlLib", "LiteHtmlLib.vcxproj", "{2E1F5B1E-430B-4FFF-963C-92229154F261}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E1F5B1E-430B-4FFF-963C-92229154F261}.Debug|x64.ActiveCfg = Debug|x64
{2E1F5B1E-430B-4FFF-963C-92229154F261}.Debug|x64.Build.0 = Debug|x64
{2E1F5B1E-430B-4FFF-963C-92229154F261}.Debug|x86.ActiveCfg = Debug|Win32
{2E1F5B1E-430B-4FFF-963C-92229154F261}.Debug|x86.Build.0 = Debug|Win32
{2E1F5B1E-430B-4FFF-963C-92229154F261}.Release|x64.ActiveCfg = Release|x64
{2E1F5B1E-430B-4FFF-963C-92229154F261}.Release|x64.Build.0 = Release|x64
{2E1F5B1E-430B-4FFF-963C-92229154F261}.Release|x86.ActiveCfg = Release|Win32
{2E1F5B1E-430B-4FFF-963C-92229154F261}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E1E7AFBD-7694-4B66-8C60-0D9D8A15DC2E}
EndGlobalSection
EndGlobal
Loading