示例#1
0
        /// <summary>
        /// The index is a collection of the words used for the autocomplete text search, and their associated Ids
        /// </summary>
        /// <param name="datatypeDefinitionId"></param>
        /// <returns></returns>
        private static List <KeyValuePair <string, int> > GetIndex(int datatypeDefinitionId)
        {
            // a sorted list is used for populated, so that it's quick to find duplicates when adding items, and this can be converted to a List for returning (so that a binary search can be used)
            SortedList <string, int> index = new SortedList <string, int>();

            // get the options so we know how to retrieve the data
            XPathAutoCompleteOptions options = XPathAutoCompleteBase.GetOptions(datatypeDefinitionId);

            switch (options.UmbracoObjectType)
            {
            case uQuery.UmbracoObjectType.Document:

                foreach (KeyValuePair <string, int> keyValuePair in uQuery.GetNodesByXPath(options.XPath).Select(x => new KeyValuePair <string, int>(x.Name, x.Id)))
                {
                    XPathAutoCompleteBase.AddToSortedList(ref index, keyValuePair);
                }

                break;

            case uQuery.UmbracoObjectType.Media:

                foreach (KeyValuePair <string, int> keyValuePair in uQuery.GetMediaByXPath(options.XPath).Select(x => new KeyValuePair <string, int>(x.Text, x.Id)))
                {
                    XPathAutoCompleteBase.AddToSortedList(ref index, keyValuePair);
                }

                break;

            case uQuery.UmbracoObjectType.Member:

                foreach (KeyValuePair <string, int> keyValuePair in uQuery.GetMembersByXPath(options.XPath).Select(x => new KeyValuePair <string, int>(x.Text, x.Id)))
                {
                    XPathAutoCompleteBase.AddToSortedList(ref index, keyValuePair);
                }

                break;
            }

            // convert the SortedList into a regular list, and store that (regular list so that we can do a binary search on it)

            return(index.ToList());
        }
 /// <summary>
 /// Initializes a new instance of XPathAutoCompleteDataEditor
 /// </summary>
 /// <param name="data"></param>
 /// <param name="options"></param>
 internal XPathAutoCompleteDataEditor(IData data, XPathAutoCompleteOptions options)
 {
     this.data    = data;
     this.options = options;
 }
 /// <summary>
 /// Initializes a new instance of XPathAutoCompleteDataEditor
 /// </summary>
 /// <param name="data"></param>
 /// <param name="options"></param>
 internal XPathAutoCompleteDataEditor(IData data, XPathAutoCompleteOptions options)
 {
     this.data = data;
     this.options = options;
 }