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

Svg Addin #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions SkiaSharpFiddle/Compiler/AssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace SkiaSharpFiddle
{
public class AssemblyLoader
{
private static readonly string[] WhitelistedAssemblies =
{
"netstandard",
"mscorlib",
"System",
"System.Core",
"System.Private.CoreLib",
"System.Runtime",
"SkiaSharp",
"SkiaSharp.Extended",
"SkiaSharp.Extended.Svg",
"System.Xml.ReaderWriter",
"System.Private.Xml",
};

public AssemblyLoader()
{
AddExternalAssemblies();
}

public IEnumerable<Assembly> GetReferences() =>
AppDomain.CurrentDomain
.GetAssemblies()
.Where(a => WhitelistedAssemblies.Any(wl => wl.Equals(a.GetName().Name, StringComparison.OrdinalIgnoreCase)));

private void AddExternalAssemblies()
{
var skiasharpExtendedReference = SkiaSharp.Extended.SKGeometry.PI;
var skiasharpSvgReference = new SkiaSharp.Extended.Svg.SKSvg();
}
}
}
20 changes: 3 additions & 17 deletions SkiaSharpFiddle/Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@ namespace SkiaSharpFiddle
{
internal class Compiler
{
private static readonly string[] WhitelistedAssemblies =
{
"netstandard",
"mscorlib",
"System",
"System.Core",
"System.Private.CoreLib",
"System.Runtime",
"SkiaSharp",
};

private readonly CSharpCompilationOptions compilationOptions;
private readonly CSharpParseOptions parseOptions;

private readonly object referencesLocker = new object();
private Assembly[] assemblyReferences;
private MetadataReference[] metadataReferences;
private AssemblyLoader assemblyLoader;

public Compiler()
{
assemblyLoader = new AssemblyLoader();
compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
parseOptions = new CSharpParseOptions(LanguageVersion.Latest, kind: SourceCodeKind.Script);
}
Expand All @@ -45,7 +36,7 @@ public async Task<CompilationResult> CompileAsync(string sourceCode, Cancellatio
// load references
lock (referencesLocker)
{
assemblyReferences = GetReferences().ToArray();
assemblyReferences = assemblyLoader.GetReferences().ToArray();
metadataReferences = assemblyReferences.Select(a => MetadataReference.CreateFromFile(a.Location)).ToArray();
}

Expand All @@ -58,11 +49,6 @@ public async Task<CompilationResult> CompileAsync(string sourceCode, Cancellatio
return result;
}

private IEnumerable<Assembly> GetReferences() =>
AppDomain.CurrentDomain
.GetAssemblies()
.Where(a => WhitelistedAssemblies.Any(wl => wl.Equals(a.GetName().Name, StringComparison.OrdinalIgnoreCase)));

private CompilationResult CompileSourceCode(SourceText sourceCode, CancellationToken cancellationToken = default)
{
var syntaxTree = SyntaxFactory.ParseSyntaxTree(
Expand Down
4 changes: 2 additions & 2 deletions SkiaSharpFiddle/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
ItemsSource="{Binding ColorCombinations}" DisplayMemberPath="Name" />
<Separator />
<Label Content="Width: " />
<TextBox Text="{Binding DrawingWidth, Mode=TwoWay}" Width="100" />
<TextBox Text="{Binding DrawingWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="100" />
<Label Content="Height: " />
<TextBox Text="{Binding DrawingHeight, Mode=TwoWay}" Width="100" />
<TextBox Text="{Binding DrawingHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="100" />
</ToolBar>
</ToolBarTray>

Expand Down
12 changes: 7 additions & 5 deletions SkiaSharpFiddle/SkiaSharpFiddle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" />
<PackageReference Include="AvalonEdit" Version="6.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.5.0" />
<PackageReference Include="Refractored.MvvmHelpers" Version="1.4.1-beta" />
<PackageReference Include="SkiaSharp" Version="1.68.1" />
<PackageReference Include="SkiaSharp.Views.WPF" Version="1.68.1" NoWarn="NU1701" />
<PackageReference Include="System.Reactive" Version="4.3.1" />
<PackageReference Include="SkiaSharp" Version="1.68.1.1" />
<PackageReference Include="SkiaSharp.Extended" Version="1.60.0" />
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
<PackageReference Include="SkiaSharp.Views.WPF" Version="1.68.1.1" NoWarn="NU1701" />
<PackageReference Include="System.Reactive" Version="4.3.2" />
</ItemGroup>

</Project>