Esempio n. 1
0
        /// <summary>
        ///     Add Concurrent Dictionary function, and remove it prior to insertion
        /// </summary>
        /// <param name="kqlFunctionName"></param>
        /// <param name="cslFunction"></param>
        public static bool Add(string kqlFunctionName, CslFunction cslFunction)
        {
            // Update the function if it exists
            if (KqlFunctions.TryGetValue(kqlFunctionName, out var existingCslFunction))
            {
                return(KqlFunctions.TryUpdate(kqlFunctionName, cslFunction, existingCslFunction));
            }

            return(KqlFunctions.TryAdd(kqlFunctionName, cslFunction));
        }
Esempio n. 2
0
        private static CslFunction[] ReadAllLines(string[] lines)
        {
            List <CslFunction> result = new List <CslFunction>();

            StringBuilder comments = new StringBuilder();
            StringBuilder query    = new StringBuilder();

            foreach (string line in lines)
            {
                if (String.IsNullOrWhiteSpace(line) && query.Length > 0)
                {
                    string text = query.ToString().Trim();
                    if (text.StartsWith(".create-or-alter function"))
                    {
                        var func = new CslFunction(comments.ToString(), text);
                        result.Add(func);
                    }
                    comments = new StringBuilder();
                    query    = new StringBuilder();
                }

                string trimmedLine = line.Trim();
                if (trimmedLine.StartsWith("//"))
                {
                    comments.AppendLine(trimmedLine);
                }
                else
                {
                    // Force each line after trimming to have a preceding space, for downstream parsing ease.
                    query.Append($" {trimmedLine}");
                }
            }

            if (query.Length > 0)
            {
                string text = query.ToString().Trim();
                if (text.StartsWith(".create-or-alter function"))
                {
                    var func = new CslFunction(comments.ToString(), text);
                    result.Add(func);
                }
            }

            return(result.ToArray());
        }