Esempio n. 1
0
        string ProcessValidPartNameContainingFields(IParseTO payload, bool addCompleteParts, IList <IIntellisenseResult> result, string[] parts, string search, bool emptyOk, string partName, IDev2DataLanguageIntellisensePart recordsetPart, string display)
        {
            if (partName.IndexOf(DataListUtil.RecordsetIndexOpeningBracket, StringComparison.Ordinal) >= 0)
            {
                partName = partName.Substring(0, partName.IndexOf(DataListUtil.RecordsetIndexOpeningBracket, StringComparison.Ordinal));
            }

            if (recordsetPart == null)
            {
                var part = IntellisenseFactory.CreateDataListValidationRecordsetPart(partName, parts[1], "");
                result.Add(IntellisenseFactory.CreateErrorResult(payload.StartIndex, parts[0].Length - 1, part, DataListUtil.OpeningSquareBrackets + display + "]] does not exist in your variable list", enIntellisenseErrorCode.NeitherRecordsetNorFieldFound, !payload.HangingOpen));
            }
            else
            {
                if (recordsetPart.Children != null && recordsetPart.Children.Count > 0 && ProcessFieldsForRecordSet(payload, addCompleteParts, result, parts, out search, out emptyOk, display, recordsetPart, partName))
                {
                    return(search);
                }
            }

            if (result.Count == 0 && !emptyOk)
            {
                var part = IntellisenseFactory.CreateDataListValidationRecordsetPart(parts[0], search);
                result.Add(char.IsNumber(search[0]) ? IntellisenseFactory.CreateErrorResult(payload.StartIndex, parts[0].Length - 1, part, "Invalid Expression: Recordset Field [ " + search + " ] starts with a number", enIntellisenseErrorCode.SyntaxError, !payload.HangingOpen) : IntellisenseFactory.CreateErrorResult(parts[0].Length, payload.EndIndex, part, "Recordset Field [ " + search + " ] does not exist for [ " + parts[0] + " ]", enIntellisenseErrorCode.FieldNotFound, !payload.HangingOpen));
            }
            return(search);
        }
Esempio n. 2
0
        static void FinalEvaluation(IParseTO payload, StringBuilder tmp, IList <IIntellisenseResult> result, IList <IDev2DataLanguageIntellisensePart> additionalParts, bool isRs)
        {
            var display = tmp.ToString().Replace("]", "");
            IDataListVerifyPart part;

            var code = enIntellisenseErrorCode.RecordsetNotFound;

            if (!isRs)
            {
                code = display.IndexOf(' ') >= 0 ? enIntellisenseErrorCode.SyntaxError : enIntellisenseErrorCode.ScalarNotFound;

                part = IntellisenseFactory.CreateDataListValidationScalarPart(display);
            }
            else
            {
                var start = display.IndexOf(DataListUtil.RecordsetIndexOpeningBracket, StringComparison.Ordinal);
                display  = display.Substring(0, start);
                display += "()";
                part     = IntellisenseFactory.CreateDataListValidationRecordsetPart(display, "");
            }
            if (additionalParts == null)
            {
                result.Add(!display.Contains(' ') ? IntellisenseFactory.CreateErrorResult(payload.StartIndex, payload.EndIndex, part, " [[" + display + "]] does not exist in your variable list", code, !payload.HangingOpen) : IntellisenseFactory.CreateErrorResult(payload.StartIndex, payload.EndIndex, part, " [[" + display + "]] contains a space, this is an invalid character for a variable name", code, !payload.HangingOpen));
            }
            else
            {
                if (!additionalParts.Select(a => a.Name).Contains(display))
                {
                    result.Add(!display.Contains(' ') ? IntellisenseFactory.CreateErrorResult(payload.StartIndex, payload.EndIndex, part, " [[" + display + "]] does not exist in your variable list", code, !payload.HangingOpen) : IntellisenseFactory.CreateErrorResult(payload.StartIndex, payload.EndIndex, part, " [[" + display + "]] contains a space, this is an invalid character for a variable name", code, !payload.HangingOpen));
                }
            }
        }
