Esempio n. 1
0
        private void ProcessHandlerException(StartupHandlerInfo startupHandler, MethodInfo methodInfo, Exception ex)
        {
            var type    = methodInfo.DeclaringType;
            var message = $"Failed to execute startup handler. Type: '{type.FullName}', Assembly: '{type.Assembly.FullName}'";

            if (startupHandler.Attribute.AbortStartupOnException)
            {
                throw new InvalidOperationException(message, ex);
            }

            Log.LogError(LogTitle, message);

            Log.LogError(LogTitle, ex is TargetInvocationException ? ex.InnerException : ex);
        }
        private void Subscribe(StartupHandlerInfo[] startupHandlers)
        {
            foreach (StartupHandlerInfo startupHandler in startupHandlers)
            {
                var type = startupHandler.Type;

                MethodInfo onBeforeInitializeMethod, onInitializedMethod;

                GetPublicStaticMethod(type, OnBeforeInitializeMethodName, out onBeforeInitializeMethod);
                GetPublicStaticMethod(type, OnInitializedMethodName, out onInitializedMethod);

                startupHandler.OnBeforeInitialeMethod = onBeforeInitializeMethod;
                startupHandler.OnInitializedMethod = onInitializedMethod;
                
                _startupHandlers.Add(startupHandler);
            }
        }