コード例 #1
0
        public IAssemblyScanner Load(IPluginRepository repository, ILogMessagesFromRemoteAppDomains logger)
        {
            try
            {
                var builder = new ContainerBuilder();
                {
                    builder.RegisterModule(new SchedulingModule());

                    builder.Register(c => new PartImportEngine(
                            c.Resolve<ISatisfyPluginRequests>()))
                        .As<IConnectParts>();

                    builder.RegisterInstance(repository)
                        .As<IPluginRepository>()
                        .As<ISatisfyPluginRequests>();
                }

                var container = builder.Build();

                Func<IBuildFixedSchedules> scheduleBuilder = () => container.Resolve<IBuildFixedSchedules>();
                return new RemoteAssemblyScanner(
                    container.Resolve<IPluginRepository>(),
                    container.Resolve<IConnectParts>(),
                    logger,
                    scheduleBuilder);
            }
            catch (Exception e)
            {
                logger.Log(LevelToLog.Error, e.ToString());
                throw;
            }
        }
コード例 #2
0
        public IAssemblyScanner Load(IPluginRepository repository, ILogMessagesFromRemoteAppDomains logger)
        {
            try
            {
                var builder = new ContainerBuilder();
                {
                    builder.RegisterModule(new SchedulingModule());

                    builder.Register(c => new PartImportEngine(
                                         c.Resolve <ISatisfyPluginRequests>()))
                    .As <IConnectParts>();

                    builder.RegisterInstance(repository)
                    .As <IPluginRepository>()
                    .As <ISatisfyPluginRequests>();
                }

                var container = builder.Build();

                Func <IBuildFixedSchedules> scheduleBuilder = () => container.Resolve <IBuildFixedSchedules>();
                return(new RemoteAssemblyScanner(
                           container.Resolve <IPluginRepository>(),
                           container.Resolve <IConnectParts>(),
                           logger,
                           scheduleBuilder));
            }
            catch (Exception e)
            {
                logger.Log(LevelToLog.Error, e.ToString());
                throw;
            }
        }
コード例 #3
0
        private Assembly LoadAssembly(string file)
        {
            if (file == null)
            {
                return(null);
            }

            if (file.Length == 0)
            {
                return(null);
            }

            // Check if the file exists.
            if (!File.Exists(file))
            {
                return(null);
            }

            // Try to load the assembly. If we can't load the assembly
            // we log the exception / problem and return a null reference
            // for the assembly.
            string fileName = Path.GetFileNameWithoutExtension(file);

            try
            {
                // Only use the file name of the assembly
                return(Assembly.Load(fileName));
            }
            catch (FileNotFoundException e)
            {
                // The file does not exist. Only possible if somebody removes the file
                // between the check and the loading.
                m_Logger.Log(
                    LevelToLog.Error,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.Plugins_LogMessage_Scanner_AssemblyLoadFailed_WithNameAndException,
                        fileName,
                        e));
            }
            catch (FileLoadException e)
            {
                // Could not load the assembly.
                m_Logger.Log(
                    LevelToLog.Error,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.Plugins_LogMessage_Scanner_AssemblyLoadFailed_WithNameAndException,
                        fileName,
                        e));
            }
            catch (BadImageFormatException e)
            {
                // incorrectly formatted assembly.
                m_Logger.Log(
                    LevelToLog.Error,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.Plugins_LogMessage_Scanner_AssemblyLoadFailed_WithNameAndException,
                        fileName,
                        e));
            }

            return(null);
        }