Esempio n. 3
0
        void ProcessRegion(IParseTO payload, IList <IDev2DataLanguageIntellisensePart> refParts, bool addCompleteParts, StringBuilder tmp, IList <IIntellisenseResult> result, IList <IDev2DataLanguageIntellisensePart> additionalParts = null)
        {
            const bool EmptyOk = false;

            if (payload != null)
            {
                var tmpString = tmp.ToString();
                var parts     = tmpString.Split('.');
                var search    = parts[0].ToLower();
                var rawSearch = search;
                var isRs      = false;

                search = RemoveRecordSetBraces(search, ref isRs);
                if (AddFieldResult(payload, result, tmpString, parts, isRs))
                {
                    return;
                }

                if (parts.Length == 1)
                {
                    MatchNonFieldVariables(payload, refParts, addCompleteParts, tmp, result, additionalParts, isRs, rawSearch, search, EmptyOk, parts);
                }
                else if (parts.Length == 2)
                {
                    MatchFieldVariables(payload, refParts, addCompleteParts, result, parts, isRs, rawSearch, search, EmptyOk);
                }
                else
                {
                    var part = IntellisenseFactory.CreateDataListValidationRecordsetPart(parts[0], parts[1]);
                    result.Add(IntellisenseFactory.CreateErrorResult(payload.StartIndex, payload.EndIndex, part, "Invalid Notation - Extra dots detected", enIntellisenseErrorCode.SyntaxError, !payload.HangingOpen));
                }
            }
        }
Esempio n. 4
0
        IList <IIntellisenseResult> ExtractIntellisenseOptions(IParseTO payload, IList <IDev2DataLanguageIntellisensePart> refParts, bool addCompleteParts, IList <IDev2DataLanguageIntellisensePart> additionalParts = null)
        {
            var tmp = new StringBuilder(payload.Payload);
            IList <IIntellisenseResult> result = new List <IIntellisenseResult>();

            if (payload.Payload == string.Empty && payload.HangingOpen)
            {
                ProcessForOnlyOpenRegion(payload, refParts, result);
            }
            else
            {
                if (tmp.Length > 0)
                {
                    ProcessRegion(payload, refParts, addCompleteParts, tmp, result, additionalParts);
                }
                else
                {
                    if (payload.Child == null)
                    {
                        result.Add(IntellisenseFactory.CreateErrorResult(0, 4, null, ErrorResource.VariableIsMissing, enIntellisenseErrorCode.SyntaxError, true));
                        return(result);
                    }
                }
            }

            IList <IIntellisenseResult> realResults = new List <IIntellisenseResult>();

            result.ToList().ForEach(r => ProcessResults(realResults, r));
            return(result);
        }
Esempio n. 5
0
        public void ParseExpressionIntoParts_GivenExpressionInCache_ShouldReturnFromCache()
        {
            //---------------Set up test pack-------------------
            var parser = new Dev2DataLanguageParser();
            var concurrentDictionary = new ConcurrentDictionary <string, IList <IIntellisenseResult> >();
            var tryAdd = concurrentDictionary.TryAdd("[[a]]", new List <IIntellisenseResult> {
                IntellisenseFactory.CreateErrorResult(1, 2, null, "", enIntellisenseErrorCode.FieldNotFound, false)
            });

            Assert.IsTrue(tryAdd);
            var fieldInfo = typeof(Dev2DataLanguageParser).GetField("_expressionCache", BindingFlags.Static | BindingFlags.NonPublic);

            if (fieldInfo != null)
            {
                fieldInfo.SetValue(parser, concurrentDictionary);
            }
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var expressionIntoParts = parser.ParseExpressionIntoParts("[[a]]", new List <IDev2DataLanguageIntellisensePart>());

            //---------------Test Result -----------------------
            Assert.AreEqual(1, expressionIntoParts.Count);
            var error = expressionIntoParts.SingleOrDefault(result => !string.IsNullOrEmpty(result.Message));

            Assert.IsNull(error);
        }
