Skip to content

Commit

Permalink
Upgrade to net core 3.0 stable, bump VncDotnet to 1.1.0, bump version…
Browse files Browse the repository at this point in the history
… to 1.1.0
  • Loading branch information
Trolldemorted committed Sep 24, 2019
1 parent 1dad455 commit f893f55
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 66 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# VncDotnet.WPF
[![Build Status](https://dev.azure.com/benediktradtke/VncDotnet/_apis/build/status/VncDotnet.VncDotnet.WPF%20CI?branchName=master)](https://dev.azure.com/benediktradtke/VncDotnet/_build/latest?definitionId=9&branchName=master)
[![Build Status](https://dev.azure.com/benediktradtke/VncDotnet/_apis/build/status/VncDotnet.VncDotnet.WPF%20CI?branchName=master)](https://dev.azure.com/benediktradtke/VncDotnet/_build)
![](https://tokei.rs/b1/github/VncDotnet/VncDotnet.WPF)
6 changes: 3 additions & 3 deletions VncDotnet.WPF/VncDotnet.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>1.0.8</Version>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="VncDotnet" Version="1.0.8" />
<PackageReference Include="VncDotnet" Version="1.1.0" />
<PackageReference Include="WriteableBitmapEx" Version="1.6.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19351-01" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
</ItemGroup>

</Project>
107 changes: 49 additions & 58 deletions VncDotnet.WPF/VncDotnetControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace VncDotnet.WPF
{
public class VncDotnetControl : Control
public class VncDotnetControl : Control, IVncHandler
{
static VncDotnetControl()
{
Expand Down Expand Up @@ -56,12 +56,11 @@ public void Start(string host, int port, string? password, IEnumerable<SecurityT
Task.Run(() => ReconnectLoop(host, port, password, securityTypes, section, token));
}

public void Start(RfbConnection preEstablishedConnection, MonitorSnippet? section)
public async Task Attach(RfbConnection preEstablishedConnection, MonitorSnippet? section)
{
Section = section;
PreEstablishedConnection = preEstablishedConnection;
PreEstablishedConnection.OnVncUpdate += Client_OnVncUpdate;
PreEstablishedConnection.OnResolutionUpdate += Client_OnResolutionUpdate;
await PreEstablishedConnection.Attach(this);
}

private async Task ReconnectLoop(string host, int port, string? password, IEnumerable<SecurityType> securityTypes, MonitorSnippet? section, CancellationToken token)
Expand All @@ -72,8 +71,6 @@ private async Task ReconnectLoop(string host, int port, string? password, IEnume
{
Connection = await RfbConnection.ConnectAsync(host, port, password, securityTypes, section, token);
Section = section;
Connection.OnVncUpdate += Client_OnVncUpdate;
Connection.OnResolutionUpdate += Client_OnResolutionUpdate;
await Connection.Start();
}
catch (OperationCanceledException) { }
Expand All @@ -85,35 +82,45 @@ private async Task ReconnectLoop(string host, int port, string? password, IEnume
}
}

private void Client_OnResolutionUpdate(int framebufferWidth, int framebufferHeight)
private int BitmapX()
{
Application.Current?.Dispatcher.Invoke(new Action(() =>
if (Section != null)
{
var image = (Image) GetTemplateChild("Scene");
if (Section != null)
{
FramebufferWidth = Section.Width;
FramebufferHeight = Section.Height;
Bitmap = BitmapFactory.New(FramebufferWidth, FramebufferHeight);
}
else
{
FramebufferWidth = framebufferWidth;
FramebufferHeight = framebufferHeight;
Bitmap = BitmapFactory.New(framebufferWidth, framebufferHeight);
}
image.Source = Bitmap;
}));
return Section.X;
}
return 0;
}

private int BitmapY()
{
if (Section != null)
{
return Section.Y;
}
return 0;
}

public async Task Stop()
{
if (Connection != null)
{
Connection.Stop();
}

if (PreEstablishedConnection != null)
{
await PreEstablishedConnection.Detach(this);
}
}

private void Client_OnVncUpdate(IEnumerable<(RfbRectangleHeader header, byte[] data)> rectangles)
public void HandleFramebufferUpdate(IEnumerable<(RfbRectangleHeader, byte[])> rectangles)
{
Application.Current?.Dispatcher.Invoke(new Action(() =>
{
var stopwatch = new Stopwatch();
stopwatch.Start();
if (Bitmap == null)
throw new InvalidOperationException();
throw new InvalidOperationException("Bitmap is null");
using (var ctx = Bitmap.GetBitmapContext())
{
Bitmap.Lock();
Expand Down Expand Up @@ -168,51 +175,35 @@ private void Client_OnVncUpdate(IEnumerable<(RfbRectangleHeader header, byte[] d
rowLength * 4);
}
}
ArrayPool<byte>.Shared.Return(data);
}
}

Bitmap.DrawRectangle(0, 0, 64, 64, Colors.GreenYellow);
Bitmap.AddDirtyRect(new Int32Rect(0, 0, Bitmap.PixelWidth, Bitmap.PixelHeight));
Bitmap.Unlock();
}
stopwatch.Stop();
//Debug.WriteLine($"Client_OnVncUpdate invocation took {stopwatch.Elapsed}");
}));
}

private int BitmapX()
{
if (Section != null)
{
return Section.X;
}
return 0;
}

private int BitmapY()
public void HandleResolutionUpdate(int framebufferWidth, int framebufferHeight)
{
if (Section != null)
{
return Section.Y;
}
return 0;
}

public void Stop()
{
if (Connection != null)
{
Connection.OnResolutionUpdate -= Client_OnResolutionUpdate;
Connection.OnVncUpdate -= Client_OnVncUpdate;
Connection.Stop();
}

if (PreEstablishedConnection != null)
Application.Current?.Dispatcher.Invoke(new Action(() =>
{
PreEstablishedConnection.OnResolutionUpdate -= Client_OnResolutionUpdate;
PreEstablishedConnection.OnVncUpdate -= Client_OnVncUpdate;
}
var image = (Image)GetTemplateChild("Scene");
if (Section != null)
{
FramebufferWidth = Section.Width;
FramebufferHeight = Section.Height;
Bitmap = BitmapFactory.New(FramebufferWidth, FramebufferHeight);
}
else
{
FramebufferWidth = framebufferWidth;
FramebufferHeight = framebufferHeight;
Bitmap = BitmapFactory.New(framebufferWidth, framebufferHeight);
}
image.Source = Bitmap;
}));
}
}
}
5 changes: 3 additions & 2 deletions azure-pipelines-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ variables:
steps:
- task: NuGetToolInstaller@1

- task: DotNetCoreInstaller@1
- task: UseDotNet@2
inputs:
version: '3.0.100-preview9-014004'
packageType: 'sdk'
version: 3.x

- task: DotNetCoreCLI@2
inputs:
Expand Down
5 changes: 3 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ variables:
buildConfiguration: 'Release'

steps:
- task: DotNetCoreInstaller@1
- task: UseDotNet@2
inputs:
version: '3.0.100-preview9-014004'
packageType: 'sdk'
version: 3.x

- task: DotNetCoreCLI@2
inputs:
Expand Down

0 comments on commit f893f55

Please sign in to comment.