/// <inheritdoc/>
        public virtual async Task <SavedSearch> CreateAsync(string name, string search,
                                                            SavedSearchAttributes attributes     = null,
                                                            SavedSearchDispatchArgs dispatchArgs = null,
                                                            SavedSearchTemplateArgs templateArgs = null)
        {
            var args = new Argument[]
            {
                new Argument("name", name),
                new Argument("search", search)
            }
            .AsEnumerable();

            if (attributes != null)
            {
                args = args.Concat(attributes);
            }

            if (dispatchArgs != null)
            {
                args = args.Concat(dispatchArgs);
            }

            if (templateArgs != null)
            {
                args = args.Concat(templateArgs);
            }

            var savedSearch = await this.CreateAsync(args).ConfigureAwait(false);

            return(savedSearch);
        }
 /// <summary>
 /// Asyncrhonously creates a new <see cref="SavedSearch"/>.
 /// </summary>
 /// <param name="name">
 /// Name of the <see cref="SavedSearch"/>.
 /// </param>
 /// <param name="search">
 /// The Splunk search command to save.
 /// </param>
 /// <param name="attributes">
 /// Optional attributes of the <see cref="SavedSearch"/>.
 /// </param>
 /// <param name="dispatchArgs">
 /// Optional dispatch arguments for the <see cref="SavedSearch"/>.
 /// </param>
 /// <param name="templateArgs">
 /// Optional template arguments for the <see cref="SavedSearch"/>.
 /// </param>
 /// <returns>
 /// The <see cref="SavedSearch"/> created.
 /// </returns>
 public Task <TSavedSearch> CreateAsync(string name, string search, SavedSearchAttributes attributes,
                                        SavedSearchDispatchArgs dispatchArgs, SavedSearchTemplateArgs templateArgs)
 {
     Contract.Requires <ArgumentNullException>(search != null);
     Contract.Requires <ArgumentNullException>(name != null);
     return(default(Task <TSavedSearch>));
 }
        /// <inheritdoc/>
        public virtual async Task <Job> DispatchSavedSearchAsync(string name,
                                                                 SavedSearchDispatchArgs dispatchArgs = null,
                                                                 SavedSearchTemplateArgs templateArgs = null)
        {
            var savedSearch = new SavedSearch(this.Context, this.Namespace, name);
            var job         = await savedSearch.DispatchAsync(dispatchArgs, templateArgs).ConfigureAwait(false);

            return(job);
        }
        /// <summary>
        /// Asynchronously creates a new saved search.
        /// </summary>
        /// <param name="searchName">
        /// Name of the saved search to be created.
        /// </param>
        /// <param name="attributes">
        /// Attributes of the saved search to be created.
        /// </param>
        /// <param name="dispatchArgs">
        /// Dispatch arguments for the saved search to be created.
        /// </param>
        /// <param name="templateArgs">
        /// Template arguments for the saved search to be created.
        /// </param>
        /// This method uses the <a href="http://goo.gl/EPQypw">POST
        /// saved/searches</a> endpoint to create the <see cref="SavedSearch"/>
        /// represented by the current instance.
        /// </remarks>
        public async Task CreateAsync(SavedSearchAttributes attributes, SavedSearchDispatchArgs dispatchArgs = null,
                                      SavedSearchTemplateArgs templateArgs = null)
        {
            var args = new Argument[] { new Argument("name", this.ResourceName.Title) };

            using (var response = await this.Context.PostAsync(this.Namespace, SavedSearchCollection.ClassResourceName,
                                                               args, attributes, dispatchArgs, templateArgs))
            {
                await response.EnsureStatusCodeAsync(HttpStatusCode.Created);

                await this.UpdateSnapshotAsync(response);
            }
        }
        /// <summary>
        /// Dispatches the current <see cref="SavedSearch"/> just like the
        /// scheduler would.
        /// </summary>
        /// <param name="dispatchArgs">
        /// A set of arguments to the dispatcher.
        /// </param>
        /// <param name="templateArgs">
        /// A set of template arguments to the saved search.
        /// </param>
        /// <returns>
        /// An object representing the search job created by the dispatcher.
        /// </returns>
        /// <remarks>
        /// This method uses the <a href="http://goo.gl/AfzBJO">POST
        /// saved/searches/{name}/dispatch</a> endpoint to dispatch the
        /// current <see cref="SavedSearch"/>. It then uses the <a href=
        /// "http://goo.gl/C9qc98">GET search/jobs/{search_id}</a> endpoint to
        /// retrieve the <see cref="Job"/> object that it returns.
        /// </remarks>
        public async Task <Job> DispatchAsync(SavedSearchDispatchArgs dispatchArgs = null, SavedSearchTemplateArgs
                                              templateArgs = null)
        {
            var    resourceName = new ResourceName(this.ResourceName, "dispatch");
            string searchId;

            using (var response = await this.Context.PostAsync(this.Namespace, resourceName, dispatchArgs, templateArgs))
            {
                await response.EnsureStatusCodeAsync(HttpStatusCode.Created);

                searchId = await response.XmlReader.ReadResponseElementAsync("sid");
            }

            Job job = new Job(this.Context, this.Namespace, searchId);
            await job.GetAsync();

            return(job);
        }
 public abstract Task <Job> DispatchSavedSearchAsync(string name, SavedSearchDispatchArgs dispatchArgs = null, SavedSearchTemplateArgs templateArgs = null);
 public Task <bool> UpdateAsync(string search = null, SavedSearchAttributes attributes = null,
                                SavedSearchDispatchArgs dispatchArgs = null, SavedSearchTemplateArgs templateArgs = null)
 {
     Contract.Requires <ArgumentException>(!(search == null && attributes == null && dispatchArgs == null && templateArgs == null));
     return(default(Task <bool>));
 }
        /// <summary>
        /// Asynchronously updates the saved search represented by the current
        /// instance.
        /// </summary>
        /// <param name="attributes">
        /// New attributes for the saved search to be updated.
        /// </param>
        /// <param name="dispatchArgs">
        /// New dispatch arguments for the saved search to be updated.
        /// </param>
        /// <param name="templateArgs">
        /// New template arguments for the saved search to be updated.
        /// </param>
        /// <exception cref="ArgumentException">
        /// <see cref="attributes"/>, <see cref="dispatchArgs"/>, and <see
        /// cref="templateArgs"/> are <c>null</c>.
        /// </exception>
        /// <remarks>
        /// This method uses the <a href="http://goo.gl/aV9eiZ">POST
        /// saved/searches{name}</a> endpoint to update the saved search
        /// represented by the current instance.
        /// </remarks>
        public async Task UpdateAsync(SavedSearchAttributes attributes           = null, SavedSearchDispatchArgs dispatchArgs =
                                      null, SavedSearchTemplateArgs templateArgs = null)
        {
            Contract.Requires <ArgumentException>(!(attributes == null && dispatchArgs == null && templateArgs == null));

            using (var response = await this.Context.PostAsync(this.Namespace, this.ResourceName, attributes,
                                                               dispatchArgs, templateArgs))
            {
                await response.EnsureStatusCodeAsync(HttpStatusCode.OK);

                await this.UpdateSnapshotAsync(response);
            }
        }