当前位置: 首页>>代码示例>>C#>>正文


C# Service.SearchOneshotAsync方法代码示例

本文整理汇总了C#中Service.SearchOneshotAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Service.SearchOneshotAsync方法的具体用法?C# Service.SearchOneshotAsync怎么用?C# Service.SearchOneshotAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Service的用法示例。


在下文中一共展示了Service.SearchOneshotAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OneshotSearch

        /// <summary>
        /// Called when [search].
        /// </summary>
        /// <param name="service">The service.</param>
        /// <returns></returns>
        static async Task OneshotSearch(Service service)
        {
            //// Login
            await service.LoginAsync("admin", "changeme");

            // Simple oneshot search
            using (SearchResults searchResults = await service.SearchOneshotAsync("search index=_internal | head 5"))
            {
                foreach (Result record in searchResults)
                {
                    Console.WriteLine(record);
                }
            }

            //Use JobArgs to define the search
            JobArgs args = new JobArgs("search index=_internal | head 5")
            {
                AutoCancel = 0,
            };

            using (SearchResults searchResults = await service.SearchOneshotAsync(args))
            {
                foreach (Result record in searchResults)
                {
                    Console.WriteLine(record);
                }
            }

            await service.LogoffAsync();
        }
开发者ID:paulcbetts,项目名称:splunk-sdk-csharp-pcl,代码行数:35,代码来源:Program.cs

示例2: Run

        static async Task Run(Service service)
        {
            //// Login

            await service.LoginAsync("admin", "changeme");

            //// Search : Pull model (foreach loop => IEnumerable)

            Job job = await service.CreateJobAsync("search index=_internal | head 10");
            SearchResults searchResults;

            using (searchResults = await job.GetSearchResultsAsync())
            {
                int recordNumber = 0;
                try
                {
                    foreach (var record in searchResults)
                    {
                        Console.WriteLine(string.Format("{0:D8}: {1}", ++recordNumber, record));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("SearchResults error: {0}", e.Message));
                }
            }

            //// Search : Push model (by way of subscription to search result records => IObservable)

            job = await service.CreateJobAsync("search index=_internal | head 10");

            using (searchResults = await job.GetSearchResultsAsync())
            {
                var manualResetEvent = new ManualResetEvent(true);
                int recordNumber = 0;

                searchResults.SubscribeOn(ThreadPoolScheduler.Instance).Subscribe(
                    onNext: (record) =>
                    {
                        Console.WriteLine(string.Format("{0:D8}: {1}", ++recordNumber, record));
                    },
                    onError: (e) =>
                    {
                        Console.WriteLine(string.Format("SearchResults error: {0}", e.Message));
                        manualResetEvent.Set();
                    },
                    onCompleted: () =>
                    {
                        manualResetEvent.Set();
                    });

                manualResetEvent.Reset();
                manualResetEvent.WaitOne();
            }

            //// Search : Export

            SearchResultsReader searchResultsReader;

            using (searchResultsReader = service.SearchExportAsync("search index=_internal | head 100").Result)
            {
                int recordNumber = 0;
                int setNumber = 0;

                foreach (var searchResultSet in searchResultsReader)
                {
                    Console.WriteLine(string.Format("Result set {0}", ++setNumber));

                    foreach (var record in searchResultSet)
                    {
                        Console.WriteLine(string.Format("{0:D8}: {1}", ++recordNumber, record));
                    }
                }
            }

            //// Search : Oneshot

            using (searchResults = await service.SearchOneshotAsync("search index=_internal | head 10"))
            {
                foreach (var record in searchResults)
                {
                    Console.WriteLine(record);
                }
            }

            //// Search : Results preview

            job = await service.CreateJobAsync("search index=_internal | head 10000");
            do
            {
                using (searchResults = await job.GetSearchResultsPreviewAsync(new SearchResultsArgs() { Count = 0 }))
                {
                    int recordNumber = 0;

                    foreach (var record in searchResults)
                    {
                        Console.WriteLine(string.Format("{0:D8}: {1}", ++recordNumber, record));
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:paulcbetts,项目名称:splunk-sdk-csharp-pcl,代码行数:101,代码来源:Program.cs


注:本文中的Service.SearchOneshotAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。