コード例 #1
0
        /// <summary>
        ///     Removes a user defined <see cref="Item"/> from the Connector Plugin's data structure.
        /// </summary>
        /// <remarks>
        ///     <para>If an Item being removed has child Items, all children are also removed.</para>
        /// </remarks>
        /// <param name="fqn">The Item to remove.</param>
        /// <returns>A Result containing the result of the operation.</returns>
        public Result RemoveItem(string fqn)
        {
            logger.EnterMethod(xLogger.Params(fqn));
            logger.Info("Removing user defined Item '" + fqn + "...");

            Result retVal = new Result <Item>();

            // check to see if the specified Item has been added previously
            if (AddedItems.ContainsKey(fqn))
            {
                // try to find the matching Item instance
                Item foundItem = Find(fqn);

                if (foundItem != default(Item))
                {
                    // leverage the Item's parent to remove it from the model. The RemoveChild() method in Item will recursively
                    // remove all children.
                    foundItem.Parent.RemoveChild(foundItem);
                }
                else
                {
                    retVal.AddWarning("The Item '" + fqn + "' was not found in the Item data structure, but exists in the list of added items.  It will be removed from the list.");
                }

                // remove the item from the AddedItems list
                AddedItems.Remove(fqn);
            }
            else
            {
                retVal.AddError("The Item '" + fqn + "' does not exist in the list of added Items.");
            }

            retVal.LogResult(logger);
            logger.ExitMethod(retVal);
            return(retVal);
        }