/// <summary> /// Method returns a task that returns a list of suggestion objects /// that are associated to the <paramref name="input"/> string /// and given <paramref name="data"/> object. /// /// The list of suggestion is empty if helper object is null. /// /// This method is usually directly invoked by the SuggestBox to query data /// sources for suggestions as the user types a string character by character. /// </summary> /// <param name="location">Represents the root of the hierarchy that is browsed here.</param> /// <param name="input">Is the input string typed by the user.</param> /// <returns></returns> public Task <SuggestQueryResultModel> SuggestAsync(LocationIndicator location, string input) { SuggestQueryResultModel retVal = new SuggestQueryResultModel(); if (location == null) { return(Task.FromResult <SuggestQueryResultModel>(retVal)); } IHierarchyHelper hhelper = location.HierarchyHelper; if (hhelper == null) { return(Task.FromResult <SuggestQueryResultModel>(retVal)); } // Get the path from input string: 'c:\Windows' -> path: 'c:\' string valuePath = hhelper.ExtractPath(input); // Get the name from input string: 'c:\Windows' -> path: 'Windows' string valueName = hhelper.ExtractName(input); // Ensure that name ends with seperator if input ended with a seperator if (String.IsNullOrEmpty(valueName) && input.EndsWith(hhelper.Separator + "")) { valueName += hhelper.Separator; } // Ensure valid path if input ends with seperator and path was currently empty if (valuePath == "" && input.EndsWith("" + hhelper.Separator)) { valuePath = valueName; } var found = hhelper.GetItem(location.RootItem, valuePath); if (found != null) { foreach (var item in hhelper.List(found)) { string valuePathName = hhelper.GetPath(item) as string; if (valuePathName.StartsWith(input, hhelper.StringComparisonOption) && !valuePathName.Equals(input, hhelper.StringComparisonOption)) { retVal.ResultList.Add(item); } } } return(Task.FromResult <SuggestQueryResultModel>(retVal)); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { try { if (!(value is string)) { return(new ValidationResult(false, "Invalid Path")); } if (_hierarchyHelper.GetItem(_root, (string)value) == null) { return(new ValidationResult(false, "Path Not Found")); } } catch (Exception) { return(new ValidationResult(false, "Invalid Path")); } return(new ValidationResult(true, null)); }
public Task <IList <object> > SuggestAsync(object data, string input, IHierarchyHelper helper) { if (helper == null) { return(Task.FromResult <IList <object> >(new List <Object>())); } string valuePath = helper.ExtractPath(input); string valueName = helper.ExtractName(input); if (String.IsNullOrEmpty(valueName) && input.EndsWith(helper.Separator + "")) { valueName += helper.Separator; } if (valuePath == "" && input.EndsWith("" + helper.Separator)) { valuePath = valueName; } var found = helper.GetItem(data, valuePath); List <object> retVal = new List <object>(); if (found != null) { foreach (var item in helper.List(found)) { string valuePathName = helper.GetPath(item) as string; if (valuePathName.StartsWith(input, helper.StringComparisonOption) && !valuePathName.Equals(input, helper.StringComparisonOption)) { retVal.Add(item); } } } return(Task.FromResult <IList <object> >(retVal)); }