protected IEnumerable <IBaseModel> LoadModel(params IListParameter[] parameters) { _cancellationTokenSource = new CancellationTokenSource(); //var ret = TaskEx.Run(() => AutoCompleteDataManager.Get<IBaseModel>(parameters), _cancellationTokenSource.Token); if (AutoCompleteDataManager == null) { return(null); } var ret = AutoCompleteDataManager.Get <IBaseModel>(parameters); _cancellationTokenSource = null; return(ret); }
private void AutoComplete() { // ReSharper disable once TooWideLocalVariableScope int count; if (!ClearOnLeave) { return; } if (Text.Length < OriginalTextStartPosition) { OriginalTextStartPosition = 0; } var strlen = Text.Length - OriginalTextStartPosition - SelectionLength; if (strlen > Text.Length - OriginalTextStartPosition || strlen < 0) { strlen = Text.Length - OriginalTextStartPosition; } var searchTerm = Text.Substring(OriginalTextStartPosition, strlen); if (!searchTerm.IsEmpty() && !Array.Exists(AutoCompleteCachedSource, s => s.Contains(searchTerm)) && searchTerm.Length > AutocompleteMinimumTextLength) { IQueryable <IBaseModel> result = null; if (AutoCompleteWheretermFormater != null) { result = AutoCompleteDataManager .Get <IBaseModel>(Paging.Instance(0, 1), out count, AutoCompleteWheretermFormater(searchTerm)) .AsQueryable(); } else if (AutoCompleteWhereExpression != null) { if (!(AutoCompleteDataManager is IExtendedQueryableDataManager)) { throw new Exception(string.Format("Autocomplete field {0} is using AutoCompleteWhereExpression property, but the AutoCompleteDataManager property does not implement IExtendedQueryableDataManager.", Name)); } var param = new AutoCompleteWhereExpressionParam(); AutoCompleteWhereExpression(searchTerm, param); result = ((IExtendedQueryableDataManager)AutoCompleteDataManager) .Get <IBaseModel>(Paging.Instance(0, 1), out count, param.Expression, param.Parameters) .AsQueryable(); } if (result != null && result.Any()) { Value = (int)result.Select(model => model.Id).ToArray().GetValue(0); DisplayString = result.Select(AutoCompleteDisplayFormater).ToArray().GetValue(0).ToString(); ByAuto = true; var strtemp = searchTerm; if (AutoCompleteText != null) { Text = result.Select(AutoCompleteText).ToArray().GetValue(0).ToString(); } else { Text = DisplayString; } OriginalTextStartPosition = Text.ToLower().IndexOf(strtemp.ToLower(), StringComparison.Ordinal); var startSel = OriginalTextStartPosition + strtemp.Length; SelectionStart = startSel; SelectionLength = Text.Length - startSel; OriginalTextStartPosition = OriginalTextStartPosition < 0 ? 0 : OriginalTextStartPosition; DisplayString = Text; } else { Value = null; DisplayString = string.Empty; } } if (Text.IsEmpty()) { Value = null; DisplayString = string.Empty; } }