Skip to content

Commit

Permalink
Merge pull request #1105 from AvaloniaUI/remote2
Browse files Browse the repository at this point in the history
Remoting & New Previewer
  • Loading branch information
kekekeks committed Oct 11, 2017
2 parents 38091ee + cde1e23 commit e755664
Show file tree
Hide file tree
Showing 57 changed files with 4,110 additions and 123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,4 @@ artifacts/
nuget
Avalonia.XBuild.sln
project.lock.json
.idea/*
219 changes: 217 additions & 2 deletions Avalonia.sln

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions packages.cake
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ public class Packages
};
});

var toolsContent = new[] {
new NuSpecContent{
Source = ((FilePath)context.File("./src/tools/Avalonia.Designer.HostApp/bin/" + parameters.DirSuffix + "/netcoreapp2.0/Avalonia.Designer.HostApp.dll")).FullPath,
Target = "tools/netcoreapp2.0/previewer"
},
new NuSpecContent{
Source = ((FilePath)context.File("./src/tools/Avalonia.Designer.HostApp.NetFx/bin/" + parameters.DirSuffix + "/Avalonia.Designer.HostApp.exe")).FullPath,
Target = "tools/net461/previewer"
}
};

var nuspecNuGetSettingsCore = new []
{
///////////////////////////////////////////////////////////////////////////////
Expand All @@ -237,6 +248,7 @@ public class Packages
new NuSpecDependency() { Id = "Splat", Version = SplatVersion },
new NuSpecDependency() { Id = "Sprache", Version = SpracheVersion },
new NuSpecDependency() { Id = "System.Reactive", Version = SystemReactiveVersion },
new NuSpecDependency() { Id = "Avalonia.Remote.Protocol", Version = parameters.Version },
//.NET Core
new NuSpecDependency() { Id = "System.Threading.ThreadPool", TargetFramework = "netcoreapp2.0", Version = "4.3.0" },
new NuSpecDependency() { Id = "Microsoft.Extensions.DependencyModel", TargetFramework = "netcoreapp2.0", Version = "1.1.0" },
Expand All @@ -245,6 +257,7 @@ public class Packages
new NuSpecDependency() { Id = "Serilog", TargetFramework = "netcoreapp2.0", Version = SerilogVersion },
new NuSpecDependency() { Id = "Sprache", TargetFramework = "netcoreapp2.0", Version = SpracheVersion },
new NuSpecDependency() { Id = "System.Reactive", TargetFramework = "netcoreapp2.0", Version = SystemReactiveVersion },
new NuSpecDependency() { Id = "Avalonia.Remote.Protocol", TargetFramework = "netcoreapp2.0", Version = parameters.Version },
}
.Deps(new string[]{null, "netcoreapp2.0"},
"System.ValueTuple", "System.ComponentModel.TypeConverter", "System.ComponentModel.Primitives",
Expand All @@ -253,6 +266,7 @@ public class Packages
Files = coreLibrariesNuSpecContent
.Concat(win32CoreLibrariesNuSpecContent).Concat(net45RuntimePlatform)
.Concat(netcoreappCoreLibrariesNuSpecContent).Concat(netCoreRuntimePlatform)
.Concat(toolsContent)
.ToList(),
BasePath = context.Directory("./"),
OutputDirectory = parameters.NugetRoot
Expand Down Expand Up @@ -291,6 +305,19 @@ public class Packages
BasePath = context.Directory("./src/Avalonia.ReactiveUI/bin/" + parameters.DirSuffix + "/netstandard2.0"),
OutputDirectory = parameters.NugetRoot
},
///////////////////////////////////////////////////////////////////////////////
// Avalonia.Remote.Protocol
///////////////////////////////////////////////////////////////////////////////
new NuGetPackSettings()
{
Id = "Avalonia.Remote.Protocol",
Files = new []
{
new NuSpecContent { Source = "Avalonia.Remote.Protocol.dll", Target = "lib/netstandard2.0" }
},
BasePath = context.Directory("./src/Avalonia.Remote.Protocol/bin/" + parameters.DirSuffix + "/netstandard2.0"),
OutputDirectory = parameters.NugetRoot
},
};

var nuspecNuGetSettingsMobile = new []
Expand Down
10 changes: 7 additions & 3 deletions samples/ControlCatalog.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ static void Main(string[] args)

// TODO: Make this work with GTK/Skia/Cairo depending on command-line args
// again.
AppBuilder.Configure<App>()
.UsePlatformDetect()
.Start<MainWindow>();
BuildAvaloniaApp().Start<MainWindow>();
}

/// <summary>
/// This method is needed for IDE previewer infrastructure
/// </summary>
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>().UsePlatformDetect();

// This will be made into a runtime configuration extension soon!
private static void InitializeLogging()
{
Expand Down
17 changes: 6 additions & 11 deletions samples/ControlCatalog.NetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ static void Main(string[] args)
System.Threading.ThreadPool.QueueUserWorkItem(_ => ConsoleSilencer());
});
else
AppBuilder.Configure<App>()
.CustomPlatformDetect()
.UseReactiveUI()
.Start<MainWindow>();
BuildAvaloniaApp().Start<MainWindow>();
}

static AppBuilder CustomPlatformDetect(this AppBuilder builder)
{
//This is needed because we still aren't ready to have MonoMac backend as default one
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return builder.UseSkia().UseMonoMac();
return builder.UsePlatformDetect();
}
/// <summary>
/// This method is needed for IDE previewer infrastructure
/// </summary>
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>().UsePlatformDetect().UseReactiveUI();

static void ConsoleSilencer()
{
Expand Down
6 changes: 6 additions & 0 deletions samples/Previewer/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Application xmlns="https://github.com/avaloniaui">
<Application.Styles>
<StyleInclude Source="resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"/>
</Application.Styles>
</Application>
14 changes: 14 additions & 0 deletions samples/Previewer/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Avalonia;
using Avalonia.Markup.Xaml;

namespace Previewer
{
public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
}

}
19 changes: 19 additions & 0 deletions samples/Previewer/Center.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Avalonia;
using Avalonia.Controls;

namespace Previewer
{
public class Center : Decorator
{
protected override Size ArrangeOverride(Size finalSize)
{
if (Child != null)
{
var desired = Child.DesiredSize;
Child.Arrange(new Rect((finalSize.Width - desired.Width) / 2, (finalSize.Height - desired.Height) / 2,
desired.Width, desired.Height));
}
return finalSize;
}
}
}
12 changes: 12 additions & 0 deletions samples/Previewer/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Window xmlns="https://github.com/avaloniaui" Width="600" Height="500"
Title="Previewer">
<Grid RowDefinitions="0.5*,200">
<ScrollViewer Name="Remote"/>

<ScrollViewer Name="ErrorsContainer" Background="#ffe0e0">
<TextBlock Name="Errors"/>
</ScrollViewer>
<TextBox Grid.Row="1" AcceptsReturn="True" Name="Xaml"/>
</Grid>

</Window>
86 changes: 86 additions & 0 deletions samples/Previewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Net;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Remote;
using Avalonia.Markup.Xaml;
using Avalonia.Remote.Protocol;
using Avalonia.Remote.Protocol.Designer;
using Avalonia.Remote.Protocol.Viewport;
using Avalonia.Threading;

namespace Previewer
{
public class MainWindow : Window
{
private const string InitialXaml = @"<Window xmlns=""https://github.com/avaloniaui"" Width=""600"" Height=""500"">
<TextBlock>Hello world!</TextBlock>
</Window>";
private IAvaloniaRemoteTransportConnection _connection;
private Control _errorsContainer;
private TextBlock _errors;
private RemoteWidget _remote;


public MainWindow()
{
this.InitializeComponent();
var tb = this.FindControl<TextBox>("Xaml");
tb.Text = InitialXaml;
var scroll = this.FindControl<ScrollViewer>("Remote");
var rem = new Center();
scroll.Content = rem;
_errorsContainer = this.FindControl<Control>("ErrorsContainer");
_errors = this.FindControl<TextBlock>("Errors");
tb.GetObservable(TextBox.TextProperty).Subscribe(text => _connection?.Send(new UpdateXamlMessage
{
Xaml = text
}));
new BsonTcpTransport().Listen(IPAddress.Loopback, 25000, t =>
{
Dispatcher.UIThread.InvokeAsync(() =>
{
if (_connection != null)
{
_connection.Dispose();
_connection.OnMessage -= OnMessage;
}
_connection = t;
rem.Child = _remote = new RemoteWidget(t);
t.Send(new UpdateXamlMessage
{
Xaml = tb.Text
});
t.OnMessage += OnMessage;
});
});
Title = "Listening on 127.0.0.1:25000";
}

private void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj)
{
Dispatcher.UIThread.InvokeAsync(() =>
{
if (transport != _connection)
return;
if (obj is UpdateXamlResultMessage result)
{
_errorsContainer.IsVisible = result.Error != null;
_errors.Text = result.Error ?? "";
}
if (obj is RequestViewportResizeMessage resize)
{
_remote.Width = Math.Min(4096, Math.Max(resize.Width, 1));
_remote.Height = Math.Min(4096, Math.Max(resize.Height, 1));
}
});
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
27 changes: 27 additions & 0 deletions samples/Previewer/Previewer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
<EmbeddedResource Include="**\*.xaml" />
<ProjectReference Include="..\..\src\Avalonia.DotNetCoreRuntime\Avalonia.DotNetCoreRuntime.csproj" />
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj" />
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup\Avalonia.Markup.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Animation\Avalonia.Animation.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Base\Avalonia.Base.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Controls\Avalonia.Controls.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Include="..\..\src\Avalonia.HtmlRenderer\Avalonia.HtmlRenderer.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Input\Avalonia.Input.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Interactivity\Avalonia.Interactivity.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Layout\Avalonia.Layout.csproj" />
<ProjectReference Include="..\..\src\Avalonia.ReactiveUI\Avalonia.ReactiveUI.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Visuals\Avalonia.Visuals.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Styling\Avalonia.Styling.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions samples/Previewer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Avalonia;

namespace Previewer
{
class Program
{
static void Main(string[] args)
{
AppBuilder.Configure<App>().UsePlatformDetect().Start<MainWindow>();
}
}
}
53 changes: 53 additions & 0 deletions samples/RemoteTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Remote;
using Avalonia.Remote.Protocol;
using Avalonia.Threading;
using ControlCatalog;

namespace RemoteTest
{
class Program
{
static void Main(string[] args)
{
AppBuilder.Configure<App>().UsePlatformDetect().SetupWithoutStarting();

var l = new TcpListener(IPAddress.Loopback, 0);
l.Start();
var port = ((IPEndPoint) l.LocalEndpoint).Port;
l.Stop();

var transport = new BsonTcpTransport();
transport.Listen(IPAddress.Loopback, port, sc =>
{
Dispatcher.UIThread.InvokeAsync(() =>
{
new RemoteServer(sc).Content = new MainView();
});
});

var cts = new CancellationTokenSource();
transport.Connect(IPAddress.Loopback, port).ContinueWith(t =>
{
Dispatcher.UIThread.InvokeAsync(() =>
{
var window = new Window()
{
Content = new RemoteWidget(t.Result)
};
window.Closed += delegate { cts.Cancel(); };
window.Show();
});
});
Dispatcher.UIThread.MainLoop(cts.Token);



}
}
}
25 changes: 25 additions & 0 deletions samples/RemoteTest/RemoteTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Animation\Avalonia.Animation.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Base\Avalonia.Base.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Controls\Avalonia.Controls.csproj" />
<ProjectReference Include="..\..\src\Avalonia.DesignerSupport\Avalonia.DesignerSupport.csproj" />
<ProjectReference Include="..\..\src\Avalonia.DotNetCoreRuntime\Avalonia.DotNetCoreRuntime.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Input\Avalonia.Input.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Interactivity\Avalonia.Interactivity.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Layout\Avalonia.Layout.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Styling\Avalonia.Styling.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Visuals\Avalonia.Visuals.csproj" />
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj" />
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup\Avalonia.Markup.csproj" />
<ProjectReference Include="..\ControlCatalog\ControlCatalog.csproj" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/Avalonia.Base/AvaloniaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class AvaloniaObject : IAvaloniaObject, IAvaloniaObjectDebug, INotifyProp
/// </summary>
public AvaloniaObject()
{
VerifyAccess();
foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegistered(this))
{
object value = property.IsDirect ?
Expand Down Expand Up @@ -817,4 +818,4 @@ private void ThrowNotRegistered(AvaloniaProperty p)
throw new ArgumentException($"Property '{p.Name} not registered on '{this.GetType()}");
}
}
}
}
Loading

0 comments on commit e755664

Please sign in to comment.