Esempio n. 1
0
        public IList <IntellisenseProviderResult> GetIntellisenseResults(IntellisenseProviderContext context)
        {
            if (context == null)
            {
                return(new List <IntellisenseProviderResult>());
            }

            if (IsDisposed)
            {
                throw new ObjectDisposedException("DefaultIntellisenseProvider");
            }

            if (!Equals(TextBox, context.TextBox))
            {
                TextBox = context.TextBox as IntellisenseTextBox;
            }
            IList <IIntellisenseResult> results;
            var input         = context.InputText ?? string.Empty;
            var caretPosition = context.CaretPosition;

            if (caretPosition > input.Length || caretPosition < 0)
            {
                return(new List <IntellisenseProviderResult>());
            }

            enIntellisensePartType       filterType       = context.FilterType;
            enIntellisensePartType       altfilterType    = context.FilterType;
            IntellisenseDesiredResultSet desiredResultSet = context.DesiredResultSet;

            string searchText     = context.FindTextToSearch();
            string recordsetIndex = string.Empty;
            string recordserName  = string.Empty;
            var    region         = input.RegionInPostion(caretPosition);
            var    regionName     = region.Name;

            if (DataListUtil.IsValueRecordset(regionName))
            {
                recordsetIndex = DataListUtil.ExtractIndexRegionFromRecordset(regionName);
                recordserName  = DataListUtil.ExtractRecordsetNameFromValue(regionName);
                if (!string.IsNullOrEmpty(recordsetIndex) && DataListUtil.IsValueRecordsetWithFields(searchText))
                {
                    altfilterType = enIntellisensePartType.RecordsetFields;
                }
            }

            if (input.Equals(DataListUtil.OpeningSquareBrackets))
            {
                searchText = context.InputText;
            }
            else
            {
                searchText = searchText.StartsWith(DataListUtil.OpeningSquareBrackets) || string.IsNullOrEmpty(searchText) ? searchText : DataListUtil.OpeningSquareBrackets + searchText;
            }

            switch (desiredResultSet)
            {
            case IntellisenseDesiredResultSet.EntireSet: results = GetIntellisenseResultsImpl(DataListUtil.OpeningSquareBrackets, filterType); break;

            default:
            {
                results = GetIntellisenseResultsImpl(searchText, filterType);
                if (results == null || results.Count == 0 && HandlesResultInsertion)
                {
                    results = new List <IIntellisenseResult>();
                    string inputText       = input;
                    var    regionInPostion = inputText.RegionInPostion(caretPosition);

                    inputText = !string.IsNullOrEmpty(regionInPostion.Name) ? regionInPostion.Name : inputText;

                    var getErrors = GetIntellisenseResultsImpl(inputText, filterType)
                                    .Where(i => i.ErrorCode != enIntellisenseErrorCode.None)
                                    .ToList();

                    getErrors.ForEach(results.Add);
                }
                break;
            }
            }

            if (altfilterType == enIntellisensePartType.RecordsetFields)
            {
                var filteredRecordsetFields = results.Where(r => r.Option.Recordset.Equals(recordserName) || r.Option.IsScalar);

                if (!string.IsNullOrEmpty(recordsetIndex))
                {
                    results = filteredRecordsetFields.ToList().Where(r => !r.Option.HasRecordsetIndex || r.Option.IsScalar).ToList();
                }
            }

            IList <IntellisenseProviderResult> trueResults = new List <IntellisenseProviderResult>();

            string[] openParts  = Regex.Split(input, @"\[\[");
            string[] closeParts = Regex.Split(input, @"\]\]");
            if (openParts.Length != closeParts.Length)
            {
                if (results != null)
                {
                    results.Add(IntellisenseFactory.CreateCalculateIntellisenseResult(2, 2, "Invalid Expression", "", StringResources.IntellisenseErrorMisMacthingBrackets));
                }
            }

            if (results != null)
            {
                foreach (IIntellisenseResult currentResult in results)
                {
                    if (currentResult.ErrorCode != enIntellisenseErrorCode.None)
                    {
                        if (currentResult.Type == enIntellisenseResultType.Error && currentResult.IsClosedRegion)
                        {
                            var displayValue = currentResult.Option == null ? string.Empty : currentResult.Option.DisplayValue;
                            trueResults.Add(new IntellisenseProviderResult(this, displayValue, currentResult.Message, currentResult.Message, true));
                        }
                    }


                    if (currentResult.Type == enIntellisenseResultType.Selectable)
                    {
                        var displayValue = currentResult.Option == null ? string.Empty : currentResult.Option.DisplayValue;
                        var description  = currentResult.Option == null ? string.Empty : currentResult.Option.Description;
                        trueResults.Add(new IntellisenseProviderResult(this, displayValue, description, description, false));
                    }
                }
            }

            return(trueResults);
        }