From 66ab434cf0c4b780ca9b92bdb765fc5eddea0275 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Tue, 25 Jun 2019 18:41:45 +1000 Subject: [PATCH 1/2] housekeeping: set to match master@f02616b --- .github/FUNDING.yml | 2 + .gitignore | 151 ++++++++-- README.md | 15 +- build.cake | 76 ++--- directory.build.props | 16 -- .../IntegrationTests.XamarinForms.csproj | 2 +- src/Directory.build.props | 41 ++- src/Directory.build.props.orig | 98 +++++++ src/EventBuilder.sln | 73 ----- src/EventBuilder/App.config | 19 -- src/EventBuilder/AutoPlatform.cs | 80 ------ .../Cecil/DelegateTemplateInformation.cs | 111 -------- .../Cecil/EventTemplateInformation.cs | 259 ------------------ .../Cecil/PathSearchAssemblyResolver.cs | 125 --------- src/EventBuilder/Cecil/README.md | 39 --- src/EventBuilder/Cecil/SafeTypes.cs | 23 -- .../Cecil/StaticEventTemplateInformation.cs | 163 ----------- src/EventBuilder/CommandLineOptions.cs | 49 ---- src/EventBuilder/DefaultTemplate.mustache | 144 ---------- .../Entities/MultiParameterMethod.cs | 33 --- src/EventBuilder/Entities/NamespaceInfo.cs | 25 -- .../Entities/ObsoleteEventInfo.cs | 23 -- src/EventBuilder/Entities/ParentInfo.cs | 18 -- src/EventBuilder/Entities/PublicEventInfo.cs | 33 --- src/EventBuilder/Entities/PublicTypeInfo.cs | 56 ---- .../Entities/SingleParameterMethod.cs | 28 -- src/EventBuilder/EventBuilder.csproj | 33 --- src/EventBuilder/EventBuilder.sln | 31 --- src/EventBuilder/ExitCode.cs | 23 -- src/EventBuilder/NuGet/NuGetLogger.cs | 101 ------- src/EventBuilder/NuGet/NuGetPackageHelper.cs | 94 ------- src/EventBuilder/NuGet/NuGetProjectContext.cs | 80 ------ .../NuGet/SourceRepositoryProvider.cs | 99 ------- src/EventBuilder/PlatformHelper.cs | 29 -- src/EventBuilder/Platforms/Android.cs | 68 ----- src/EventBuilder/Platforms/BasePlatform.cs | 38 --- src/EventBuilder/Platforms/Bespoke.cs | 26 -- src/EventBuilder/Platforms/Essentials.cs | 54 ---- src/EventBuilder/Platforms/IPlatform.cs | 38 --- src/EventBuilder/Platforms/Mac.cs | 61 ----- src/EventBuilder/Platforms/Tizen.cs | 47 ---- src/EventBuilder/Platforms/UWP.cs | 33 --- src/EventBuilder/Platforms/WPF.cs | 38 --- src/EventBuilder/Platforms/Winforms.cs | 130 --------- src/EventBuilder/Platforms/XamForms.cs | 58 ---- src/EventBuilder/Platforms/iOS.cs | 66 ----- src/EventBuilder/Platforms/tvOS.cs | 61 ----- src/EventBuilder/Program.cs | 205 -------------- .../XamarinEssentialsTemplate.mustache | 47 ---- .../ControlFetcherMixin.cs | 135 +-------- .../ReactiveRecyclerViewAdapter.cs | 25 +- .../FollowObservableStateBehavior.cs | 2 +- .../Platforms/net4/ObservableTrigger.cs | 2 +- src/ReactiveUI.Blend/ReactiveUI.Blend.csproj | 2 +- .../ReactiveUI.Events.WPF.csproj | 11 +- .../ReactiveUI.Events.Winforms.csproj | 9 +- .../ReactiveUI.Events.XamEssentials.csproj | 14 +- .../ReactiveUI.Events.XamForms.csproj | 16 +- .../ReactiveUI.Events.csproj | 19 +- src/ReactiveUI.Events/SingleAwaitSubject.cs | 47 ---- .../ReactiveUI.Fody.Helpers.csproj | 2 +- ...provalTests.ReactiveUI.net461.approved.txt | 78 +++--- ...ests.ReactiveUI.netcoreapp2.0.approved.txt | 78 +++--- ...ApiApprovalTests.Blend.net461.approved.txt | 4 +- .../ApiApprovalTests.Wpf.net461.approved.txt | 8 + .../ReactiveObject/ReactiveObjectTests.cs | 14 + src/ReactiveUI.Tests/ReactiveUI.Tests.csproj | 2 +- .../ReactiveUI.Winforms.csproj | 2 +- src/ReactiveUI.Wpf/ReactiveUI.Wpf.csproj | 2 +- .../ReactiveUI.XamForms.csproj | 2 +- .../ReactiveNotifyPropertyChangedMixin.cs | 2 +- .../Platforms/android/ControlFetcherMixin.cs | 219 ++++++--------- .../Platforms/android/HandlerScheduler.cs | 5 - .../netstandard2.0/PlatformRegistrations.cs | 2 +- .../Platforms/windows-common/ReactivePage.cs | 114 ++++++++ .../windows-common/RoutedViewHost.cs | 2 +- .../windows-common/ViewModelViewHost.cs | 2 +- .../IReactiveObjectExtensions.cs | 3 + src/ReactiveUI/ReactiveUI.csproj | 2 +- src/global.json | 2 +- tools/nuget/nuget.exe | 3 - tools/packages.config | 4 + 82 files changed, 676 insertions(+), 3320 deletions(-) create mode 100644 .github/FUNDING.yml delete mode 100644 directory.build.props create mode 100644 src/Directory.build.props.orig delete mode 100644 src/EventBuilder.sln delete mode 100644 src/EventBuilder/App.config delete mode 100644 src/EventBuilder/AutoPlatform.cs delete mode 100644 src/EventBuilder/Cecil/DelegateTemplateInformation.cs delete mode 100644 src/EventBuilder/Cecil/EventTemplateInformation.cs delete mode 100644 src/EventBuilder/Cecil/PathSearchAssemblyResolver.cs delete mode 100644 src/EventBuilder/Cecil/README.md delete mode 100644 src/EventBuilder/Cecil/SafeTypes.cs delete mode 100644 src/EventBuilder/Cecil/StaticEventTemplateInformation.cs delete mode 100644 src/EventBuilder/CommandLineOptions.cs delete mode 100644 src/EventBuilder/DefaultTemplate.mustache delete mode 100644 src/EventBuilder/Entities/MultiParameterMethod.cs delete mode 100644 src/EventBuilder/Entities/NamespaceInfo.cs delete mode 100644 src/EventBuilder/Entities/ObsoleteEventInfo.cs delete mode 100644 src/EventBuilder/Entities/ParentInfo.cs delete mode 100644 src/EventBuilder/Entities/PublicEventInfo.cs delete mode 100644 src/EventBuilder/Entities/PublicTypeInfo.cs delete mode 100644 src/EventBuilder/Entities/SingleParameterMethod.cs delete mode 100644 src/EventBuilder/EventBuilder.csproj delete mode 100644 src/EventBuilder/EventBuilder.sln delete mode 100644 src/EventBuilder/ExitCode.cs delete mode 100644 src/EventBuilder/NuGet/NuGetLogger.cs delete mode 100644 src/EventBuilder/NuGet/NuGetPackageHelper.cs delete mode 100644 src/EventBuilder/NuGet/NuGetProjectContext.cs delete mode 100644 src/EventBuilder/NuGet/SourceRepositoryProvider.cs delete mode 100644 src/EventBuilder/PlatformHelper.cs delete mode 100644 src/EventBuilder/Platforms/Android.cs delete mode 100644 src/EventBuilder/Platforms/BasePlatform.cs delete mode 100644 src/EventBuilder/Platforms/Bespoke.cs delete mode 100644 src/EventBuilder/Platforms/Essentials.cs delete mode 100644 src/EventBuilder/Platforms/IPlatform.cs delete mode 100644 src/EventBuilder/Platforms/Mac.cs delete mode 100644 src/EventBuilder/Platforms/Tizen.cs delete mode 100644 src/EventBuilder/Platforms/UWP.cs delete mode 100644 src/EventBuilder/Platforms/WPF.cs delete mode 100644 src/EventBuilder/Platforms/Winforms.cs delete mode 100644 src/EventBuilder/Platforms/XamForms.cs delete mode 100644 src/EventBuilder/Platforms/iOS.cs delete mode 100644 src/EventBuilder/Platforms/tvOS.cs delete mode 100644 src/EventBuilder/Program.cs delete mode 100644 src/EventBuilder/XamarinEssentialsTemplate.mustache delete mode 100644 src/ReactiveUI.Events/SingleAwaitSubject.cs create mode 100644 src/ReactiveUI/Platforms/windows-common/ReactivePage.cs delete mode 100644 tools/nuget/nuget.exe create mode 100644 tools/packages.config diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000000..860a0b101e --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +open_collective: reactiveui + diff --git a/.gitignore b/.gitignore index c88ebe9bf7..d5ff53b4b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files +*.rsuser *.suo *.user *.userosscache @@ -10,6 +13,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# Mono auto generated files +mono_crash.* + # Build results [Dd]ebug/ [Dd]ebugPublic/ @@ -17,18 +23,20 @@ [Rr]eleases/ x64/ x86/ -build/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ bld/ [Bb]in/ [Oo]bj/ +[Ll]og/ -# Visual Studio 2015 cache/options directory +# Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ -# Visual Studio code -.vscode/ +# Visual Studio 2017 auto generated files +Generated\ Files/ # MSTest test Results [Tt]est[Rr]esult*/ @@ -37,26 +45,35 @@ bld/ # NUNIT *.VisualState.xml TestResult.xml +nunit-*.xml # Build Results of an ATL Project [Dd]ebugPS/ [Rr]eleasePS/ dlldata.c -# DNX -*.lock.json +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json artifacts/ -*.nuget.props -*.nuget.targets +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio *_i.c *_p.c -*_i.h +*_h.h *.ilk *.meta *.obj +*.iobj *.pch *.pdb +*.ipdb *.pgc *.pgd *.rsp @@ -66,6 +83,7 @@ artifacts/ *.tlh *.tmp *.tmp_proj +*_wpftmp.csproj *.log *.vspscc *.vssscc @@ -73,7 +91,6 @@ artifacts/ *.pidb *.svclog *.scc -*.binlog # Chutzpah Test files _Chutzpah* @@ -86,6 +103,8 @@ ipch/ *.opensdf *.sdf *.cachefile +*.VC.db +*.VC.VC.opendb # Visual Studio profiler *.psess @@ -93,6 +112,9 @@ ipch/ *.vspx *.sap +# Visual Studio Trace Files +*.e2e + # TFS 2012 Local Workspace $tf/ @@ -113,6 +135,14 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch _NCrunch_* .*crunch*.local.xml @@ -144,37 +174,52 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings +# Note: Comment the next line if you want to checkin your web deploy settings, # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + # NuGet Packages *.nupkg +# NuGet Symbol Packages +*.snupkg # The packages folder can be ignored because of Package Restore -**/packages/* +**/[Pp]ackages/* # except build/, which is used as an MSBuild target. -!**/packages/build/ +!**/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets -# Windows Azure Build Output +# Microsoft Azure Build Output csx/ *.build.csdef -# Windows Azure Emulator +# Microsoft Azure Emulator ecf/ rcf/ -# Windows Store app package directory +# Windows Store app package directories and files AppPackages/ BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload # Visual Studio cache files # files ending in .cache can be ignored *.[Cc]ache # but keep track of directories ending in .cache -!*.[Cc]ache/ +!?*.[Cc]ache/ # Others ClientBin/ @@ -182,11 +227,19 @@ ClientBin/ *~ *.dbmdl *.dbproj.schemaview +*.jfm *.pfx *.publishsettings -node_modules/ orleans.codegen.cs +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + # RIA/Silverlight projects Generated_Code/ @@ -197,15 +250,22 @@ _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak # SQL Server files *.mdf *.ldf +*.ndf # Business Intelligence projects *.rdl.data *.bim.layout *.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl # Microsoft Fakes FakesAssemblies/ @@ -215,6 +275,7 @@ FakesAssemblies/ # Node.js Tools for Visual Studio .ntvs_analysis.dat +node_modules/ # Visual Studio 6 build log *.plg @@ -222,6 +283,9 @@ FakesAssemblies/ # Visual Studio 6 workspace options file *.opt +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts @@ -232,12 +296,57 @@ _Pvt_Extensions # Paket dependency manager .paket/paket.exe +paket-files/ # FAKE - F# Make .fake/ -# Tools -tools/ +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +tools/** +!tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ # ReactiveUI artifacts/ diff --git a/README.md b/README.md index 67f335b236..1ed01c905c 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,9 @@ 🔨 Get Started 🛍 Install Packages 🎞 Watch Videos 🎓 View Samples 🎤 Discuss ReactiveUI +

