Esempio n. 1
0
        public static CslParagraph[] ReadFile(string cslFile)
        {
            var           queries  = new List <CslParagraph>();
            StringBuilder comments = new StringBuilder();
            StringBuilder query    = new StringBuilder();

            string[] lines = File.ReadAllLines(cslFile);

            var functions = ReadFunctionsFromFile(cslFile);

            foreach (var f in functions)
            {
                GlobalFunctions.Add(f.Name, f);
            }

            foreach (string line in lines)
            {
                if (String.IsNullOrWhiteSpace(line) && query.Length > 0)
                {
                    var result = new CslParagraph
                    {
                        Comment = comments.ToString(),
                        Query   = query.ToString()
                    };

                    // Only allow one Comments line to be read, usually the first one!
                    if (string.IsNullOrEmpty(comments.ToString()))
                    {
                        comments = new StringBuilder();
                    }

                    query = new StringBuilder();

                    // Ignore system commands in the file
                    if (!string.IsNullOrWhiteSpace(result.Query) && !result.Query.StartsWith("."))
                    {
                        queries.Add(result);
                    }
                }

                string currentLine = line.Trim();

                if (currentLine.StartsWith("//"))
                {
                    comments.AppendLine(currentLine);
                }
                else
                {
                    if (!string.IsNullOrEmpty(currentLine))
                    {
                        query.AppendLine(currentLine);
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(query.ToString()) && query.Length > 0)
            {
                var result = new CslParagraph
                {
                    Comment = comments.ToString(),
                    Query   = query.ToString()
                };

                // Ignore system commands in the file
                if (!result.Query.StartsWith("."))
                {
                    queries.Add(result);
                }
            }

            return(queries.ToArray());
        }
Esempio n. 2
0
 /// <summary>
 /// Add a Kql function directly from it's definition
 /// </summary>
 /// <param name="kqlFunctionQuery"></param>
 public void RemoveKqlFunction(string kqlFunctionName)
 {
     // Load any functions for use across the node
     GlobalFunctions.Remove(kqlFunctionName);
 }
Esempio n. 3
0
 /// <summary>
 /// Retrieve a Kql function directly from it's definition
 /// </summary>
 /// <param name="kqlFunctionName"></param>
 public CslFunction GetKqlFunction(string kqlFunctionName)
 {
     // Retrieve requested function the node
     return(GlobalFunctions.GetFunction(kqlFunctionName));
 }
Esempio n. 4
0
 /// <summary>
 /// Add a Kql function directly from it's definition
 /// </summary>
 /// <param name="kqlFunctionQuery"></param>
 public void AddKqlFunction(string kqlFunctionQuery)
 {
     // Load any functions for use across the node
     GlobalFunctions.ReadFunctionsFromQuery(kqlFunctionQuery);
 }