Пример #1
0
        public QueryParts Parse(string query)
        {
            var hash = _hashProvider.Create(query).ToString("X");

            if (_parsedQueries.ContainsKey(hash))
            {
                return(_parsedQueries[hash]);
            }

            var cleanQuery = CleanAndFormatQueryText(query);

            var commentResult = _queryParser.StripComments(cleanQuery);

            cleanQuery = commentResult.commentFreeQuery;

            var typeAndBody = _queryParser.ParseQueryBody(cleanQuery);

            var qp = new QueryParts
            {
                VariableName   = _queryParser.ParseVariables(cleanQuery),
                QueryBody      = typeAndBody.queryBody.Trim(),
                QueryType      = typeAndBody.queryType.Trim(),
                QueryFrom      = _queryParser.ParseFromBody(cleanQuery).Trim(),
                QueryWhere     = _queryParser.ParseWhere(cleanQuery).Trim(),
                RollbackName   = _queryParser.ParseRollback(cleanQuery).Trim(),
                TransactionId  = _queryParser.ParseTransaction(cleanQuery).Trim(),
                QueryOrderBy   = _queryParser.ParseOrderBy(cleanQuery).Trim(),
                QueryJoin      = _queryParser.ParseJoins(cleanQuery).Trim(),
                Comments       = commentResult.comments,
                OrginalQuery   = query,
                CollectionName = _queryParser.GetCollectionName(cleanQuery)
            };

            switch (typeAndBody.queryType.Trim())
            {
            case Constants.QueryParsingKeywords.SELECT:
                qp.QueryOffset  = _queryParser.ParseOffsetLimit(cleanQuery).Trim();
                qp.QueryGroupBy = _queryParser.ParseGroupBy(cleanQuery).Trim();
                break;

            case Constants.QueryParsingKeywords.UPDATE:
                var updateTypeAndBody = _queryParser.ParseUpdateBody(cleanQuery);
                qp.QueryUpdateBody = updateTypeAndBody.updateBody.Trim();
                qp.QueryUpdateType = updateTypeAndBody.updateType.Trim();
                qp.QueryOrderBy    = string.Empty;
                qp.QueryJoin       = string.Empty;
                break;

            case Constants.QueryParsingKeywords.INSERT:
                qp.QueryInto    = _queryParser.ParseIntoBody(cleanQuery).Trim();
                qp.QueryFrom    = string.Empty;
                qp.QueryOrderBy = string.Empty;
                qp.QueryJoin    = string.Empty;
                break;
            }

            _parsedQueries.Add(hash, qp);
            return(qp);
        }
Пример #2
0
        public IEnumerable <OpenedWindow> GetOpenedWindows()
        {
            var openedWindows = new List <OpenedWindow>();

            var filter = new EnumerateFunc((hwnd, param) =>
            {
                var buffer = new StringBuilder(255);
                LowLevel.GetWindowText(hwnd, buffer, buffer.Capacity + 1);

                var title = buffer.ToString();

                if (!LowLevel.IsWindowVisible(hwnd) || string.IsNullOrEmpty(title) || hwnd == (IntPtr)0x0)
                {
                    return(true);
                }

                LowLevel.GetWindowThreadProcessId(hwnd, out var processId);
                var executablePath = LowLevelHelper.GetUwpApplicationName(hwnd, processId);

                if (executablePath == null)
                {
                    return(true);
                }

                if (_excludedProcesses.Any(x => executablePath.Contains(x) || title.Contains(x)))
                {
                    return(true);
                }

                openedWindows.Add(new OpenedWindow
                {
                    Hwnd           = hwnd,
                    Title          = title,
                    ExecutablePath = executablePath,
                    Uid            = _hashProvider.Create(hwnd.ToString())
                });

                return(true);
            });

            LowLevel.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);
            return(openedWindows);
        }