Esempio n. 6
0
        private bool CreateDataList(string input = "", IList <IIntellisenseResult> results = null)
        {
            bool succeeded = false;

            StringBuilder result = new StringBuilder("<ADL>");
            ObservableCollection <IDataListItemModel> dataList = null;

            var activeDataList = DataListSingleton.ActiveDataList;

            if (activeDataList != null)
            {
                var activeDataListViewModels = activeDataList.DataList;

                if (activeDataList != null && activeDataListViewModels != null)
                {
                    dataList = activeDataListViewModels;
                }

                if (dataList != null)
                {
                    if (!HasCachedDatalist || IsUpdated)
                    {
                        HasCachedDatalist = true;
                        IsUpdated         = false;
                    }
                }

                result.Append("</ADL>");

                if (activeDataList.Resource != null && activeDataList.Resource.DataList != null)
                {
                    if (activeDataList.HasErrors)
                    {
                        if (activeDataListViewModels != null && results != null)
                        {
                            var error = activeDataListViewModels
                                        .FirstOrDefault(d => d.HasError && input.Contains(d.DisplayName.Replace("()", "")));

                            if (error != null)
                            {
                                results.Add(IntellisenseFactory.CreateErrorResult(1, 1, null, error.ErrorMessage, enIntellisenseErrorCode.SyntaxError, true));
                            }
                            else
                            {
                                CachedDataList = activeDataList.Resource.DataList;
                                succeeded      = true;
                            }
                        }
                    }
                    else
                    {
                        CachedDataList = activeDataList.Resource.DataList;
                        succeeded      = true;
                    }
                }
            }

            return(succeeded);
        }
Esempio n. 7
0
        void MatchFieldVariables(IParseTO payload, IList <IDev2DataLanguageIntellisensePart> refParts, bool addCompleteParts, IList <IIntellisenseResult> result, string[] parts, bool isRs, string rawSearch, string search, bool emptyOk)
        {
            var tmpTo = new ParseTO {
                Payload = parts[0], StartIndex = 0, EndIndex = parts[0].Length - 1
            };

            var isRecName = isRs && rawSearch.Contains(DataListUtil.RecordsetIndexOpeningBracket) && rawSearch.EndsWith(DataListUtil.RecordsetIndexClosingBracket);

            const string DisplayString = "Recordset";

            if ((!isRecName || parts[1] == string.Empty) && payload.Child == null)
            {
                if (ValidateName(rawSearch, DisplayString, result, out IList <IIntellisenseResult> intellisenseResults))
                {
                    return;
                }
            }
            else
            {
                if (ValidateName(search, DisplayString, result, out IList <IIntellisenseResult> intellisenseResults))
                {
                    return;
                }
            }

            try
            {
                IsValidIndex(tmpTo);
            }
            catch (Dev2DataLanguageParseError e)
            {
                result.Add(AddErrorToResults(isRs, parts[0], e, !payload.HangingOpen));
            }

            var recordsetPart = refParts.FirstOrDefault(c => c.Name.ToLower() == search && c.Children != null);

            var display  = parts[0];
            var partName = parts[0];
            var start    = display.IndexOf(DataListUtil.RecordsetIndexOpeningBracket, StringComparison.Ordinal);

            if (start >= 0 && recordsetPart == null)
            {
                display  = display.Substring(0, start);
                display += "()";
            }

            if (partName.IndexOf(' ') < 0)
            {
                search = ProcessValidPartNameContainingFields(payload, addCompleteParts, result, parts, search, emptyOk, partName, recordsetPart, display);
            }
            else
            {
                var part = IntellisenseFactory.CreateDataListValidationRecordsetPart(parts[0], "." + parts[1], true);
                result.Add(IntellisenseFactory.CreateErrorResult(payload.StartIndex, payload.EndIndex, part, " [[" + display + "]] contains a space, this is an invalid character for a variable name", enIntellisenseErrorCode.SyntaxError, !payload.HangingOpen));
            }
        }
