Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        public async Task <IList <object> > SuggestAsync(object data, string input, IHierarchyHelper helper)
        {
            if (helper == null)
            {
                return(ImmutableList <object> .Empty);
            }

            var valuePath = helper.ExtractPath(input);
            var 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 = await helper.GetItemAsync(data, valuePath);

            if (found == null)
            {
                return(ImmutableList <object> .Empty);
            }

            var result = new List <object>();
            var enuma  = await helper.ListAsync(found);

            foreach (var item in enuma)
            {
                string valuePathName = helper.GetPath(item);
                if (valuePathName.StartsWith(input, helper.StringComparisonOption) &&
                    !valuePathName.Equals(input, helper.StringComparisonOption))
                {
                    result.Add(item);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        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));
        }