Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loggerEngineType"></param>
        /// <param name="assemblyName"></param>
        /// <param name="domainName"></param>
        /// <returns></returns>
        public bool LoadAssembly(string loggerEngineType, string assemblyName, string domainName)
        {
            ValidationUtil.CheckArgumentNull(loggerEngineType, "loggerEngineType");
            ValidationUtil.CheckArgumentNull(assemblyName, "assemblyName");
            ValidationUtil.CheckArgumentNull(domainName, "domainName");

            bool assemblyLoaded = true;

            try
            {
                var adSetup = new AppDomainSetup();
                adSetup.ApplicationBase = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase);

                // Create the new AppDomain
                var newDomain = AppDomain.CreateDomain(domainName, null, adSetup);

                // Load the Assembly
                var newAssembly = newDomain.Load(assemblyName);

                CurrentDomains[loggerEngineType]    = newDomain;
                CurrentAssemblies[loggerEngineType] = newAssembly;
            }
            catch (Exception ex)
            {
                assemblyLoaded = false;
            }

            return(assemblyLoaded);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loggerEngineType"></param>
        /// <param name="assemblyName"></param>
        /// <param name="domainName"></param>
        /// <returns></returns>
        public bool UnloadAssembly(string loggerEngineType, string assemblyName, string domainName)
        {
            ValidationUtil.CheckArgumentNull(loggerEngineType, "loggerEngineType");
            ValidationUtil.CheckArgumentNull(assemblyName, "assemblyName");
            ValidationUtil.CheckArgumentNull(domainName, "domainName");

            var assemblyUnloadedFromDomain = true;

            try
            {
                if (!CurrentDomains.ContainsKey(loggerEngineType))
                {
                    return(true);
                }

                var domainNameToUnload = CurrentDomains[loggerEngineType];

                AppDomain.Unload(domainNameToUnload);
                CurrentDomains.Remove(loggerEngineType);
                CurrentAssemblies.Remove(loggerEngineType);
            }
            catch (Exception ex)
            {
                assemblyUnloadedFromDomain = false;
            }

            return(assemblyUnloadedFromDomain);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loggerEngineType"></param>
        /// <param name="methodToInvoke"></param>
        /// <returns></returns>
        public bool ProcessMethod(string loggerEngineType, string methodToInvoke, LoggerEntities.Log logMessage)
        {
            ValidationUtil.CheckArgumentNull(loggerEngineType, "loggerEngineType");
            ValidationUtil.CheckArgumentNull(methodToInvoke, "methodToInvoke");
            ValidationUtil.CheckArgumentNull(logMessage, "logMessage");

            bool methodProcessed = true;

            try
            {
                if (!CurrentAssemblies.ContainsKey(loggerEngineType))
                {
                    return(false);
                }

                var assemblyToUse = CurrentAssemblies[loggerEngineType];

                //Getting the Logger component -- All assemblies (DatabaseLogger, FileLogger, ConsoleLogger) has the same Name
                Type type         = assemblyToUse.GetTypes().FirstOrDefault(typess => typess.Name == "Logger");
                var  totalMethods = type.GetMethods();
                var  loggerMethod = type.GetMethod(methodToInvoke);

                object classInstance    = Activator.CreateInstance(type, null);
                var    logMessageParams = new object[] { logMessage.LogType, logMessage.LogMessage };
                object result           = loggerMethod.Invoke(classInstance, logMessageParams);

                //The DoLog method in all assemblies should return a boolean
                methodProcessed = Convert.ToBoolean(result);

                //updating the status of the Log
                logMessage.LogStatus = methodProcessed ? AppConstant.LogStatus.Saved : AppConstant.LogStatus.Failed;
            }
            catch (Exception ex)
            {
                methodProcessed      = false;
                logMessage.LogStatus = AppConstant.LogStatus.Failed;
            }

            return(methodProcessed);
        }