private async Task SearchAsync(string queryText)
{
// flag...
this.SearchDone = true;
// set...
this.QueryText = queryText;
// set the narrative...
if (string.IsNullOrEmpty(queryText))
{
this.QueryNarrative = string.Empty;
}
else
{
this.QueryNarrative = string.Format("Results for '{0}'", queryText);
}
// load...
var reports = await ReportItem.SearchCacheAsync(queryText);
this.MasterItems.Clear();
foreach (var report in reports)
{
this.MasterItems.Add(new ReportViewItem(report));
}
// what was our selected filter?
var current = this.ActiveFilter;
if (current != null)
{
var builder = new ToastNotificationBuilder(current.Description);
builder.Update();
}
// do we have anything?
this.Filters.Clear();
if (this.MasterItems.Any())
{
// all filter...
var allFilter = new SearchFilter("all", this.MasterItems.Count, null, false);
allFilter.SelectionCommand = new DelegateCommand(async(args) => await HandleFilterActivatedAsync(allFilter));
this.Filters.Add(allFilter);
// build up a list of nouns...
var nouns = new Dictionary <string, int>();
var regex = new Regex(@"\b\w+$", RegexOptions.Singleline | RegexOptions.IgnoreCase);
foreach (var report in reports)
{
var match = regex.Match(report.Title);
// word...
string noun = match.Value.ToLower();
if (!(nouns.ContainsKey(noun)))
{
nouns[noun] = 0;
}
nouns[noun]++;
}
// add the filters...
foreach (var noun in nouns.Keys)
{
var filter = new SearchFilter(noun, nouns[noun], noun);
filter.SelectionCommand = new DelegateCommand(async(args) => await HandleFilterActivatedAsync(filter));
this.Filters.Add(filter);
}
// update...
var manager = new ReportImageCacheManager();
foreach (var report in this.MasterItems)
{
await report.InitializeAsync(manager);
}
}
// do we need to select the filter?
var lastQuery = await SettingItem.GetValueAsync(LastQueryKey);
if (lastQuery == queryText)
{
// select the filter...
var lastFilterName = await SettingItem.GetValueAsync(LastFilterKey);
if (!(string.IsNullOrEmpty(lastFilterName)))
{
ActivateFilter(lastFilterName);
}
}
else
{
// update...
await SettingItem.SetValueAsync(LastQueryKey, queryText);
}
// apply the filter...
this.ApplyFilter();
}