Esempio n. 8
0
        IList <IIntellisenseResult> PartsGeneration(string payload, IList <IDev2DataLanguageIntellisensePart> parts, bool addCompleteParts, bool isFromIntellisense = false, IList <IDev2DataLanguageIntellisensePart> additionalParts = null)
        {
            IList <IIntellisenseResult> result = new List <IIntellisenseResult>();

            try
            {
                if (payload.Contains(CdataStart))
                {
                    payload = payload.Replace(CdataStart, "");
                    var idx = payload.LastIndexOf(CdataEnd, StringComparison.Ordinal);
                    payload = payload.Substring(0, idx);
                }

                if (payload.Equals("[[]]"))
                {
                    result.Add(IntellisenseFactory.CreateErrorResult(0, 4, null, ErrorResource.VariableIsMissing, enIntellisenseErrorCode.SyntaxError, true));
                    return(result);
                }

                if (payload.Contains(DataListUtil.OpeningSquareBrackets))
                {
                    var              rootItems   = MakeParts(payload, addCompleteParts);
                    IParseTO         magicRegion = null;
                    IList <IParseTO> evalParts   = new List <IParseTO>();
                    magicRegion = GetMagicRegion(rootItems, magicRegion, evalParts);
                    if (magicRegion != null)
                    {
                        result = isFromIntellisense ? TryExtractActualIntellisenseOptions(magicRegion, parts, false) : ExtractIntellisenseOptions(magicRegion, parts, false);
                    }
                    evalParts
                    .ToList()
                    .ForEach(evalPart =>
                    {
                        var tmp = ExtractIntellisenseOptions(evalPart, parts, !isFromIntellisense && addCompleteParts, additionalParts);
                        if (tmp != null)
                        {
                            result = result.Union(tmp).ToList();
                        }
                    });
                }
            }
            catch (Dev2DataLanguageParseError e)
            {
                var p = IntellisenseFactory.CreateDataListValidationScalarPart(payload);
                result.Add(IntellisenseFactory.CreateErrorResult(e.StartIndex, e.EndIndex, p, e.Message, e.ErrorCode, true));
            }
            return(result);
        }
Esempio n. 9
0
        public IIntellisenseResult ValidateName(string name, string displayString)
        {
            displayString = displayString ?? string.Empty;

            if (!string.IsNullOrEmpty(name))
            {
                var dataListVerifyPart = new DataListVerifyPart(name, "");
                var displayName        = displayString == "Recordset field" ? name : DataListUtil.OpeningSquareBrackets + name + DataListUtil.ClosingSquareBrackets;
                var intellisenseResult = IntellisenseFactory.CreateErrorResult(1, 1, dataListVerifyPart, displayString + " name " + displayName + " contains invalid character(s). Only use alphanumeric _ and - ", enIntellisenseErrorCode.SyntaxError, true);
                try
                {
                    if (!string.IsNullOrEmpty(name))
                    {
#pragma warning disable S134 // Control flow statements "if", "switch", "for", "foreach", "while", "do"  and "try" should not be nested too deeply
                        if (Char.IsNumber(name[0]))
                        {
                            return(IntellisenseFactory.CreateErrorResult(1, 1, dataListVerifyPart, displayString + " name " + displayName + " begins with a number", enIntellisenseErrorCode.SyntaxError, true));
                        }
                        if (name.Contains(":"))
                        {
                            return(intellisenseResult);
                        }
                        if (name.Contains("."))
                        {
                            return(intellisenseResult);
                        }
                        if (name.Contains(' '))
                        {
                            return(intellisenseResult);
                        }
                        if (name.ContainsUnicodeCharacter())
                        {
                            return(intellisenseResult);
                        }
#pragma warning restore S134 // Control flow statements "if", "switch", "for", "foreach", "while", "do"  and "try" should not be nested too deeply
                        XmlConvert.VerifyName(name);
                    }
                }
                catch (Exception ex)
                {
                    return(intellisenseResult);
                }
            }
            return(null);
        }
Esempio n. 10
0
        public IIntellisenseResult ValidateName(string name, string displayString)
        {
            displayString = displayString ?? string.Empty;

            if (!string.IsNullOrEmpty(name))
            {
                var dataListVerifyPart = new DataListVerifyPart(name, "");
                var displayName        = displayString == "Recordset field" ? name : DataListUtil.OpeningSquareBrackets + name + DataListUtil.ClosingSquareBrackets;
                var intellisenseResult = IntellisenseFactory.CreateErrorResult(1, 1, dataListVerifyPart, displayString + " name " + displayName + " contains invalid character(s). Only use alphanumeric _ and - ", enIntellisenseErrorCode.SyntaxError, true);
                try
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        if (Char.IsNumber(name[0]))
                        {
                            return(IntellisenseFactory.CreateErrorResult(1, 1, dataListVerifyPart, displayString + " name " + displayName + " begins with a number", enIntellisenseErrorCode.SyntaxError, true));
                        }
                        if (name.Contains(":"))
                        {
                            return(intellisenseResult);
                        }
                        if (name.Contains("."))
                        {
                            return(intellisenseResult);
                        }
                        if (name.Contains(' '))
                        {
                            return(intellisenseResult);
                        }
                        if (name.ContainsUnicodeCharacter())
                        {
                            return(intellisenseResult);
                        }
                        XmlConvert.VerifyName(name);
                    }
                }
                catch
                {
                    return(intellisenseResult);
                }
            }
            return(null);
        }
