Example #1
0
        public void AddKqlQuery(CslParagraph para)
        {
            try
            {
                // Load any functions for use across the node
                GlobalFunctions.ReadFunctionsFromQuery(para.Query);

                // Create the KqlQuery info, and hold reference to the object to prevent GC from releasing.
                var newKqlQuery = new KqlQuery(this, para.Comment, para.Query)
                {
                    IsValid = true,
                    Message = "Success",
                    KqlQueryEngagedDateTime = DateTime.UtcNow
                };

                KqlQueryList.Add(newKqlQuery);
                SubscriptionReferenceDisposables.Add(newKqlQuery);
            }
            catch (Exception ex)
            {
                FailedKqlQueryList.Add(new KqlQuery
                {
                    Node          = this,
                    Comment       = para.Comment,
                    Query         = para.Query,
                    IsValid       = false,
                    Message       = ex.Message,
                    FailureReason = ex,
                });
            }
        }
Example #2
0
        public bool TryAddKqlQuery(CslParagraph para, out Exception exception)
        {
            bool result = true;

            exception = null;

            this.AddKqlQuery(para);

            exception = this.FailedKqlQueryList
                        .Where(a => string.Equals(a.Query, para.Query, StringComparison.OrdinalIgnoreCase))
                        .Select(a => a.FailureReason)
                        .FirstOrDefault();

            result = exception == null;

            return(result);
        }
Example #3
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());
        }