/// <summary> /// Gets the object in the collection, given the key, with a scoped /// name-spaced constraint. /// </summary> /// <param name="key">The key.</param> /// <param name="splunkNamespace">The namespace.</param> /// <returns>The object, or default(object) if not found.</returns> public virtual T Get(object key, Args splunkNamespace) { this.Validate(); if (!this.Items.ContainsKey((string)key)) { return(default(T)); } List <T> entities = this.Items[(string)key]; if (entities.Count == 0) { return(default(T)); } string pathMatcher; pathMatcher = Service.Fullpath(string.Empty, splunkNamespace); foreach (T entity in entities) { if (entity.Path.StartsWith(pathMatcher)) { return(entity); } } return(default(T)); }
/// <summary> /// Removes an entity from this collection, with a namespace /// restriction. /// </summary> /// <param name="key">The name of this entity.</param> /// <param name="splunkNamespace">The namespace.</param> /// <returns>The removed entity.</returns> public virtual T Remove(string key, Args splunkNamespace) { this.Validate(); if (!this.ContainsKey(key)) { return(default(T)); } List <T> entities = Items[key]; string pathMatcher = Service.Fullpath(string.Empty, splunkNamespace); if (entities.Count == 0) { return(default(T)); } foreach (T entity in entities) { if (entity.Path.StartsWith(pathMatcher)) { entity.Remove(); this.Invalidate(); return(entity); } } return(default(T)); }
/// <summary> /// Initializes a new instance of the <see cref="Resource"/> class. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The path of the resource.</param> public Resource(Service service, string path) { this.Path = service.Fullpath(path); this.PartialPath = path; this.Service = service; this.RefreshArgs = new Args("count", "-1"); this.MaybeValid = false; }
/// <summary> /// Creates a collection member. /// </summary> /// <param name="itemClass">The object type being created.</param> /// <param name="path">The path to the resource.</param> /// <param name="splunkNamespace">The namespace.</param> /// <returns>The new object.</returns> public T CreateItem(Type itemClass, string path, Args splunkNamespace) { ConstructorInfo ctor = itemClass.GetConstructor(itemSig); T item = (T)ctor.Invoke(new object[] { Service, Service.Fullpath(path, splunkNamespace) }); return(item); }
/// <summary> /// Initializes a new instance of the <see cref="Resource"/> class, /// adding optional arguments for namespace and other endpoint /// arguments. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The path of this resource.</param> /// <param name="args">The variable arguments.</param> public Resource(Service service, string path, Args args) { this.Service = service; /* Pull out namespace items (app, owner, sharing) from the args, and * then use to create the full path. */ Args clonedArgs = new Args(args); Args splunkNamespace = new Args(); if (args.ContainsKey("app")) { splunkNamespace.Set("app", args["app"].ToString()); clonedArgs.Remove("app"); } if (args.ContainsKey("owner")) { splunkNamespace.Set("owner", args["owner"].ToString()); clonedArgs.Remove("owner"); } if (args.ContainsKey("sharing")) { splunkNamespace.Set( "sharing", args["sharing"].ToString()); clonedArgs.Remove("sharing"); } if (!clonedArgs.ContainsKey("count")) { clonedArgs.Set("count", "-1"); } this.RefreshArgs = clonedArgs; this.Path = service.Fullpath( path, splunkNamespace.Count == 0 ? null : splunkNamespace); this.MaybeValid = false; }