コード例 #1
0
ファイル: ProviderCollector.cs プロジェクト: devio-at/STW6
        /// <summary>
        /// Gets all the Providers (copied array).
        /// </summary>
        public T[] GetAllProviders(string wiki)
        {
            string wikiKey = wiki != null ? wiki : "-";

            lock (this) {
                List <T> providers = new List <T>(assembliesDictionary.Count);
                foreach (Type key in assembliesDictionary.Keys)
                {
                    T provider = null;
                    if (!instancesDictionary.ContainsKey(wikiKey))
                    {
                        instancesDictionary[wikiKey] = new Dictionary <Type, T>(3);
                    }
                    if (instancesDictionary[wikiKey].ContainsKey(key))
                    {
                        provider = instancesDictionary[wikiKey][key];
                    }
                    else
                    {
                        provider = ProviderLoader.CreateInstance <T>(assembliesDictionary[key], key);
                        ProviderLoader.Initialize <T>(provider, ProviderLoader.LoadProviderConfiguration(key.FullName, typeof(T), wiki), wiki);
                        instancesDictionary[wikiKey][key] = provider;
                    }
                    providers.Add(provider);
                }
                return(providers.ToArray());
            }
        }
コード例 #2
0
ファイル: ProviderCollector.cs プロジェクト: devio-at/STW6
        /// <summary>
        /// Gets a Provider, searching for its Type Name.
        /// </summary>
        /// <param name="typeName">The Type Name.</param>
        /// <param name="wiki">The wiki.</param>
        /// <returns>The Provider, or null if the Provider was not found.</returns>
        public T GetProvider(string typeName, string wiki)
        {
            string wikiKey = wiki != null ? wiki : "-";

            lock (this) {
                foreach (Type type in assembliesDictionary.Keys)
                {
                    if (type.FullName.Equals(typeName))
                    {
                        T provider = null;
                        if (!instancesDictionary.ContainsKey(wikiKey))
                        {
                            instancesDictionary[wikiKey] = new Dictionary <Type, T>(3);
                        }
                        if (instancesDictionary[wikiKey].ContainsKey(type))
                        {
                            provider = instancesDictionary[wikiKey][type];
                        }
                        else
                        {
                            provider = ProviderLoader.CreateInstance <T>(assembliesDictionary[type], type);
                            ProviderLoader.Initialize <T>(provider, ProviderLoader.LoadProviderConfiguration(type.FullName, typeof(T), wiki), wiki);
                            instancesDictionary[wikiKey][type] = provider;
                        }
                        return(provider);
                    }
                }
                return(default(T));
            }
        }
コード例 #3
0
        /// <summary>
        /// Try to setup a provider.
        /// </summary>
        /// <typeparam name="T">The type of the provider, which must implement <b>IProvider</b>.</typeparam>
        /// <param name="provider">The provider to setup.</param>
        /// <param name="configuration">The configuration string.</param>
        public static void SetUp <T>(Type provider, string configuration) where T : class, IProviderV60
        {
            try {
                T providerInstance = ProviderLoader.CreateInstance <T>(Assembly.GetAssembly(provider), provider);
                providerInstance.SetUp(Host.Instance, configuration);

                // Verify constraints
                VerifyConstraints <T>(providerInstance);

                Log.LogEntry("Provider " + provider.FullName + " loaded.", EntryType.General, Log.SystemUsername, null);

                // Dispose the provider
                providerInstance.Dispose();
            }
            catch (InvalidConfigurationException) {
                Log.LogEntry("Unable to load provider " + provider.FullName + " (configuration rejected).", EntryType.Error, Log.SystemUsername, null);
                // Throw InvalidConfigurationException in order to disable plugin
                throw;
            }
            catch (Exception exception) {
                Log.LogEntry(String.Format("Unable to load provider " + provider.FullName + " ({0}).", exception.Message), EntryType.Error, Log.SystemUsername, null);
                UnloadPlugin(provider.FullName);
                throw; // Exception is rethrown because it's not a normal condition
            }
        }
コード例 #4
0
        /// <summary>
        /// The settings storage provider.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <returns>The settingsProvider initialized for the given wiki.</returns>
        public ISettingsStorageProviderV60 GetSettingsProvider(string wiki)
        {
            string wikiKey = wiki != null ? wiki : "-";

            if (!_settingsProvider.ContainsKey(wikiKey))
            {
                _settingsProvider[wikiKey] = ProviderLoader.CreateInstance <ISettingsStorageProviderV60>(_settingsProviderAssembly, _settingsProviderType);
                _settingsProvider[wikiKey].Init(Host.Instance, ProviderLoader.LoadStorageProviderConfiguration(_settingsProviderType.FullName), wiki);
            }
            return(_settingsProvider[wikiKey]);
        }
コード例 #5
0
ファイル: CollectorsBox.cs プロジェクト: ahmedfe/screwturn
        /// <summary>
        /// The index directory provider.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <returns>The indexDirectoryProvider initialized for the given wiki.</returns>
        public IIndexDirectoryProviderV40 GetIndexDirectoryProvider(string wiki)
        {
            string wikiKey = wiki != null ? wiki : "-";

            if (!_indexDirectoryProvider.ContainsKey(wikiKey))
            {
                _indexDirectoryProvider[wikiKey] = ProviderLoader.CreateInstance <IIndexDirectoryProviderV40>(_indexDirectoryProviderAssembly, _indexDirectoryProviderType);
                _indexDirectoryProvider[wikiKey].Init(Host.Instance, ProviderLoader.LoadStorageProviderConfiguration(_indexDirectoryProviderType.FullName), wiki);
            }
            return(_indexDirectoryProvider[wikiKey]);
        }