Example #1
0
 public InProcessBackgroundServiceExecutor(IUnityContainer container, Type backgroundServiceType, OxiteModuleConfigurationElement moduleConfiguration)
 {
     this.container             = container;
     this.backgroundServiceType = backgroundServiceType;
     this.moduleConfiguration   = moduleConfiguration;
     interval = TimeSpan.FromMinutes(1);
     timer    = new Timer(timerCallback);
 }
Example #2
0
        public IOxiteModule Load(OxiteConfigurationSection config, OxiteModuleConfigurationElement module)
        {
            if (module == null || !module.Enabled)
            {
                return(null);
            }

            foreach (OxiteDataProviderConfigurationElement dataProvider in config.Providers)
            {
                if (dataProvider.Name == module.DataProvider)
                {
                    Type dataProviderType = Type.GetType(dataProvider.Type);

                    if (dataProviderType == null)
                    {
                        throw new TypeLoadException(string.Format("Could not load type '{0}'.", dataProvider.Type));
                    }

                    IOxiteDataProvider dataProviderInstance = container.Resolve(dataProviderType) as IOxiteDataProvider;

                    if (dataProviderInstance != null)
                    {
                        dataProviderInstance.ConfigureProvider(config, dataProvider, container);
                    }

                    break;
                }
            }

            Type type = Type.GetType(module.Type);

            if (type == null)
            {
                foreach (var assembly in BuildManager.CodeAssemblies)
                {
                    type = ((Assembly)assembly).GetExportedTypes().FirstOrDefault(t => t.FullName == module.Type);

                    if (type != null)
                    {
                        break;
                    }
                }
            }

            if (type == null)
            {
                throw new TypeLoadException(string.Format("Could not load type '{0}'.", module.Type));
            }

            IOxiteModule moduleInstance = container.Resolve(type) as IOxiteModule;

            modules.Add(moduleInstance);

            return(moduleInstance);
        }
 public void Add <TExecutor, TService>(OxiteModuleConfigurationElement moduleConfiguration, string name, TimeSpan defaultInterval) where TExecutor : class, IBackgroundServiceExecutor where TService : IBackgroundService
 {
     executors.Add((TExecutor)Activator.CreateInstance(typeof(TExecutor), container, typeof(TService), moduleConfiguration));
 }