Example #1
0
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException">Ignore.</exception>
        protected override bool Process(AssemblyStitcherContext context)
        {
            BlobberHelper.Setup();

#if DEBUG
            _logging = new MultiLogging(new DefaultLogging(Logging), new FileLogging("MrAdvice.log"));
            _logging.WriteDebug("Start");
#else
            _logging = Logging;
#endif
            if (context.Module is null)
            {
                _logging.WriteError("Target assembly {0} could not be loaded", context.AssemblyPath);
                return(false);
            }

            try
            {
                // instances are created here
                // please also note poor man's dependency injection (which is enough for us here)
                var assemblyResolver = context.AssemblyResolver;
                var typeResolver     = new TypeResolver(context.Module)
                {
                    Logging = _logging, AssemblyResolver = assemblyResolver
                };
                var typeLoader   = new TypeLoader(() => LoadWeavedAssembly(context, assemblyResolver));
                var aspectWeaver = new AspectWeaver {
                    Logging = _logging, TypeResolver = typeResolver, TypeLoader = typeLoader
                };

                // second chance: someone had the marker file missing
                if (aspectWeaver.FindShortcutType(context.Module) is not null)
                {
                    return(false);
                }

                return(aspectWeaver.Weave(context.Module));
            }
            catch (Exception e)
            {
                _logging.WriteError("Internal error: {0}", e.ToString());
                for (var ie = e.InnerException; ie is not null; ie = ie.InnerException)
                {
                    _logging.WriteError("Inner exception: {0}", e.ToString());
                }
            }
            return(false);
        }
Example #2
0
        protected override bool Process(AssemblyStitcherContext context)
        {
            BlobberHelper.Setup();

            if (AlreadyProcessed(context))
            {
                return(false);
            }

#if DEBUG
            _logging = new MultiLogging(new DefaultLogging(Logging), new FileLogging("MrAdvice.log"));
            _logging.WriteDebug("Start");
#else
            _logging = Logging;
#endif
            if (context.Module == null)
            {
                _logging.WriteError("Target assembly {0} could not be loaded", context.AssemblyPath);
                return(false);
            }

            try
            {
                try
                {
                    const string mrAdviceAssemblyName = "MrAdvice, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c0e7e6eab6f293d8";
                    var          mrAdviceAssembly     = LoadEmbeddedAssembly(mrAdviceAssemblyName);
                    if (mrAdviceAssembly == null)
                    {
                        _logging.WriteError("Can't find/load embedded MrAdvice assembly (WTF?), exiting");
                        return(false);
                    }
                }
                catch (FileNotFoundException)
                {
                    _logging.WriteError("Can't load MrAdvice assembly (WTF?), exiting");
                    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        _logging.Write("Assembly in AppDomain: {0}", assembly.GetName());
                    }
                    return(false);
                }

                // instances are created here
                // please also note poor man's dependency injection (which is enough for us here)
                var assemblyResolver = context.AssemblyResolver;
                var typeResolver     = new TypeResolver(context.Module)
                {
                    Logging = _logging, AssemblyResolver = assemblyResolver
                };
                var typeLoader   = new TypeLoader(() => LoadWeavedAssembly(context, assemblyResolver));
                var aspectWeaver = new AspectWeaver {
                    Logging = _logging, TypeResolver = typeResolver, TypeLoader = typeLoader
                };

                // second chance: someone had the marker file missing
                if (aspectWeaver.FindShortcutType(context.Module) != null)
                {
                    return(false);
                }

                return(aspectWeaver.Weave(context.Module));
            }
            catch (Exception e)
            {
                _logging.WriteError("Internal error: {0}", e.ToString());
                for (var ie = e.InnerException; ie != null; ie = ie.InnerException)
                {
                    _logging.WriteError("Inner exception: {0}", e.ToString());
                }
            }
            return(false);
        }