public void ProcessAssembly(AssemblyDefinition assembly)
        {
            var aspects = _aspectExtractor.Extract(assembly);

            foreach (var aspect in aspects)
            {
                _cache.Cache(aspect);
            }

            var injections = _injectionCollector.Collect(assembly).ToList();

            _janitor.Cleanup(assembly);

            if (_log.IsErrorThrown)
            {
                return;
            }

            _cache.FlushCache(assembly);

            foreach (var aspect in aspects)
            {
                _assectWeaver.WeaveGlobalAssests(aspect);
            }

            foreach (var injector in _effectWeavers.OrderByDescending(i => i.Priority))
            {
                _log.LogInfo($"Executing {injector.GetType().Name}");

                foreach (var prioritizedInjections in injections.GroupBy(i => i.Priority).OrderByDescending(a => a.Key).ToList())
                {
                    foreach (var injection in prioritizedInjections.OrderByDescending(i => i.Effect.Priority))
                    {
                        if (injector.CanWeave(injection))
                        {
                            injector.Weave(injection);
                            injections.Remove(injection);
                        }
                    }
                }
            }

            foreach (var injection in injections)
            {
                _log.LogError(CompilationMessage.From($"Couldn't find weaver for {injection.ToString()}", injection.Target));
            }
        }
        private void ProcessAssembly(AssemblyDefinition assembly)
        {
            var aspects = _aspectExtractor.Extract(assembly);

            foreach (var aspect in aspects)
            {
                _cache.Cache(aspect);
            }

            var injections = _injectionCollector.Collect(assembly).ToList();

            injections = ExcludeAspectInjections(injections, aspects);

            _janitor.Cleanup(assembly);

            if (_log.IsErrorThrown)
            {
                return;
            }

            _cache.FlushCache(assembly);

            foreach (var aspect in aspects)
            {
                _aspectWeaver.WeaveGlobalAssests(aspect);
            }

            foreach (var injector in _effectWeavers.OrderByDescending(i => i.Priority))
            {
                _log.LogInfo($"Executing {injector.GetType().Name}");

                foreach (var prioritizedInjections in injections.GroupBy(i => i.Priority).OrderByDescending(a => a.Key).ToList())
                {
                    foreach (var injection in prioritizedInjections.OrderByDescending(i => i.Effect.Priority))
                    {
                        if (injector.CanWeave(injection))
                        {
                            injector.Weave(injection);
                            injections.Remove(injection);
                        }
                    }
                }
            }

            foreach (var injection in injections)
            {
                _log.LogError(CompilationMessage.From($"Couldn't find weaver for {injection.ToString()}", injection.Target));
            }

            var isInRelease = false;

            var debugAttr = assembly.CustomAttributes.FirstOrDefault(a => a.AttributeType.IsTypeOf(typeof(DebuggableAttribute)));

            if (!debugAttr.GetConstructorValue <DebuggableAttribute.DebuggingModes>(0).HasFlag(DebuggableAttribute.DebuggingModes.DisableOptimizations))
            {
                isInRelease = true;
            }

            foreach (var module in assembly.Modules)
            {
                if (isInRelease)
                {
                    EditorFactory.Optimize(module);
                }
                EditorFactory.CleanUp(module);
            }
        }
Beispiel #3
0
        public void ProcessAssembly(AssemblyDefinition assembly, bool optimize)
        {
            var aspects = _aspectExtractor.Extract(assembly);

            foreach (var aspect in aspects)
            {
                _cache.Cache(aspect);
            }


            var injections = _injectionCollector.Collect(assembly).ToList();

            injections = ExcludeAspectInjections(injections, aspects);

            _janitor.Cleanup(assembly);

            if (_log.IsErrorThrown)
            {
                return;
            }

            _cache.FlushCache(assembly);
            _log.LogInfo($"Stored {aspects.Count} aspects");

            foreach (var aspect in aspects)
            {
                _aspectWeaver.WeaveGlobalAssests(aspect);
            }

            _log.LogInfo($"Found {injections.Count} injections");

            foreach (var injector in _effectWeavers.OrderByDescending(i => i.Priority))
            {
                _log.LogInfo($"Executing {injector.GetType().Name}");

                foreach (var prioritizedInjections in injections.GroupBy(i => i.Priority).OrderByDescending(a => a.Key).ToList())
                {
                    foreach (var injection in prioritizedInjections.OrderByDescending(i => i.Effect.Priority))
                    {
                        if (injector.CanWeave(injection))
                        {
                            injector.Weave(injection);
                            injections.Remove(injection);
                        }
                    }
                }
            }

            foreach (var injection in injections)
            {
                _log.LogError(CompilationMessage.From($"Couldn't find weaver for {injection.ToString()}", injection.Target));
            }


            if (optimize)
            {
                _log.LogInfo($"Cleanup and optimize.");
            }
            else
            {
                _log.LogInfo($"Cleanup.");
            }

            foreach (var module in assembly.Modules)
            {
                if (optimize)
                {
                    EditorFactory.Optimize(module);
                }

                EditorFactory.CleanUp(module);
            }
        }