Esempio n. 1
0
        private void DeparseLockingNode(ScriptWriter writer, MySqlLockingNode node)
        {
            if (node.TableLockType == MySqlTableLockType.ShareMode)
            {
                writer.Write("LOCK IN SHARE MODE");
            }
            else
            {
                writer.Write("FOR ");
                writer.Write(node.TableLockType == MySqlTableLockType.Update ? "UPDATE" : "SHARE");

                if (!ListUtility.IsNullOrEmpty(node.Tables))
                {
                    writer.WriteSpace();
                    writer.Write("OF ");
                    writer.WriteJoin(", ", node.Tables);
                }

                if (node.RowLockType.HasValue)
                {
                    writer.WriteSpace();
                    writer.Write(node.RowLockType == MySqlRowLockType.SkipLocked ? "SKIP LOCKED" : "NOWAIT");
                }
            }
        }
Esempio n. 2
0
        public static QsiExpressionNode VisitTermMultiplication(TermMultiplicationContext context)
        {
            MultiplicationOperatorContext[] operators = context.multiplicationOperator();
            var left = VisitTermGroup(context.left);

            if (ListUtility.IsNullOrEmpty(operators))
            {
                return(left);
            }

            TermGroupContext[] rights = context.termGroup();

            for (int i = 0; i < operators.Length; i++)
            {
                var node = new QsiBinaryExpressionNode
                {
                    Operator = operators[i].GetText()
                };

                node.Left.SetValue(left);
                node.Right.SetValue(VisitTermGroup(rights[i + 1]));

                left = node;

                var leftSpan  = CqlTree.Span[node.Left.Value];
                var rightSpan = CqlTree.Span[node.Right.Value];

                CqlTree.Span[node] = new Range(leftSpan.Start, rightSpan.End);
            }

            return(left);
        }
Esempio n. 3
0
        public IQsiDefinitionNode VisitViewStatementBody(ViewStatementBody viewStatementBody)
        {
            if (viewStatementBody is not(CreateViewStatement or CreateOrAlterViewStatement))
            {
                throw TreeHelper.NotSupportedTree(viewStatementBody);
            }

            var node = new SqlServerViewDefinitionNode
            {
                IsAlter         = viewStatementBody is CreateOrAlterViewStatement,
                IsMaterialiazed = viewStatementBody.IsMaterialized,
                WithCheckOption = viewStatementBody.WithCheckOption,
                ViewOptions     = viewStatementBody.ViewOptions?.Select(option => option.OptionKind.ToString()).ToArray(),
                Identifier      = IdentifierVisitor.CreateQualifiedIdentifier(viewStatementBody.SchemaObjectName)
            };

            if (ListUtility.IsNullOrEmpty(viewStatementBody.Columns))
            {
                node.Columns.SetValue(TreeHelper.CreateAllColumnsDeclaration());
            }
            else
            {
                var columnsDeclaration = new QsiColumnsDeclarationNode();
                columnsDeclaration.Columns.AddRange(TableVisitor.CreateSequentialColumnNodes(viewStatementBody.Columns));
                node.Columns.SetValue(columnsDeclaration);
            }

            node.Source.SetValue(TableVisitor.VisitSelectStatement(viewStatementBody.SelectStatement));

            SqlServerTree.PutFragmentSpan(node, viewStatementBody);

            return(node);
        }