Book

+There has been an excellent book written by our Alumni maintainer Kent Boogart. +

Introduction to Reactive Programming

Long ago, when computer programming first came to be, machines had to be programmed quite manually. If the technician entered the correct sequence of machine codes in the correct order, then the resulting program behavior would satisfy the business requirements. Instead of telling a computer how to do its job, which error-prone and relies too heavily on the infallibility of the programmer, why don't we just tell it what it's job is and let it figure the rest out? @@ -301,12 +304,6 @@ ReactiveUI is part of the [.NET Foundation](https://www.dotnetfoundation.org/). Geoffrey Huntley

Sydney, Australia

- - -
- Kent Boogaart -

Adelaide, Australia

-
@@ -342,6 +339,12 @@ The following have been core team members in the past. +
+ +
+ Kent Boogaart +

Brisbane, Australia

+

diff --git a/build.cake b/build.cake index bb702c24c0..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,26 +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/"))), - ("tizen4", MakeAbsolute(Directory("src/ReactiveUI.Events/"))), - ("essentials", MakeAbsolute(Directory("src/ReactiveUI.Events.XamEssentials/"))), - ("tvos", MakeAbsolute(Directory("src/ReactiveUI.Events/"))), - ("xamforms", MakeAbsolute(Directory("src/ReactiveUI.Events.XamForms/"))), + (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/"))), - ("NetCoreAppWPF", MakeAbsolute(Directory("src/ReactiveUI.Events.WPF/"))), - ("NetCoreAppWinforms", MakeAbsolute(Directory("src/ReactiveUI.Events.Winforms/"))), + (new[] { "uwp" }, MakeAbsolute(Directory("src/ReactiveUI.Events/"))), }); } @@ -95,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/directory.build.props b/directory.build.props deleted file mode 100644 index 1d4ece3727..0000000000 --- a/directory.build.props +++ /dev/null @@ -1,16 +0,0 @@ - - - .NET Foundation and Contributors - Copyright (c) .NET Foundation and Contributors - MIT - https://reactiveui.net - https://github.com/reactiveui/styleguide/blob/master/logo/main.png?raw=true - xanaisbettsx;ghuntley - ReactiveUI ($(TargetFramework)) - mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;xamarin.tvos;wpf;net;netstandard;net461;uwp;tizen - https://github.com/reactiveui/ReactiveUI/releases - https://github.com/reactiveui/reactiveui - git - true - - diff --git a/integrationtests/IntegrationTests.XamarinForms/IntegrationTests.XamarinForms.csproj b/integrationtests/IntegrationTests.XamarinForms/IntegrationTests.XamarinForms.csproj index 92f4c151b5..f9f10014c7 100644 --- a/integrationtests/IntegrationTests.XamarinForms/IntegrationTests.XamarinForms.csproj +++ b/integrationtests/IntegrationTests.XamarinForms/IntegrationTests.XamarinForms.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Directory.build.props b/src/Directory.build.props index b2d6f386d8..3be0c1cb2b 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -1,24 +1,37 @@ - xanaisbettsx;ghuntley - mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;xamarin.tvos;wpf;net;netstandard;net461;uwp;tizen - https://reactiveui.net/blog/ true $(NoWarn);1591;1701;1702;1705;VSX1000 AnyCPU $(MSBuildProjectName.Contains('Tests')) embedded + $(MSBuildThisFileDirectory)analyzers.ruleset + + .NET Foundation and Contributors + Copyright (c) .NET Foundation and Contributors + MIT + https://reactiveui.net + https://github.com/reactiveui/styleguide/blob/master/logo/main.png?raw=true + xanaisbettsx;ghuntley + mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;xamarin.tvos;wpf;net;netstandard;net461;uwp;tizen + https://github.com/reactiveui/ReactiveUI/releases + https://github.com/reactiveui/reactiveui + git + + + false + $(EnableSourceLink) true true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - $(MSBuildThisFileDirectory)analyzers.ruleset + - - false - $(EnableSourceLink) + + + Full @@ -27,14 +40,14 @@ - + - - - + + + @@ -42,7 +55,7 @@ - + @@ -61,11 +74,9 @@ - + - - diff --git a/src/Directory.build.props.orig b/src/Directory.build.props.orig new file mode 100644 index 0000000000..84317392a3 --- /dev/null +++ b/src/Directory.build.props.orig @@ -0,0 +1,98 @@ + + +<<<<<<< HEAD + xanaisbettsx;ghuntley + mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;xamarin.tvos;wpf;net;netstandard;net461;uwp;tizen + https://reactiveui.net/blog/ +======= +>>>>>>> master + true + $(NoWarn);1591;1701;1702;1705;VSX1000 + AnyCPU + $(MSBuildProjectName.Contains('Tests')) + embedded + $(MSBuildThisFileDirectory)analyzers.ruleset + + .NET Foundation and Contributors + Copyright (c) .NET Foundation and Contributors + MIT + https://reactiveui.net + https://github.com/reactiveui/styleguide/blob/master/logo/main.png?raw=true + xanaisbettsx;ghuntley + mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;xamarin.tvos;wpf;net;netstandard;net461;uwp;tizen + https://github.com/reactiveui/ReactiveUI/releases + https://github.com/reactiveui/reactiveui + git + + + false + $(EnableSourceLink) + + true + + true + + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + + Full + + + + $(MSBuildThisFileDirectory)analyzers.tests.ruleset + false + + + +<<<<<<< HEAD + +======= + +>>>>>>> master + + + + +<<<<<<< HEAD + + + +======= + + + +>>>>>>> master + + + + + + + + + + + + $(MSBuildThisFileDirectory) + + + + + + + + + + + + + + + + + + + + diff --git a/src/EventBuilder.sln b/src/EventBuilder.sln deleted file mode 100644 index 59b3db58fe..0000000000 --- a/src/EventBuilder.sln +++ /dev/null @@ -1,73 +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 - net_3_5_Debug_ReadOnly|Any CPU = net_3_5_Debug_ReadOnly|Any CPU - net_3_5_Debug|Any CPU = net_3_5_Debug|Any CPU - net_3_5_Release_ReadOnly|Any CPU = net_3_5_Release_ReadOnly|Any CPU - net_3_5_Release|Any CPU = net_3_5_Release|Any CPU - net_4_0_Debug_ReadOnly|Any CPU = net_4_0_Debug_ReadOnly|Any CPU - net_4_0_Debug|Any CPU = net_4_0_Debug|Any CPU - net_4_0_Release_ReadOnly|Any CPU = net_4_0_Release_ReadOnly|Any CPU - net_4_0_Release|Any CPU = net_4_0_Release|Any CPU - net_462_Debug_ReadOnly|Any CPU = net_462_Debug_ReadOnly|Any CPU - net_462_Debug|Any CPU = net_462_Debug|Any CPU - net_462_Release_ReadOnly|Any CPU = net_462_Release_ReadOnly|Any CPU - net_462_Release|Any CPU = net_462_Release|Any CPU - netstandard_Debug_ReadOnly|Any CPU = netstandard_Debug_ReadOnly|Any CPU - netstandard_Debug|Any CPU = netstandard_Debug|Any CPU - netstandard_Release_ReadOnly|Any CPU = netstandard_Release_ReadOnly|Any CPU - netstandard_Release|Any CPU = netstandard_Release|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}.net_3_5_Debug_ReadOnly|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_3_5_Debug_ReadOnly|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_3_5_Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_3_5_Debug|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_3_5_Release_ReadOnly|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_3_5_Release_ReadOnly|Any CPU.Build.0 = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_3_5_Release|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_3_5_Release|Any CPU.Build.0 = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_4_0_Debug_ReadOnly|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_4_0_Debug_ReadOnly|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_4_0_Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_4_0_Debug|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_4_0_Release_ReadOnly|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_4_0_Release_ReadOnly|Any CPU.Build.0 = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_4_0_Release|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_4_0_Release|Any CPU.Build.0 = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_462_Debug_ReadOnly|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_462_Debug_ReadOnly|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_462_Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_462_Debug|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_462_Release_ReadOnly|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_462_Release_ReadOnly|Any CPU.Build.0 = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_462_Release|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.net_462_Release|Any CPU.Build.0 = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.netstandard_Debug_ReadOnly|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.netstandard_Debug_ReadOnly|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.netstandard_Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.netstandard_Debug|Any CPU.Build.0 = Debug|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.netstandard_Release_ReadOnly|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.netstandard_Release_ReadOnly|Any CPU.Build.0 = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.netstandard_Release|Any CPU.ActiveCfg = Release|Any CPU - {A6B86E12-057F-4591-98A3-FD50E9CEAE69}.netstandard_Release|Any CPU.Build.0 = Release|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 32fd9962f3..0000000000 --- a/src/EventBuilder/AutoPlatform.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. - -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, - - /// - /// WPF for NetCoreApp 3.0 and above. - /// - NetCoreAppWPF, - - /// - /// WinForms for NetCoreApp 3.0 and above. - /// - NetCoreAppWinforms, - - /// - /// 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 547e7f22dc..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 f5ea59a080..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.5.0.129452")), - }; - - /// - 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 e6a2699a77..0000000000 --- a/src/EventBuilder/Program.cs +++ /dev/null @@ -1,205 +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; - - case AutoPlatform.NetCoreAppWPF: - platform = new NetCoreAppWPF(); - break; - - case AutoPlatform.NetCoreAppWinforms: - platform = new NetCoreAppWinforms(); - 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.AndroidSupport/ControlFetcherMixin.cs b/src/ReactiveUI.AndroidSupport/ControlFetcherMixin.cs index 1990863e3a..b7da77fa45 100644 --- a/src/ReactiveUI.AndroidSupport/ControlFetcherMixin.cs +++ b/src/ReactiveUI.AndroidSupport/ControlFetcherMixin.cs @@ -4,16 +4,9 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; -using Android.App; -using Android.Support.V7.App; using Android.Views; -using Java.Interop; using static ReactiveUI.ControlFetcherMixin; +using Fragment = Android.Support.V4.App.Fragment; namespace ReactiveUI.AndroidSupport { @@ -22,135 +15,35 @@ namespace ReactiveUI.AndroidSupport /// Fragments via property names, similar to Butter Knife, as well as allows /// you to fetch controls manually. /// - public static class ControlFetcherMixin + public static class ControlFetcherMixin { - private static readonly Dictionary controlIds; - - private static readonly ConditionalWeakTable> viewCache = - new ConditionalWeakTable>(); - - private static readonly MethodInfo getControlActivity; - private static readonly MethodInfo getControlView; - - static ControlFetcherMixin() - { - // NB: This is some hacky shit, but on Xamarin.Android at the moment, - // this is always the entry assembly. - var assm = AppDomain.CurrentDomain.GetAssemblies()[1]; - var resources = assm.GetModules().SelectMany(x => x.GetTypes()).First(x => x.Name == "Resource"); - - controlIds = resources.GetNestedType("Id").GetFields() - .Where(x => x.FieldType == typeof(int)) - .ToDictionary(k => k.Name.ToLowerInvariant(), v => (int)v.GetRawConstantValue()); - - var type = typeof(ControlFetcherMixin); - getControlActivity = type.GetMethod("GetControl", new[] { typeof(AppCompatActivity), typeof(string) }); - getControlView = type.GetMethod("GetControl", new[] { typeof(View), typeof(string) }); - } - /// - /// Gets the control from an activiy. + /// Wires a control to a property. + /// This should be called in the Fragment's OnCreateView, with the newly inflated layout. /// - /// The control type. - /// The activity. - /// The property name. - /// Returns a view. - public static T GetControl(this AppCompatActivity @this, [CallerMemberName]string propertyName = null) - where T : View => (T)GetCachedControl(propertyName, @this, () => @this.FindViewById(controlIds[propertyName.ToLowerInvariant()]).JavaCast()); - - /// - /// Gets the control from a view. - /// - /// The control type. - /// The view. - /// The property name. - /// A . - public static T GetControl(this View @this, [CallerMemberName]string propertyName = null) - where T : View => (T)GetCachedControl(propertyName, @this, () => @this.FindViewById(controlIds[propertyName.ToLowerInvariant()]).JavaCast()); - - /// - /// A helper method to automatically resolve properties in an to their respective elements in the layout. - /// This should be called in the Fragement's OnCreateView, with the newly inflated layout. - /// - /// The fragment. - /// The newly inflated returned from Inflate. - /// The strategy used to resolve properties that either subclass , have a or have a . - public static void WireUpControls(this Android.Support.V4.App.Fragment @this, View inflatedView, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) + /// The fragment. + /// The inflated view. + /// The resolve members. + public static void WireUpControls(this Fragment fragment, View inflatedView, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) { - var members = @this.GetWireUpMembers(resolveMembers); + var members = fragment.GetWireUpMembers(resolveMembers); - members.ToList().ForEach(m => + foreach (var member in members) { try { // Find the android control with the same name from the view - var view = inflatedView.GetControlInternal(m.PropertyType, m.GetResourceName()); + var view = inflatedView.GetControl(fragment.GetType().Assembly, member.GetResourceName()); // Set the activity field's value to the view with that identifier - m.SetValue(@this, view); + member.SetValue(fragment, view); } catch (Exception ex) { - throw new MissingFieldException( - "Failed to wire up the Property " - + m.Name + " to a View in your layout with a corresponding identifier", ex); + throw new + MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex); } - }); - } - - // Copied from ReactiveUI/Platforms/android/ControlFetcherMixins.cs - private static IEnumerable GetWireUpMembers(this object @this, ResolveStrategy resolveStrategy) - { - var members = @this.GetType().GetRuntimeProperties(); - - switch (resolveStrategy) - { - default: // Implicit uses the default case. - return members.Where(m => m.PropertyType.IsSubclassOf(typeof(View)) - || m.GetCustomAttribute(true) != null); - - case ResolveStrategy.ExplicitOptIn: - return members.Where(m => m.GetCustomAttribute(true) != null); - - case ResolveStrategy.ExplicitOptOut: - return members.Where(m => typeof(View).IsAssignableFrom(m.PropertyType) - && m.GetCustomAttribute(true) == null); } } - - // Also copied from ReactiveUI/Platforms/android/ControlFetcherMixins.cs - private static string GetResourceName(this PropertyInfo member) - { - var resourceNameOverride = member.GetCustomAttribute()?.ResourceNameOverride; - return resourceNameOverride ?? member.Name; - } - - private static View GetControlInternal(this View parent, Type viewType, string name) - { - var mi = getControlView.MakeGenericMethod(new[] { viewType }); - return (View)mi.Invoke(null, new object[] { parent, name }); - } - - private static View GetControlInternal(this AppCompatActivity parent, Type viewType, string name) - { - var mi = getControlActivity.MakeGenericMethod(new[] { viewType }); - return (View)mi.Invoke(null, new object[] { parent, name }); - } - - private static View GetCachedControl(string propertyName, object rootView, Func fetchControlFromView) - { - var ret = default(View); - var ourViewCache = viewCache.GetOrCreateValue(rootView); - - if (ourViewCache.TryGetValue(propertyName, out ret)) - { - return ret; - } - - ret = fetchControlFromView(); - - ourViewCache.Add(propertyName, ret); - return ret; - } } } diff --git a/src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs b/src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs index 591e6f6dc7..f3f237d272 100644 --- a/src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs +++ b/src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs @@ -52,10 +52,28 @@ protected ReactiveRecyclerViewAdapter(IObservable> backin /// public override int ItemCount => _list.Count; + /// + public override int GetItemViewType(int position) + { + return GetItemViewType(position, GetViewModelByPosition(position)); + } + + /// + /// Determine the View that will be used/re-used in lists where + /// the list contains different cell designs. + /// + /// The position of the current view in the list. + /// The ViewModel associated with the current View. + /// An ID to be used in OnCreateViewHolder. + public virtual int GetItemViewType(int position, TViewModel viewModel) + { + return base.GetItemViewType(position); + } + /// public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) { - ((IViewFor)holder).ViewModel = _list.Items.ElementAt(position); + ((IViewFor)holder).ViewModel = GetViewModelByPosition(position); } /// @@ -70,6 +88,11 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } + private TViewModel GetViewModelByPosition(int position) + { + return position >= _list.Count ? null : _list.Items.ElementAt(position); + } + private void UpdateBindings(Change change) { switch (change.Reason) diff --git a/src/ReactiveUI.Blend/FollowObservableStateBehavior.cs b/src/ReactiveUI.Blend/FollowObservableStateBehavior.cs index 3cfd5cdf45..940ef27625 100644 --- a/src/ReactiveUI.Blend/FollowObservableStateBehavior.cs +++ b/src/ReactiveUI.Blend/FollowObservableStateBehavior.cs @@ -12,7 +12,7 @@ #else using System.Windows; using System.Windows.Controls; -using System.Windows.Interactivity; +using Microsoft.Xaml.Behaviors; #endif #pragma warning disable SA1201 // A field should not follow a property - macro if statements make this hard diff --git a/src/ReactiveUI.Blend/Platforms/net4/ObservableTrigger.cs b/src/ReactiveUI.Blend/Platforms/net4/ObservableTrigger.cs index add0d80e0a..13fdcc6dec 100644 --- a/src/ReactiveUI.Blend/Platforms/net4/ObservableTrigger.cs +++ b/src/ReactiveUI.Blend/Platforms/net4/ObservableTrigger.cs @@ -9,7 +9,7 @@ using System.Reactive.Linq; using System.Text; using System.Windows; -using System.Windows.Interactivity; +using Microsoft.Xaml.Behaviors; namespace ReactiveUI.Blend { diff --git a/src/ReactiveUI.Blend/ReactiveUI.Blend.csproj b/src/ReactiveUI.Blend/ReactiveUI.Blend.csproj index e93a4f7bad..8384618963 100644 --- a/src/ReactiveUI.Blend/ReactiveUI.Blend.csproj +++ b/src/ReactiveUI.Blend/ReactiveUI.Blend.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/ReactiveUI.Events.WPF/ReactiveUI.Events.WPF.csproj b/src/ReactiveUI.Events.WPF/ReactiveUI.Events.WPF.csproj index 547ace3b95..b5fd71dd66 100644 --- a/src/ReactiveUI.Events.WPF/ReactiveUI.Events.WPF.csproj +++ b/src/ReactiveUI.Events.WPF/ReactiveUI.Events.WPF.csproj @@ -4,28 +4,27 @@ ReactiveUI.Events Provides Observable-based events API for WPF UI controls/eventhandlers. The contents of this package is automatically generated, please target pull-requests to the code generator. ReactiveUI.Events.WPF - true - true + true $(NoWarn);CS1570;CA1812 - - + - + + + - \ No newline at end of file diff --git a/src/ReactiveUI.Events.Winforms/ReactiveUI.Events.Winforms.csproj b/src/ReactiveUI.Events.Winforms/ReactiveUI.Events.Winforms.csproj index c6bf70461d..04dfaa5e43 100644 --- a/src/ReactiveUI.Events.Winforms/ReactiveUI.Events.Winforms.csproj +++ b/src/ReactiveUI.Events.Winforms/ReactiveUI.Events.Winforms.csproj @@ -5,7 +5,6 @@ ReactiveUI.Events Provides Observable-based events API for Winforms UI controls/eventhandlers. The contents of this package is automatically generated, please target pull-requests to the code generator. ReactiveUI.Events.Winforms - true true $(NoWarn);CS1570;CA1812 @@ -13,15 +12,16 @@ - - + - + + + @@ -30,6 +30,5 @@ - \ No newline at end of file diff --git a/src/ReactiveUI.Events.XamEssentials/ReactiveUI.Events.XamEssentials.csproj b/src/ReactiveUI.Events.XamEssentials/ReactiveUI.Events.XamEssentials.csproj index fd8b2c0f35..b978c5df29 100644 --- a/src/ReactiveUI.Events.XamEssentials/ReactiveUI.Events.XamEssentials.csproj +++ b/src/ReactiveUI.Events.XamEssentials/ReactiveUI.Events.XamEssentials.csproj @@ -9,14 +9,8 @@ - - - - + + + - - - - - - \ No newline at end of file + diff --git a/src/ReactiveUI.Events.XamForms/ReactiveUI.Events.XamForms.csproj b/src/ReactiveUI.Events.XamForms/ReactiveUI.Events.XamForms.csproj index 8176e5bd54..e9febdd1f9 100644 --- a/src/ReactiveUI.Events.XamForms/ReactiveUI.Events.XamForms.csproj +++ b/src/ReactiveUI.Events.XamForms/ReactiveUI.Events.XamForms.csproj @@ -9,14 +9,8 @@ - - - - - - - - - - - \ No newline at end of file + + + + + diff --git a/src/ReactiveUI.Events/ReactiveUI.Events.csproj b/src/ReactiveUI.Events/ReactiveUI.Events.csproj index 261ee301c4..11c8c74f07 100644 --- a/src/ReactiveUI.Events/ReactiveUI.Events.csproj +++ b/src/ReactiveUI.Events/ReactiveUI.Events.csproj @@ -12,12 +12,12 @@ - - + + - + @@ -25,22 +25,21 @@ - + + - + - - - - - + + + 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/src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj b/src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj index 1006234e3f..233f49d956 100644 --- a/src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj +++ b/src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt index 3e1bcb0e62..8098ad958a 100644 --- a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt +++ b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt @@ -186,31 +186,15 @@ namespace ReactiveUI void RegisterScheduler(System.Reactive.Concurrency.IScheduler scheduler, string contract = null); void SendMessage(T message, string contract = null); } - public interface INotifyPropertyChanging - { - public event ReactiveUI.PropertyChangingEventHandler PropertyChanging; - } public class INPCObservableForProperty : ReactiveUI.ICreatesObservableForProperty, Splat.IEnableLogger { public INPCObservableForProperty() { } public int GetAffinityForObject(System.Type type, string propertyName, bool beforeChanged) { } public System.IObservable> GetNotificationForProperty(object sender, System.Linq.Expressions.Expression expression, string propertyName, bool beforeChanged, bool suppressWarnings = False) { } } - public class Interaction - { - public Interaction(System.Reactive.Concurrency.IScheduler handlerScheduler = null) { } - protected System.Func<, >[] GetHandlers() { } - public virtual System.IObservable Handle(TInput input) { } - public System.IDisposable RegisterHandler(System.Action> handler) { } - public System.IDisposable RegisterHandler(System.Func, System.Threading.Tasks.Task> handler) { } - public System.IDisposable RegisterHandler(System.Func, System.IObservable> handler) { } - } - public sealed class InteractionContext + public interface INotifyPropertyChanging { - public TInput Input { get; } - public bool IsHandled { get; } - public TOutput GetOutput() { } - public void SetOutput(TOutput output) { } + public event ReactiveUI.PropertyChangingEventHandler PropertyChanging; } public interface IObservedChange { @@ -244,6 +228,12 @@ namespace ReactiveUI { bool ExecuteHook(object source, object target, System.Func[]> getCurrentViewModelProperties, System.Func[]> getCurrentViewProperties, ReactiveUI.BindingDirection direction); } + public class IROObservableForProperty : ReactiveUI.ICreatesObservableForProperty, Splat.IEnableLogger + { + public IROObservableForProperty() { } + public int GetAffinityForObject(System.Type type, string propertyName, bool beforeChanged = False) { } + public System.IObservable> GetNotificationForProperty(object sender, System.Linq.Expressions.Expression expression, string propertyName, bool beforeChanged = False, bool suppressWarnings = False) { } + } public interface IReactiveBinding : System.IDisposable where out TView : ReactiveUI.IViewFor where out TViewModel : class @@ -285,12 +275,6 @@ namespace ReactiveUI string PropertyName { get; } TSender Sender { get; } } - public class IROObservableForProperty : ReactiveUI.ICreatesObservableForProperty, Splat.IEnableLogger - { - public IROObservableForProperty() { } - public int GetAffinityForObject(System.Type type, string propertyName, bool beforeChanged = False) { } - public System.IObservable> GetNotificationForProperty(object sender, System.Linq.Expressions.Expression expression, string propertyName, bool beforeChanged = False, bool suppressWarnings = False) { } - } public interface IRoutableViewModel : ReactiveUI.INotifyPropertyChanging, ReactiveUI.IReactiveObject, Splat.IEnableLogger, System.ComponentModel.INotifyPropertyChanged { ReactiveUI.IScreen HostScreen { get; } @@ -339,6 +323,22 @@ namespace ReactiveUI ReactiveUI.IViewFor ResolveView(T viewModel, string contract = null) where T : class; } + public sealed class InteractionContext + { + public TInput Input { get; } + public bool IsHandled { get; } + public TOutput GetOutput() { } + public void SetOutput(TOutput output) { } + } + public class Interaction + { + public Interaction(System.Reactive.Concurrency.IScheduler handlerScheduler = null) { } + protected System.Func<, >[] GetHandlers() { } + public virtual System.IObservable Handle(TInput input) { } + public System.IDisposable RegisterHandler(System.Action> handler) { } + public System.IDisposable RegisterHandler(System.Func, System.Threading.Tasks.Task> handler) { } + public System.IDisposable RegisterHandler(System.Func, System.IObservable> handler) { } + } public class MessageBus : ReactiveUI.IMessageBus, Splat.IEnableLogger { public MessageBus() { } @@ -406,17 +406,17 @@ namespace ReactiveUI public static System.Collections.Generic.IComparer OrderByDescending(System.Func selector) { } public static System.Collections.Generic.IComparer OrderByDescending(System.Func selector, System.Collections.Generic.IComparer comparer) { } } - public class PlatformRegistrations - { - public PlatformRegistrations() { } - public void Register(System.Action, System.Type> registerFunction) { } - } public class POCOObservableForProperty : ReactiveUI.ICreatesObservableForProperty, Splat.IEnableLogger { public POCOObservableForProperty() { } public int GetAffinityForObject(System.Type type, string propertyName, bool beforeChanged = False) { } public System.IObservable> GetNotificationForProperty(object sender, System.Linq.Expressions.Expression expression, string propertyName, bool beforeChanged = False, bool suppressWarnings = False) { } } + public class PlatformRegistrations + { + public PlatformRegistrations() { } + public void Register(System.Action, System.Type> registerFunction) { } + } public class PropertyBinderImplementation : ReactiveUI.IPropertyBinderImplementation, Splat.IEnableLogger { public PropertyBinderImplementation() { } @@ -482,16 +482,6 @@ namespace ReactiveUI public static ReactiveUI.ReactiveCommand CreateFromTask(System.Func execute, System.IObservable canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { } public static ReactiveUI.ReactiveCommand CreateFromTask(System.Func execute, System.IObservable canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { } } - public class ReactiveCommand : ReactiveUI.ReactiveCommandBase - { - protected internal ReactiveCommand(System.Func> execute, System.IObservable canExecute, System.Reactive.Concurrency.IScheduler outputScheduler) { } - public override System.IObservable CanExecute { get; } - public override System.IObservable IsExecuting { get; } - public override System.IObservable ThrownExceptions { get; } - protected override void Dispose(bool disposing) { } - public override System.IObservable Execute(TParam parameter = null) { } - public override System.IDisposable Subscribe(System.IObserver observer) { } - } public abstract class ReactiveCommandBase : ReactiveUI.IHandleObservableErrors, ReactiveUI.IReactiveCommand, System.IDisposable, System.IObservable, System.Windows.Input.ICommand { protected ReactiveCommandBase() { } @@ -516,6 +506,16 @@ namespace ReactiveUI public static System.IDisposable InvokeCommand(this System.IObservable @this, TTarget target, System.Linq.Expressions.Expression>> commandProperty) where TTarget : class { } } + public class ReactiveCommand : ReactiveUI.ReactiveCommandBase + { + protected internal ReactiveCommand(System.Func> execute, System.IObservable canExecute, System.Reactive.Concurrency.IScheduler outputScheduler) { } + public override System.IObservable CanExecute { get; } + public override System.IObservable IsExecuting { get; } + public override System.IObservable ThrownExceptions { get; } + protected override void Dispose(bool disposing) { } + public override System.IObservable Execute(TParam parameter = null) { } + public override System.IDisposable Subscribe(System.IObserver observer) { } + } public class static ReactiveNotifyPropertyChangedMixin { public static System.IObservable> ObservableForProperty(this TSender @this, System.Linq.Expressions.Expression> property, bool beforeChange = False, bool skipInitial = True) { } diff --git a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp2.0.approved.txt b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp2.0.approved.txt index 012e1426d0..b1b2ded040 100644 --- a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp2.0.approved.txt +++ b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp2.0.approved.txt @@ -180,31 +180,15 @@ namespace ReactiveUI void RegisterScheduler(System.Reactive.Concurrency.IScheduler scheduler, string contract = null); void SendMessage(T message, string contract = null); } - public interface INotifyPropertyChanging - { - public event ReactiveUI.PropertyChangingEventHandler PropertyChanging; - } public class INPCObservableForProperty : ReactiveUI.ICreatesObservableForProperty, Splat.IEnableLogger { public INPCObservableForProperty() { } public int GetAffinityForObject(System.Type type, string propertyName, bool beforeChanged) { } public System.IObservable> GetNotificationForProperty(object sender, System.Linq.Expressions.Expression expression, string propertyName, bool beforeChanged, bool suppressWarnings = False) { } } - public class Interaction - { - public Interaction(System.Reactive.Concurrency.IScheduler handlerScheduler = null) { } - protected System.Func<, >[] GetHandlers() { } - public virtual System.IObservable Handle(TInput input) { } - public System.IDisposable RegisterHandler(System.Action> handler) { } - public System.IDisposable RegisterHandler(System.Func, System.Threading.Tasks.Task> handler) { } - public System.IDisposable RegisterHandler(System.Func, System.IObservable> handler) { } - } - public sealed class InteractionContext + public interface INotifyPropertyChanging { - public TInput Input { get; } - public bool IsHandled { get; } - public TOutput GetOutput() { } - public void SetOutput(TOutput output) { } + public event ReactiveUI.PropertyChangingEventHandler PropertyChanging; } public interface IObservedChange { @@ -238,6 +222,12 @@ namespace ReactiveUI { bool ExecuteHook(object source, object target, System.Func[]> getCurrentViewModelProperties, System.Func[]> getCurrentViewProperties, ReactiveUI.BindingDirection direction); } + public class IROObservableForProperty : ReactiveUI.ICreatesObservableForProperty, Splat.IEnableLogger + { + public IROObservableForProperty() { } + public int GetAffinityForObject(System.Type type, string propertyName, bool beforeChanged = False) { } + public System.IObservable> GetNotificationForProperty(object sender, System.Linq.Expressions.Expression expression, string propertyName, bool beforeChanged = False, bool suppressWarnings = False) { } + } public interface IReactiveBinding : System.IDisposable where out TView : ReactiveUI.IViewFor where out TViewModel : class @@ -279,12 +269,6 @@ namespace ReactiveUI string PropertyName { get; } TSender Sender { get; } } - public class IROObservableForProperty : ReactiveUI.ICreatesObservableForProperty, Splat.IEnableLogger - { - public IROObservableForProperty() { } - public int GetAffinityForObject(System.Type type, string propertyName, bool beforeChanged = False) { } - public System.IObservable> GetNotificationForProperty(object sender, System.Linq.Expressions.Expression expression, string propertyName, bool beforeChanged = False, bool suppressWarnings = False) { } - } public interface IRoutableViewModel : ReactiveUI.INotifyPropertyChanging, ReactiveUI.IReactiveObject, Splat.IEnableLogger, System.ComponentModel.INotifyPropertyChanged { ReactiveUI.IScreen HostScreen { get; } @@ -333,6 +317,22 @@ namespace ReactiveUI ReactiveUI.IViewFor ResolveView(T viewModel, string contract = null) where T : class; } + public sealed class InteractionContext + { + public TInput Input { get; } + public bool IsHandled { get; } + public TOutput GetOutput() { } + public void SetOutput(TOutput output) { } + } + public class Interaction + { + public Interaction(System.Reactive.Concurrency.IScheduler handlerScheduler = null) { } + protected System.Func<, >[] GetHandlers() { } + public virtual System.IObservable Handle(TInput input) { } + public System.IDisposable RegisterHandler(System.Action> handler) { } + public System.IDisposable RegisterHandler(System.Func, System.Threading.Tasks.Task> handler) { } + public System.IDisposable RegisterHandler(System.Func, System.IObservable> handler) { } + } public class MessageBus : ReactiveUI.IMessageBus, Splat.IEnableLogger { public MessageBus() { } @@ -400,17 +400,17 @@ namespace ReactiveUI public static System.Collections.Generic.IComparer OrderByDescending(System.Func selector) { } public static System.Collections.Generic.IComparer OrderByDescending(System.Func selector, System.Collections.Generic.IComparer comparer) { } } - public class PlatformRegistrations - { - public PlatformRegistrations() { } - public void Register(System.Action, System.Type> registerFunction) { } - } public class POCOObservableForProperty : ReactiveUI.ICreatesObservableForProperty, Splat.IEnableLogger { public POCOObservableForProperty() { } public int GetAffinityForObject(System.Type type, string propertyName, bool beforeChanged = False) { } public System.IObservable> GetNotificationForProperty(object sender, System.Linq.Expressions.Expression expression, string propertyName, bool beforeChanged = False, bool suppressWarnings = False) { } } + public class PlatformRegistrations + { + public PlatformRegistrations() { } + public void Register(System.Action, System.Type> registerFunction) { } + } public class PropertyBinderImplementation : ReactiveUI.IPropertyBinderImplementation, Splat.IEnableLogger { public PropertyBinderImplementation() { } @@ -476,16 +476,6 @@ namespace ReactiveUI public static ReactiveUI.ReactiveCommand CreateFromTask(System.Func execute, System.IObservable canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { } public static ReactiveUI.ReactiveCommand CreateFromTask(System.Func execute, System.IObservable canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { } } - public class ReactiveCommand : ReactiveUI.ReactiveCommandBase - { - protected internal ReactiveCommand(System.Func> execute, System.IObservable canExecute, System.Reactive.Concurrency.IScheduler outputScheduler) { } - public override System.IObservable CanExecute { get; } - public override System.IObservable IsExecuting { get; } - public override System.IObservable ThrownExceptions { get; } - protected override void Dispose(bool disposing) { } - public override System.IObservable Execute(TParam parameter = null) { } - public override System.IDisposable Subscribe(System.IObserver observer) { } - } public abstract class ReactiveCommandBase : ReactiveUI.IHandleObservableErrors, ReactiveUI.IReactiveCommand, System.IDisposable, System.IObservable, System.Windows.Input.ICommand { protected ReactiveCommandBase() { } @@ -510,6 +500,16 @@ namespace ReactiveUI public static System.IDisposable InvokeCommand(this System.IObservable @this, TTarget target, System.Linq.Expressions.Expression>> commandProperty) where TTarget : class { } } + public class ReactiveCommand : ReactiveUI.ReactiveCommandBase + { + protected internal ReactiveCommand(System.Func> execute, System.IObservable canExecute, System.Reactive.Concurrency.IScheduler outputScheduler) { } + public override System.IObservable CanExecute { get; } + public override System.IObservable IsExecuting { get; } + public override System.IObservable ThrownExceptions { get; } + protected override void Dispose(bool disposing) { } + public override System.IObservable Execute(TParam parameter = null) { } + public override System.IDisposable Subscribe(System.IObserver observer) { } + } public class static ReactiveNotifyPropertyChangedMixin { public static System.IObservable> ObservableForProperty(this TSender @this, System.Linq.Expressions.Expression> property, bool beforeChange = False, bool skipInitial = True) { } diff --git a/src/ReactiveUI.Tests/Platforms/windows-xaml/Api/ApiApprovalTests.Blend.net461.approved.txt b/src/ReactiveUI.Tests/Platforms/windows-xaml/Api/ApiApprovalTests.Blend.net461.approved.txt index b41cce3e66..902d975511 100644 --- a/src/ReactiveUI.Tests/Platforms/windows-xaml/Api/ApiApprovalTests.Blend.net461.approved.txt +++ b/src/ReactiveUI.Tests/Platforms/windows-xaml/Api/ApiApprovalTests.Blend.net461.approved.txt @@ -1,7 +1,7 @@ [assembly: System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.6.1", FrameworkDisplayName=".NET Framework 4.6.1")] namespace ReactiveUI.Blend { - public class FollowObservableStateBehavior : System.Windows.Interactivity.Behavior + public class FollowObservableStateBehavior : Microsoft.Xaml.Behaviors.Behavior { public static readonly System.Windows.DependencyProperty StateObservableProperty; public static readonly System.Windows.DependencyProperty TargetObjectProperty; @@ -12,7 +12,7 @@ namespace ReactiveUI.Blend protected override void OnDetaching() { } protected static void OnStateObservableChanged(System.Windows.DependencyObject sender, System.Windows.DependencyPropertyChangedEventArgs e) { } } - public class ObservableTrigger : System.Windows.Interactivity.TriggerBase + public class ObservableTrigger : Microsoft.Xaml.Behaviors.TriggerBase { public static readonly System.Windows.DependencyProperty ObservableProperty; public ObservableTrigger() { } diff --git a/src/ReactiveUI.Tests/Platforms/wpf/API/ApiApprovalTests.Wpf.net461.approved.txt b/src/ReactiveUI.Tests/Platforms/wpf/API/ApiApprovalTests.Wpf.net461.approved.txt index 20682b541f..a2b9191edc 100644 --- a/src/ReactiveUI.Tests/Platforms/wpf/API/ApiApprovalTests.Wpf.net461.approved.txt +++ b/src/ReactiveUI.Tests/Platforms/wpf/API/ApiApprovalTests.Wpf.net461.approved.txt @@ -44,6 +44,14 @@ namespace ReactiveUI public PlatformOperations() { } public string GetOrientation() { } } + public abstract class ReactivePage : System.Windows.Controls.Page, ReactiveUI.IActivatable, ReactiveUI.IViewFor, ReactiveUI.IViewFor + where TViewModel : class + { + public static readonly System.Windows.DependencyProperty ViewModelProperty; + protected ReactivePage() { } + public TViewModel BindingRoot { get; } + public TViewModel ViewModel { get; set; } + } public abstract class ReactiveUserControl : System.Windows.Controls.UserControl, ReactiveUI.IActivatable, ReactiveUI.IViewFor, ReactiveUI.IViewFor where TViewModel : class { diff --git a/src/ReactiveUI.Tests/ReactiveObject/ReactiveObjectTests.cs b/src/ReactiveUI.Tests/ReactiveObject/ReactiveObjectTests.cs index 2e47410095..4c4278cf10 100644 --- a/src/ReactiveUI.Tests/ReactiveObject/ReactiveObjectTests.cs +++ b/src/ReactiveUI.Tests/ReactiveObject/ReactiveObjectTests.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Reactive.Concurrency; +using System.Reactive.Linq; using DynamicData; using Xunit; @@ -196,5 +197,18 @@ public void ReactiveObjectSmokeTest() output.AssertAreEqual(output_changing); results.AssertAreEqual(output); } + + [Fact] + public void ReactiveObjectShouldRethrowException() + { + var fixture = new TestFixture(); + var observable = fixture.WhenAnyValue(x => x.IsOnlyOneWord).Skip(1); + observable.Subscribe(x => throw new Exception("This is a test.")); + + var result = Record.Exception(() => fixture.IsOnlyOneWord = "Two Words"); + + Assert.IsType(result); + Assert.Equal("This is a test.", result.Message); + } } } diff --git a/src/ReactiveUI.Tests/ReactiveUI.Tests.csproj b/src/ReactiveUI.Tests/ReactiveUI.Tests.csproj index 5b16da1a74..bdf27d6562 100644 --- a/src/ReactiveUI.Tests/ReactiveUI.Tests.csproj +++ b/src/ReactiveUI.Tests/ReactiveUI.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/ReactiveUI.Winforms/ReactiveUI.Winforms.csproj b/src/ReactiveUI.Winforms/ReactiveUI.Winforms.csproj index b9d1e6994e..ee1b40b4a6 100644 --- a/src/ReactiveUI.Winforms/ReactiveUI.Winforms.csproj +++ b/src/ReactiveUI.Winforms/ReactiveUI.Winforms.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/ReactiveUI.Wpf/ReactiveUI.Wpf.csproj b/src/ReactiveUI.Wpf/ReactiveUI.Wpf.csproj index fb27945b55..5fdef0e80b 100644 --- a/src/ReactiveUI.Wpf/ReactiveUI.Wpf.csproj +++ b/src/ReactiveUI.Wpf/ReactiveUI.Wpf.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/ReactiveUI.XamForms/ReactiveUI.XamForms.csproj b/src/ReactiveUI.XamForms/ReactiveUI.XamForms.csproj index 8d9b25c7f0..76886b934d 100644 --- a/src/ReactiveUI.XamForms/ReactiveUI.XamForms.csproj +++ b/src/ReactiveUI.XamForms/ReactiveUI.XamForms.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/ReactiveUI/Mixins/ReactiveNotifyPropertyChangedMixin.cs b/src/ReactiveUI/Mixins/ReactiveNotifyPropertyChangedMixin.cs index a5423dd4bf..6b7dc518e7 100644 --- a/src/ReactiveUI/Mixins/ReactiveNotifyPropertyChangedMixin.cs +++ b/src/ReactiveUI/Mixins/ReactiveNotifyPropertyChangedMixin.cs @@ -205,7 +205,7 @@ private static IObservable> NotifyForProperty(ob if (result == null) { - throw new Exception($"Could not find a ICreatesObservableForProperty for {sender.GetType()} property {propertyName}. This should never happen, your service locator is probably broken. Please make sure you have installed the latest version of the ReactiveUI packages for your platform. See https://reactiveui.net/docs/getting-started/installation/nuget-packages for guidance."); + throw new Exception($"Could not find a ICreatesObservableForProperty for {sender.GetType()} property {propertyName}. This should never happen, your service locator is probably broken. Please make sure you have installed the latest version of the ReactiveUI packages for your platform. See https://reactiveui.net/docs/getting-started/installation for guidance."); } return result.GetNotificationForProperty(sender, expression, propertyName, beforeChange, suppressWarnings); diff --git a/src/ReactiveUI/Platforms/android/ControlFetcherMixin.cs b/src/ReactiveUI/Platforms/android/ControlFetcherMixin.cs index 703f6fae66..83bdebb565 100644 --- a/src/ReactiveUI/Platforms/android/ControlFetcherMixin.cs +++ b/src/ReactiveUI/Platforms/android/ControlFetcherMixin.cs @@ -4,14 +4,13 @@ // See the LICENSE file in the project root for full license information. using System; +using System.Collections.Concurrent; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using Android.App; using Android.Views; -using Java.Interop; namespace ReactiveUI { @@ -20,238 +19,194 @@ namespace ReactiveUI /// Fragments via property names, similar to Butter Knife, as well as allows /// you to fetch controls manually. /// - public static partial class ControlFetcherMixin + public static partial class ControlFetcherMixin { - private static readonly Dictionary controlIds; + private static readonly ConcurrentDictionary> _controlIds + = new ConcurrentDictionary>(); - private static readonly ConditionalWeakTable> viewCache = - new ConditionalWeakTable>(); - - private static readonly MethodInfo getControlActivity; - private static readonly MethodInfo getControlView; - - [SuppressMessage("Design", "CA1065: Not not throw exceptions in static constructor", Justification = "TODO: Future fix")] - static ControlFetcherMixin() - { - // NB: This is some hacky shit, but on Xamarin.Android at the moment, - // this is always the entry assembly. - var assm = AppDomain.CurrentDomain.GetAssemblies()[1]; - var resources = assm.GetModules().SelectMany(x => x.GetTypes()).First(x => x.Name == "Resource"); - - try - { - controlIds = resources.GetNestedType("Id").GetFields() - .Where(x => x.FieldType == typeof(int)) - .ToDictionary(k => k.Name.ToLowerInvariant(), v => (int)v.GetRawConstantValue()); - } - catch (ArgumentException argumentException) - { - var duplicates = resources.GetNestedType("Id").GetFields() - .Where(x => x.FieldType == typeof(int)) - .GroupBy(k => k.Name.ToLowerInvariant()) - .Where(g => g.Count() > 1) - .Select(g => "{ " + string.Join(" = ", g.Select(v => v.Name)) + " }") - .ToList(); - - if (duplicates.Any()) - { - throw new InvalidOperationException("You're using multiple resource ID's with the same name but with different casings which isn't allowed for WireUpControls: " + string.Join(", ", duplicates), argumentException); - } - - throw; - } - - var type = typeof(ControlFetcherMixin); - getControlActivity = type.GetMethod("GetControl", new[] { typeof(Activity), typeof(string) }); - getControlView = type.GetMethod("GetControl", new[] { typeof(View), typeof(string) }); - } + private static readonly ConditionalWeakTable> viewCache + = new ConditionalWeakTable>(); /// /// Gets the control from an activity. /// - /// The control type. - /// The activity. + /// The activity. /// The property name. /// The return view. - public static T GetControl(this Activity @this, [CallerMemberName]string propertyName = null) - where T : View => (T)GetCachedControl(propertyName, @this, () => @this.FindViewById(controlIds[propertyName.ToLowerInvariant()]).JavaCast()); + public static View GetControl(this Activity activity, [CallerMemberName] string propertyName = null) + => GetCachedControl(propertyName, activity, () => activity.FindViewById(GetControlIdByName(activity.GetType().Assembly, propertyName))); /// - /// Gets the control from an activity. + /// Gets the control from a view. /// - /// The control type. - /// The view. + /// The view. + /// The assembly containing the user-defined view. /// The property. /// The return view. - public static T GetControl(this View @this, [CallerMemberName]string propertyName = null) - where T : View => (T)GetCachedControl(propertyName, @this, () => @this.FindViewById(controlIds[propertyName.ToLowerInvariant()]).JavaCast()); - - /// - /// Gets the control from an activity. - /// - /// The control type. - /// The fragment. - /// The property name. - /// The return view. - public static T GetControl(this Fragment @this, [CallerMemberName]string propertyName = null) - where T : View => GetControl(@this.View, propertyName); + public static View GetControl(this View view, Assembly assembly, [CallerMemberName] string propertyName = null) + => GetCachedControl(propertyName, view, () => view.FindViewById(GetControlIdByName(assembly, propertyName))); /// /// Wires a control to a property. /// - /// The layout view host. + /// The layout view host. /// The resolve members. - public static void WireUpControls(this ILayoutViewHost @this, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) + public static void WireUpControls(this ILayoutViewHost layoutHost, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) { - var members = @this.GetWireUpMembers(resolveMembers); - - members.ToList().ForEach(m => + var members = layoutHost.GetWireUpMembers(resolveMembers).ToList(); + foreach (var member in members) { try { - // Find the android control with the same name - var view = @this.View.GetControlInternal(m.PropertyType, m.GetResourceName()); - - // Set the activity field's value to the view with that identifier - m.SetValue(@this, view); + var view = layoutHost.View.GetControl(layoutHost.GetType().Assembly, member.GetResourceName()); + member.SetValue(layoutHost, view); } catch (Exception ex) { - throw new MissingFieldException("Failed to wire up the Property " + m.Name + " to a View in your layout with a corresponding identifier", ex); + throw new + MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex); } - }); + } } /// /// Wires a control to a property. /// - /// The view. + /// The view. /// The resolve members. - public static void WireUpControls(this View @this, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) + public static void WireUpControls(this View view, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) { - var members = @this.GetWireUpMembers(resolveMembers); + var members = view.GetWireUpMembers(resolveMembers); - members.ToList().ForEach(m => + foreach (var member in members) { try { // Find the android control with the same name - var view = @this.GetControlInternal(m.PropertyType, m.GetResourceName()); + var currentView = view.GetControl(view.GetType().Assembly, member.GetResourceName()); // Set the activity field's value to the view with that identifier - m.SetValue(@this, view); + member.SetValue(view, currentView); } catch (Exception ex) { - throw new MissingFieldException("Failed to wire up the Property " + m.Name + " to a View in your layout with a corresponding identifier", ex); + throw new + MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex); } - }); + } } /// /// Wires a control to a property. - /// This should be called in the Fragement's OnCreateView, with the newly inflated layout. + /// This should be called in the Fragment's OnCreateView, with the newly inflated layout. /// - /// The fragment. + /// The fragment. /// The inflated view. /// The resolve members. - public static void WireUpControls(this Fragment @this, View inflatedView, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) + public static void WireUpControls(this Fragment fragment, View inflatedView, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) { - var members = @this.GetWireUpMembers(resolveMembers); + var members = fragment.GetWireUpMembers(resolveMembers); - members.ToList().ForEach(m => + foreach (var member in members) { try { // Find the android control with the same name from the view - var view = inflatedView.GetControlInternal(m.PropertyType, m.GetResourceName()); + var view = inflatedView.GetControl(fragment.GetType().Assembly, member.GetResourceName()); // Set the activity field's value to the view with that identifier - m.SetValue(@this, view); + member.SetValue(fragment, view); } catch (Exception ex) { - throw new MissingFieldException("Failed to wire up the Property " + m.Name + " to a View in your layout with a corresponding identifier", ex); + throw new + MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex); } - }); + } } /// /// Wires a control to a property. /// - /// The Activity. + /// The Activity. /// The resolve members. - public static void WireUpControls(this Activity @this, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) + public static void WireUpControls(this Activity activity, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) { - var members = @this.GetWireUpMembers(resolveMembers); + var members = activity.GetWireUpMembers(resolveMembers); - members.ToList().ForEach(m => + foreach (var member in members) { try { // Find the android control with the same name - var view = @this.GetControlInternal(m.PropertyType, m.GetResourceName()); + var view = activity.GetControl(member.GetResourceName()); // Set the activity field's value to the view with that identifier - m.SetValue(@this, view); + member.SetValue(activity, view); } catch (Exception ex) { - throw new MissingFieldException("Failed to wire up the Property " + m.Name + " to a View in your layout with a corresponding identifier", ex); + throw new + MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex); } - }); + } } - private static View GetControlInternal(this View parent, Type viewType, string name) + internal static IEnumerable GetWireUpMembers(this object @this, ResolveStrategy resolveStrategy) { - var mi = getControlView.MakeGenericMethod(new[] { viewType }); - return (View)mi.Invoke(null, new object[] { parent, name }); + var members = @this.GetType().GetRuntimeProperties(); + + switch (resolveStrategy) + { + default: // Implicit matches the Default. + return members.Where(member => member.PropertyType.IsSubclassOf(typeof(View)) + || member.GetCustomAttribute(true) != null); + + case ResolveStrategy.ExplicitOptIn: + return members.Where(member => member.GetCustomAttribute(true) != null); + + case ResolveStrategy.ExplicitOptOut: + return members.Where(member => typeof(View).IsAssignableFrom(member.PropertyType) + && member.GetCustomAttribute(true) == null); + } } - private static View GetControlInternal(this Activity parent, Type viewType, string name) + internal static string GetResourceName(this PropertyInfo member) { - var mi = getControlActivity.MakeGenericMethod(new[] { viewType }); - return (View)mi.Invoke(null, new object[] { parent, name }); + var resourceNameOverride = member.GetCustomAttribute()?.ResourceNameOverride; + return resourceNameOverride ?? member.Name; } private static View GetCachedControl(string propertyName, object rootView, Func fetchControlFromView) { + View ret; var ourViewCache = viewCache.GetOrCreateValue(rootView); - if (ourViewCache.TryGetValue(propertyName, out View view)) + if (ourViewCache.TryGetValue(propertyName, out ret)) { - return view; + return ret; } - view = fetchControlFromView(); + ret = fetchControlFromView(); - ourViewCache.Add(propertyName, view); - return view; + ourViewCache.Add(propertyName, ret); + return ret; } - private static string GetResourceName(this PropertyInfo member) + private static int GetControlIdByName(Assembly assembly, string name) { - var resourceNameOverride = member.GetCustomAttribute()?.ResourceNameOverride; - return resourceNameOverride ?? member.Name; - } - - private static IEnumerable GetWireUpMembers(this object @this, ResolveStrategy resolveStrategy) - { - var members = @this.GetType().GetRuntimeProperties(); - - switch (resolveStrategy) - { - default: // Implicit matches the Default. - return members.Where(m => m.PropertyType.IsSubclassOf(typeof(View)) - || m.GetCustomAttribute(true) != null); + var ids = _controlIds.GetOrAdd( + assembly, + currentAssembly => + { + var resources = currentAssembly.GetModules().SelectMany(x => x.GetTypes()).First(x => x.Name == "Resource"); - case ResolveStrategy.ExplicitOptIn: - return members.Where(m => m.GetCustomAttribute(true) != null); + return resources.GetNestedType("Id").GetFields() + .Where(x => x.FieldType == typeof(int)) + .ToDictionary(k => k.Name, v => (int)v.GetRawConstantValue(), StringComparer.InvariantCultureIgnoreCase); + }); - case ResolveStrategy.ExplicitOptOut: - return members.Where(m => typeof(View).IsAssignableFrom(m.PropertyType) - && m.GetCustomAttribute(true) == null); - } + return ids[name]; } } } diff --git a/src/ReactiveUI/Platforms/android/HandlerScheduler.cs b/src/ReactiveUI/Platforms/android/HandlerScheduler.cs index 0ca6fc9dd3..7090b21c8a 100644 --- a/src/ReactiveUI/Platforms/android/HandlerScheduler.cs +++ b/src/ReactiveUI/Platforms/android/HandlerScheduler.cs @@ -51,11 +51,6 @@ public IDisposable Schedule(TState state, Func 0 && _looperId == Java.Lang.Thread.CurrentThread().Id) - { - return action(this, state); - } - _handler.Post(() => { if (isCancelled) diff --git a/src/ReactiveUI/Platforms/netstandard2.0/PlatformRegistrations.cs b/src/ReactiveUI/Platforms/netstandard2.0/PlatformRegistrations.cs index d3ab33b32f..df364f2a25 100644 --- a/src/ReactiveUI/Platforms/netstandard2.0/PlatformRegistrations.cs +++ b/src/ReactiveUI/Platforms/netstandard2.0/PlatformRegistrations.cs @@ -16,7 +16,7 @@ public class PlatformRegistrations : IWantsToRegisterStuff /// public void Register(Action, Type> registerFunction) { - throw new Exception("You are referencing the Portable version of ReactiveUI in an App. Please change your reference to the specific version for your platform found here: https://reactiveui.net/docs/getting-started/installation/nuget-packages"); + throw new Exception("You are referencing the Portable version of ReactiveUI in an App. Please change your reference to the specific version for your platform found here: https://reactiveui.net/docs/getting-started/installation"); } } } diff --git a/src/ReactiveUI/Platforms/windows-common/ReactivePage.cs b/src/ReactiveUI/Platforms/windows-common/ReactivePage.cs new file mode 100644 index 0000000000..2a98bafeae --- /dev/null +++ b/src/ReactiveUI/Platforms/windows-common/ReactivePage.cs @@ -0,0 +1,114 @@ +// 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 ReactiveUI +{ + using System.Diagnostics.CodeAnalysis; +#if NETFX_CORE || HAS_UNO + using Windows.UI.Xaml; + using Windows.UI.Xaml.Controls; +#else + using System.Windows; + using System.Windows.Controls; +#endif + + /// + /// A that is reactive. + /// + /// + /// + /// This class is a that is also reactive. That is, it implements . + /// You can extend this class to get an implementation of rather than writing one yourself. + /// + /// + /// Note that the XAML for your control must specify the same base class, including the generic argument you provide for your view + /// model. To do this, use the TypeArguments attribute as follows: + /// + /// + /// + /// + /// ]]> + /// + /// + /// + /// Note that UWP projects do not support the TypeArguments attribute. The XAML designer window in WPF projects also does not + /// support generic types. To use in XAML documents you need to create a base class + /// where you derive from with the type argument filled in. + /// + /// { /* No code needed here */ } + /// + /// public partial class YourView : YourViewBase + /// { + /// /* Your code */ + /// } + /// ]]> + /// + /// Then you can use this base class as root in your XAML document. + /// + /// + /// + /// + /// ]]> + /// + /// + /// + /// + /// The type of the view model backing the view. + /// + [SuppressMessage("Design", "CA1010:Collections should implement generic interface", Justification = "Deliberate usage")] + public abstract class ReactivePage : + Page, IViewFor + where TViewModel : class + { + /// + /// The view model dependency property. + /// + public static readonly DependencyProperty ViewModelProperty = + DependencyProperty.Register( + "ViewModel", + typeof(TViewModel), + typeof(ReactivePage), + new PropertyMetadata(null)); + + /// + /// Gets the binding root view model. + /// + public TViewModel BindingRoot => ViewModel; + + /// + public TViewModel ViewModel + { + get => (TViewModel)GetValue(ViewModelProperty); + set => SetValue(ViewModelProperty, value); + } + + /// + object IViewFor.ViewModel + { + get => ViewModel; + set => ViewModel = (TViewModel)value; + } + } +} diff --git a/src/ReactiveUI/Platforms/windows-common/RoutedViewHost.cs b/src/ReactiveUI/Platforms/windows-common/RoutedViewHost.cs index d4751c0ff5..e48eb30616 100644 --- a/src/ReactiveUI/Platforms/windows-common/RoutedViewHost.cs +++ b/src/ReactiveUI/Platforms/windows-common/RoutedViewHost.cs @@ -69,7 +69,7 @@ public RoutedViewHost() { // NB: This used to be an error but WPF design mode can't read // good or do other stuff good. - this.Log().Error("Couldn't find an IPlatformOperations implementation. Please make sure you have installed the latest version of the ReactiveUI packages for your platform. See https://reactiveui.net/docs/getting-started/installation/nuget-packages for guidance."); + this.Log().Error("Couldn't find an IPlatformOperations implementation. Please make sure you have installed the latest version of the ReactiveUI packages for your platform. See https://reactiveui.net/docs/getting-started/installation for guidance."); } else { diff --git a/src/ReactiveUI/Platforms/windows-common/ViewModelViewHost.cs b/src/ReactiveUI/Platforms/windows-common/ViewModelViewHost.cs index c63ad25063..3f7ccf1154 100644 --- a/src/ReactiveUI/Platforms/windows-common/ViewModelViewHost.cs +++ b/src/ReactiveUI/Platforms/windows-common/ViewModelViewHost.cs @@ -73,7 +73,7 @@ public ViewModelViewHost() { // NB: This used to be an error but WPF design mode can't read // good or do other stuff good. - this.Log().Error("Couldn't find an IPlatformOperations implementation. Please make sure you have installed the latest version of the ReactiveUI packages for your platform. See https://reactiveui.net/docs/getting-started/installation/nuget-packages for guidance."); + this.Log().Error("Couldn't find an IPlatformOperations implementation. Please make sure you have installed the latest version of the ReactiveUI packages for your platform. See https://reactiveui.net/docs/getting-started/installation for guidance."); } else { diff --git a/src/ReactiveUI/ReactiveObject/IReactiveObjectExtensions.cs b/src/ReactiveUI/ReactiveObject/IReactiveObjectExtensions.cs index 088a424a81..126761665e 100644 --- a/src/ReactiveUI/ReactiveObject/IReactiveObjectExtensions.cs +++ b/src/ReactiveUI/ReactiveObject/IReactiveObjectExtensions.cs @@ -391,7 +391,10 @@ internal void NotifyObservable(TSender rxObj, T item, ISubject subject) if (_thrownExceptions.IsValueCreated) { _thrownExceptions.Value.OnNext(ex); + return; } + + throw; } } } diff --git a/src/ReactiveUI/ReactiveUI.csproj b/src/ReactiveUI/ReactiveUI.csproj index ca0c759646..2a559313e9 100644 --- a/src/ReactiveUI/ReactiveUI.csproj +++ b/src/ReactiveUI/ReactiveUI.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/global.json b/src/global.json index e973e5b345..12fd38086c 100644 --- a/src/global.json +++ b/src/global.json @@ -3,6 +3,6 @@ "version": "3.0.100-preview" }, "msbuild-sdks": { - "MSBuild.Sdk.Extras": "2.0.24" + "MSBuild.Sdk.Extras": "2.0.29" } } 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 diff --git a/tools/packages.config b/tools/packages.config new file mode 100644 index 0000000000..945c3e86ac --- /dev/null +++ b/tools/packages.config @@ -0,0 +1,4 @@ + + + + From d5ae2770eb206d888c5cf2aedad71ec644ee0dc0 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Tue, 25 Jun 2019 19:39:40 +1000 Subject: [PATCH 2/2] remove orig file --- src/Directory.build.props.orig | 98 ---------------------------------- 1 file changed, 98 deletions(-) delete mode 100644 src/Directory.build.props.orig diff --git a/src/Directory.build.props.orig b/src/Directory.build.props.orig deleted file mode 100644 index 84317392a3..0000000000 --- a/src/Directory.build.props.orig +++ /dev/null @@ -1,98 +0,0 @@ - - -<<<<<<< HEAD - xanaisbettsx;ghuntley - mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;xamarin.tvos;wpf;net;netstandard;net461;uwp;tizen - https://reactiveui.net/blog/ -======= ->>>>>>> master - true - $(NoWarn);1591;1701;1702;1705;VSX1000 - AnyCPU - $(MSBuildProjectName.Contains('Tests')) - embedded - $(MSBuildThisFileDirectory)analyzers.ruleset - - .NET Foundation and Contributors - Copyright (c) .NET Foundation and Contributors - MIT - https://reactiveui.net - https://github.com/reactiveui/styleguide/blob/master/logo/main.png?raw=true - xanaisbettsx;ghuntley - mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;xamarin.tvos;wpf;net;netstandard;net461;uwp;tizen - https://github.com/reactiveui/ReactiveUI/releases - https://github.com/reactiveui/reactiveui - git - - - false - $(EnableSourceLink) - - true - - true - - $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - - - - Full - - - - $(MSBuildThisFileDirectory)analyzers.tests.ruleset - false - - - -<<<<<<< HEAD - -======= - ->>>>>>> master - - - - -<<<<<<< HEAD - - - -======= - - - ->>>>>>> master - - - - - - - - - - - - $(MSBuildThisFileDirectory) - - - - - - - - - - - - - - - - - - - -