예제 #1
0
        public DatabaseModel(string name, DocumentStore documentStore)
        {
            this.name          = name;
            this.documentStore = documentStore;

            Statistics = new Observable <DatabaseStatistics>();
            Status     = new Observable <string>
            {
                Value = "Offline"
            };
            OnPropertyChanged(() => StatusImage);

            asyncDatabaseCommands = name.Equals(Constants.SystemDatabase, StringComparison.OrdinalIgnoreCase)
                                                                                        ? documentStore.AsyncDatabaseCommands.ForSystemDatabase()
                                                        : documentStore.AsyncDatabaseCommands.ForDatabase(name);

            DocumentChanges.Select(c => Unit.Default).Merge(IndexChanges.Select(c => Unit.Default))
            .SampleResponsive(TimeSpan.FromSeconds(2))
            .Subscribe(_ => RefreshStatistics());

            databaseChanges.ConnectionStatusChanged += (sender, args) =>
            {
                ApplicationModel.Current.Server.Value.SetConnected(((IDatabaseChanges)sender).Connected);
                UpdateStatus();
            };

            RefreshStatistics();
        }
예제 #2
0
        public DatabaseModel(string name, DocumentStore documentStore)
        {
            this.name          = name;
            this.documentStore = documentStore;

            Tasks = new BindableCollection <TaskModel>(x => x.Name)
            {
                new ImportTask(),
                new ExportTask(),
                new StartBackupTask(),
                new IndexingTask(),
                new SampleDataTask()
            };

            SelectedTask = new Observable <TaskModel> {
                Value = Tasks.FirstOrDefault()
            };
            Statistics = new Observable <DatabaseStatistics>();
            Status     = new Observable <string>
            {
                Value = "Offline"
            };

            asyncDatabaseCommands = name.Equals(Constants.SystemDatabase, StringComparison.OrdinalIgnoreCase)
                                                                                        ? documentStore.AsyncDatabaseCommands.ForDefaultDatabase()
                                                                                        : documentStore.AsyncDatabaseCommands.ForDatabase(name);

            DocumentChanges.Select(c => Unit.Default).Merge(IndexChanges.Select(c => Unit.Default))
            .SampleResponsive(TimeSpan.FromSeconds(2))
            .Subscribe(_ => RefreshStatistics(), exception => ApplicationModel.Current.Server.Value.IsConnected.Value = false);

            RefreshStatistics();
        }
        private void AddDocumentToTree(DocumentChanges changes, SolutionNodeViewModel rootFolder)
        {
            var documentRoot = GetDocumentNode(changes.TargetDocument, rootFolder);

            documentRoot.Folders.Add(new SolutionNodeViewModel(
                                         changes.TargetDocument.Name,
                                         ExtensionResources.CsIcon,
                                         ExtensionResources.CsIcon,
                                         documentRoot,
                                         changes));
        }
        public SolutionNodeViewModel(
            string name,
            Bitmap expandedIcon,
            Bitmap closedIcon,
            SolutionNodeViewModel parentNode,
            DocumentChanges documentChanges = null)
        {
            Name            = name;
            DocumentChanges = documentChanges;
            _parentNode     = parentNode;

            _expandedIconSource = GetBitmapSource(expandedIcon);
            _closedBitmapSource = GetBitmapSource(closedIcon);
        }
예제 #5
0
            public void AddEdits(Uri uri, int version, params TextEdit[] edits)
            {
                Changes[uri.AbsoluteUri] = edits;

                DocumentChanges = DocumentChanges?.Append(new TextDocumentEdit()
                {
                    Edits        = edits,
                    TextDocument = new VersionedTextDocumentIdentifier()
                    {
                        Uri     = uri,
                        Version = version
                    }
                }).ToArray();
            }