Esempio n. 4
0
        public static QsiTableNode VisitCommonSelectStatement(CommonSelectStatementContext context)
        {
            var node = new CqlDerivedTableNode
            {
                IsJson         = context.IsJson,
                IsDistinct     = context.IsDistinct,
                AllowFiltering = context.AllowFiltering
            };

            node.Columns.SetValue(VisitSelectors(context.Selectors));
            node.Source.SetValue(VisitColumnFamilyName(context.FromSource));

            if (context.WhereClause != null)
            {
                var whereContext = new ParserRuleContextWrapper <WhereClauseContext>
                                   (
                    context.WhereClause,
                    context.WhereStart,
                    context.WhereClause.Stop
                                   );

                node.Where.SetValue(ExpressionVisitor.CreateWhere(whereContext));
            }

            if (!ListUtility.IsNullOrEmpty(context.GroupByClauses))
            {
                var groupingContext = new ParserRuleContextWrapper <GroupByClauseContext[]>
                                      (
                    context.GroupByClauses,
                    context.GroupByStart,
                    context.GroupByClauses[^ 1].Stop
Esempio n. 5
0
        private static List <FileSystemItem> GetSubfolderDirectly(List <string> rootFolders)
        {
            if (ListUtility.IsNullOrEmpty(rootFolders))
            {
                rootFolders = DirectoryUtility.GetHardDriveRootFolders();
            }

            List <FileSystemItem> subfolders = new List <FileSystemItem>();

            foreach (string rootFolder in rootFolders)
            {
                DirectoryInfo rootFolderInfo;
                try
                {
                    rootFolderInfo = new DirectoryInfo(rootFolder);
                }
                catch
                {
                    //Not enough permissions.
                    continue;
                }

                subfolders.AddRange(GetFoldersRecursively(rootFolderInfo));

                FileSystemItem rootItem = GetFileSystemItem(rootFolderInfo);
                if (rootItem != null)
                {
                    subfolders.Add(rootItem);
                }
            }

            return(subfolders);
        }
Esempio n. 6
0
        public IQsiDefinitionNode VisitViewStmt(ViewStmt stmt)
        {
            var node = new PgViewDefinitionNode
            {
                Identifier  = IdentifierVisitor.VisitRangeVar(stmt.view[0]),
                Source      = { Value = TableVisitor.Visit(stmt.query[0]) },
                CheckOption = stmt.withCheckOption?.ToString()
            };

            if (stmt.replace ?? false)
            {
                node.ConflictBehavior = QsiDefinitionConflictBehavior.Replace;
            }

            // stmt.options: DefElem[]
            // Syntax: WITH ( key=<value_expression> [, ...] )

            if (!ListUtility.IsNullOrEmpty(stmt.aliases))
            {
                node.Columns.Value = new QsiColumnsDeclarationNode();
                node.Columns.Value.Columns.AddRange(TableVisitor.CreateSequentialColumnNodes(stmt.aliases.Cast <PgString>()));
            }

            return(node);
        }
        private static bool IsInRootFolder(FileSystemItem item, List <string> rootFolders)
        {
            if (ListUtility.IsNullOrEmpty(rootFolders))
            {
                return(true);
            }

            return(rootFolders.Any(rf => IsInRootFolder(item.FullPath, rf)));
        }
Esempio n. 8
0
        private static bool HasParameter(IEnumerable <string> parameters, string parameterName)
        {
            if (string.IsNullOrEmpty(parameterName) || parameters == null)
            {
                return(false);
            }

            List <string> list = parameters.ToList();

            return(!ListUtility.IsNullOrEmpty(list) && list.Contains(parameterName));
        }
        private static List <FileSystemItem> FilterCache(List <FileSystemItem> items,
                                                         List <string> rootFolders, List <string> excludeFolderTemplates)
        {
            if (ListUtility.IsNullOrEmpty(items))
            {
                return(new List <FileSystemItem>());
            }

            List <Regex> excludeRegexes = GetExcludeRegexes(excludeFolderTemplates);

            List <FileSystemItem> filteredItems = items
                                                  .Where(item => IsCorrect(item, rootFolders, excludeRegexes))
                                                  .ToList();

            return(filteredItems);
        }
        public List <MatchedFileSystemItem> GetMatches(List <FileSystemItem> items, string searchText)
        {
            if (ListUtility.IsNullOrEmpty(items) || string.IsNullOrEmpty(searchText))
            {
                return(new List <MatchedFileSystemItem>());
            }

            Regex searchRegex = GetSearchRegex(searchText);

            List <MatchedFileSystemItem> matches =
                items
                .Select(i => GetMatchedItem(i, searchRegex))
                .Where(mi => mi != null)
                .ToList();

            return(matches);
        }
        public MatchModel MoveSelectionDown(ObservableCollection <MatchModel> matches, MatchModel selectedMatch)
        {
            if (ListUtility.IsNullOrEmpty(matches))
            {
                return(null);
            }

            int selectionIndex = matches.IndexOf(selectedMatch);

            selectionIndex++;

            if (selectionIndex == matches.Count)
            {
                selectionIndex = 0;
            }

            return(matches[selectionIndex]);
        }
Esempio n. 12
0
    private void UpdateView(CubeManager cubeManager)
    {
        UIUtility.TrySetActive(toioCubePlayerIndicators, false);
        foreach (var(cube, index) in cubeManager.cubes.WithIndex())
        {
            ListUtility.TryGetValue(toioCubePlayerIndicators, index, out var indicator);
            if (indicator == null)
            {
                continue;
            }

            UIUtility.TrySetActive(indicator, true);
            indicator.UpdateView(cube, index);
        }

        connectButton.interactable = cubeManager.cubes.Count < toioCubePlayerIndicators.Count;
        startButton.interactable   = !ListUtility.IsNullOrEmpty(cubeManager.cubes);
    }
        private static Regex GetSearchRegex(string searchText)
        {
            IList <string> substrings = searchText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (ListUtility.IsNullOrEmpty(substrings))
            {
                return(null);
            }

            string[] substringTemplates = substrings.Select(GetWordStartTemplate).ToArray();

            //All meaningful substrings may be separated with any amount of non-space characters (as we split by space),
            //then followed by spaces (spaces will be specified in substringTemplates).
            string template    = string.Join(@"\S*", substringTemplates);
            Regex  searchRegex = new Regex(template);

            return(searchRegex);
        }
        private static List <Regex> GetExcludeRegexes(List <string> excludeFolderTemplates)
        {
            if (ListUtility.IsNullOrEmpty(excludeFolderTemplates))
            {
                return(new List <Regex>());
            }

            //Here we enclose each regex into double slashes (to make them escaped in the regex).
            //It's needed to allow exact matches of folder names.
            //I tried using \b{0}\b, but it doesn't work for folder names like .svn
            //(as \b matches at the word boundary if the first and/or last characters in the string are _word characters_).
            List <Regex> excludeRegexes = excludeFolderTemplates
                                          .Select(t => string.Format(CultureInfo.InvariantCulture, @"\\{0}\\", t))
                                          .Select(t => new Regex(t, RegexOptions.IgnoreCase))
                                          .ToList();

            return(excludeRegexes);
        }
        public void StartListening(List <string> foldersToListen)
        {
            if (!_stopped)
            {
                throw new InvalidOperationException("Call Stop before starting listening.");
            }

            if (ListUtility.IsNullOrEmpty(foldersToListen))
            {
                foldersToListen = DirectoryUtility.GetHardDriveRootFolders();
            }

            foreach (string path in foldersToListen)
            {
                FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();
                string            fullPath;
                try
                {
                    fullPath = Path.GetFullPath(path);
                }
                catch (PathTooLongException)
                {
                    continue;
                }

                fileSystemWatcher.Path = fullPath;

                NotifyFilters filters = NotifyFilters.DirectoryName;

                fileSystemWatcher.NotifyFilter          = filters;
                fileSystemWatcher.IncludeSubdirectories = true;

                // Add event handlers.
                fileSystemWatcher.Created += HandleFolderCreated;
                fileSystemWatcher.Deleted += HandleFolderDeleted;
                fileSystemWatcher.Renamed += HandleFolderRenamed;

                _fileSystemWatchers.Add(fileSystemWatcher);

                // Begin watching.
                fileSystemWatcher.EnableRaisingEvents = true;
            }
            _stopped = false;
        }
Esempio n. 16
0
        private void MatchesCorrect(FileSystemItem item, string searchText, MatchedFileSystemItem expectedMatch)
        {
            List <FileSystemItem> items = new List <FileSystemItem> {
                item
            };

            List <MatchedFileSystemItem> actualMatches = _matchSearcher.GetMatches(items, searchText);

            bool matchExistenceCorrect = ((expectedMatch == null) && (ListUtility.IsNullOrEmpty(actualMatches))) ||
                                         ((expectedMatch != null) && (!ListUtility.IsNullOrEmpty(actualMatches)));

            Assert.That(matchExistenceCorrect, Is.True);

            if (expectedMatch == null)
            {
                return;
            }

            Assert.That(MatchesEqual(actualMatches[0], expectedMatch));
        }
Esempio n. 17
0
        public QsiTableNode VisitInlineDerivedTable(InlineDerivedTable inlineDerivedTable)
        {
            return(TreeHelper.Create <QsiInlineDerivedTableNode>(n =>
            {
                if (inlineDerivedTable.Alias != null)
                {
                    n.Alias.SetValue(CreateAliasNode(inlineDerivedTable.Alias));
                }

                if (!ListUtility.IsNullOrEmpty(inlineDerivedTable.Columns))
                {
                    var columnsDeclaration = new QsiColumnsDeclarationNode();
                    columnsDeclaration.Columns.AddRange(CreateSequentialColumnNodes(inlineDerivedTable.Columns));
                    n.Columns.SetValue(columnsDeclaration);
                }

                n.Rows.AddRange(inlineDerivedTable.RowValues.Select(ExpressionVisitor.VisitRowValue));

                SqlServerTree.PutFragmentSpan(n, inlineDerivedTable);
            }));
        }
Esempio n. 18
0
        public QsiActionNode VisitInsertSpecificiation(InsertSpecification insertSpecification)
        {
            var node      = new QsiDataInsertActionNode();
            var tableNode = TableVisitor.VisitTableReference(insertSpecification.Target);

            if (tableNode is not QsiTableReferenceNode tableReferenceNode)
            {
                throw new QsiException(QsiError.Syntax);
            }

            node.Target.SetValue(tableReferenceNode);

            if (!ListUtility.IsNullOrEmpty(insertSpecification.Columns))
            {
                node.Columns = insertSpecification.Columns
                               .Select(ExpressionVisitor.VisitColumnReferenceExpression)
                               .Select(c => c.Column.Value switch
                {
                    QsiColumnReferenceNode columnReferenceNode => columnReferenceNode.Name,
                    QsiAllColumnNode allColumnNode => allColumnNode.Path,
                    _ => throw new QsiException(QsiError.Syntax)
                })
Esempio n. 19
0
        public List <MatchModel> GetMatchModels(List <MatchedFileSystemItem> folderMatches)
        {
            if (ListUtility.IsNullOrEmpty(folderMatches))
            {
                return(new List <MatchModel> {
                    new MatchModel(this, Resources.NoMatchesFound)
                });
            }

            folderMatches.Sort(Compare);
            List <MatchModel> matchRepresentations = folderMatches
                                                     .Take(Constants.MaxMatchesToDisplay)
                                                     .Select(GetMatchModel)
                                                     .ToList();

            if (folderMatches.Count > Constants.MaxMatchesToDisplay)
            {
                matchRepresentations.Add(new MatchModel(this, Resources.TooManyMatchesText));
            }

            return(matchRepresentations);
        }
Esempio n. 20
0
        public static QsiTableNode VisitSelectStmt(SelectStmt selectStmt)
        {
            QsiTableNode tableNode;

            if (!ListUtility.IsNullOrEmpty(selectStmt.intoClause))
            {
                throw TreeHelper.NotSupportedFeature("Into clause");
            }

            switch (selectStmt.op)
            {
            case SetOperation.SETOP_NONE:
                tableNode = VisitSelectStmtNone(selectStmt);
                break;

            case SetOperation.SETOP_UNION:
            case SetOperation.SETOP_EXCEPT:
            case SetOperation.SETOP_INTERSECT:
                tableNode = VisitSelectStmtComposite(selectStmt);
                break;

            default:
                throw TreeHelper.NotSupportedTree($"{selectStmt.GetType().Name}({selectStmt.op})");
            }

            if (ListUtility.IsNullOrEmpty(selectStmt.withClause))
            {
                return(tableNode);
            }

            QsiDerivedTableNode derivedTableNode;

            if (tableNode is QsiDerivedTableNode derivedTable && derivedTable.Directives.IsEmpty)
            {
                derivedTableNode = derivedTable;
            }
        private static bool ShouldBeExcluded(FileSystemItem item, List <Regex> excludeRegexes)
        {
            if (ListUtility.IsNullOrEmpty(excludeRegexes))
            {
                return(false);
            }

            List <string> foldersInPath = DirectoryUtility.SplitPath(item.FullPath);

            foreach (string folder in foldersInPath)
            {
                //The regexes assume inclosing slashes.
                string normalizedFolder = string.Format("\\{0}\\", folder);
                foreach (Regex excludeRegex in excludeRegexes)
                {
                    if (excludeRegex.IsMatch(normalizedFolder))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }