Beispiel #1
0
        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 <Entities.NamespaceInfo>();

            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("&lt;", "<")
                              .Replace("&gt;", ">")
                              .Replace("`1", string.Empty)
                              .Replace("`2", string.Empty)
                              .Replace("`3", string.Empty);

                await File.WriteAllTextAsync(outputPath, result).ConfigureAwait(false);
            }
        }
Beispiel #2
0
        public static void ExtractEventsFromAssemblies(IPlatform platform)
        {
            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 template = File.ReadAllText(_mustacheTemplate, Encoding.UTF8);

            var namespaceData = Array.Empty <Entities.NamespaceInfo>();

            switch (platform.Platform)
            {
            case AutoPlatform.Essentials:
                namespaceData = StaticEventTemplateInformation.Create(targetAssemblies);
                break;

            default:
                namespaceData = EventTemplateInformation.Create(targetAssemblies);
                break;
            }

            var delegateData = DelegateTemplateInformation.Create(targetAssemblies);

            var result = Render.StringToString(
                template,
                new { Namespaces = namespaceData, DelegateNamespaces = delegateData })
                         .Replace("System.String", "string")
                         .Replace("System.Object", "object")
                         .Replace("&lt;", "<")
                         .Replace("&gt;", ">")
                         .Replace("`1", string.Empty)
                         .Replace("`2", string.Empty)
                         .Replace("`3", string.Empty);

            Console.WriteLine(result);
        }