Esempio n. 11
0
        public IIntellisenseResult AddErrorToResults(bool isRs, string part, IDev2DataLangaugeParseError dev2DataLanguageParseError, bool isOpen)
        {
            // add error
            IDataListVerifyPart pTo;

            if (isRs)
            {
                var start = part.IndexOf(DataListUtil.RecordsetIndexOpeningBracket, StringComparison.Ordinal);
                var rs    = part;
                if (start >= 0)
                {
                    rs = rs.Substring(0, start);
                }
                pTo = IntellisenseFactory.CreateDataListValidationRecordsetPart(rs, "", "");
            }
            else
            {
                pTo = IntellisenseFactory.CreateDataListValidationScalarPart(part.Replace("]", ""));
            }

            return(IntellisenseFactory.CreateErrorResult(dev2DataLanguageParseError.StartIndex, dev2DataLanguageParseError.EndIndex, pTo, dev2DataLanguageParseError.Message, dev2DataLanguageParseError.ErrorCode, isOpen));
        }
Esempio n. 12
0
        public void RecordsetMatch_GivenValidArgs_ShouldNotThrowException()
        {
            //---------------Set up test pack-------------------
            //RecordsetMatch(IList<IIntellisenseResult> result, string rawSearch, string search)
            var parser = new Dev2DataLanguageParser();
            var intellisenseResults = new List <IIntellisenseResult> {
                IntellisenseFactory.CreateErrorResult(1, 2, new Mock <IDataListVerifyPart>().Object, "msg", enIntellisenseErrorCode.None, false)
            };
            var privateObject = new PrivateObject(parser);

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                privateObject.Invoke("RecordsetMatch", intellisenseResults, "rawSearch", "seach");
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
            //---------------Test Result -----------------------
        }
Esempio n. 13
0
        public bool ProcessFieldsForRecordSet(IParseTO payload, bool addCompleteParts, IList <IIntellisenseResult> result, string[] parts, out string search, out bool emptyOk, string display, IDev2DataLanguageIntellisensePart recordsetPart, string partName)
        {
            emptyOk = false;
            search  = "";
            if (parts[0].IndexOf(DataListUtil.RecordsetIndexClosingBracket, StringComparison.Ordinal) <= 0)
            {
                // its an error ;)
                var part = IntellisenseFactory.CreateDataListValidationRecordsetPart(parts[0], "." + parts[1], true);
                result.Add(IntellisenseFactory.CreateErrorResult(payload.StartIndex, payload.EndIndex, part, " [[" + display + "]] is a malformed recordset", enIntellisenseErrorCode.InvalidRecordsetNotation, !payload.HangingOpen));
            }
            else
            {
                search = parts[1].ToLower();
                var intellisenseResult = ValidateName(search, "Recordset field");
                if (intellisenseResult != null)
                {
                    result.Add(intellisenseResult);
                    return(true);
                }
                foreach (IDev2DataLanguageIntellisensePart t in recordsetPart.Children)
                {
                    var match = t.Name.ToLower();
                    if (match.Contains(search) && ((match != search) || (match == search && addCompleteParts)))
                    {
                        var index = payload.Child != null ? payload.Child.Payload : DataListUtil.ExtractIndexRegionFromRecordset(parts[0]);

                        var part = IntellisenseFactory.CreateDataListValidationRecordsetPart(partName, t.Name, t.Description, index);
                        result.Add(IntellisenseFactory.CreateSelectableResult(parts[0].Length, payload.EndIndex, part, part.Description));
                    }
                    else
                    {
                        ShouldUpdateEmptyOk(search, ref emptyOk, match);
                    }
                }
            }
            return(false);
        }