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


C# Service.SearchExportAsync方法代码示例

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


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

示例1: 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

示例2: Other

        static async void Other()
        {
            SearchResults searchResults;
            Job job;

            //// Login

            var service = new Service(Scheme.Https, "localhost", 8089, new Namespace(user: "nobody", app: "search"));
            await service.LoginAsync("admin", "changeme");

            Console.WriteLine("Blocking search");
            job = await service.CreateJobAsync("search index=_internal | head 10", ExecutionMode.Blocking);

            using (searchResults = await job.GetSearchResultsAsync())
            {
                foreach (var record in searchResults)
                {
                    Console.WriteLine(record);
                }
            }

            using (var searchResultsReader = await service.SearchExportAsync("search index=_internal | head 100000"))
            {
                Console.WriteLine("Begin: Service.SearchExportAsync: Asyncrhonous use case");
                int recordNumber = 0;
                int setNumber = 0;

                foreach (var resultSet in searchResultsReader)
                {
                    Console.WriteLine(string.Format("Result set {0}", ++setNumber));
                    var manualResetEvent = new ManualResetEvent(true);

                    resultSet.SubscribeOn(ThreadPoolScheduler.Instance).Subscribe(
                        onNext: (record) =>
                        {
                            Console.WriteLine(string.Format("{0:D8}: {1}", ++recordNumber, record));
                        },
                        onError: (exception) =>
                        {
                            Console.WriteLine(string.Format("SearchResults error: {0}", exception.Message));
                            manualResetEvent.Set();
                        },
                        onCompleted: () =>
                        {
                            Console.WriteLine("Service.SearchExportAsync: Asyncrhonous use case");
                            manualResetEvent.Set();
                        });

                    manualResetEvent.Reset(); 
                    manualResetEvent.WaitOne();
                }
            }
        }
开发者ID:paulcbetts,项目名称:splunk-sdk-csharp-pcl,代码行数:53,代码来源:Program.cs


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