Exemplo n.º 1
0
 protected override void OnDispose(bool inIsDisposing)
 {
     if (inIsDisposing)
     {
         if (_loader != null)
         {
             _loader.Release();
             _loader = null;
         }
     }
 }
Exemplo n.º 2
0
        protected virtual PluginDomainInstanceLoader GetPluginInstanceLoader(string pluginConfigFilePath, string pluginFilePath)
        {
            if (string.IsNullOrEmpty(pluginConfigFilePath) || (PluginInstanceLoadersCacheTimeInMinutes <= 0))
            {
                // This is not an expensive case with string.IsNullOrEmpty(pluginConfigFilePath), since we are
                // not creating spring objects, so don't cache
                //
                // OR
                //
                // we've specified to turn off the cache with PluginInstanceLoadersCacheTimeInMinutes <= 0
                return(new PluginDomainInstanceLoader(pluginConfigFilePath, pluginFilePath));
            }
            const string CACHED_PLUGIN_INSTANCE_LOADERS = "_CACHED_PLUGIN_INSTANCE_LOADERS";
            string       cacheName = CACHED_PLUGIN_INSTANCE_LOADERS + "_" + pluginConfigFilePath + "_" + pluginFilePath;
            PluginDomainInstanceLoader loader;

            lock (s_CachedPluginInstanceLoadersLock)
            {
                loader = HttpRuntime.Cache[cacheName] as PluginDomainInstanceLoader;
            }
            if (loader != null)
            {
                return(loader);
            }
            string parentDirPath = Path.GetDirectoryName(Path.GetDirectoryName(pluginFilePath));

            loader = new PluginDomainInstanceLoader(pluginConfigFilePath, pluginFilePath);

            PluginDomainInstanceLoader loaderAlreadyThere = null;

            lock (s_CachedPluginInstanceLoadersLock)
            {
                loaderAlreadyThere = HttpRuntime.Cache[cacheName] as PluginDomainInstanceLoader;
                if (loaderAlreadyThere == null)
                {
                    loader.Acquire();
                    HttpRuntime.Cache.Add(cacheName, loader, new CacheDependency(parentDirPath),
                                          Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(PluginInstanceLoadersCacheTimeInMinutes),
                                          CacheItemPriority.AboveNormal, OnCachePluginDomainInstanceLoaderRemovedCallback);
                }
            }
            if (loaderAlreadyThere != null)
            {
                // Switch over to already cached instance
                DisposableBase.SafeDispose(ref loader);
                loader = loaderAlreadyThere;
            }
            return(loader);
        }
Exemplo n.º 3
0
 public virtual void GetDataServiceParameters(IEnumerable <DataService> dataServices)
 {
     if (CollectionUtils.IsNullOrEmpty(dataServices))
     {
         return;
     }
     try
     {
         string pluginRootFilePath         = GetPluginFilePath(CollectionUtils.FirstItem(dataServices), true);
         PluginDomainInstanceLoader loader = GetPluginInstanceLoader(null, pluginRootFilePath);
         using (PluginDisposer disposer = new PluginDisposer(loader))
         {
             foreach (DataService dataService in dataServices)
             {
                 if ((dataService.PluginInfo != null) && !string.IsNullOrEmpty(dataService.PluginInfo.ImplementingClassName))
                 {
                     try
                     {
                         string                  pluginFilePath = GetPluginFilePath(dataService, true);
                         BaseWNOSPlugin          plugin         = loader.GetInstance <BaseWNOSPlugin>(pluginFilePath, dataService.PluginInfo.ImplementingClassName);
                         DataServicePublishFlags publishFlags;
                         dataService.ServiceParameters = plugin.GetDataServiceParameters(dataService.Name, out publishFlags);
                         dataService.PublishFlags      = publishFlags;
                     }
                     catch (Exception e)
                     {
                         // Don't publish on load error
                         dataService.PublishFlags = DataServicePublishFlags.DoNotPublish;
                         LOG.Error("Failed to GetDataServiceParameters for data service \"{0}\"", e, dataService.Name);
                     }
                 }
                 else
                 {
                     // Don't publish if not implementer
                     dataService.PublishFlags = DataServicePublishFlags.DoNotPublish;
                 }
             }
         }
     }
     catch (Exception)
     {
         foreach (DataService dataService in dataServices)
         {
             // Don't publish if can't load
             dataService.PublishFlags = DataServicePublishFlags.DoNotPublish;
         }
     }
 }
Exemplo n.º 4
0
        protected virtual ICollection <SimpleDataService> GetDataServiceImplementersInDirectory(string inDirectoryPath,
                                                                                                bool ignoreInstallingAssemblies)
        {
            OrderedSet <SimpleDataService> implementers = new OrderedSet <SimpleDataService>();

            if (Directory.Exists(inDirectoryPath))
            {
                OrderedSet <string>        processedAssemblies = new OrderedSet <string>();
                PluginDomainInstanceLoader loader = null;
                try
                {
                    PluginInstanceFinder pluginFinder = null;
                    foreach (string dllPath in Directory.GetFiles(inDirectoryPath, "*.dll", SearchOption.AllDirectories))
                    {
                        if (!ignoreInstallingAssemblies || !IsInstallingPluginAssemblyPath(dllPath))
                        {
                            string assemblyName = Path.GetFileName(dllPath);
                            if (!processedAssemblies.Contains(assemblyName))
                            {
                                string assemblyPath = GetPluginFilePathInDirectory(assemblyName, inDirectoryPath,
                                                                                   ignoreInstallingAssemblies);
                                if (assemblyPath != null)
                                {
                                    if (loader == null)
                                    {
                                        // Don't need to load spring objects here
                                        loader       = GetPluginInstanceLoader(null, assemblyPath);
                                        pluginFinder = loader.GetInstance <PluginInstanceFinder>();
                                    }
                                    GetDataServiceImplementers(pluginFinder, assemblyPath, ref implementers);
                                }
                                processedAssemblies.Add(assemblyName);
                            }
                        }
                    }
                }
                finally
                {
                    DisposableBase.SafeDispose(ref loader);
                }
            }
            return(implementers);
        }
Exemplo n.º 5
0
        protected virtual IPluginDisposer LoadPluginInterfaceInstance <T>(DataService inDataService,
                                                                          bool ignoreInstallingAssemblies,
                                                                          string pluginConfigFilePath,
                                                                          out T plugin) where T : class
        {
            string pluginFilePath               = GetPluginFilePath(inDataService, ignoreInstallingAssemblies);
            PluginDomainInstanceLoader loader   = GetPluginInstanceLoader(pluginConfigFilePath, pluginFilePath);
            PluginDisposer             disposer = new PluginDisposer(loader);

            try
            {
                plugin = loader.GetInstance <T>(pluginFilePath, inDataService.PluginInfo.ImplementingClassName);
            }
            catch (Exception)
            {
                DisposableBase.SafeDispose(ref disposer);
                throw;
            }
            return(disposer);
        }
Exemplo n.º 6
0
 public PluginDisposer(PluginDomainInstanceLoader loader)
 {
     _loader = loader;
     _loader.Acquire();
 }
Exemplo n.º 7
0
        protected virtual void OnCachePluginDomainInstanceLoaderRemovedCallback(string key, object value, CacheItemRemovedReason reason)
        {
            PluginDomainInstanceLoader loader = (PluginDomainInstanceLoader)value;

            loader.Release();
        }