Skip to content

Commit

Permalink
Initial support for new .NET tooling
Browse files Browse the repository at this point in the history
POCO and Revenj Postgres support new tooling (and build to source also)
Support for Typescript
  • Loading branch information
zapov committed Nov 2, 2018
1 parent f2a3ed8 commit 52a8bb3
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 40 deletions.
24 changes: 16 additions & 8 deletions VisualStudioPlugin/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ public static string TempPath
}
}

private static readonly char[] InvalidFileChars = Path.GetInvalidFileNameChars();
private static readonly char[] InvalidFileChars = Path.GetInvalidFileNameChars().Except(new[] { '/' }).ToArray();

public static string BuildDotnet(string project, string output, Dictionary<string, string> dependencies, Dictionary<string, string> files)
public static string BuildDotnet(LibraryInfo library, string[] customDlls, Dictionary<string, string> files)
{
var folder = Path.Combine(TempPath, project);
var folder = Path.Combine(TempPath, library.Type);
if (!Directory.Exists(folder))
Directory.CreateDirectory(folder);
else
{
foreach (var f in Directory.GetFiles(folder, "*.cs"))
File.Delete(f);
}
var outputName = output.IndexOf('/') == -1 ? output : output.Substring(output.LastIndexOf('/'));
var outputName = library.Name.IndexOf('/') == -1 ? library.Name : library.Name.Substring(library.Name.LastIndexOf('/'));
var csproj = new StringBuilder(@"<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand All @@ -137,22 +137,30 @@ public static string BuildDotnet(string project, string output, Dictionary<strin
csproj.Append(@"</AssemblyName>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>");
if (dependencies.Count != 0)
if (library.Nugets.Count != 0 || customDlls.Length != 0)
{
csproj.Append(@"
<ItemGroup>");
foreach (var kv in dependencies)
foreach (var n in library.Nugets)
{
csproj.AppendFormat(@"
<PackageReference Include=""{0}"" Version=""{1}"" />", kv.Key, kv.Value);
<PackageReference Include=""{0}"" Version=""{1}"" />", n.Project, n.Version);
}
foreach (var dll in customDlls)
{
var fullPath = Path.Combine(LibraryInfo.BasePath, dll);
csproj.AppendFormat(@"
<Reference Include=""{0}"">
<HintPath>{1}</HintPath>
</Reference>", Path.GetFileNameWithoutExtension(dll), fullPath);
}
csproj.Append(@"
</ItemGroup>
");
}
csproj.Append(@"
</Project>");
File.WriteAllText(Path.Combine(folder, project + ".csproj"), csproj.ToString());
File.WriteAllText(Path.Combine(folder, library.Type + ".csproj"), csproj.ToString());
foreach (var kv in files)
{
var name = kv.Key;
Expand Down
7 changes: 7 additions & 0 deletions VisualStudioPlugin/DDDLanguage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<Compile Include="Gui\View\ConfigurationPostgresControl.xaml.cs">
<DependentUpon>ConfigurationPostgresControl.xaml</DependentUpon>
</Compile>
<Compile Include="Gui\View\ConfigurationTypescriptControl.xaml.cs">
<DependentUpon>ConfigurationTypescriptControl.xaml</DependentUpon>
</Compile>
<Compile Include="Gui\View\DiffControl.xaml.cs">
<DependentUpon>DiffControl.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -272,6 +275,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Gui\View\ConfigurationTypescriptControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Gui\View\DiffControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
18 changes: 18 additions & 0 deletions VisualStudioPlugin/DDDLanguagePackage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel.Design;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using EnvDTE;
Expand Down Expand Up @@ -188,6 +189,16 @@ private void ReadInfo(LibraryInfo info, IPropertyBag pBag)
info.Name = TryReadString(info.Type + ".Name", pBag) ?? info.Name;
info.Target = TryReadString(info.Type + ".Target", pBag) ?? info.Target;
info.Dependencies = TryReadString(info.Type + ".Dependencies", pBag) ?? info.Dependencies;
var nugets = TryReadString(info.Type + ".Nugets", pBag);
if (!string.IsNullOrWhiteSpace(nugets))
{
var values = nugets.Split(';');
info.Nugets = values.Select(it =>
{
var parts = it.Split(':');
return new LibraryInfo.Nuget { Project = parts[0], Version = parts[parts.Length - 1] };
}).ToList();
}
info.Namespace = TryReadString(info.Type + ".Namespace", pBag) ?? info.Namespace;
info.WithActiveRecord = TryReadBool(info.Type + ".ActiveRecord", pBag, info.WithActiveRecord);
info.WithHelperMethods = TryReadBool(info.Type + ".HelperMethods", pBag, info.WithHelperMethods);
Expand All @@ -209,6 +220,7 @@ public int ReadSolutionProps(IVsHierarchy pHierarchy, string pszProjectName, str
ReadInfo(Presenter.ClientLibrary, pPropBag);
ReadInfo(Presenter.PortableLibrary, pPropBag);
ReadInfo(Presenter.PhpLibrary, pPropBag);
ReadInfo(Presenter.TypescriptLibrary, pPropBag);
ReadInfo(Presenter.WpfLibrary, pPropBag);
ReadInfo(Presenter.PostgresLibrary, pPropBag);
ReadInfo(Presenter.OracleLibrary, pPropBag);
Expand Down Expand Up @@ -320,6 +332,11 @@ private void WriteInfo(LibraryInfo info, LibraryInfo reference, IPropertyBag pBa
val = info.Dependencies;
pBag.Write(info.Type + ".Dependencies", ref val);
}
if (!LibraryInfo.Nuget.Equal(info.Nugets, reference.Nugets))
{
val = string.Join(";", info.Nugets.Select(it => it.Project + ":" + it.Version));
pBag.Write(info.Type + ".Nugets", ref val);
}
if (reference.Namespace != info.Namespace)
{
val = info.Namespace;
Expand Down Expand Up @@ -381,6 +398,7 @@ public int WriteSolutionProps(IVsHierarchy pHierarchy, string pszKey, IPropertyB
WriteInfo(Presenter.ClientLibrary, CompileTargets.ClientLibraryDefault, pPropBag);
WriteInfo(Presenter.PortableLibrary, CompileTargets.PortableLibraryDefault, pPropBag);
WriteInfo(Presenter.PhpLibrary, CompileTargets.PhpSourceDefault, pPropBag);
WriteInfo(Presenter.TypescriptLibrary, CompileTargets.TypescriptSourceDefault, pPropBag);
WriteInfo(Presenter.WpfLibrary, CompileTargets.WpfLibraryDefault, pPropBag);
WriteInfo(Presenter.PostgresLibrary, CompileTargets.PostgresLibraryDefault, pPropBag);
WriteInfo(Presenter.OracleLibrary, CompileTargets.OracleLibraryDefault, pPropBag);
Expand Down
44 changes: 32 additions & 12 deletions VisualStudioPlugin/Gui/CompileTargets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ namespace DDDLanguage
{
internal class CompileTargets
{
private static readonly Dictionary<string, string> NoDependencies = new Dictionary<string, string>();
private static readonly Dictionary<string, string> RevenjStandard = new Dictionary<string, string>() { { "revenj", "1.4.2" } };
private static List<LibraryInfo.Nuget> NoDependencies()
{
return new List<LibraryInfo.Nuget>();
}
private static List<LibraryInfo.Nuget> RevenjStandard()
{
return new List<LibraryInfo.Nuget>(new[] { new LibraryInfo.Nuget { Project = "revenj", Version = "1.4.2" } });
}

private static readonly string[] PocoDependencies = new[] {
typeof(string).Assembly.Location,
Expand Down Expand Up @@ -67,32 +73,35 @@ public string CompilerPath
}

private LibraryInfo oldPocoLibrary;
public static readonly LibraryInfo PocoLibraryDefault = new LibraryInfo("Poco", "dotnet_poco", false, PocoDependencies, NoDependencies, BuildTypes.LegacyDotNet, ".cs", BuildTypes.LegacyDotNet, BuildTypes.DotNetStandard);
public static readonly LibraryInfo PocoLibraryDefault = new LibraryInfo("Poco", "dotnet_poco", false, PocoDependencies, NoDependencies(), BuildTypes.LegacyDotNet, ".cs", BuildTypes.LegacyDotNet, BuildTypes.DotNetStandard, BuildTypes.Source);
public readonly LibraryInfo PocoLibrary = PocoLibraryDefault.Clone();
private LibraryInfo oldClientLibrary;
public static readonly LibraryInfo ClientLibraryDefault = new LibraryInfo("Client", "dotnet_client", true, PocoDependencies, NoDependencies, BuildTypes.LegacyDotNet, ".cs");
public static readonly LibraryInfo ClientLibraryDefault = new LibraryInfo("Client", "dotnet_client", true, PocoDependencies, NoDependencies(), BuildTypes.LegacyDotNet, ".cs");
public readonly LibraryInfo ClientLibrary = ClientLibraryDefault.Clone();
private LibraryInfo oldPortableLibrary;
public static readonly LibraryInfo PortableLibraryDefault = new LibraryInfo("Portable", "dotnet_portable", true, new string[0], NoDependencies, BuildTypes.LegacyDotNet, ".cs");
public static readonly LibraryInfo PortableLibraryDefault = new LibraryInfo("Portable", "dotnet_portable", true, new string[0], NoDependencies(), BuildTypes.LegacyDotNet, ".cs");
public readonly LibraryInfo PortableLibrary = PortableLibraryDefault.Clone();
private LibraryInfo oldPhpSource;
public static readonly LibraryInfo PhpSourceDefault = new LibraryInfo("Php", "php_client", false, new string[0], NoDependencies, BuildTypes.Source, ".php");
public static readonly LibraryInfo PhpSourceDefault = new LibraryInfo("Php", "php_client", false, new string[0], NoDependencies(), BuildTypes.Source, ".php");
public readonly LibraryInfo PhpSource = PhpSourceDefault.Clone();
private LibraryInfo oldTypescriptSource;
public static readonly LibraryInfo TypescriptSourceDefault = new LibraryInfo("Typescript", "typescript", false, new string[0], NoDependencies(), BuildTypes.Source, string.Empty);
public readonly LibraryInfo TypescriptSource = TypescriptSourceDefault.Clone();
private LibraryInfo oldWpfLibrary;
public static readonly LibraryInfo WpfLibraryDefault = new LibraryInfo("Wpf", "wpf", true, WpfDependencies, NoDependencies, BuildTypes.LegacyDotNet, ".cs");
public static readonly LibraryInfo WpfLibraryDefault = new LibraryInfo("Wpf", "wpf", true, WpfDependencies, NoDependencies(), BuildTypes.LegacyDotNet, ".cs");
public readonly LibraryInfo WpfLibrary = WpfLibraryDefault.Clone();
private LibraryInfo oldPostgresLibrary;
public static readonly LibraryInfo PostgresLibraryDefault = new LibraryInfo("Postgres", "dotnet_server_postgres", true, RevenjDependencies, RevenjStandard, BuildTypes.LegacyDotNet, ".cs", BuildTypes.LegacyDotNet, BuildTypes.DotNetStandard);
public static readonly LibraryInfo PostgresLibraryDefault = new LibraryInfo("Postgres", "dotnet_server_postgres", true, RevenjDependencies, RevenjStandard(), BuildTypes.LegacyDotNet, ".cs", BuildTypes.LegacyDotNet, BuildTypes.DotNetStandard, BuildTypes.Source);
public readonly LibraryInfo PostgresLibrary = PostgresLibraryDefault.Clone();
private LibraryInfo oldOracleLibrary;
public static readonly LibraryInfo OracleLibraryDefault = new LibraryInfo("Oracle", "dotnet_server_oracle", true, RevenjDependencies, NoDependencies, BuildTypes.LegacyDotNet, ".cs");
public static readonly LibraryInfo OracleLibraryDefault = new LibraryInfo("Oracle", "dotnet_server_oracle", true, RevenjDependencies, NoDependencies(), BuildTypes.LegacyDotNet, ".cs");
public readonly LibraryInfo OracleLibrary = OracleLibraryDefault.Clone();

private readonly LibraryInfo[] Targets;

public CompileTargets()
{
Targets = new[] { PocoLibrary, ClientLibrary, PortableLibrary, PhpSource, WpfLibrary, PostgresLibrary, OracleLibrary };
Targets = new[] { PocoLibrary, ClientLibrary, PortableLibrary, PhpSource, TypescriptSource, WpfLibrary, PostgresLibrary, OracleLibrary };
}

public bool HasChanges()
Expand All @@ -101,6 +110,7 @@ public bool HasChanges()
|| !ClientLibrary.Equals(oldClientLibrary)
|| !PortableLibrary.Equals(oldPortableLibrary)
|| !PhpSource.Equals(oldPhpSource)
|| !TypescriptSource.Equals(oldTypescriptSource)
|| !WpfLibrary.Equals(oldWpfLibrary)
|| !PostgresLibrary.Equals(oldPostgresLibrary)
|| !OracleLibrary.Equals(oldOracleLibrary);
Expand All @@ -113,6 +123,7 @@ public void Reset(string compilerPath)
oldClientLibrary = ClientLibrary.Clone();
oldPortableLibrary = PortableLibrary.Clone();
oldPhpSource = PhpSource.Clone();
oldTypescriptSource = TypescriptSource.Clone();
oldWpfLibrary = WpfLibrary.Clone();
oldPostgresLibrary = PostgresLibrary.Clone();
oldOracleLibrary = OracleLibrary.Clone();
Expand Down Expand Up @@ -146,6 +157,10 @@ private Either<Dictionary<string, string>> RunCompiler(string dslCompiler, Libra
sb.Append(" settings=legacy");
if (target.MutableSnowflake)
sb.Append(" settings=mutable-snowflake");
if (!string.IsNullOrWhiteSpace(target.Namespace))
sb.Append(" namespace=").Append(target.Namespace);
if (string.IsNullOrEmpty(target.Extension))
sb.Append(" file-extension");
sb.Append(" format=xml");
var result = Compiler.CompileDsl(sb, dsls, null, cms => XElement.Load(cms));
if (result.Success)
Expand Down Expand Up @@ -190,6 +205,7 @@ public void CompileAll(Dictionary<string, string> files)
ProcessResult(PortableLibrary, files, true);
ProcessResult(WpfLibrary, files, true);
ProcessResult(PhpSource, files, true);
ProcessResult(TypescriptSource, files, true);
ProcessResult(PostgresLibrary, files, true);
ProcessResult(OracleLibrary, files, true);
}
Expand All @@ -205,7 +221,7 @@ private void CopySource(LibraryInfo info, Dictionary<string, string> files, bool
DumpToDisk(info.TargetPath, sources, info.Extension, 3);
}

private static readonly char[] InvalidFileChars = Path.GetInvalidFileNameChars();
private static readonly char[] InvalidFileChars = Path.GetInvalidFileNameChars().Except(new[] { '/' }).ToArray();

private static void DumpToDisk(string folder, Dictionary<string, string> files, string extension, int retries)
{
Expand Down Expand Up @@ -259,7 +275,11 @@ private void ProcessResult(LibraryInfo info, Dictionary<string, string> files, b
}
else
{
var file = Compiler.BuildDotnet(info.Type, info.Name, info.ReferencesNew, files);
var depLen = info.DependenciesPath.Length - info.Dependencies.Length;
var references =
(info.DependenciesExists ? Directory.GetFiles(info.DependenciesPath, "*.dll").Select(it => it.Substring(depLen)) : new string[0])
.Except(info.DependenciesExists ? new[] { Path.Combine(info.Dependencies, info.Name + ".dll") } : new string[0]);
var file = Compiler.BuildDotnet(info, references.ToArray(), files);
File.Copy(file, target, true);
}
}
Expand Down
28 changes: 23 additions & 5 deletions VisualStudioPlugin/Gui/LibraryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,23 @@ public string Dependencies
public readonly bool RequireDependenciesLegacy;
public string Extension { get; private set; }
public string[] ReferencesLegacy { get; private set; }
public Dictionary<string, string> ReferencesNew { get; private set; }
public List<Nuget> Nugets { get; set; }

public class Nuget
{
public string Project { get; set; }
public string Version { get; set; }
public Nuget Clone()
{
return new Nuget { Project = Project, Version = Version };
}

public static bool Equal(List<Nuget> left, List<Nuget> right)
{
if (left.Count != right.Count) return false;
return left.Zip(right, (l, r) => new { l, r }).All(kv => kv.l.Project == kv.r.Project && kv.l.Version == kv.r.Version);
}
}

public static string BasePath { get; set; }
public readonly BuildTypes[] SupportedBuilds;
Expand All @@ -60,7 +76,7 @@ public LibraryInfo(
string compilerName,
bool requireDependenciesLegacy,
string[] referencesLegacy,
Dictionary<string, string> referencesNew,
List<Nuget> nugets,
BuildTypes buildType,
string extension,
params BuildTypes[] supportedBuilds)
Expand All @@ -80,7 +96,7 @@ public LibraryInfo(
}
CompilerName = compilerName;
ReferencesLegacy = referencesLegacy;
ReferencesNew = referencesNew;
Nugets = nugets;
Extension = extension;
this.BuildType = buildType;
Dependencies = Path.Combine("dependencies", type);
Expand All @@ -92,6 +108,7 @@ public LibraryInfo(
public Visibility BuildVisibility { get { return SupportedBuilds != null && SupportedBuilds.Length > 1 ? Visibility.Visible : Visibility.Collapsed; } }
public Visibility DllVisibility { get { return BuildType != BuildTypes.Source ? Visibility.Visible : Visibility.Collapsed; } }
public Visibility LegacyVisibility { get { return BuildType == BuildTypes.LegacyDotNet ? Visibility.Visible : Visibility.Collapsed; } }
public Visibility NetStandardVisibility { get { return BuildType == BuildTypes.DotNetStandard ? Visibility.Visible : Visibility.Collapsed; } }
public string DependenciesPath { get { return Path.Combine(BasePath, Dependencies); } }
public bool TargetExists { get { return PathExists(Target); } }
public bool DependenciesExists { get { return PathExists(Dependencies); } }
Expand Down Expand Up @@ -174,7 +191,7 @@ public bool CanCompile

public LibraryInfo Clone()
{
return new LibraryInfo(Type, CompilerName, RequireDependenciesLegacy, ReferencesLegacy, ReferencesNew, BuildType, Extension, SupportedBuilds)
return new LibraryInfo(Type, CompilerName, RequireDependenciesLegacy, ReferencesLegacy, Nugets.Select(it => it.Clone()).ToList(), BuildType, Extension, SupportedBuilds)
{
CompileOption = CompileOption,
Name = Name,
Expand Down Expand Up @@ -208,7 +225,8 @@ public bool Equals(LibraryInfo other)
&& other.NoPrepareExecute == this.NoPrepareExecute
&& other.Legacy == this.Legacy
&& other.Namespace == this.Namespace
&& other.BuildType == this.BuildType;
&& other.BuildType == this.BuildType
&& Nuget.Equal(other.Nugets, this.Nugets);
}
}
}
4 changes: 4 additions & 0 deletions VisualStudioPlugin/Gui/ToolPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public string DslCompiler
public LibraryInfo OracleLibrary { get { return Targets.OracleLibrary; } }
public LibraryInfo PostgresLibrary { get { return Targets.PostgresLibrary; } }
public LibraryInfo PhpLibrary { get { return Targets.PhpSource; } }
public LibraryInfo TypescriptLibrary { get { return Targets.TypescriptSource; } }

public DatabaseInfo PostgresDb { get; private set; }
public DatabaseInfo OracleDb { get; private set; }
Expand All @@ -55,6 +56,7 @@ public string DslCompiler
public ICommand ConfigureClient { get; private set; }
public ICommand ConfigurePortable { get; private set; }
public ICommand ConfigurePhp { get; private set; }
public ICommand ConfigureTypescript { get; private set; }
public ICommand ConfigureWpf { get; private set; }
public ICommand ConfigurePostgres { get; private set; }
public ICommand ConfigureOracle { get; private set; }
Expand Down Expand Up @@ -136,6 +138,7 @@ public ToolPresenter()
ConfigureClient = new RelayCommand(() => OpenConfigurationAction(new ConfigurationClientControl()));
ConfigurePortable = new RelayCommand(() => OpenConfigurationAction(new ConfigurationPortableControl()));
ConfigurePhp = new RelayCommand(() => OpenConfigurationAction(new ConfigurationPhpControl()));
ConfigureTypescript = new RelayCommand(() => OpenConfigurationAction(new ConfigurationTypescriptControl()));
ConfigureWpf = new RelayCommand(() => OpenConfigurationAction(new ConfigurationWpfControl()));
ConfigurePostgres = new RelayCommand(() => OpenConfigurationAction(new ConfigurationPostgresControl()));
ConfigureOracle = new RelayCommand(() => OpenConfigurationAction(new ConfigurationOracleControl()));
Expand Down Expand Up @@ -379,6 +382,7 @@ public bool CanCompile()
|| ClientLibrary.Compile || PortableLibrary.Compile
|| WpfLibrary.Compile
|| PhpLibrary.Compile
|| TypescriptLibrary.Compile
|| PostgresLibrary.Compile || OracleLibrary.Compile
|| PostgresDb.CompileMigration || OracleDb.CompileMigration);
}
Expand Down
8 changes: 8 additions & 0 deletions VisualStudioPlugin/Gui/View/ConfigurationPocoControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ Build C# classes based on DSL definition
ToolTip="Dependencies for specialized library are used during compilation process."
Foreground="{Binding Path=PocoLibrary.DependenciesColor}" />
</DockPanel>
<DataGrid Visibility="{Binding Path=PostgresLibrary.NetStandardVisibility}"
ItemsSource="{Binding Path=PostgresLibrary.Nugets}"
AutoGenerateColumns="False" CanUserAddRows="True" CanUserResizeColumns="True" CanUserDeleteRows="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Nuget package" Binding="{Binding Project}" Width="*"/>
<DataGridTextColumn Header="Version" Binding="{Binding Version}" Width="*"/>
</DataGrid.Columns>
</DataGrid>
<CheckBox IsChecked="{Binding Path=PocoLibrary.UseUtc}"
Content="UTC time"
Margin="5"
Expand Down
Loading

0 comments on commit 52a8bb3

Please sign in to comment.