Пример #1
0
 /// <summary>
 /// Unregisters the specified plugin item from the plugin tree.
 /// </summary>
 /// <param name="itemMetadata">Meta data structure of the item to unregister.</param>
 /// <returns>Plugin item registration structure of the item to be unregistered.</returns>
 internal void UnregisterItem(PluginItemMetadata itemMetadata)
 {
     lock (_syncObj)
         try
         {
             IRegistryNode node = GetRegistryNode(itemMetadata.RegistrationLocation, false);
             if (node == null || node.Items == null)
             {
                 return;
             }
             if (node.Items.ContainsKey(itemMetadata.Id))
             {
                 PluginItemRegistration itemRegistration = (PluginItemRegistration)node.Items[itemMetadata.Id];
                 // Check, if there are additional redundant items registered at this position. If yes, we'll use
                 // the first of them instead of the old item to be unregistered.
                 PluginItemMetadata newItemMetadata          = null;
                 IEnumerator <PluginItemMetadata> enumerator = itemRegistration.AdditionalRedundantItemsMetadata.GetEnumerator();
                 if (enumerator.MoveNext())
                 {
                     newItemMetadata = enumerator.Current;
                     itemRegistration.AdditionalRedundantItemsMetadata.Remove(newItemMetadata);
                 }
                 node.Items.Remove(itemMetadata.Id);
                 if (newItemMetadata != null)
                 {
                     newItemMetadata.PluginRuntime.RegisterItem(newItemMetadata);
                 }
             }
         }
         finally
         {
             _itemRegistrations.Remove(itemMetadata);
         }
 }
Пример #2
0
 public IRegistryNode GetSubNodeByPath(string path, bool createOnNotExist)
 {
     lock (_syncObj)
     {
         if (_subNodes == null && !createOnNotExist)
         {
             return(null);
         }
         if (path.StartsWith("/"))
         {
             throw new ArgumentException("Registry path expression has to be a relative path (no '/' character at the beginning)");
         }
         path = StringUtils.RemoveSuffixIfPresent(path, "/");
         int    i        = path.IndexOf('/');
         string nodeName = i == -1 ? path : path.Substring(0, i);
         CheckSubNodeCollectionPresent();
         IRegistryNode node = _subNodes.ContainsKey(nodeName) ? _subNodes[nodeName] : null;
         if (node == null)
         {
             if (createOnNotExist)
             {
                 node = new RegistryNode(this, nodeName, _syncObj);
                 _subNodes.Add(nodeName, node);
             }
             else
             {
                 return(null);
             }
         }
         return(i == -1 ? node : node.GetSubNodeByPath(RegistryHelper.RemoveRootFromAbsolutePath(path.Substring(i)), createOnNotExist));
     }
 }
Пример #3
0
 /// <summary>
 /// Registers the specified plugin item in the plugin tree.
 /// </summary>
 /// <param name="itemMetadata">Metadata structure of the item to register.</param>
 /// <returns><c>true</c>, if the plugin item could be registered, <c>false</c>,
 /// if the item already existed and <see cref="PluginItemMetadata.IsRedundant"/> is specified.</returns>
 /// <exception cref="ArgumentException">If there is already an item registered at the registration
 /// location and the <see cref="PluginItemMetadata.IsRedundant"/> flag is not set.</exception>
 internal bool RegisterItem(PluginItemMetadata itemMetadata)
 {
     lock (_syncObj)
     {
         IRegistryNode node = GetRegistryNode(itemMetadata.RegistrationLocation, true);
         itemMetadata.PluginRuntime = this;
         if (node.Items != null && node.Items.ContainsKey(itemMetadata.Id))
         {
             if (itemMetadata.IsRedundant)
             {
                 PluginItemRegistration itemRegistration = (PluginItemRegistration)node.Items[itemMetadata.Id];
                 itemRegistration.AdditionalRedundantItemsMetadata.Add(itemMetadata);
                 return(false);
             }
             else
             {
                 throw new ArgumentException(string.Format("At location '{0}', a plugin item with id '{1}' is already registered",
                                                           itemMetadata.RegistrationLocation, itemMetadata.Id));
             }
         }
         PluginItemRegistration resultItemRegistration = new PluginItemRegistration(itemMetadata);
         node.AddItem(itemMetadata.Id, resultItemRegistration);
         _itemRegistrations.Add(itemMetadata, resultItemRegistration);
     }
     return(true);
 }
