Exemple #1
0
    async Task CompileReactiveEvents()
    {
        var avaloniaBuildOutput = Path.Combine(RootDirectory, "packages", "Avalonia", "bin", Parameters.Configuration);
        var avaloniaAssemblies  = GlobFiles(avaloniaBuildOutput, "**/Avalonia*.dll")
                                  .Where(file => !file.Contains("Avalonia.Build.Tasks") &&
                                         !file.Contains("Avalonia.Remote.Protocol"));

        var eventsDirectory = GlobDirectories($"{RootDirectory}/src/**/Avalonia.ReactiveUI.Events").First();
        var eventsBuildFile = Path.Combine(eventsDirectory, "Events_Avalonia.cs");

        if (File.Exists(eventsBuildFile))
        {
            File.Delete(eventsBuildFile);
        }

        using (var stream = File.Create(eventsBuildFile))
            using (var writer = new StreamWriter(stream))
            {
                await ObservablesForEventGenerator.ExtractEventsFromAssemblies(
                    writer, avaloniaAssemblies, new string[0], "netstandard2.0"
                    );
            }

        var eventsProject = Path.Combine(eventsDirectory, "Avalonia.ReactiveUI.Events.csproj");

        if (Parameters.IsRunningOnWindows)
        {
            MsBuildCommon(eventsProject, c => c
                          .SetArgumentConfigurator(a => a.Add("/r"))
                          .AddTargets("Build")
                          );
        }
        else
        {
            DotNetBuild(c => c
                        .SetProjectFile(eventsProject)
                        .AddProperty("PackageVersion", Parameters.Version)
                        .SetConfiguration(Parameters.Configuration)
                        );
        }
    }
Exemple #2
0
        public async Task IntegrationTestAssemblyTest()
        {
            using (var memoryStream = new MemoryStream())
            {
                var input = await NuGetPackageHelper.DownloadPackageFilesAndFolder(new[] { new PackageIdentity("NETStandard.Library", new NuGetVersion("2.0.0")) }).ConfigureAwait(false);

                using (var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8, 1024, true))
                {
                    await ObservablesForEventGenerator.ExtractEventsFromAssemblies(streamWriter, input, FrameworkConstants.CommonFrameworks.NetStandard20).ConfigureAwait(false);
                }

                memoryStream.Flush();

                memoryStream.Position = 0;
                using (var sr = new StreamReader(memoryStream))
                {
                    var contents = sr.ReadToEnd();

                    contents.ShouldNotBeEmpty();
                }
            }
        }
Exemple #3
0
        public static async Task <int> Main(string[] args)
        {
            // allow app to be debugged in visual studio.
            if (args.Length == 0 && Debugger.IsAttached)
            {
                args = "generate-platform --platforms=uwp --output-path=test.txt".Split(' ');
            }

            var funcLogManager = new FuncLogManager(type => new WrappingFullLogger(new WrappingPrefixLogger(new ConsoleLogger(), type)));

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));

            var parserResult = new Parser(parserSettings => parserSettings.CaseInsensitiveEnumValues = true)
                               .ParseArguments <CustomAssembliesCommandLineOptions, PlatformCommandLineOptions>(args);

            var result = await parserResult.MapResult(
                async (PlatformCommandLineOptions options) =>
            {
                try
                {
                    var referenceAssembliesLocation = !string.IsNullOrWhiteSpace(options.ReferenceAssemblies)
                            ? options.ReferenceAssemblies !
                            : ReferenceLocator.GetReferenceLocation();

                    if (string.IsNullOrWhiteSpace(options.OutputPath))
                    {
                        throw new Exception("Invalid output path for the event generation.");
                    }

                    if (string.IsNullOrWhiteSpace(options.OutputPrefix))
                    {
                        throw new Exception("Invalid output prefix for the event generation.");
                    }

                    if (options.Platforms == null)
                    {
                        throw new Exception("Invalid platforms for the event generation.");
                    }

                    await ObservablesForEventGenerator.ExtractEventsFromPlatforms(options.OutputPath !, options.OutputPrefix !, ".cs", referenceAssembliesLocation, options.Platforms).ConfigureAwait(false);

                    return(ExitCode.Success);
                }
                catch (Exception ex)
                {
                    LogHost.Default.Fatal(ex);
                    return(ExitCode.Error);
                }
            },
                async (CustomAssembliesCommandLineOptions options) =>
            {
                try
                {
                    using (var writer = new StreamWriter(Path.Combine(options.OutputPath, options.OutputPrefix + ".cs")))
                    {
                        if (options.Assemblies == null)
                        {
                            throw new Exception("Invalid specified assemblies for observable generation.");
                        }

                        if (options.SearchDirectories == null)
                        {
                            throw new Exception("Invalid search directories specified for observable generation.");
                        }

                        if (string.IsNullOrWhiteSpace(options.TargetFramework))
                        {
                            throw new Exception("Invalid target framework for the event generation.");
                        }

                        await ObservablesForEventGenerator.WriteHeader(writer, options.Assemblies !).ConfigureAwait(false);

                        await ObservablesForEventGenerator.ExtractEventsFromAssemblies(writer, options.Assemblies !, options.SearchDirectories !, options.TargetFramework !).ConfigureAwait(false);
                    }

                    return(ExitCode.Success);
                }
                catch (Exception ex)
                {
                    LogHost.Default.Fatal(ex);
                    return(ExitCode.Error);
                }
            },
                async (NugetCommandLineOptions options) =>
            {
                try
                {
                    using (var writer = new StreamWriter(Path.Combine(options.OutputPath, options.OutputPrefix + ".cs")))
                    {
                        if (string.IsNullOrWhiteSpace(options.TargetFramework))
                        {
                            throw new Exception("Invalid target framework for the event generation.");
                        }

                        var packageIdentity = new[] { new LibraryRange(options.NugetPackageName, VersionRange.Parse(options.NugetVersion), LibraryDependencyTarget.Package) };
                        var nugetFramework  = options.TargetFramework !.ToFrameworks();
                        await ObservablesForEventGenerator.WriteHeader(writer, packageIdentity).ConfigureAwait(false);
                        await ObservablesForEventGenerator.ExtractEventsFromNuGetPackages(writer, packageIdentity, nugetFramework, options.PackageFolder).ConfigureAwait(false);
                    }

                    return(ExitCode.Success);
                }
                catch (Exception ex)
                {
                    LogHost.Default.Fatal(ex);
                    return(ExitCode.Error);
                }
            },
                _ =>
            {
                System.Console.WriteLine(HelpText.AutoBuild(parserResult));
                return(Task.FromResult(ExitCode.Error));
            }).ConfigureAwait(false);

            return((int)result);
        }