/// <summary>
        /// Retrieves the named, scoped, and namespace-constrained input from
        /// the list, or null if it does not exist.
        /// </summary>
        /// <param name="key">The name of the input.</param>
        /// <param name="splunkNamespace">The namespace.</param>
        /// <returns>The retrieved input.</returns>
        private Input RetrieveInput(string key, Args splunkNamespace)
        {
            Util.EnsureNamespaceIsExact(splunkNamespace);
            this.Validate();

            string pathMatcher =
                this.Service.Fullpath(string.Empty, splunkNamespace);

            foreach (KeyValuePair <string, List <Input> > entry in this.Items)
            {
                string       entryKey   = entry.Key;
                List <Input> entryValue = entry.Value;
                InputKind    kind       = entryValue[0].GetKind();

                if (InputCollection.MatchesInputName(kind, key, entryKey))
                {
                    List <Input> entities = this.Items[key];
                    if (entities.Count == 0)
                    {
                        continue;
                    }
                    foreach (Input entity in entities)
                    {
                        if (entity.Path.StartsWith(pathMatcher))
                        {
                            return(entity);
                        }
                    }
                }
            }
            return(null);
        }
        /// <summary>
        /// Creates a new data input based on an Atom entry.
        /// </summary>
        /// <param name="entry">The Atom data representing the object.</param>
        /// <returns>The new input object.</returns>
        protected override Input CreateItem(AtomEntry entry)
        {
            string    path       = this.ItemPath(entry);
            InputKind kind       = this.ItemKind(path);
            Type      inputClass = kind.InputClass;

            return(this.CreateItem(inputClass, path, null));
        }
        MatchesInputName(InputKind kind, string searchFor, string searchIn)
        {
            if (kind == InputKind.Script)
            {
                return(searchIn.EndsWith("/" + searchFor) ||
                       searchIn.EndsWith("\\" + searchFor));
            }

            return(searchFor.Equals(searchIn));
        }
        Create(string name, InputKind kind, Dictionary <string, object> args)
        {
            args = Args.Create(args);
            args.Add("name", name);
            string path = this.Path + "/" + kind.RelPath;

            this.Service.Post(path, args);
            this.Invalidate();
            return(this.Get(name));
        }
        /// <summary>
        /// Assembles the input kind list by refreshing from the server.
        /// </summary>
        /// <param name="subPath">The sub path.</param>
        /// <returns>The list of input kinds.</returns>
        private List <InputKind> AssembleInputKindList(ArrayList subPath)
        {
            List <InputKind> kinds    = new List <InputKind>();
            ResponseMessage  response =
                this.Service.Get(this.Path + "/" + Util.Join("/", subPath));
            AtomFeed feed = AtomFeed.Parse(response.Content);

            foreach (AtomEntry entry in feed.Entries)
            {
                string itemKeyName   = ItemKey(entry);
                bool   hasCreateLink = entry.Links.ContainsKey("create");

                ArrayList thisSubPath = new ArrayList(subPath);
                thisSubPath.Add(itemKeyName);

                string relPath = Util.Join("/", thisSubPath);

                if (relPath.Equals("all") || relPath.Equals("tcp/ssl"))
                {
                    continue;
                }
                else if (hasCreateLink)
                {
                    InputKind newKind = InputKind.Create(relPath);
                    kinds.Add(newKind);
                }
                else
                {
                    List <InputKind> subKinds =
                        this.AssembleInputKindList(thisSubPath);
                    kinds.AddRange(subKinds);
                }
            }

            return(kinds);
        }
        /// <summary>
        /// Retrieves the named input from the list, or null if it
        /// does not exist.
        /// </summary>
        /// <param name="key">The name of the input.</param>
        /// <returns>The retrieved input.</returns>
        private Input RetrieveInput(string key)
        {
            this.Validate();

            foreach (KeyValuePair <string, List <Input> > entry in this.Items)
            {
                string       entryKey   = entry.Key;
                List <Input> entryValue = entry.Value;
                InputKind    kind       = entryValue[0].GetKind();

                if (InputCollection.MatchesInputName(kind, key, entryKey))
                {
                    if (entryValue.Count > 1)
                    {
                        throw new SplunkException(
                                  SplunkException.AMBIGUOUS,
                                  "Key has multiple values, specify a namespace");
                    }

                    return(entryValue[0]);
                }
            }
            return(null);
        }
 /// <summary>
 /// Creates a new data input based on the input kind.
 /// </summary>
 /// <param name="name">The input name.</param>
 /// <param name="kind">The kind of input to create.</param>
 /// <returns>The new input object.</returns>
 public Input Create(string name, InputKind kind)
 {
     return(this.Create(name, kind, (Dictionary <string, object>)null));
 }