示例#1
0
        /// <summary>
        /// Loads the assemblies specified for this <c>AssemblyLoader</c> instance and executes their entry point.
        /// </summary>
        private void Execute(bool isDelayed, int waitForAppDomainReadinessElapsedMs)
        {
#if DEBUG
            const string BuildConfiguration = "Debug";
#else
            const string BuildConfiguration = "Release";
#endif
            Log.Info(LoggingComponentMoniker,
                     "Initializing...",
                     "Managed Loader build configuration", BuildConfiguration,
                     nameof(isDelayed), isDelayed,
                     nameof(waitForAppDomainReadinessElapsedMs), waitForAppDomainReadinessElapsedMs,
                     $"{nameof(IsExecuteDelayedEnabled)}()", IsExecuteDelayedEnabled(),
                     $"{nameof(IsAppHostedInIis)}()", IsAppHostedInIis(),
                     $"{nameof(GetIisExecutionDelayMs)}()", GetIisExecutionDelayMs());

            AnalyzeAppDomain();

            AssemblyResolveEventHandler assemblyResolveEventHandler = CreateAssemblyResolveEventHandler();
            if (assemblyResolveEventHandler == null)
            {
                return;
            }

            Log.Info(LoggingComponentMoniker, "Registering AssemblyResolve handler");

            try
            {
                AppDomain.CurrentDomain.AssemblyResolve += assemblyResolveEventHandler.OnAssemblyResolve;
            }
            catch (Exception ex)
            {
                Log.Error(LoggingComponentMoniker, "Error while registering an AssemblyResolve event handler", ex);
            }

            LogStartingToLoadAssembliesInfo(assemblyResolveEventHandler);

            for (int i = 0; i < assemblyResolveEventHandler.AssemblyNamesToLoad.Count; i++)
            {
                string assemblyName = assemblyResolveEventHandler.AssemblyNamesToLoad[i];

                try
                {
                    LoadAndStartAssembly(assemblyName);
                }
                catch (Exception ex)
                {
                    Log.Error(LoggingComponentMoniker, "Error loading or starting a managed assembly", ex, "assemblyName", assemblyName);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Loads the assemblied specified for this <c>AssemblyLoader</c> instance and executes their entry point.
        /// </summary>
        public void Execute()
        {
            Log.Info(LoggingComponentMoniker,
                     "Initializing...",
                     "Managed Loader build configuration",
#if DEBUG
                     "Debug"
#else
                     "Release"
#endif
                     );

            AnalyzeAppDomain();

            AssemblyResolveEventHandler assemblyResolveEventHandler = CreateAssemblyResolveEventHandler();
            if (assemblyResolveEventHandler == null)
            {
                return;
            }

            Log.Info(LoggingComponentMoniker, "Registering AssemblyResolve handler");

            try
            {
                AppDomain.CurrentDomain.AssemblyResolve += assemblyResolveEventHandler.OnAssemblyResolve;
            }
            catch (Exception ex)
            {
                Log.Error(LoggingComponentMoniker, "Error while registering an AssemblyResolve event handler", ex);
            }

            LogStartingToLoadAssembliesInfo(assemblyResolveEventHandler);

            for (int i = 0; i < assemblyResolveEventHandler.AssemblyNamesToLoad.Count; i++)
            {
                string assemblyName = assemblyResolveEventHandler.AssemblyNamesToLoad[i];

                try
                {
                    LoadAndStartAssembly(assemblyName);
                }
                catch (Exception ex)
                {
                    Log.Error(LoggingComponentMoniker, "Error loading or starting a managed assembly", ex, "assemblyName", assemblyName);
                }
            }
        }
示例#3
0
        private static void LogStartingToLoadAssembliesInfo(AssemblyResolveEventHandler assemblyResolveEventHandler)
        {
            var logEntryDetails = new List <object>();

            logEntryDetails.Add("Number of assemblies");
            logEntryDetails.Add(assemblyResolveEventHandler.AssemblyNamesToLoad.Count);
            logEntryDetails.Add("Number of product binaries directories");
            logEntryDetails.Add(assemblyResolveEventHandler.ManagedProductBinariesDirectories.Count);

            for (int i = 0; i < assemblyResolveEventHandler.ManagedProductBinariesDirectories.Count; i++)
            {
                logEntryDetails.Add($"managedProductBinariesDirectories[{i}]");
                logEntryDetails.Add(assemblyResolveEventHandler.ManagedProductBinariesDirectories[i]);
            }

            Log.Info(LoggingComponentMoniker, "Starting to load assemblies", logEntryDetails);
        }
示例#4
0
        private AssemblyResolveEventHandler CreateAssemblyResolveEventHandler()
        {
            // Pick the list that we want to load:
            string[] assemblyListToUse = _isDefaultAppDomain
                                                ? _assemblyNamesToLoadIntoDefaultAppDomain
                                                : _assemblyNamesToLoadIntoNonDefaultAppDomains;

            // Set class fields to null so that the arrays can be collected. The "assemblyResolveEventHandler" will encpsulate the data needed.
            _assemblyNamesToLoadIntoDefaultAppDomain = _assemblyNamesToLoadIntoNonDefaultAppDomains = null;

            IReadOnlyList <string> assemblyNamesToLoad = CleanAssemblyNamesToLoad(assemblyListToUse);

            if (assemblyNamesToLoad == null)
            {
                return(null);
            }

            IReadOnlyList <string> managedProductBinariesDirectories = ResolveManagedProductBinariesDirectories();

            var assemblyResolveEventHandler = new AssemblyResolveEventHandler(assemblyNamesToLoad, managedProductBinariesDirectories);

            return(assemblyResolveEventHandler);
        }