예제 #6
0
        public DatabaseModel(string name, DocumentStore documentStore)
        {
            this.name          = name;
            this.documentStore = documentStore;

            Tasks = new BindableCollection <TaskModel>(x => x.Name)
            {
                new ImportTask(),
                new ExportTask(),
                new StartBackupTask(),
                new IndexingTask(),
                new SampleDataTask(),
                new CsvImportTask()
            };

            if (name == null || name == Constants.SystemDatabase)
            {
                Tasks.Insert(3, new StartRestoreTask());
            }

            SelectedTask = new Observable <TaskModel> {
                Value = Tasks.FirstOrDefault()
            };
            Statistics = new Observable <DatabaseStatistics>();
            Status     = new Observable <string>
            {
                Value = "Offline"
            };
            OnPropertyChanged(() => StatusImage);

            asyncDatabaseCommands = name.Equals(Constants.SystemDatabase, StringComparison.OrdinalIgnoreCase)
                                                        ? documentStore.AsyncDatabaseCommands.ForDefaultDatabase()
                                                        : documentStore.AsyncDatabaseCommands.ForDatabase(name);

            DocumentChanges.Select(c => Unit.Default).Merge(IndexChanges.Select(c => Unit.Default))
            .SampleResponsive(TimeSpan.FromSeconds(2))
            .Subscribe(_ => RefreshStatistics());

            databaseChanges.ConnectionStatusCahnged += (sender, args) =>
            {
                ApplicationModel.Current.Server.Value.SetConnected(((IDatabaseChanges)sender).Connected);
                UpdateStatus();
            };

            RefreshStatistics();
        }
예제 #7
0
        public async Task RenamingIdentifierAccessOrDeclarationShouldRenameDeclarationAndAllReferences(DataSet dataSet)
        {
            var(compilation, _, fileUri) = await dataSet.SetupPrerequisitesAndCreateCompilation(TestContext);

            var uri = DocumentUri.From(fileUri);

            using var helper = await LanguageServerHelper.StartServerWithTextAsync(this.TestContext, dataSet.Bicep, uri);

            var client      = helper.Client;
            var symbolTable = compilation.ReconstructSymbolTable();
            var lineStarts  = compilation.SourceFileGrouping.EntryPoint.LineStarts;

            var symbolToSyntaxLookup = symbolTable
                                       .Where(pair => pair.Value.Kind != SymbolKind.Error)
                                       .ToLookup(pair => pair.Value, pair => pair.Key);

            var validVariableAccessPairs = symbolTable
                                           .Where(pair => (pair.Key is VariableAccessSyntax || pair.Key is ResourceAccessSyntax || pair.Key is ITopLevelNamedDeclarationSyntax) &&
                                                  pair.Value.Kind != SymbolKind.Error &&
                                                  pair.Value.Kind != SymbolKind.Function &&
                                                  pair.Value.Kind != SymbolKind.Namespace
                                                  // symbols whose identifiers have parse errors will have a name like <error> or <missing>
                                                  && pair.Value.Name.Contains("<") == false);

            const string expectedNewText = "NewIdentifier";

            foreach (var(syntax, symbol) in validVariableAccessPairs)
            {
                var edit = await client.RequestRename(new RenameParams
                {
                    NewName      = expectedNewText,
                    TextDocument = new TextDocumentIdentifier(uri),
                    Position     = IntegrationTestHelper.GetPosition(lineStarts, syntax)
                });

                edit.Should().NotBeNull();
                edit !.DocumentChanges.Should().BeNullOrEmpty();
                edit.Changes.Should().NotBeNull();
                edit.Changes.Should().HaveCount(1);
                edit.Changes.Should().ContainKey(uri);

                var textEdits = edit.Changes ![uri];
        public ICollection <Inline> Build(DocumentChanges documentChanges)
        {
            var lines      = new List <Inline>();
            var textSource = documentChanges.TargetDocument.GetTextAsync().Result;

            if (textSource != null)
            {
                var changesToApply   = documentChanges.Changes.OfType <Change>().OrderBy(x => x.SpanToChange.Start).ToList();
                var linesWithChanges = textSource.Lines.Select(l => new
                {
                    Line    = l,
                    Changes = changesToApply.Where(c => IsLineContainsChange(l, c.SpanToChange)).ToList()
                });

                var newLinePartsFromPrevStep = new List <Inline>();
                foreach (var lineWithChanges in linesWithChanges)
                {
                    if (!lineWithChanges.Changes.Any())
                    {
                        lines.Add(CreateRun(lineWithChanges.Line.ToString(), Color.FromRgb(255, 255, 255)));
                        lines.Add(new LineBreak());
                        continue;
                    }

                    var result = GetLineParts(lineWithChanges.Line, lineWithChanges.Changes, newLinePartsFromPrevStep);
                    lines.AddRange(result.OldLineParts);
                    lines.Add(new LineBreak());
                    if (result.NewLineIsBuilded)
                    {
                        lines.AddRange(result.NewLineParts);
                        lines.Add(new LineBreak());
                        newLinePartsFromPrevStep.Clear();
                    }
                }
            }

            return(lines);
        }