Skip to content

Commit

Permalink
cleanup solution files
Browse files Browse the repository at this point in the history
  • Loading branch information
budcribar committed Mar 10, 2024
1 parent a179bd5 commit be32afd
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 386 deletions.
357 changes: 19 additions & 338 deletions RemoteBlazorWebView.sln

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Benchmarks/Startup/Startup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
<Platforms>x64</Platforms>
</PropertyGroup>

</Project>
13 changes: 7 additions & 6 deletions src/EditWebView/EditWebView.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions src/RemoteBlazorWebView/RemoteBlazorWebView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReleaseNotes>Based on maui 8.0.7 </PackageReleaseNotes>
<DebugType>full</DebugType>
<Configurations>Debug;Release;Embedded</Configurations>
<Platforms>x64</Platforms>
</PropertyGroup>

<Target Name="SetPackageVersion" DependsOnTargets="Build">
Expand Down
9 changes: 3 additions & 6 deletions src/RemoteWebView/RemoteWebView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>Based on maui 8.0.7 </PackageReleaseNotes>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x64</PlatformTarget>
<Platforms>x64</Platforms>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Developer|x64'">
<DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Developer|AnyCPU'">
<DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Properties\**" />
<EmbeddedResource Remove="Properties\**" />
Expand All @@ -62,7 +59,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2277.86" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2365.46" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
58 changes: 52 additions & 6 deletions testassets/NUnitTestProject/TestBlazorFormControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public static class BlazorWebViewFormFactory
BlazorWebViewFormFactory.MainForm?.Invoke(() =>
{

control = new BlazorWebView();
control.Services = serviceCollection.BuildServiceProvider();
control = new BlazorWebView
{
Services = serviceCollection.BuildServiceProvider()
};
control.RootComponents.Add(rootComponent);


Expand Down Expand Up @@ -163,7 +165,7 @@ public void TestSetMirrorPropertyLate()

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void TestGrouplLate()
public void TestGroupLate()
{
var rootComponent = new RootComponent
(
Expand All @@ -188,7 +190,7 @@ public void TestGrouplLate()

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void TestMarkupslLate()
public void TestMarkupLate()
{
var rootComponent = new RootComponent
(
Expand Down Expand Up @@ -392,9 +394,53 @@ public void TestConnectedEvent()

}


[TestMethod]
public void TestJsDownload()
{
var rootComponent = new RootComponent ("#app", typeof(Home),null);
var webView = BlazorWebViewFormFactory.CreateBlazorComponent(rootComponent);
Assert.IsNotNull(webView);
AutoResetEvent threadInitialized = new AutoResetEvent(false);
BlazorWebViewFormFactory.MainForm?.Invoke(() =>
{
webView.Id = Guid.NewGuid();
webView.ServerUri = new System.Uri("https://localhost:5001");

webView.EnableMirrors = true;
webView.Connected += (sender, e) =>
{
webView.WebView.CoreWebView2.Navigate($"{e.Url}mirror/{e.Id}");
var user = e.User.Length > 0 ? $"by user {e.User.Length}" : "";
BlazorWebViewFormFactory.MainForm.Text += $" Controlled remotely {user}from ip address {e.IpAddress}";
//Task.Delay(60000).Wait();
//threadInitialized.Set();
};
webView.ReadyToConnect += (sender, e) =>
{
webView.NavigateToString($"<a href='{e.Url}app/{e.Id}' target='_blank'> {e.Url}app/{e.Id}</a>");
Utilities.OpenUrlInBrowserWithDevTools($"{e.Url}app/{e.Id}");

};

// 800 1k files are marginal
// 80 10k fails
// 5, 100k fails
Stopwatch sw = new Stopwatch();
sw.Start();
Console.WriteLine("Generating JS files");
Utilities.GenJavascript(50,100_000);
Console.WriteLine($"Done Generating JS files in {sw.Elapsed}");
webView.HostPage = @"wwwroot\index.html";

});
//Assert.IsTrue(threadInitialized.WaitOne(100_000));
Task.Delay(TimeSpan.FromSeconds(20)).Wait();

}



public static Process process;
public static Process? process;
public TestContext? TestContext { get; set; }

[ClassInitialize]
Expand Down
4 changes: 2 additions & 2 deletions testassets/NUnitTestProject/TestBlazorWpfControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ await Application.Current.Dispatcher.InvokeAsync(async () =>

var tcs = new TaskCompletionSource<bool>();

EventHandler<CoreWebView2NavigationCompletedEventArgs> handler = null;
EventHandler<CoreWebView2NavigationCompletedEventArgs>? handler = null;
handler = (sender, args) =>
{

Expand Down Expand Up @@ -403,7 +403,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => {
});
}

public static Process process;
public static Process? process;
public TestContext? TestContext { get; set; }

[ClassInitialize]
Expand Down
78 changes: 51 additions & 27 deletions testassets/NUnitTestProject/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static Process StartRustServer()
process.StartInfo.UseShellExecute = true;

process.Start();
Console.WriteLine($"Started server in {sw.Elapsed}");
Debug.WriteLine($"Started RUST server in {sw.Elapsed}");
return process;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ public static void DeleteGeneratedJsFiles(string directoryPath)
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
public static void GenJavascript(int numberOfFiles = 10)
public static void GenJavascript(int numberOfFiles = 10, int stringLength = 1000)
{
string basePath = @"wwwroot"; // Set your base path
string indexPath = Path.Combine(basePath, "index.html");
Expand All @@ -284,27 +284,31 @@ public static void GenJavascript(int numberOfFiles = 10)
{
string fileName = $"script{i}.js";
string filePath = Path.Combine(basePath, fileName);
string randomString = GenerateRandomString(1000);
string randomString = GenerateRandomString(stringLength);
string checksum = CalculateChecksum(randomString);

string jsContent = $@"
const string = '{randomString}';
const checksum = '{checksum}';
function verifyChecksum() {{
const calculatedChecksum = sha256(string);
if(calculatedChecksum !== checksum) {{
alert('Checksum verification failed for {fileName}.');
throw new Error('Checksum verification failed.');
(function() {{
const string = '{randomString}';
const checksum = '{checksum}';
async function verifyChecksum() {{
const calculatedChecksum = await sha256(string);
if(calculatedChecksum !== checksum) {{
alert('Checksum verification failed for {fileName}.');
throw new Error('Checksum verification failed.');
}}
}}
async function sha256(message) {{
const msgBuffer = new TextEncoder().encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
return hashHex;
}}
}}
async function sha256(message) {{
const msgBuffer = new TextEncoder().encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
return hashHex;
}}
verifyChecksum();";
//verifyChecksum();
console.log('{fileName} passed');
}})();
";

File.WriteAllText(filePath, jsContent);

Expand All @@ -326,16 +330,14 @@ static string GenerateRandomString(int length)

static string CalculateChecksum(string input)
{
using (SHA256 sha256Hash = SHA256.Create())
using SHA256 sha256Hash = SHA256.Create();
byte[] data = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
byte[] data = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
}
public static void OpenUrlInBrowser(string url)
{
Expand All @@ -354,6 +356,28 @@ public static void OpenUrlInBrowser(string url)
Console.WriteLine($"Failed to open URL: {ex.Message}");
}
}
public static void OpenUrlInBrowserWithDevTools(string url)
{
try
{
// Specify the path to the Chrome executable
string chromePath = @"C:\Program Files\Google\Chrome\Application\chrome.exe";

// Use the --auto-open-devtools-for-tabs command line switch to open dev tools
Process.Start(new ProcessStartInfo
{
FileName = chromePath,
Arguments = $"--new-window --auto-open-devtools-for-tabs {url}",
UseShellExecute = true
});
Console.WriteLine($"Opened {url} in Chrome with developer tools.");
}
catch (Exception ex)
{
Console.WriteLine($"Failed to open URL in Chrome with developer tools: {ex.Message}");
}
}

}

#endregion
Expand Down
3 changes: 2 additions & 1 deletion testassets/NUnitTestProject/WebdriverTestProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<RazorLangVersion>3.0</RazorLangVersion>
<LangVersion>9</LangVersion>
<Configurations>Debug;Release;Embedded;NoAuthorization</Configurations>
<Platforms>x64</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -48,7 +49,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\index.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

Expand Down

0 comments on commit be32afd

Please sign in to comment.