diff --git a/build.cake b/build.cake index ad3977a60d..0c0e13e2fb 100644 --- a/build.cake +++ b/build.cake @@ -6,6 +6,8 @@ const string project = "ReactiveUI"; +private const string PharmacistTool = "#tool dotnet:?package=Pharmacist&prerelease"; + ////////////////////////////////////////////////////////////////////// // PROJECTS ////////////////////////////////////////////////////////////////////// @@ -52,21 +54,18 @@ if (IsRunningOnWindows()) }); } -var eventGenerators = new List<(string targetName, DirectoryPath destination)> +var eventGenerators = new List<(string[] targetNames, DirectoryPath destination)> { - ("android", MakeAbsolute(Directory("src/ReactiveUI.Events/"))), - ("ios", MakeAbsolute(Directory("src/ReactiveUI.Events/"))), - ("mac", MakeAbsolute(Directory("src/ReactiveUI.Events/"))), - ("tvos", MakeAbsolute(Directory("src/ReactiveUI.Events/"))), + (new[] { "android", "ios", "mac", "tvos" }, MakeAbsolute(Directory("src/ReactiveUI.Events/"))), + (new[] { "wpf" }, MakeAbsolute(Directory("src/ReactiveUI.Events.WPF/"))), + (new[] { "winforms" }, MakeAbsolute(Directory("src/ReactiveUI.Events.Winforms/"))), }; if (IsRunningOnWindows()) { eventGenerators.AddRange(new [] { - ("wpf", MakeAbsolute(Directory("src/ReactiveUI.Events.WPF/"))), - ("uwp", MakeAbsolute(Directory("src/ReactiveUI.Events/"))), - ("winforms", MakeAbsolute(Directory("src/ReactiveUI.Events.Winforms/"))), + (new[] { "uwp" }, MakeAbsolute(Directory("src/ReactiveUI.Events/"))), }); } @@ -90,58 +89,30 @@ ToolSettings.SetToolSettings(context: Context); // TASKS ////////////////////////////////////////////////////////////////////// -Task("BuildEventBuilder") - .Does(() => -{ - BuildProject("./src/EventBuilder.sln", false); -}); - Task("GenerateEvents") - .IsDependentOn("BuildEventBuilder") - .Does (() => + .Does(() => RequireGlobalTool(PharmacistTool, () => { var eventsArtifactDirectory = BuildParameters.ArtifactsDirectory.Combine("Events"); EnsureDirectoryExists(eventsArtifactDirectory); - var workingDirectory = MakeAbsolute(Directory("./src/EventBuilder/bin/Release/netcoreapp2.1")); - var eventBuilder = workingDirectory.CombineWithFilePath("EventBuilder.dll"); - - DirectoryPath referenceAssembliesPath = null; - if (IsRunningOnWindows()) - { - referenceAssembliesPath = ToolSettings.VsLocation.Combine("./Common7/IDE/ReferenceAssemblies/Microsoft/Framework"); - } - else - { - referenceAssembliesPath = Directory("⁨/Library⁩/Frameworks⁩/Libraries/⁨mono⁩"); - } - foreach (var eventGenerator in eventGenerators) { - var (platform, directory) = eventGenerator; - - var settings = new DotNetCoreExecuteSettings - { - WorkingDirectory = workingDirectory, - }; - - var filename = String.Format("Events_{0}.cs", platform); - var output = directory.CombineWithFilePath(filename); - - Information("Generating events for '{0}'", platform); - DotNetCoreExecute( - eventBuilder, - new ProcessArgumentBuilder() - .AppendSwitch("--platform","=", platform) - .AppendSwitchQuoted("--reference","=", referenceAssembliesPath.ToString()) - .AppendSwitchQuoted("--output-path", "=", output.ToString()), - settings); - - Information("The events have been written to '{0}'", output); + var (platforms, directory) = eventGenerator; + + Information("Generating events for '{0}'", string.Join(", ", platforms)); + StartProcess(Context.Tools.Resolve("Pharmacist*").ToString(), new ProcessSettings { + Arguments = new ProcessArgumentBuilder() + .Append("generate-platform") + .AppendSwitch("-p", string.Join(",", platforms)) + .AppendSwitch("-o", directory.ToString()) + .AppendSwitch("--output-prefix", "Events_") + }); + + Information("The events have been written to '{0}'", directory); } CopyFiles(GetFiles("./src/ReactiveUI.**/Events_*.cs"), eventsArtifactDirectory); -}); +})); BuildParameters.Tasks.BuildTask.IsDependentOn("GenerateEvents"); diff --git a/src/EventBuilder.sln b/src/EventBuilder.sln deleted file mode 100644 index 985dcc3fe6..0000000000 --- a/src/EventBuilder.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26228.12 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBuilder", "EventBuilder\EventBuilder.csproj", "{A6B86E12-057F-4591-98A3-FD50E9CEAE69}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {238383E8-35F5-48A0-9043-8347D6C27876} - EndGlobalSection -EndGlobal diff --git a/src/EventBuilder/App.config b/src/EventBuilder/App.config deleted file mode 100644 index 96e5fcd879..0000000000 --- a/src/EventBuilder/App.config +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/src/EventBuilder/AutoPlatform.cs b/src/EventBuilder/AutoPlatform.cs deleted file mode 100644 index 7a6bd9a064..0000000000 --- a/src/EventBuilder/AutoPlatform.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -namespace EventBuilder -{ - /// - /// The event builder platform. - /// - public enum AutoPlatform - { - /// - /// No platform. - /// - None, - - /// - /// Android platform. - /// - Android, - -#pragma warning disable SA1300 // Element should begin with upper-case letter - /// - /// iOS platform. - /// - iOS, -#pragma warning restore SA1300 // Element should begin with upper-case letter - - /// - /// Mac platform. - /// - Mac, - - /// - /// Tizen platform. - /// - Tizen4, - - /// - /// WPF platform. - /// - WPF, - - /// - /// Xamarin Forms platform. - /// - XamForms, - - /// - /// UWP platform. - /// - UWP, - - /// - /// Win Forms platform. - /// - Winforms, - - /// - /// TV OS platform. - /// - TVOS, - - /// - /// Xamarin Essentials platform. - /// - Essentials - } -} diff --git a/src/EventBuilder/Cecil/DelegateTemplateInformation.cs b/src/EventBuilder/Cecil/DelegateTemplateInformation.cs deleted file mode 100644 index 523541fee5..0000000000 --- a/src/EventBuilder/Cecil/DelegateTemplateInformation.cs +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Globalization; -using System.Linq; -using EventBuilder.Entities; -using Mono.Cecil; - -namespace EventBuilder.Cecil -{ - /// - /// Represents delegate handler mapping from assemblies. - /// - public static class DelegateTemplateInformation - { - /// - /// Creates namespace information from the specified target assemblies. - /// - /// The target assemblies. - /// The namespaces in the target assemblies. - public static NamespaceInfo[] Create(AssemblyDefinition[] targetAssemblies) - { - var garbageTypeList = new[] - { - "AVPlayerItemLegibleOutputPushDelegate" - - // NB: Aparrently this used to break "build on device because of reasons". We don't know what these reasons are and this may not be needed anymore. - }; - - var publicDelegateTypes = targetAssemblies - .SelectMany(SafeTypes.GetSafeTypes) - .Where(x => x.IsPublic && !x.IsInterface && !x.HasGenericParameters && IsCocoaDelegateName(x.Name)) - .Where(x => x.BaseType == null || !x.BaseType.FullName.Contains("MulticastDelegate", StringComparison.InvariantCulture)) - .Where(x => !garbageTypeList.Any(y => x.FullName.Contains(y, StringComparison.InvariantCulture))) - .Select(x => new { Type = x, Delegates = GetPublicDelegateMethods(x) }) - .Where(x => x.Delegates.Length > 0) - .ToArray(); - - return publicDelegateTypes - .GroupBy(x => x.Type.Namespace) - .Select(x => new NamespaceInfo - { - Name = x.Key, - Types = x.Select(y => new PublicTypeInfo - { - Name = y.Type.Name, - Type = y.Type, - Abstract = y.Type.IsAbstract ? "abstract" : string.Empty, - ZeroParameterMethods = - y.Delegates.Where(z => z.Parameters.Count == 0).Select(z => new ParentInfo - { - Name = z.Name - }).ToArray(), - SingleParameterMethods = - y.Delegates.Where(z => z.Parameters.Count == 1).Select(z => new SingleParameterMethod - { - Name = z.Name, - ParameterType = z.Parameters[0].ParameterType.FullName, - ParameterName = z.Parameters[0].Name - }).ToArray(), - MultiParameterMethods = - y.Delegates.Where(z => z.Parameters.Count > 1).Select(z => new MultiParameterMethod - { - Name = z.Name, - ParameterList = - string.Join( - ", ", - z.Parameters.Select( - a => string.Format( - CultureInfo.InvariantCulture, - "{0} {1}", - a.ParameterType.FullName, - a.Name))), - ParameterTypeList = - string.Join(", ", z.Parameters.Select(a => a.ParameterType.FullName)), - ParameterNameList = string.Join(", ", z.Parameters.Select(a => a.Name)) - }).ToArray() - }).ToArray() - }).ToArray(); - } - - private static bool IsCocoaDelegateName(string name) - { - if (name.EndsWith("Delegate", StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - if (name.EndsWith("UITableViewSource", StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return false; - } - - private static MethodDefinition[] GetPublicDelegateMethods(TypeDefinition t) - { - var bannedMethods = new[] { "Dispose", "Finalize" }; - return t.Methods - .Where(x => x.IsVirtual && !x.IsConstructor && !x.IsSetter && x.ReturnType.FullName == "System.Void") - .Where(x => x.Parameters.All(y => !y.ParameterType.FullName.Contains("&", StringComparison.InvariantCulture))) - .Where(x => !bannedMethods.Contains(x.Name)) - .GroupBy(x => x.Name).Select(x => x.OrderByDescending(y => y.Parameters.Count).First()) - .ToArray(); - } - } -} diff --git a/src/EventBuilder/Cecil/EventTemplateInformation.cs b/src/EventBuilder/Cecil/EventTemplateInformation.cs deleted file mode 100644 index 3a709622c8..0000000000 --- a/src/EventBuilder/Cecil/EventTemplateInformation.cs +++ /dev/null @@ -1,259 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using EventBuilder.Entities; -using Mono.Cecil; -using Serilog; - -namespace EventBuilder.Cecil -{ - /// - /// Event template information about events and handlers. - /// - public static class EventTemplateInformation - { - private static readonly Dictionary SubstitutionList = new Dictionary - { - { "Windows.UI.Xaml.Data.PropertyChangedEventArgs", "global::System.ComponentModel.PropertyChangedEventArgs" }, - { "Windows.UI.Xaml.Data.PropertyChangedEventHandler", "global::System.ComponentModel.PropertyChangedEventHandler" }, - { "Windows.Foundation.EventHandler", "EventHandler" }, - { "Windows.Foundation.EventHandler`1", "EventHandler" }, - { "Windows.Foundation.EventHandler`2", "EventHandler" }, - { "System.Boolean", "Boolean" }, - { "System.Boolean`1", "Boolean" }, - { "System.EventHandler", "EventHandler" }, - { "System.EventHandler`1", "EventHandler" }, - { "System.EventHandler`2", "EventHandler" }, - { "System.EventArgs", "EventArgs" }, - { "System.EventArgs`1", "EventArgs" }, - { "System.EventArgs`2", "EventArgs" }, - { "Tizen.NUI.EventHandlerWithReturnType", "Tizen.NUI.EventHandlerWithReturnType" }, - { "Tizen.NUI.EventHandlerWithReturnType`1", "Tizen.NUI.EventHandlerWithReturnType" }, - { "Tizen.NUI.EventHandlerWithReturnType`2", "Tizen.NUI.EventHandlerWithReturnType" }, - { "Tizen.NUI.EventHandlerWithReturnType`3", "Tizen.NUI.EventHandlerWithReturnType" }, - }; - - /// - /// Creates namespace information from the specified target assemblies. - /// - /// The target assemblies. - /// The namespaces in the target assemblies. - public static NamespaceInfo[] Create(AssemblyDefinition[] targetAssemblies) - { - var publicTypesWithEvents = targetAssemblies - .SelectMany(SafeTypes.GetSafeTypes) - .Where(x => x.IsPublic && !x.HasGenericParameters) - .Select(x => new { Type = x, Events = GetPublicEvents(x) }) - .Where(x => x.Events.Length > 0) - .ToArray(); - - var garbageNamespaceList = new[] - { - "Windows.UI.Xaml.Data", - "Windows.UI.Xaml.Interop", - "Windows.UI.Xaml.Input", - "MonoTouch.AudioToolbox", - "MonoMac.AudioToolbox", - "ReactiveUI.Events", - - // Winforms - "System.Collections.Specialized", - "System.Configuration", - "System.ComponentModel.Design", - "System.ComponentModel.Design.Serialization", - "System.CodeDom", - "System.Data.SqlClient", - "System.Data.OleDb", - "System.Data.Odbc", - "System.Data.Common", - "System.Drawing.Design", - "System.Media", - "System.Net", - "System.Net.Mail", - "System.Net.NetworkInformation", - "System.Net.Sockets", - "System.ServiceProcess.Design", - "System.Windows.Input", - "System.Windows.Forms.ComponentModel.Com2Interop", - "System.Windows.Forms.Design", - "System.Timers" - }; - - var namespaceData = publicTypesWithEvents - .GroupBy(x => x.Type.Namespace) - .Where(x => !garbageNamespaceList.Contains(x.Key)) - .Select(x => new NamespaceInfo - { - Name = x.Key, - Types = x.Select(y => new PublicTypeInfo - { - Name = y.Type.Name, - Type = y.Type, - Events = y.Events.Select(z => new PublicEventInfo - { - Name = z.Name, - EventHandlerType = GetRealTypeName(z.EventType), - EventArgsType = GetEventArgsTypeForEvent(z), - ObsoleteEventInfo = GetObsoleteInfo(z) - }).ToArray() - }).ToArray() - }).ToArray(); - - foreach (var type in namespaceData.SelectMany(x => x.Types)) - { - var parentWithEvents = GetParents(type.Type).FirstOrDefault(x => GetPublicEvents(x).Any()); - if (parentWithEvents == null) - { - continue; - } - - type.Parent = new ParentInfo { Name = parentWithEvents.FullName }; - } - - return namespaceData; - } - - private static string RenameBogusTypes(string typeName) - { - if (SubstitutionList.ContainsKey(typeName)) - { - return SubstitutionList[typeName]; - } - - return typeName; - } - - [SuppressMessage("Globalization", "CA1307: Specify StringComparison", Justification = "Replace overload is for .NET Standard only")] - private static string GetEventArgsTypeForEvent(EventDefinition ei) - { - // Find the EventArgs type parameter of the event via digging around via reflection - var type = ei.EventType.Resolve(); - - if (type == null) - { - Log.Debug($"Type for {ei.EventType} is not valid"); - return null; - } - - var invoke = type.Methods.First(x => x.Name == "Invoke"); - if (invoke.Parameters.Count < 2) - { - return null; - } - - var param = invoke.Parameters[1]; - var ret = RenameBogusTypes(param.ParameterType.FullName); - - var generic = ei.EventType as GenericInstanceType; - if (generic != null) - { - foreach ( - var kvp in - type.GenericParameters.Zip(generic.GenericArguments, (name, actual) => new { name, actual })) - { - var realType = GetRealTypeName(kvp.actual); - - var temp = ret.Replace(kvp.name.FullName, realType); - if (temp != ret) - { - ret = temp; - break; - } - } - } - - // NB: Inner types in Mono.Cecil get reported as 'Foo/Bar' - return ret.Replace('/', '.'); - } - - private static string GetRealTypeName(TypeDefinition t) - { - if (t.GenericParameters.Count == 0) - { - return RenameBogusTypes(t.FullName); - } - - var ret = string.Format( - CultureInfo.InvariantCulture, - "{0}<{1}>", - RenameBogusTypes(t.Namespace + "." + t.Name), - string.Join(",", t.GenericParameters.Select(x => GetRealTypeName(x.Resolve())))); - - // NB: Inner types in Mono.Cecil get reported as 'Foo/Bar' - return ret.Replace('/', '.'); - } - - private static string GetRealTypeName(TypeReference t) - { - var generic = t as GenericInstanceType; - if (generic == null) - { - return RenameBogusTypes(t.FullName); - } - - var ret = string.Format( - CultureInfo.InvariantCulture, - "{0}<{1}>", - RenameBogusTypes(generic.Namespace + "." + generic.Name), - string.Join(",", generic.GenericArguments.Select(GetRealTypeName))); - - // NB: Handy place to hook to troubleshoot if something needs to be added to SubstitutionList - // if (generic.FullName.Contains("MarkReachedEventArgs")) { - // // Tizen.NUI.EventHandlerWithReturnType`3 - // // - // } - - // NB: Inner types in Mono.Cecil get reported as 'Foo/Bar' - return ret.Replace('/', '.'); - } - - private static ObsoleteEventInfo GetObsoleteInfo(EventDefinition ei) - { - var obsoleteAttribute = ei.CustomAttributes - .FirstOrDefault(attr => attr.AttributeType.FullName.Equals("System.ObsoleteAttribute", StringComparison.InvariantCulture)); - - if (obsoleteAttribute == null) - { - return null; - } - - return new ObsoleteEventInfo - { - Message = obsoleteAttribute.ConstructorArguments?.ElementAtOrDefault(0).Value?.ToString() ?? string.Empty, - IsError = bool.Parse(obsoleteAttribute.ConstructorArguments?.ElementAtOrDefault(1).Value?.ToString() ?? bool.FalseString) - }; - } - - private static EventDefinition[] GetPublicEvents(TypeDefinition t) - { - return - t.Events.Where(x => x.AddMethod.IsPublic && !x.AddMethod.IsStatic && GetEventArgsTypeForEvent(x) != null) - .ToArray(); - } - - private static IEnumerable GetParents(TypeDefinition type) - { - var current = type.BaseType != null - ? type.BaseType.Resolve() - : null; - - while (current != null) - { - yield return current.Resolve(); - - current = current.BaseType != null - ? current.BaseType.Resolve() - : null; - } - } - } -} diff --git a/src/EventBuilder/Cecil/PathSearchAssemblyResolver.cs b/src/EventBuilder/Cecil/PathSearchAssemblyResolver.cs deleted file mode 100644 index e285960682..0000000000 --- a/src/EventBuilder/Cecil/PathSearchAssemblyResolver.cs +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.IO; -using System.Linq; -using Mono.Cecil; -using Serilog; - -namespace EventBuilder.Cecil -{ - /// - /// Assembly resolver. - /// - /// - public sealed class PathSearchAssemblyResolver : IAssemblyResolver - { - private readonly string[] _targetAssemblyDirs; - - /// - /// Initializes a new instance of the class. - /// - /// The target assembly dirs. - public PathSearchAssemblyResolver(string[] targetAssemblyDirs) - { - _targetAssemblyDirs = targetAssemblyDirs; - } - - /// - public void Dispose() - { - } - - /// - /// Resolves the specified full assembly name. - /// - /// The full name. - /// The parameters. - /// The assembly definition. - public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters) - { - var dllName = fullName.Split(',')[0] + ".dll"; - - var fullPath = _targetAssemblyDirs.Select(x => Path.Combine(x, dllName)).FirstOrDefault(File.Exists); - if (fullPath == null) - { - dllName = fullName.Split(',')[0] + ".winmd"; - fullPath = _targetAssemblyDirs.Select(x => Path.Combine(x, dllName)).FirstOrDefault(File.Exists); - } - - // NB: This hacks WinRT's weird mscorlib to just use the regular one - // We forget why this was needed, maybe it's not needed anymore? - if (fullName.Contains("mscorlib", StringComparison.InvariantCulture) && fullName.Contains("255", StringComparison.InvariantCulture)) - { - fullPath = - Environment.ExpandEnvironmentVariables( - @"%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll"); - } - - if (fullPath == null) - { - var errorMessage = $"Failed to resolve!!! {fullName}"; - Log.Error(errorMessage); - throw new Exception(errorMessage); - } - - return AssemblyDefinition.ReadAssembly(fullPath, parameters); - } - - /// - /// Resolves the specified full assembly name. - /// - /// The full name. - /// The assembly definition. - public AssemblyDefinition Resolve(string fullName) - { - var dllName = fullName.Split(',')[0] + ".dll"; - - var fullPath = _targetAssemblyDirs.Select(x => Path.Combine(x, dllName)).FirstOrDefault(File.Exists); - if (fullPath == null) - { - dllName = fullName.Split(',')[0] + ".winmd"; - fullPath = _targetAssemblyDirs.Select(x => Path.Combine(x, dllName)).FirstOrDefault(File.Exists); - } - - // NB: This hacks WinRT's weird mscorlib to just use the regular one - if (fullName.Contains("mscorlib", StringComparison.InvariantCulture) && fullName.Contains("255", StringComparison.InvariantCulture)) - { - fullPath = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll"); - } - - if (fullPath == null) - { - var errorMessage = $"Failed to resolve!!! {fullName}"; - Log.Error(errorMessage); - throw new Exception(errorMessage); - } - - return AssemblyDefinition.ReadAssembly(fullPath); - } - - /// - /// Resolves the specified full assembly name. - /// - /// The assembly name reference. - /// The reader parameters. - /// The assembly definition. - public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) - { - return Resolve(name.FullName, parameters); - } - - /// - /// Resolves the specified full assembly name. - /// - /// The assembly name reference. - /// The assembly definition. - public AssemblyDefinition Resolve(AssemblyNameReference name) - { - return Resolve(name.FullName); - } - } -} diff --git a/src/EventBuilder/Cecil/README.md b/src/EventBuilder/Cecil/README.md deleted file mode 100644 index d39ac823ad..0000000000 --- a/src/EventBuilder/Cecil/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# Here be dragons (tm) -This section of EventBuilder is a hairball of complexity, it has served us well but it was written in a fit of rage and there now exist better ways which that at the time did not exist. If you have the skills and time, we would _really_ appreciate a pull request that contains a refactor of this away from `Mono.Cecil` towards the `System.Reflection.Metadata` nuget package. - -Deliverables: - -* Unit tests. -* Proper OO modeling instead of static everywhere. -* Refactored to use System.Reflection.Metadata. -* Inline comments explaining what it is doing, how it works and why it's doing what it does. - -Here's an example of how to use `System.Reflection.Metadata` we hope it sets you on the right path forward. - -```csharp -//string path = @"C:\windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll"; -string path = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Xamarin.iOS.dll"; -//string path = @"C:\PROGRA~2\Windows Phone Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd"; -using ( - var peReader = new PEReader(new FileStream(path, FileMode.Open, FileAccess.Read), - PEStreamOptions.PrefetchMetadata)) -{ - var contractReader = peReader.GetMetadataReader(); - - MetadataReader metadataReader = peReader.GetMetadataReader(); - foreach (var type in metadataReader.TypeDefinitions) - { - TypeDefinition typeDefinition = metadataReader.GetTypeDefinition(type); - - foreach (var eventDefinitionHandle in typeDefinition.GetEvents()) - { - var event = metadataReader.GetEvent(eventDefinitionHandle); - var eventName = metadataReader.GetString(test.Name); - - Console.WriteLine(eventName); - } - - } -} -``` - diff --git a/src/EventBuilder/Cecil/SafeTypes.cs b/src/EventBuilder/Cecil/SafeTypes.cs deleted file mode 100644 index 4b44997a61..0000000000 --- a/src/EventBuilder/Cecil/SafeTypes.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.Linq; -using Mono.Cecil; - -namespace EventBuilder.Cecil -{ - /// - /// Safe type helper methods. - /// - public static class SafeTypes - { - /// - /// Gets the safe types from an assembly definition. - /// - /// The assembly definition. - /// Type definitions from the assembly. - public static TypeDefinition[] GetSafeTypes(AssemblyDefinition a) => a.Modules.SelectMany(x => x.GetTypes()).ToArray(); - } -} diff --git a/src/EventBuilder/Cecil/StaticEventTemplateInformation.cs b/src/EventBuilder/Cecil/StaticEventTemplateInformation.cs deleted file mode 100644 index 5d9bc5ba55..0000000000 --- a/src/EventBuilder/Cecil/StaticEventTemplateInformation.cs +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using EventBuilder.Entities; -using Mono.Cecil; - -namespace EventBuilder.Cecil -{ - /// - /// Static event template methods. - /// - public static class StaticEventTemplateInformation - { - /// - /// Creates the specified target assemblies. - /// - /// The target assemblies. - /// The namespace information for the assemblies. - public static NamespaceInfo[] Create(AssemblyDefinition[] targetAssemblies) - { - var publicTypesWithEvents = targetAssemblies - .SelectMany(SafeTypes.GetSafeTypes) - .Where(x => x.IsPublic && !x.HasGenericParameters) - .Select(x => new { Type = x, Events = GetPublicEvents(x) }) - .Where(x => x.Events.Length > 0) - .ToArray(); - - var garbageNamespaceList = new[] - { - "ReactiveUI.Events" - }; - - var namespaceData = publicTypesWithEvents - .GroupBy(x => x.Type.Namespace) - .Where(x => !garbageNamespaceList.Contains(x.Key)) - .Select(x => new NamespaceInfo - { - Name = x.Key, - Types = x.Select(y => new PublicTypeInfo - { - Name = y.Type.Name, - Type = y.Type, - Events = y.Events.Select(z => new PublicEventInfo - { - Name = z.Name, - EventHandlerType = GetRealTypeName(z.EventType), - EventArgsType = GetEventArgsTypeForEvent(z) - }).ToArray() - }).ToArray() - }).ToArray(); - - foreach (var type in namespaceData.SelectMany(x => x.Types)) - { - var parentWithEvents = GetParents(type.Type).FirstOrDefault(x => GetPublicEvents(x).Any()); - if (parentWithEvents == null) - { - continue; - } - - type.Parent = new ParentInfo { Name = parentWithEvents.FullName }; - } - - return namespaceData; - } - - private static IEnumerable GetParents(TypeDefinition type) - { - var current = type.BaseType != null && type.BaseType.ToString() != "System.Object" - ? type.BaseType.Resolve() - : null; - - while (current != null) - { - yield return current.Resolve(); - - current = current.BaseType != null - ? current.BaseType.Resolve() - : null; - } - } - - [SuppressMessage("Globalization", "CA1307: Specify StringComparison", Justification = "Replace overload is for .NET Standard only")] - private static string GetEventArgsTypeForEvent(EventDefinition ei) - { - // Find the EventArgs type parameter of the event via digging around via reflection - var type = ei.EventType.Resolve(); - var invoke = type.Methods.First(x => x.Name == "Invoke"); - if (invoke.Parameters.Count < 1) - { - return null; - } - - var param = invoke.Parameters.Count == 1 ? invoke.Parameters[0] : invoke.Parameters[1]; - var ret = param.ParameterType.FullName; - - var generic = ei.EventType as GenericInstanceType; - if (generic != null) - { - foreach ( - var kvp in - type.GenericParameters.Zip(generic.GenericArguments, (name, actual) => new { name, actual })) - { - var realType = GetRealTypeName(kvp.actual); - - ret = ret.Replace(kvp.name.FullName, realType); - } - } - - // NB: Inner types in Mono.Cecil get reported as 'Foo/Bar' - return ret.Replace('/', '.'); - } - - private static string GetRealTypeName(TypeDefinition t) - { - if (t.GenericParameters.Count == 0) - { - return t.FullName; - } - - var ret = string.Format( - CultureInfo.InvariantCulture, - "{0}<{1}>", - t.Namespace + "." + t.Name, - string.Join(",", t.GenericParameters.Select(x => GetRealTypeName(x.Resolve())))); - - // NB: Inner types in Mono.Cecil get reported as 'Foo/Bar' - return ret.Replace('/', '.'); - } - - private static string GetRealTypeName(TypeReference t) - { - var generic = t as GenericInstanceType; - if (generic == null) - { - return t.FullName; - } - - var ret = string.Format( - CultureInfo.InvariantCulture, - "{0}<{1}>", - generic.Namespace + "." + generic.Name, - string.Join(",", generic.GenericArguments.Select(GetRealTypeName))); - - // NB: Inner types in Mono.Cecil get reported as 'Foo/Bar' - return ret.Replace('/', '.'); - } - - private static EventDefinition[] GetPublicEvents(TypeDefinition t) - { - return - t.Events - - .Where(x => x.AddMethod.IsPublic && GetEventArgsTypeForEvent(x) != null) - .ToArray(); - } - } -} diff --git a/src/EventBuilder/CommandLineOptions.cs b/src/EventBuilder/CommandLineOptions.cs deleted file mode 100644 index 2415ef2d98..0000000000 --- a/src/EventBuilder/CommandLineOptions.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.Collections.Generic; -using CommandLine; - -namespace EventBuilder -{ - /// - /// Command line options for the event builder. - /// - public class CommandLineOptions - { - /// - /// Gets or sets the platform. - /// - [Option('p', "platform", Required = true, HelpText = "Platform to automatically generate. Possible options include: NONE, ANDROID, IOS, WPF, MAC, TIZEN, UWP, XAMFORMS, WINFORMS, TVOS")] - public AutoPlatform Platform { get; set; } - - /// - /// Gets or sets the path where to output the contents. - /// - [Option('o', "output-path", Required = true, HelpText = "The file path where to output the contents.")] - public string OutputPath { get; set; } - - /// - /// Gets or sets the template. - /// - [Option('t', "template", Required = false, HelpText = "Specify another mustache template other than the default.")] - public string Template { get; set; } - - /// - /// Gets or sets the reference assemblies. - /// - [Option('r', "reference", Required = false, HelpText = "Specify a Reference Assemblies location to override the default")] - public string ReferenceAssemblies { get; set; } - - /// - /// Gets or sets the assemblies. - /// Manual generation using the specified assemblies. Use with --platform=NONE. - /// - [Option('a', "assemblies", Required = false, HelpText = "List of assemblies to process. Used for the NONE option")] -#pragma warning disable CA2227 // Collection properties should be read only - public IEnumerable Assemblies { get; set; } -#pragma warning restore CA2227 // Collection properties should be read only - } -} diff --git a/src/EventBuilder/DefaultTemplate.mustache b/src/EventBuilder/DefaultTemplate.mustache deleted file mode 100644 index b7a752e505..0000000000 --- a/src/EventBuilder/DefaultTemplate.mustache +++ /dev/null @@ -1,144 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -//------------------------------------------------------------------------------ -// -// This code was generated from a template. -// -// Manual changes to this file may cause unexpected behavior in your application. -// Manual changes to this file will be overwritten if the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591,0618,0105,0672,0108,SA1402,SA1200,SA1514,SA1615,SA1210,SA1001,SA1403,SA1201,SA1306,SA1601,SA1513,SA1004,SA1516,SA1508,SA1629,SA1507,SA1121,SA1208 - -using System; -using System.Reactive; -using System.Reactive.Linq; -using System.Reactive.Subjects; -using ReactiveUI.Events; - -{{#Namespaces}} -using {{Name}}; -{{/Namespaces}} -{{#DelegateNamespaces}} -using {{Name}}; -{{/DelegateNamespaces}} - -{{#Namespaces}} -namespace {{Name}} -{ - /// - /// Methods that expose events for the platform. - /// - public static class EventsMixin - { -{{#Types}} - /// - /// This class emits {{Name}} events as observables. - /// - /// This instance of {{Name}}. - public static {{Name}}Events Events(this {{Name}} @this) => new {{Name}}Events(@this); -{{/Types}} - } - -{{#Types}} - - /// - /// This class emits {{Name}} events as observables. - /// - public class {{Name}}Events -{{#Parent}} - : {{Name}}Events -{{/Parent}} - { - private {{Name}} _this; - - /// - /// Initializes a new instance of the class. - /// - /// This instance of {{Name}}. - public {{Name}}Events({{Name}} @this) -{{#Parent}} - : base(@this) -{{/Parent}} - { - _this = @this; - } -{{#Events}} - - /// - /// Returns an observable sequence of {{EventArgsType}}. - /// -{{#ObsoleteEventInfo}} - [Obsolete{{#ObsoleteEventInfo.Message}}("{{ObsoleteEventInfo.Message}}"{{#ObsoleteEventInfo.IsError}}, true{{/ObsoleteEventInfo.IsError}}){{/ObsoleteEventInfo.Message}}] -{{/ObsoleteEventInfo}} - public IObservable<{{EventArgsType}}> {{Name}} => - Observable.FromEventPattern<{{EventHandlerType}}, {{EventArgsType}}>(x => _this.{{Name}} += x, x => _this.{{Name}} -= x).Select(x => x.EventArgs); - {{/Events}} - } - {{/Types}} -} - -{{/Namespaces}} -{{#DelegateNamespaces}} - -namespace {{Name}}.Rx -{ - {{#Types}} - public {{Abstract}} partial class {{Name}}Rx : {{Name}} - { - {{#ZeroParameterMethods}} - private readonly SingleAwaitSubject _{{Name}} = new SingleAwaitSubject(); - - /// - /// An observable sequence of signals. - /// - public IObservable {{Name}}Obs => _{{Name}}; - - /// - public override void {{Name}}() - { - _{{Name}}.OnNext(Unit.Default); - } - - {{/ZeroParameterMethods}} - {{#SingleParameterMethods}} - private readonly SingleAwaitSubject<{{ParameterType}}> - _{{Name}} = new SingleAwaitSubject<{{ParameterType}}>(); - - /// - /// An observable sequence of {{ParameterType}}. - /// - public IObservable<{{ParameterType}}> {{Name}}Obs => _{{Name}}; - - /// - public override void {{Name}}({{ParameterType}} {{ParameterName}}) - { - _{{Name}}.OnNext({{ParameterName}}); - } - - {{/SingleParameterMethods}} - - {{#MultiParameterMethods}} - private readonly SingleAwaitSubject> _{{Name}} = new SingleAwaitSubject>(); - - /// - /// An observable sequence of elements. - /// - public IObservable> {{Name}}Obs => _{{Name}}; - - /// - public override void {{Name}}({{ParameterList}}) - { - _{{Name}}.OnNext(Tuple.Create({{ParameterNameList}})); - } - - {{/MultiParameterMethods}} - } - {{/Types}} -} -{{/DelegateNamespaces}} - -#pragma warning restore 1591,0618,0105,0672,0108,SA1402,SA1200,SA1514,SA1615,SA1210,SA1001,SA1403,SA1201,SA1306,SA1601,SA1513,SA1004,SA1516,SA1508,SA1629,SA1507,SA1121,SA1208 diff --git a/src/EventBuilder/Entities/MultiParameterMethod.cs b/src/EventBuilder/Entities/MultiParameterMethod.cs deleted file mode 100644 index d7e66364b2..0000000000 --- a/src/EventBuilder/Entities/MultiParameterMethod.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -namespace EventBuilder.Entities -{ - /// - /// Respresents a method with a mutiple parameters. - /// - public class MultiParameterMethod - { - /// - /// Gets or sets the name. - /// - public string Name { get; set; } - - /// - /// Gets or sets the parameter list. - /// - public string ParameterList { get; set; } // "FooType foo, BarType bar, BazType baz" - - /// - /// Gets or sets the parameter type list. - /// - public string ParameterTypeList { get; set; } // "FooType, BarType, BazType" - - /// - /// Gets or sets the parameter name list. - /// - public string ParameterNameList { get; set; } // "foo, bar, baz" - } -} diff --git a/src/EventBuilder/Entities/NamespaceInfo.cs b/src/EventBuilder/Entities/NamespaceInfo.cs deleted file mode 100644 index 8d5d0610c2..0000000000 --- a/src/EventBuilder/Entities/NamespaceInfo.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.Collections.Generic; - -namespace EventBuilder.Entities -{ - /// - /// Respresents namespace information. - /// - public class NamespaceInfo - { - /// - /// Gets or sets the name. - /// - public string Name { get; set; } - - /// - /// Gets or sets the types. - /// - public IEnumerable Types { get; set; } - } -} diff --git a/src/EventBuilder/Entities/ObsoleteEventInfo.cs b/src/EventBuilder/Entities/ObsoleteEventInfo.cs deleted file mode 100644 index 6cbaae1f01..0000000000 --- a/src/EventBuilder/Entities/ObsoleteEventInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -namespace EventBuilder.Entities -{ - /// - /// Represents an obsolete event. - /// - public class ObsoleteEventInfo - { - /// - /// Gets or sets the message. - /// - public string Message { get; set; } - - /// - /// Gets or sets a value indicating whether the obsolete event is an error. - /// - public bool IsError { get; set; } - } -} diff --git a/src/EventBuilder/Entities/ParentInfo.cs b/src/EventBuilder/Entities/ParentInfo.cs deleted file mode 100644 index 76bdaeec0f..0000000000 --- a/src/EventBuilder/Entities/ParentInfo.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -namespace EventBuilder.Entities -{ - /// - /// Parent information. - /// - public class ParentInfo - { - /// - /// Gets or sets the name. - /// - public string Name { get; set; } - } -} diff --git a/src/EventBuilder/Entities/PublicEventInfo.cs b/src/EventBuilder/Entities/PublicEventInfo.cs deleted file mode 100644 index ec34fd3ee6..0000000000 --- a/src/EventBuilder/Entities/PublicEventInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -namespace EventBuilder.Entities -{ - /// - /// Represents a public event. - /// - public class PublicEventInfo - { - /// - /// Gets or sets the name of the public event. - /// - public string Name { get; set; } - - /// - /// Gets or sets the type of the event handler. - /// - public string EventHandlerType { get; set; } - - /// - /// Gets or sets the type of the event arguments. - /// - public string EventArgsType { get; set; } - - /// - /// Gets or sets the obsolete event information. - /// - public ObsoleteEventInfo ObsoleteEventInfo { get; set; } - } -} diff --git a/src/EventBuilder/Entities/PublicTypeInfo.cs b/src/EventBuilder/Entities/PublicTypeInfo.cs deleted file mode 100644 index 52fbf71ea3..0000000000 --- a/src/EventBuilder/Entities/PublicTypeInfo.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.Collections.Generic; -using Mono.Cecil; - -namespace EventBuilder.Entities -{ - /// - /// Represents public type information. - /// - public class PublicTypeInfo - { - /// - /// Gets or sets the name. - /// - public string Name { get; set; } - - /// - /// Gets or sets the abstract. - /// - public string Abstract { get; set; } - - /// - /// Gets or sets the type. - /// - public TypeDefinition Type { get; set; } - - /// - /// Gets or sets the parent. - /// - public ParentInfo Parent { get; set; } - - /// - /// Gets or sets the events. - /// - public IEnumerable Events { get; set; } - - /// - /// Gets or sets the zero parameter methods. - /// - public IEnumerable ZeroParameterMethods { get; set; } - - /// - /// Gets or sets the single parameter methods. - /// - public IEnumerable SingleParameterMethods { get; set; } - - /// - /// Gets or sets the multi parameter methods. - /// - public IEnumerable MultiParameterMethods { get; set; } - } -} diff --git a/src/EventBuilder/Entities/SingleParameterMethod.cs b/src/EventBuilder/Entities/SingleParameterMethod.cs deleted file mode 100644 index ff2d9b59e2..0000000000 --- a/src/EventBuilder/Entities/SingleParameterMethod.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -namespace EventBuilder.Entities -{ - /// - /// Respresents a method with a single parameter. - /// - public class SingleParameterMethod - { - /// - /// Gets or sets the name. - /// - public string Name { get; set; } - - /// - /// Gets or sets the type of the parameter. - /// - public string ParameterType { get; set; } - - /// - /// Gets or sets the name of the parameter. - /// - public string ParameterName { get; set; } - } -} diff --git a/src/EventBuilder/EventBuilder.csproj b/src/EventBuilder/EventBuilder.csproj deleted file mode 100644 index 879f267df5..0000000000 --- a/src/EventBuilder/EventBuilder.csproj +++ /dev/null @@ -1,33 +0,0 @@ - - - Exe - netcoreapp2.1 - EventBuilder - EventBuilder - latest - false - - - - - PreserveNewest - - - PreserveNewest - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/EventBuilder/EventBuilder.sln b/src/EventBuilder/EventBuilder.sln deleted file mode 100644 index 2438ddbb8f..0000000000 --- a/src/EventBuilder/EventBuilder.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26228.9 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBuilder", "EventBuilder.csproj", "{A6B86E12-057F-4591-98A3-FD50E9CEAE69}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|x86.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|x86.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|Any CPU.Build.0 = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|x86.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {8AD09057-1163-45D2-A260-CB034E6DFD07} - EndGlobalSection -EndGlobal diff --git a/src/EventBuilder/ExitCode.cs b/src/EventBuilder/ExitCode.cs deleted file mode 100644 index 19823af6c5..0000000000 --- a/src/EventBuilder/ExitCode.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -namespace EventBuilder -{ - /// - /// The exit/return code (aka %ERRORLEVEL%) on application exit. - /// - public enum ExitCode - { - /// - /// Success - /// - Success = 0, - - /// - /// Error - /// - Error = 1, - } -} diff --git a/src/EventBuilder/NuGet/NuGetLogger.cs b/src/EventBuilder/NuGet/NuGetLogger.cs deleted file mode 100644 index 57e60018df..0000000000 --- a/src/EventBuilder/NuGet/NuGetLogger.cs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.Threading.Tasks; -using NuGet.Common; - -namespace EventBuilder.NuGet -{ - /// - /// A logger provider for the NuGet clients API. - /// - internal class NuGetLogger : ILogger - { - /// - public void Log(LogLevel level, string data) - { - switch (level) - { - case LogLevel.Warning: - Serilog.Log.Warning(data); - break; - case LogLevel.Error: - Serilog.Log.Error(data); - break; - case LogLevel.Information: - Serilog.Log.Information(data); - break; - case LogLevel.Debug: - Serilog.Log.Debug(data); - break; - default: - Serilog.Log.Verbose(data); - break; - } - } - - /// - public void Log(ILogMessage message) - { - Log(message.Level, message.Message); - } - - /// - public Task LogAsync(LogLevel level, string data) - { - Log(level, data); - return Task.CompletedTask; - } - - /// - public Task LogAsync(ILogMessage message) - { - Log(message); - return Task.CompletedTask; - } - - /// - public void LogDebug(string data) - { - Serilog.Log.Debug(data); - } - - /// - public void LogError(string data) - { - Serilog.Log.Error(data); - } - - /// - public void LogInformation(string data) - { - Serilog.Log.Information(data); - } - - /// - public void LogInformationSummary(string data) - { - Serilog.Log.Information(data); - } - - /// - public void LogMinimal(string data) - { - Serilog.Log.Information(data); - } - - /// - public void LogVerbose(string data) - { - Serilog.Log.Verbose(data); - } - - /// - public void LogWarning(string data) - { - Serilog.Log.Warning(data); - } - } -} diff --git a/src/EventBuilder/NuGet/NuGetPackageHelper.cs b/src/EventBuilder/NuGet/NuGetPackageHelper.cs deleted file mode 100644 index c9ff2aa0ba..0000000000 --- a/src/EventBuilder/NuGet/NuGetPackageHelper.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using NuGet.Configuration; -using NuGet.Frameworks; -using NuGet.PackageManagement; -using NuGet.Packaging; -using NuGet.Packaging.Core; -using NuGet.ProjectManagement; -using NuGet.Protocol.Core.Types; -using NuGet.Resolver; -using Polly; -using Serilog; - -namespace EventBuilder.NuGet -{ - /// - /// A helper class for handling NuGet packages. - /// - public static class NuGetPackageHelper - { - /// - /// Installs a nuget package into the specified directory. - /// - /// The identities of the packages to find. - /// The name of the platform. - /// Optional framework parameter which will force NuGet to evaluate as the specified Framework. If null it will use .NET Standard 2.0. - /// The directory where the NuGet packages are unzipped to. - public static async Task InstallPackages(IEnumerable packageIdentities, AutoPlatform platform, NuGetFramework framework = null) - { - var packageUnzipPath = Path.Combine(Path.GetTempPath(), "EventBuilder.NuGet", platform.ToString()); - if (!Directory.Exists(packageUnzipPath)) - { - Directory.CreateDirectory(packageUnzipPath); - } - - await Task.WhenAll(packageIdentities.Select(x => InstallPackage(x, packageUnzipPath, framework))).ConfigureAwait(false); - - return packageUnzipPath; - } - - private static async Task InstallPackage(PackageIdentity packageIdentity, string packageRoot, NuGetFramework framework) - { - var packagesPath = Path.Combine(packageRoot, "packages"); - var settings = Settings.LoadDefaultSettings(packageRoot, null, new XPlatMachineWideSetting()); - var sourceRepositoryProvider = new SourceRepositoryProvider(settings); - var folder = new FolderNuGetProject(packageRoot, new PackagePathResolver(packageRoot), framework ?? FrameworkConstants.CommonFrameworks.NetStandard20); - var packageManager = new NuGetPackageManager(sourceRepositoryProvider, settings, packagesPath) - { - PackagesFolderNuGetProject = folder - }; - - var resolutionContext = new ResolutionContext( - DependencyBehavior.Lowest, - includePrelease: false, - includeUnlisted: false, - VersionConstraints.None); - var projectContext = new NuGetProjectContext(settings); - - var retryPolicy = Policy - .Handle() - .WaitAndRetryAsync( - 5, - retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), - (exception, _, __) => - { - Log.Warning( - "An exception was thrown whilst retrieving or installing {0}: {1}", - packageIdentity, - exception); - }); - - await retryPolicy.ExecuteAsync(async () => - { - await packageManager.InstallPackageAsync( - packageManager.PackagesFolderNuGetProject, - packageIdentity, - resolutionContext, - projectContext, - sourceRepositoryProvider.GetDefaultRepositories(), - Array.Empty(), - CancellationToken.None).ConfigureAwait(false); - }).ConfigureAwait(false); - } - } -} diff --git a/src/EventBuilder/NuGet/NuGetProjectContext.cs b/src/EventBuilder/NuGet/NuGetProjectContext.cs deleted file mode 100644 index 82a38077aa..0000000000 --- a/src/EventBuilder/NuGet/NuGetProjectContext.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Xml.Linq; -using NuGet.Configuration; -using NuGet.Packaging; -using NuGet.Packaging.Signing; -using NuGet.ProjectManagement; - -namespace EventBuilder.NuGet -{ - /// - /// Context for handling logging inside the nuget project system. - /// - internal class NuGetProjectContext : INuGetProjectContext - { - public NuGetProjectContext(ISettings settings) - { - var nuGetLogger = new NuGetLogger(); - PackageExtractionContext = new PackageExtractionContext( - PackageSaveMode.Files, - XmlDocFileSaveMode.None, - ClientPolicyContext.GetClientPolicy(settings, nuGetLogger), - nuGetLogger); - } - - /// - public PackageExtractionContext PackageExtractionContext { get; set; } - - /// - public XDocument OriginalPackagesConfig { get; set; } - - /// - public NuGetActionType ActionType { get; set; } - - /// - public Guid OperationId { get; set; } - - /// - public ISourceControlManagerProvider SourceControlManagerProvider => null; - - /// - public ExecutionContext ExecutionContext => null; - - /// - public void Log(MessageLevel level, string message, params object[] args) - { - switch (level) - { - case MessageLevel.Warning: - Serilog.Log.Warning(message, args); - break; - case MessageLevel.Error: - Serilog.Log.Error(message, args); - break; - case MessageLevel.Info: - Serilog.Log.Information(message, args); - break; - case MessageLevel.Debug: - Serilog.Log.Debug(message, args); - break; - default: - Serilog.Log.Verbose(message, args); - break; - } - } - - /// - public FileConflictAction ResolveFileConflict(string message) => FileConflictAction.Ignore; - - /// - public void ReportError(string message) - { - Serilog.Log.Error(message); - } - } -} diff --git a/src/EventBuilder/NuGet/SourceRepositoryProvider.cs b/src/EventBuilder/NuGet/SourceRepositoryProvider.cs deleted file mode 100644 index b2b9bc8b97..0000000000 --- a/src/EventBuilder/NuGet/SourceRepositoryProvider.cs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using NuGet.Configuration; -using NuGet.Protocol; -using NuGet.Protocol.Core.Types; - -namespace EventBuilder.NuGet -{ - /// - /// Based off Dave Glick's articles here: https://daveaglick.com/posts/exploring-the-nuget-v3-libraries-part-3 - /// Creates and caches SourceRepository objects, which are - /// the combination of PackageSource instances with a set - /// of supported resource providers. It also manages the set - /// of default source repositories. - /// - internal class SourceRepositoryProvider : ISourceRepositoryProvider - { - private static readonly string[] DefaultSources = - { - "https://api.nuget.org/v3/index.json" - }; - - private readonly List _defaultRepositories = new List(); - - private readonly ConcurrentDictionary _repositoryCache - = new ConcurrentDictionary(); - - private readonly List> _resourceProviders; - - public SourceRepositoryProvider(ISettings settings) - { - // Create the package source provider (needed primarily to get default sources) - PackageSourceProvider = new PackageSourceProvider(settings); - - // Add the v3 provider as default - _resourceProviders = new List>(); - _resourceProviders.AddRange(Repository.Provider.GetCoreV3()); - - AddGlobalDefaults(); - AddDefaultPackageSources(); - } - - /// - public IPackageSourceProvider PackageSourceProvider { get; } - - /// - /// Add the global sources to the default repositories. - /// - public void AddGlobalDefaults() - { - _defaultRepositories.AddRange(PackageSourceProvider.LoadPackageSources() - .Where(x => x.IsEnabled) - .Select(x => new SourceRepository(x, _resourceProviders))); - } - - public void AddDefaultPackageSources() - { - foreach (string defaultSource in DefaultSources) - { - AddDefaultRepository(defaultSource); - } - } - - /// - /// Adds a default source repository to the front of the list. - /// - public void AddDefaultRepository(string packageSource) => _defaultRepositories.Insert(0, CreateRepository(packageSource)); - - public IEnumerable GetDefaultRepositories() => _defaultRepositories; - - /// - /// Creates or gets a non-default source repository. - /// - public SourceRepository CreateRepository(string packageSource) => CreateRepository(new PackageSource(packageSource), FeedType.Undefined); - - /// - /// Creates or gets a non-default source repository by PackageSource. - /// - public SourceRepository CreateRepository(PackageSource packageSource) => CreateRepository(packageSource, FeedType.Undefined); - - /// - /// Creates or gets a non-default source repository by PackageSource. - /// - public SourceRepository CreateRepository(PackageSource packageSource, FeedType feedType) => - _repositoryCache.GetOrAdd(packageSource, x => new SourceRepository(packageSource, _resourceProviders)); - - /// - /// Gets all cached repositories. - /// - public IEnumerable GetRepositories() => _repositoryCache.Values; - } -} diff --git a/src/EventBuilder/PlatformHelper.cs b/src/EventBuilder/PlatformHelper.cs deleted file mode 100644 index e8e8dede5d..0000000000 --- a/src/EventBuilder/PlatformHelper.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Runtime.InteropServices; - -namespace EventBuilder -{ - /// - /// Platform helper methods. - /// - public static class PlatformHelper - { - private static readonly Lazy _IsRunningOnMono = new Lazy(() => !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); - - /// - /// Determines whether the platform is running on mono. - /// - /// - /// true if [is running on mono]; otherwise, false. - /// - public static bool IsRunningOnMono() - { - return _IsRunningOnMono.Value; - } - } -} diff --git a/src/EventBuilder/Platforms/Android.cs b/src/EventBuilder/Platforms/Android.cs deleted file mode 100644 index c2285ab2c6..0000000000 --- a/src/EventBuilder/Platforms/Android.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// - /// The Android platform. - /// - /// - public class Android : BasePlatform - { - private const string DesiredVersion = "v8.1"; - - private readonly string _referenceAssembliesLocation; - - /// - /// Initializes a new instance of the class. - /// - /// The reference assemblies location. - public Android(string referenceAssembliesLocation) - { - _referenceAssembliesLocation = referenceAssembliesLocation; - } - - /// - public override AutoPlatform Platform => AutoPlatform.Android; - - /// - public override Task Extract() - { - var sdks = new List(); - if (PlatformHelper.IsRunningOnMono()) - { - CecilSearchDirectories.Add( - "/Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild-frameworks/MonoAndroid/v1.0"); - - sdks.AddRange(Directory.GetFiles( - "/Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild-frameworks/MonoAndroid", - "Mono.Android.dll", - SearchOption.AllDirectories)); - } - else - { - CecilSearchDirectories.Add(Path.Combine(_referenceAssembliesLocation, "MonoAndroid", "v1.0")); - sdks.AddRange(Directory.GetFiles( - Path.Combine(_referenceAssembliesLocation, "MonoAndroid"), - "Mono.Android.dll", - SearchOption.AllDirectories)); - } - - // Pin to a particular framework version https://github.com/reactiveui/ReactiveUI/issues/1517 - var latestVersion = sdks.Last(x => x.Contains(DesiredVersion, StringComparison.InvariantCulture)); - Assemblies.Add(latestVersion); - CecilSearchDirectories.Add(Path.GetDirectoryName(latestVersion)); - - return Task.CompletedTask; - } - } -} diff --git a/src/EventBuilder/Platforms/BasePlatform.cs b/src/EventBuilder/Platforms/BasePlatform.cs deleted file mode 100644 index aeaa9bf9e1..0000000000 --- a/src/EventBuilder/Platforms/BasePlatform.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// Base platform. - /// - /// - public abstract class BasePlatform : IPlatform - { - /// - /// Initializes a new instance of the class. - /// - protected BasePlatform() - { - Assemblies = new List(); - CecilSearchDirectories = new List(); - } - - /// - public abstract AutoPlatform Platform { get; } - - /// - public List Assemblies { get; } - - /// - public List CecilSearchDirectories { get; } - - /// - public abstract Task Extract(); - } -} diff --git a/src/EventBuilder/Platforms/Bespoke.cs b/src/EventBuilder/Platforms/Bespoke.cs deleted file mode 100644 index a02d3e52b6..0000000000 --- a/src/EventBuilder/Platforms/Bespoke.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// - /// The Bespoke platform. - /// - /// - public class Bespoke : BasePlatform - { - /// - public override AutoPlatform Platform => AutoPlatform.None; - - /// - public override Task Extract() - { - return Task.CompletedTask; - } - } -} diff --git a/src/EventBuilder/Platforms/Essentials.cs b/src/EventBuilder/Platforms/Essentials.cs deleted file mode 100644 index 91ec97eb74..0000000000 --- a/src/EventBuilder/Platforms/Essentials.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using EventBuilder.NuGet; -using NuGet.Packaging.Core; -using NuGet.Versioning; -using Serilog; - -namespace EventBuilder.Platforms -{ - /// - /// Xamarin Essentials platform. - /// - /// - public class Essentials : BasePlatform - { - private readonly PackageIdentity[] _packageNames = new[] - { - new PackageIdentity("Xamarin.Essentials", new NuGetVersion("1.0.1")), - new PackageIdentity("NetStandard.Library", new NuGetVersion("2.0.0")), - }; - - /// - public override AutoPlatform Platform => AutoPlatform.Essentials; - - /// - public override async Task Extract() - { - var packageUnzipPath = await NuGetPackageHelper.InstallPackages(_packageNames, Platform).ConfigureAwait(false); - - Log.Debug($"Package unzip path is {packageUnzipPath}"); - - var xamarinForms = - Directory.GetFiles( - packageUnzipPath, - "Xamarin.Essentials.dll", - SearchOption.AllDirectories); - - var latestVersion = xamarinForms.First(x => x.Contains("netstandard2.0", StringComparison.InvariantCulture)); - Assemblies.Add(latestVersion); - - foreach (var directory in Directory.GetDirectories(packageUnzipPath, "*.*", SearchOption.AllDirectories)) - { - CecilSearchDirectories.Add(directory); - } - } - } -} diff --git a/src/EventBuilder/Platforms/IPlatform.cs b/src/EventBuilder/Platforms/IPlatform.cs deleted file mode 100644 index 41dbeae0ca..0000000000 --- a/src/EventBuilder/Platforms/IPlatform.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// Interface representing a platform assemblies and events. - /// - public interface IPlatform - { - /// - /// Gets the event builder platform. - /// - AutoPlatform Platform { get; } - - /// - /// Gets the assemblies. - /// - List Assemblies { get; } - - /// - /// Gets the cecil search directories. - /// Cecil when run on Mono needs some direction as to the location of the platform specific MSCORLIB. - /// - List CecilSearchDirectories { get; } - - /// - /// Extract details about the platform. - /// - /// A task to monitor the progress. - Task Extract(); - } -} diff --git a/src/EventBuilder/Platforms/Mac.cs b/src/EventBuilder/Platforms/Mac.cs deleted file mode 100644 index fc1de51c1e..0000000000 --- a/src/EventBuilder/Platforms/Mac.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// Mac platform assemblies and events. - /// - /// - // ReSharper disable once InconsistentNaming - public class Mac : BasePlatform - { - private readonly string _referenceAssembliesLocation; - - /// - /// Initializes a new instance of the class. - /// - /// The reference assemblies location. - public Mac(string referenceAssembliesLocation) - { - _referenceAssembliesLocation = referenceAssembliesLocation; - } - - /// - public override AutoPlatform Platform => AutoPlatform.Mac; - - /// - public override Task Extract() - { - if (PlatformHelper.IsRunningOnMono()) - { - var assembly = - @"/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/Xamarin.Mac/Xamarin.Mac.dll"; - Assemblies.Add(assembly); - - CecilSearchDirectories.Add(Path.GetDirectoryName(assembly)); - } - else - { - var assemblies = - Directory.GetFiles( - Path.Combine(_referenceAssembliesLocation, "Xamarin.Mac"), - "Xamarin.Mac.dll", - SearchOption.AllDirectories); - - var latestVersion = assemblies.Last(); - Assemblies.Add(latestVersion); - - CecilSearchDirectories.Add(Path.GetDirectoryName(latestVersion)); - } - - return Task.CompletedTask; - } - } -} diff --git a/src/EventBuilder/Platforms/Tizen.cs b/src/EventBuilder/Platforms/Tizen.cs deleted file mode 100644 index c21708b62a..0000000000 --- a/src/EventBuilder/Platforms/Tizen.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.IO; -using System.Threading.Tasks; -using EventBuilder.NuGet; -using NuGet.Frameworks; -using NuGet.Packaging.Core; -using NuGet.Versioning; -using Serilog; - -namespace EventBuilder.Platforms -{ - /// - /// Tizen platform assemblies and events. - /// - /// - public class Tizen : BasePlatform - { - private readonly PackageIdentity[] _packageNames = new[] - { - new PackageIdentity("Tizen.Net", new NuGetVersion("5.0.0.14562")), - new PackageIdentity("NetStandard.Library", new NuGetVersion("2.0.0")), - }; - - /// - public override AutoPlatform Platform => AutoPlatform.Tizen4; - - /// - public override async Task Extract() - { - var packageUnzipPath = await NuGetPackageHelper.InstallPackages(_packageNames, Platform, FrameworkConstants.CommonFrameworks.Tizen4).ConfigureAwait(false); - - Log.Debug($"Package unzip path is {packageUnzipPath}"); - - Assemblies.AddRange(Directory.GetFiles(packageUnzipPath, "ElmSharp*.dll", SearchOption.AllDirectories)); - Assemblies.AddRange(Directory.GetFiles(packageUnzipPath, "Tizen*.dll", SearchOption.AllDirectories)); - - foreach (var directory in Directory.GetDirectories(packageUnzipPath, "*.*", SearchOption.AllDirectories)) - { - CecilSearchDirectories.Add(directory); - } - } - } -} diff --git a/src/EventBuilder/Platforms/UWP.cs b/src/EventBuilder/Platforms/UWP.cs deleted file mode 100644 index f55b770d3d..0000000000 --- a/src/EventBuilder/Platforms/UWP.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// UWP platform assemblies and events. - /// - /// - public class UWP : BasePlatform - { - /// - public override AutoPlatform Platform => AutoPlatform.UWP; - - /// - public override Task Extract() - { - if (PlatformHelper.IsRunningOnMono()) - { - throw new NotSupportedException("Building events for UWP on Mac is not implemented yet."); - } - - Assemblies.Add(@"C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd"); - - return Task.CompletedTask; - } - } -} diff --git a/src/EventBuilder/Platforms/WPF.cs b/src/EventBuilder/Platforms/WPF.cs deleted file mode 100644 index d1a01b8074..0000000000 --- a/src/EventBuilder/Platforms/WPF.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// WPF platform assemblies and events. - /// - /// - public class WPF : BasePlatform - { - /// - public override AutoPlatform Platform => AutoPlatform.WPF; - - /// - /// Building events for WPF on Mac is not implemented. - public override Task Extract() - { - if (PlatformHelper.IsRunningOnMono()) - { - throw new NotSupportedException("Building events for WPF on Mac is not implemented."); - } - - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\WindowsBase.dll"); - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\PresentationCore.dll"); - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\PresentationFramework.dll"); - - CecilSearchDirectories.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1"); - - return Task.CompletedTask; - } - } -} diff --git a/src/EventBuilder/Platforms/Winforms.cs b/src/EventBuilder/Platforms/Winforms.cs deleted file mode 100644 index 58c2878aff..0000000000 --- a/src/EventBuilder/Platforms/Winforms.cs +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// Win Forms platform assemblies and events. - /// - /// - public class Winforms : BasePlatform - { - /// - public override AutoPlatform Platform => AutoPlatform.Winforms; - - /// - /// Building events for Winforms on Mac is not implemented. - public override Task Extract() - { - if (PlatformHelper.IsRunningOnMono()) - { - throw new NotSupportedException("Building events for Winforms on Mac is not implemented."); - } - - // BackgroundWorker - // EventLog - // FileSystemWatcher - // PerformanceCounter - // Process - // SerialPort - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll"); - - // DataSet - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll"); - - // DirectoryEntry - // DirectorySearcher - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.DirectoryServices.dll"); - - // PrintDocument - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Drawing.dll"); - - // MessageQueue - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Messaging.dll"); - - // BindingNavigator - // ToolStripButton - // ToolStripLabel - // ToolStripButton - // ToolStripButton - // ToolStripButton - // ToolStripSeparator - // ToolStripTextBox - // ToolStripSeparator - // ToolStripButton - // ToolStripButton - // ToolStripSeparator - // BindingSource - // Button - // CheckBox - // CheckedListBox - // ColorDialog - // ComboBox - // ContextMenuStrip - // DataGridView - // DateTimePicker - // DomainUpDown - // ErrorProvider - // WebBrowser - // VScrollBar - // TreeView - // ToolStripContainer - // TrackBar - // ToolStrip - // SplitContainer - // TabControl - // TabPage - // TableLayoutPanel - // TextBox - // TabPage - // StatusStrip - // Splitter - // RichTextBox - // RadioButton - // PropertyGrid - // ProgressBar - // PrintPreviewControl - // PictureBox - // Panel - // NumericUpDown - // MonthCalendar - // MaskedTextBox - // ListView - // ListBox - // LinkLabel - // Label - // HScrollBar - // GroupBox - // FlowLayoutPanel - // MenuStrip - // FolderBrowserDialog - // FontDialog - // HelpProvider - // ImageList - // NotifyIcon - // OpenFileDialog - // PageSetupDialog - // PrintDialog - // PrintPreviewDialog - // SaveFileDialog - // Timer - // ToolTip - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Windows.Forms.dll"); - - // Chart - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Windows.Forms.DataVisualization.dll"); - - // ServiceController - Assemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.ServiceProcess.dll"); - - CecilSearchDirectories.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1"); - - return Task.CompletedTask; - } - } -} diff --git a/src/EventBuilder/Platforms/XamForms.cs b/src/EventBuilder/Platforms/XamForms.cs deleted file mode 100644 index cdc409aa43..0000000000 --- a/src/EventBuilder/Platforms/XamForms.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using EventBuilder.NuGet; -using NuGet.Packaging.Core; -using NuGet.Versioning; -using Serilog; - -namespace EventBuilder.Platforms -{ - /// - /// Xamarin Forms assemblies and events. - /// - /// - public class XamForms : BasePlatform - { - private readonly PackageIdentity[] _packageNames = new[] - { - new PackageIdentity("Xamarin.Forms", new NuGetVersion("3.6.0.220655")), - }; - - /// - public override AutoPlatform Platform => AutoPlatform.XamForms; - - /// - public override async Task Extract() - { - var packageUnzipPath = await NuGetPackageHelper.InstallPackages(_packageNames, Platform).ConfigureAwait(false); - - Log.Debug($"Package unzip path is {packageUnzipPath}"); - - var xamarinForms = - Directory.GetFiles( - packageUnzipPath, - "Xamarin.Forms.Core.dll", - SearchOption.AllDirectories); - - var latestVersion = xamarinForms.Last(); - Assemblies.Add(latestVersion); - - if (PlatformHelper.IsRunningOnMono()) - { - CecilSearchDirectories.Add( - @"/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks/.NETPortable/v4.5/Profile/Profile111"); - CecilSearchDirectories.Add(@"/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Facades"); - } - else - { - CecilSearchDirectories.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Facades"); - } - } - } -} diff --git a/src/EventBuilder/Platforms/iOS.cs b/src/EventBuilder/Platforms/iOS.cs deleted file mode 100644 index 529e8ce876..0000000000 --- a/src/EventBuilder/Platforms/iOS.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// - /// iOS platform assemblies and events. - /// - /// - // ReSharper disable once InconsistentNaming -#pragma warning disable IDE1006 // Naming Styles -#pragma warning disable SA1300 // Element should begin with upper-case letter - public class iOS : BasePlatform -#pragma warning restore SA1300 // Element should begin with upper-case letter -#pragma warning restore IDE1006 // Naming Styles - { - private readonly string _referenceAssembliesLocation; - - /// - /// Initializes a new instance of the class. - /// - /// The reference assemblies location. - public iOS(string referenceAssembliesLocation) - { - _referenceAssembliesLocation = referenceAssembliesLocation; - } - - /// - public override AutoPlatform Platform => AutoPlatform.iOS; - - /// - public override Task Extract() - { - if (PlatformHelper.IsRunningOnMono()) - { - var assembly = - @"/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll"; - Assemblies.Add(assembly); - - CecilSearchDirectories.Add(Path.GetDirectoryName(assembly)); - } - else - { - var assemblies = - Directory.GetFiles( - Path.Combine(_referenceAssembliesLocation, "Xamarin.iOS"), - "Xamarin.iOS.dll", - SearchOption.AllDirectories); - - var latestVersion = assemblies.Last(); - Assemblies.Add(latestVersion); - - CecilSearchDirectories.Add(Path.GetDirectoryName(latestVersion)); - } - - return Task.CompletedTask; - } - } -} diff --git a/src/EventBuilder/Platforms/tvOS.cs b/src/EventBuilder/Platforms/tvOS.cs deleted file mode 100644 index fb2e821ce6..0000000000 --- a/src/EventBuilder/Platforms/tvOS.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace EventBuilder.Platforms -{ - /// - /// TV OS platform assemblies and events. - /// - /// - // ReSharper disable once InconsistentNaming - public class TVOS : BasePlatform - { - private readonly string _referenceAssembliesLocation; - - /// - /// Initializes a new instance of the class. - /// - /// The reference assemblies location. - public TVOS(string referenceAssembliesLocation) - { - _referenceAssembliesLocation = referenceAssembliesLocation; - } - - /// - public override AutoPlatform Platform => AutoPlatform.TVOS; - - /// - public override Task Extract() - { - if (PlatformHelper.IsRunningOnMono()) - { - var assembly = - @"/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.TVOS/Xamarin.TVOS.dll"; - Assemblies.Add(assembly); - - CecilSearchDirectories.Add(Path.GetDirectoryName(assembly)); - } - else - { - var assemblies = - Directory.GetFiles( - Path.Combine(_referenceAssembliesLocation, "Xamarin.TVOS"), - "Xamarin.TVOS.dll", - SearchOption.AllDirectories); - - var latestVersion = assemblies.Last(); - Assemblies.Add(latestVersion); - - CecilSearchDirectories.Add(Path.GetDirectoryName(latestVersion)); - } - - return Task.CompletedTask; - } - } -} diff --git a/src/EventBuilder/Program.cs b/src/EventBuilder/Program.cs deleted file mode 100644 index 46c524883b..0000000000 --- a/src/EventBuilder/Program.cs +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using CommandLine; -using EventBuilder.Cecil; -using EventBuilder.Platforms; -using Mono.Cecil; -using Serilog; -using Stubble.Core.Builders; -using Parser = CommandLine.Parser; - -namespace EventBuilder -{ - internal static class Program - { - private static string _mustacheTemplate = "DefaultTemplate.mustache"; - private static string _referenceAssembliesLocation = PlatformHelper.IsRunningOnMono() ? - @"/Library⁩/Frameworks⁩/Libraries/⁨mono⁩" : - @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework"; - - public static async Task Main(string[] args) - { - Log.Logger = new LoggerConfiguration() - .ReadFrom.AppSettings() - .CreateLogger(); - - // allow app to be debugged in visual studio. - if (Debugger.IsAttached) - { - args = "--platform=android --output-path=test.txt".Split(' '); - } - - await new Parser(parserSettings => parserSettings.CaseInsensitiveEnumValues = true).ParseArguments(args).MapResult( - async options => - { - try - { - if (!string.IsNullOrWhiteSpace(options.Template)) - { - _mustacheTemplate = options.Template; - - Log.Debug("Using {template} instead of the default template.", _mustacheTemplate); - } - - if (!string.IsNullOrWhiteSpace(options.ReferenceAssemblies)) - { - _referenceAssembliesLocation = options.ReferenceAssemblies; - Log.Debug($"Using {_referenceAssembliesLocation} instead of the default reference assemblies location."); - } - - IPlatform platform = null; - switch (options.Platform) - { - case AutoPlatform.None: - if (options.Assemblies.Any() == false) - { - throw new Exception("Assemblies to be used for manual generation were not specified."); - } - - platform = new Bespoke(); - platform.Assemblies.AddRange(options.Assemblies); - - if (PlatformHelper.IsRunningOnMono()) - { - platform.CecilSearchDirectories.AddRange(platform.Assemblies.Select(Path.GetDirectoryName).Distinct().ToList()); - } - else - { - platform.CecilSearchDirectories.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5"); - } - - break; - - case AutoPlatform.Android: - platform = new Android(_referenceAssembliesLocation); - break; - - case AutoPlatform.iOS: - platform = new iOS(_referenceAssembliesLocation); - break; - - case AutoPlatform.Mac: - platform = new Mac(_referenceAssembliesLocation); - break; - - case AutoPlatform.TVOS: - platform = new TVOS(_referenceAssembliesLocation); - break; - - case AutoPlatform.WPF: - platform = new WPF(); - break; - - case AutoPlatform.XamForms: - platform = new XamForms(); - break; - - case AutoPlatform.Tizen4: - platform = new Tizen(); - break; - - case AutoPlatform.UWP: - platform = new UWP(); - break; - - case AutoPlatform.Winforms: - platform = new Winforms(); - break; - - case AutoPlatform.Essentials: - platform = new Essentials(); - _mustacheTemplate = "XamarinEssentialsTemplate.mustache"; - break; - - default: - throw new ArgumentException($"Platform not {options.Platform} supported"); - } - - await ExtractEventsFromAssemblies(options.OutputPath, platform).ConfigureAwait(false); - - Environment.Exit((int)ExitCode.Success); - } - catch (Exception ex) - { - Log.Fatal(ex.ToString()); - - if (Debugger.IsAttached) - { - Debugger.Break(); - } - } - - Environment.Exit((int)ExitCode.Error); - }, - _ => Task.CompletedTask).ConfigureAwait(false); - } - - [SuppressMessage("Globalization", "CA1307: Specify StringComparison", Justification = "Replace overload is for .NET Standard only")] - private static async Task ExtractEventsFromAssemblies(string outputPath, IPlatform platform) - { - await platform.Extract().ConfigureAwait(false); - - Log.Debug("Extracting events from the following assemblies: {assemblies}", platform.Assemblies); - - Log.Debug("Using the following search directories: {assemblies}", platform.CecilSearchDirectories); - var targetAssemblyDirs = platform.CecilSearchDirectories; - - var rp = new ReaderParameters - { - AssemblyResolver = new PathSearchAssemblyResolver(targetAssemblyDirs.ToArray()) - }; - - var targetAssemblies = platform.Assemblies.Select(x => AssemblyDefinition.ReadAssembly(x, rp)).ToArray(); - - Log.Debug("Using {template} as the mustache template", _mustacheTemplate); - - var namespaceData = Array.Empty(); - - switch (platform.Platform) - { - case AutoPlatform.Essentials: - namespaceData = StaticEventTemplateInformation.Create(targetAssemblies); - break; - default: - namespaceData = EventTemplateInformation.Create(targetAssemblies); - break; - } - - var delegateData = DelegateTemplateInformation.Create(targetAssemblies); - - using (var streamReader = new StreamReader(_mustacheTemplate, Encoding.UTF8)) - { - var template = await streamReader.ReadToEndAsync().ConfigureAwait(false); - var stubble = new StubbleBuilder().Build(); - var result = (await stubble.RenderAsync(template, new { Namespaces = namespaceData, DelegateNamespaces = delegateData }).ConfigureAwait(false)) - .Replace("System.String", "string") - .Replace("System.Object", "object") - .Replace("<", "<") - .Replace(">", ">") - .Replace("`1", string.Empty) - .Replace("`2", string.Empty) - .Replace("`3", string.Empty); - - await File.WriteAllTextAsync(outputPath, result).ConfigureAwait(false); - } - } - } -} diff --git a/src/EventBuilder/XamarinEssentialsTemplate.mustache b/src/EventBuilder/XamarinEssentialsTemplate.mustache deleted file mode 100644 index 3f19c975ed..0000000000 --- a/src/EventBuilder/XamarinEssentialsTemplate.mustache +++ /dev/null @@ -1,47 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -//------------------------------------------------------------------------------ -// -// This code was generated from a template. -// -// Manual changes to this file may cause unexpected behavior in your application. -// Manual changes to this file will be overwritten if the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591,0618,0105,0672,0108,SA1402,SA1200,SA1514,SA1615,SA1210,SA1001,SA1403,SA1201,SA1306,SA1601,SA1513,SA1004,SA1516,SA1508,SA1629,SA1507,SA1121,SA1208 - -using System; -using System.Reactive; -using System.Reactive.Linq; -using System.Reactive.Subjects; - -{{#Namespaces}} -using {{Name}}; -{{/Namespaces}} -{{#DelegateNamespaces}} -using {{Name}}; -{{/DelegateNamespaces}} - -{{#Namespaces}} -namespace {{Name}} -{ - public static class Events - { - -{{#Types}} -{{#Events}} - public static IObservable<{{EventArgsType}}> - {{#Type}}{{Name}}{{/Type}}{{Name}}() => - Observable.FromEventPattern<{{EventArgsType}}>( - x => {{#Type}}{{Name}}{{/Type}}.{{Name}} += x, - x => {{#Type}}{{Name}}{{/Type}}.{{Name}} -= x) - .Select(x => x.EventArgs); - - {{/Events}} - {{/Types}} - } - } - {{/Namespaces}} \ No newline at end of file diff --git a/src/ReactiveUI.Events.WPF/ReactiveUI.Events.WPF.csproj b/src/ReactiveUI.Events.WPF/ReactiveUI.Events.WPF.csproj index b39539f464..7fa338b6b2 100644 --- a/src/ReactiveUI.Events.WPF/ReactiveUI.Events.WPF.csproj +++ b/src/ReactiveUI.Events.WPF/ReactiveUI.Events.WPF.csproj @@ -12,8 +12,7 @@ - - + diff --git a/src/ReactiveUI.Events.Winforms/ReactiveUI.Events.Winforms.csproj b/src/ReactiveUI.Events.Winforms/ReactiveUI.Events.Winforms.csproj index cc2914e4da..3d174711ce 100644 --- a/src/ReactiveUI.Events.Winforms/ReactiveUI.Events.Winforms.csproj +++ b/src/ReactiveUI.Events.Winforms/ReactiveUI.Events.Winforms.csproj @@ -13,9 +13,8 @@ - - - + + diff --git a/src/ReactiveUI.Events/ReactiveUI.Events.csproj b/src/ReactiveUI.Events/ReactiveUI.Events.csproj index edfefdc0c4..b7dac04f68 100644 --- a/src/ReactiveUI.Events/ReactiveUI.Events.csproj +++ b/src/ReactiveUI.Events/ReactiveUI.Events.csproj @@ -12,8 +12,7 @@ - - + @@ -23,7 +22,7 @@ Windows Mobile Extensions for the UWP - + @@ -31,11 +30,12 @@ - + + - + @@ -43,11 +43,8 @@ - - - - + diff --git a/src/ReactiveUI.Events/SingleAwaitSubject.cs b/src/ReactiveUI.Events/SingleAwaitSubject.cs deleted file mode 100644 index 634641484a..0000000000 --- a/src/ReactiveUI.Events/SingleAwaitSubject.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for full license information. - -using System; -using System.Reactive.Linq; -using System.Reactive.Subjects; - -namespace ReactiveUI.Events -{ - internal sealed class SingleAwaitSubject : ISubject, IDisposable - { - private readonly Subject _inner = new Subject(); - - public AsyncSubject GetAwaiter() - { - return _inner.Take(1).GetAwaiter(); - } - - public void OnNext(T value) - { - _inner.OnNext(value); - } - - public void OnError(Exception error) - { - _inner.OnError(error); - } - - public void OnCompleted() - { - _inner.OnCompleted(); - } - - public IDisposable Subscribe(IObserver observer) - { - return _inner.Subscribe(observer); - } - - /// - public void Dispose() - { - _inner?.Dispose(); - } - } -} diff --git a/tools/nuget/nuget.exe b/tools/nuget/nuget.exe deleted file mode 100644 index 1ada5b2b67..0000000000 --- a/tools/nuget/nuget.exe +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1051f2053643a9fb5d8bf9ba7cf638164a3118541e90a671442cf3499c9606ef -size 5688608