本文整理汇总了C#中Service.CreateJobAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Service.CreateJobAsync方法的具体用法?C# Service.CreateJobAsync怎么用?C# Service.CreateJobAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Service
的用法示例。
在下文中一共展示了Service.CreateJobAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
}
}
//.........这里部分代码省略.........
示例2: SearchRealTime
/// <summary>
/// Do real time seach
/// </summary>
/// <param name="service">The service.</param>
/// <returns></returns>
static async Task SearchRealTime(Service service)
{
await service.LoginAsync("admin", "changeme");
// Realtime window is 5 minutes
var jobArgs = new JobArgs("search index=_internal")
{
SearchMode = SearchMode.Realtime,
EarliestTime = "rt-5m",
LatestTime = "rt",
};
Job job = await service.CreateJobAsync(jobArgs);
//this sleep should be removed if DVPL-4503 is fixed.
//Thread.Sleep(5000);
for (var i = 0; i < 5; i++)
{
System.Console.WriteLine("============================= Snapshot {0}=================================", i);
using (SearchResults searchResults = await job.GetSearchResultsPreviewAsync())
{
System.Diagnostics.Debug.Assert(!searchResults.AreFinal);
System.Console.WriteLine("searchResults count:{0}", searchResults.Count());
}
Thread.Sleep(1000);
}
await job.CancelAsync();
await service.LogoffAsync();
}
示例3: 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();
}
}
}