Пример #4
0
        /// <summary>
        /// Returns the item registration instance for the specified <paramref name="location"/> and the specified
        /// <paramref name="id"/>.
        /// </summary>
        /// <remarks>
        /// The plugin manager's synchronization object must be locked when this method is called.
        /// </remarks>
        /// <param name="location">Registration location of the requested item registration instance.</param>
        /// <param name="id">Id of the requested item registration instance.</param>
        /// <returns>Requested item registration instance, if it exists.</returns>
        internal static PluginItemRegistration GetItemRegistration(string location, string id)
        {
            IRegistryNode node = GetRegistryNode(location, false);

            if (node != null && node.Items != null && node.Items.ContainsKey(id))
            {
                return((PluginItemRegistration)node.Items[id]);
            }
            return(null);
        }
Пример #5
0
        /// <summary>
        /// Returns a collection of available child locations of the given <paramref name="location"/>.
        /// </summary>
        /// <remarks>
        /// The plugin manager's synchronization object must be locked when this method is called.
        /// </remarks>
        /// <param name="location">Location for that the child locations should be returned.</param>
        /// <returns>Collection of child locations of the given parent <paramref name="location"/>.</returns>
        internal static ICollection <string> GetAvailableChildLocations(string location)
        {
            IRegistryNode node   = GetRegistryNode(location, false);
            List <string> result = new List <string>();

            if (node != null && node.SubNodes != null)
            {
                result.AddRange(node.SubNodes.Keys.Select(childName => RegistryHelper.ConcatenatePaths(location, childName)));
            }
            return(result);
        }
Пример #6
0
        /// <summary>
        /// Returns all item registration instances for the specified <paramref name="location"/>.
        /// </summary>
        /// <remarks>
        /// The plugin manager's synchronization object must be locked when this method is called.
        /// </remarks>
        /// <param name="location">Registration location of the requested item registration instances.</param>
        /// <returns>Collection of item registration instances at the specified location.</returns>
        internal static ICollection <PluginItemRegistration> GetItemRegistrations(string location)
        {
            IRegistryNode node = GetRegistryNode(location, false);
            List <PluginItemRegistration> result = new List <PluginItemRegistration>();

            if (node != null && node.Items != null)
            {
                result.AddRange(node.Items.Values.OfType <PluginItemRegistration>());
            }
            return(result);
        }
Пример #7
0
        /// <summary>
        /// Returns all plugin item change listeners for the given <paramref name="location"/>.
        /// </summary>
        /// <param name="location">Location to return the listeners for.</param>
        /// <param name="createOnNotExist">If set to <c>true</c>, the plugin tree node will be created, if it doesn't exist.</param>
        /// <remarks>
        /// The plugin manager's synchronization object must be locked when this method is called.
        /// </remarks>
        protected static ICollection <IItemRegistrationChangeListener> GetListenersForLocation(string location, bool createOnNotExist)
        {
            IRegistryNode node = GetRegistryNode(location, createOnNotExist);

            if (node == null)
            {
                return(null);
            }
            object resultObj;

            if (node.Items != null && node.Items.TryGetValue(ITEMCHANGELISTENER_ID, out resultObj))
            {
                return((ICollection <IItemRegistrationChangeListener>)resultObj);
            }
            if (createOnNotExist)
            {
                ICollection <IItemRegistrationChangeListener> result = new List <IItemRegistrationChangeListener>();
                node.AddItem(ITEMCHANGELISTENER_ID, result);
                return(result);
            }
            return(null);
        }