private async Task <bool> TryDeserializeProjectDiagnosticsAsync( IPersistentStorageService persistentService, DiagnosticDataSerializer serializer, Project project, Builder builder, CancellationToken cancellationToken ) { var diagnostics = await DeserializeDiagnosticsAsync( persistentService, serializer, project, document : null, project.Id, _owner.NonLocalStateName, cancellationToken ) .ConfigureAwait(false); if (!diagnostics.IsDefault) { builder.AddOthers(diagnostics); return(true); } return(false); }
public async Task SaveAsync(IPersistentStorageService persistentService, Project project, DiagnosticAnalysisResult result) { Contract.ThrowIfTrue(result.IsAggregatedForm); Contract.ThrowIfNull(result.DocumentIds); RemoveInMemoryCache(_lastResult); // save last aggregated form of analysis result _lastResult = result.ToAggregatedForm(); // serialization can't be cancelled. var serializer = new DiagnosticDataSerializer(_owner.AnalyzerVersion, result.Version); foreach (var documentId in result.DocumentIds) { var document = project.GetTextDocument(documentId); if (document == null) { // it can happen with build synchronization since, in build case, // we don't have actual snapshot (we have no idea what sources out of proc build has picked up) // so we might be out of sync. // example of such cases will be changing anything about solution while building is going on. // it can be user explicit actions such as unloading project, deleting a file, but also it can be // something project system or roslyn workspace does such as populating workspace right after // solution is loaded. continue; } await SerializeAsync(persistentService, serializer, project, document, document.Id, _owner.SyntaxStateName, result.GetDocumentDiagnostics(document.Id, AnalysisKind.Syntax)).ConfigureAwait(false); await SerializeAsync(persistentService, serializer, project, document, document.Id, _owner.SemanticStateName, result.GetDocumentDiagnostics(document.Id, AnalysisKind.Semantic)).ConfigureAwait(false); await SerializeAsync(persistentService, serializer, project, document, document.Id, _owner.NonLocalStateName, result.GetDocumentDiagnostics(document.Id, AnalysisKind.NonLocal)).ConfigureAwait(false); } await SerializeAsync(persistentService, serializer, project, document : null, result.ProjectId, _owner.NonLocalStateName, result.GetOtherDiagnostics()).ConfigureAwait(false); }
private async Task <DiagnosticAnalysisResult> LoadInitialProjectAnalysisDataAsync( IPersistentStorageService persistentService, Project project, CancellationToken cancellationToken ) { // loading data can be cancelled any time. var version = await GetDiagnosticVersionAsync(project, cancellationToken) .ConfigureAwait(false); var serializer = new DiagnosticDataSerializer(_owner.AnalyzerVersion, version); var builder = new Builder(project, version); if ( !await TryDeserializeProjectDiagnosticsAsync( persistentService, serializer, project, builder, cancellationToken ) .ConfigureAwait(false) ) { return(DiagnosticAnalysisResult.CreateEmpty(project.Id, VersionStamp.Default)); } return(builder.ToResult()); }
public DiagnosticIncrementalAnalyzer( DiagnosticAnalyzerService analyzerService, int correlationId, Workspace workspace, DiagnosticAnalyzerInfoCache analyzerInfoCache ) { Contract.ThrowIfNull(analyzerService); AnalyzerService = analyzerService; Workspace = workspace; PersistentStorageService = workspace.Services.GetRequiredService <IPersistentStorageService>(); _documentTrackingService = workspace.Services.GetService <IDocumentTrackingService>(); _correlationId = correlationId; _stateManager = new StateManager(PersistentStorageService, analyzerInfoCache); _stateManager.ProjectAnalyzerReferenceChanged += OnProjectAnalyzerReferenceChanged; _telemetry = new DiagnosticAnalyzerTelemetry(); _diagnosticAnalyzerRunner = new InProcOrRemoteHostAnalyzerRunner( analyzerInfoCache, analyzerService.Listener ); _projectCompilationsWithAnalyzers = new ConditionalWeakTable <Project, CompilationWithAnalyzers?>(); }
private ValueTask <ImmutableArray <DiagnosticData> > DeserializeDiagnosticsAsync( IPersistentStorageService persistentService, DiagnosticDataSerializer serializer, Project project, TextDocument?document, object key, string stateKey, CancellationToken cancellationToken ) { Contract.ThrowIfFalse(document == null || document.Project == project); if ( InMemoryStorage.TryGetValue(_owner.Analyzer, (key, stateKey), out var entry) && serializer.Version == entry.Version ) { return(ValueTaskFactory.FromResult(entry.Diagnostics)); } return(serializer.DeserializeAsync( persistentService, project, document, stateKey, cancellationToken )); }
public async Task <bool> SerializeAsync(IPersistentStorageService persistentService, Project project, TextDocument?textDocument, string key, ImmutableArray <DiagnosticData> items, CancellationToken cancellationToken) { Contract.ThrowIfFalse(textDocument == null || textDocument.Project == project); using var stream = SerializableBytes.CreateWritableStream(); using (var writer = new ObjectWriter(stream, leaveOpen: true, cancellationToken)) { WriteDiagnosticData(writer, items, cancellationToken); } var storage = await persistentService.GetStorageAsync(project.Solution, cancellationToken).ConfigureAwait(false); await using var _ = storage.ConfigureAwait(false); stream.Position = 0; var writeTask = (textDocument != null) ? textDocument is Document document? storage.WriteStreamAsync(document, key, stream, cancellationToken) : storage.WriteStreamAsync(GetSerializationKeyForNonSourceDocument(textDocument, key), stream, cancellationToken) : storage.WriteStreamAsync(project, key, stream, cancellationToken); return(await writeTask.ConfigureAwait(false)); }
public CustomersController(ILogger <CustomersController> logger, IPersistentStorageService <CustomerViewModel, Customer> persistentStorageService, HealthService healthService) { _logger = logger; _persistentStorageService = persistentStorageService; _healthService = healthService; }
public StateManager(IPersistentStorageService persistentStorageService, DiagnosticAnalyzerInfoCache analyzerInfoCache) { _persistentStorageService = persistentStorageService; _analyzerInfoCache = analyzerInfoCache; _hostAnalyzerStateMap = ImmutableDictionary <string, HostAnalyzerStateSets> .Empty; _projectAnalyzerStateMap = new ConcurrentDictionary <ProjectId, ProjectAnalyzerStateSets>(concurrencyLevel: 2, capacity: 10); }
public VerificationProfilesController(IConfiguration configuration, ISessionStateService sessionStateService, SpeakerRecognitionClient mSpeakerRecognitionClient, IPersistentStorageService persistantStorageService) { _persistantStorageService = persistantStorageService; this.mSpeakerRecognitionClient = mSpeakerRecognitionClient; mSessionStateService = sessionStateService; }
public AuthorizationController( OpenIddictApplicationManager <OpenIddictApplication> applicationManager, IOptions <IdentityOptions> identityOptions, ISessionStateService sessionStateService, IPersistentStorageService persistantStorageService, SpeakerRecognitionClient speakerRecognitionClient) { _applicationManager = applicationManager; _identityOptions = identityOptions; _sessionStateService = sessionStateService; }
public VerificationProfilesController(IConfiguration configuration, ISessionStateService sessionStateService, SpeakerRecognitionClient speakerRecognitionClient, IPersistentStorageService persistantStorageService, IJwtHandler jwtHandler) { _persistantStorageService = persistantStorageService; _speakerRecognitionClient = speakerRecognitionClient; _sessionStateService = sessionStateService; _jwtHandler = jwtHandler; }
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) { lock (_gate) { if (_singleton == null) { _singleton = GetPersistentStorageService(workspaceServices); } return(_singleton); } }
private async Task SerializeAsync(IPersistentStorageService persistentService, DiagnosticDataSerializer serializer, Project project, TextDocument?document, object key, string stateKey, ImmutableArray <DiagnosticData> diagnostics) { Contract.ThrowIfFalse(document == null || document.Project == project); // try to serialize it if (await serializer.SerializeAsync(persistentService, project, document, stateKey, diagnostics, CancellationToken.None).ConfigureAwait(false)) { // we succeeded saving it to persistent storage. remove it from in memory cache if it exists RemoveInMemoryCacheEntry(key, stateKey); return; } // if serialization fail, hold it in the memory InMemoryStorage.Cache(_owner.Analyzer, (key, stateKey), new CacheEntry(serializer.Version, diagnostics)); }
public async Task <bool> OnDocumentClosedAsync(IPersistentStorageService persistentStorageService, TextDocument document) { // can not be cancelled // remove active file state and put it in project state if (!_activeFileStates.TryRemove(document.Id, out var activeFileState)) { return(false); } // active file exist, put it in the project state var projectState = GetOrCreateProjectState(document.Project.Id); await projectState.MergeAsync(persistentStorageService, activeFileState, document).ConfigureAwait(false); return(true); }
public async ValueTask <ImmutableArray <DiagnosticData> > DeserializeAsync(IPersistentStorageService persistentService, Project project, Document?document, string key, CancellationToken cancellationToken) { Contract.ThrowIfFalse(document == null || document.Project == project); using var storage = persistentService.GetStorage(project.Solution); var readTask = (document != null) ? storage.ReadStreamAsync(document, key, cancellationToken) : storage.ReadStreamAsync(project, key, cancellationToken); using var stream = await readTask.ConfigureAwait(false); using var reader = ObjectReader.TryGetReader(stream); if (reader == null) { return(default);
public async Task MergeAsync(IPersistentStorageService persistentService, ActiveFileState state, TextDocument document) { Contract.ThrowIfFalse(state.DocumentId == document.Id); // merge active file state to project state var lastResult = _lastResult; var syntax = state.GetAnalysisData(AnalysisKind.Syntax); var semantic = state.GetAnalysisData(AnalysisKind.Semantic); var project = document.Project; // if project didn't successfully loaded, then it is same as FSA off var fullAnalysis = SolutionCrawlerOptions.GetBackgroundAnalysisScope(project) == BackgroundAnalysisScope.FullSolution && await project.HasSuccessfullyLoadedAsync(CancellationToken.None).ConfigureAwait(false); // keep from build flag if full analysis is off var fromBuild = fullAnalysis ? false : lastResult.FromBuild; var openFileOnlyAnalyzer = _owner.Analyzer.IsOpenFileOnly(document.Project.Solution.Options); // if it is allowed to keep project state, check versions and if they are same, bail out. // if full solution analysis is off or we are asked to reset document state, we always merge. if (fullAnalysis && !openFileOnlyAnalyzer && syntax.Version != VersionStamp.Default && syntax.Version == semantic.Version && syntax.Version == lastResult.Version) { // all data is in sync already. return; } // we have mixed versions or full analysis is off, set it to default so that it can be re-calculated next time so data can be in sync. var version = VersionStamp.Default; // serialization can't be cancelled. var serializer = new DiagnosticDataSerializer(_owner.AnalyzerVersion, version); // save active file diagnostics back to project state await SerializeAsync(persistentService, serializer, project, document, document.Id, _owner.SyntaxStateName, syntax.Items).ConfigureAwait(false); await SerializeAsync(persistentService, serializer, project, document, document.Id, _owner.SemanticStateName, semantic.Items).ConfigureAwait(false); // save last aggregated form of analysis result _lastResult = _lastResult.UpdateAggregatedResult(version, state.DocumentId, fromBuild); }
public async ValueTask <ImmutableArray <DiagnosticData> > DeserializeAsync( IPersistentStorageService persistentService, Project project, TextDocument?textDocument, string key, CancellationToken cancellationToken ) { Contract.ThrowIfFalse(textDocument == null || textDocument.Project == project); var storage = await persistentService .GetStorageAsync(project.Solution, cancellationToken) .ConfigureAwait(false); await using var _ = storage.ConfigureAwait(false); var readTask = (textDocument != null) ? textDocument is Document document ? storage.ReadStreamAsync(document, key, cancellationToken) : storage.ReadStreamAsync( GetSerializationKeyForNonSourceDocument(textDocument, key), cancellationToken ) : storage.ReadStreamAsync(project, key, cancellationToken); using var stream = await readTask.ConfigureAwait(false); using var reader = ObjectReader.TryGetReader( stream, cancellationToken: cancellationToken ); if ( reader == null || !TryReadDiagnosticData( reader, project, textDocument, cancellationToken, out var data ) ) { return(default);
public async Task <bool> OnDocumentOpenedAsync( IPersistentStorageService persistentStorageService, TextDocument document ) { // can not be cancelled if ( !TryGetProjectState(document.Project.Id, out var projectState) || projectState.IsEmpty(document.Id) ) { // nothing to do return(false); } var result = await projectState .GetAnalysisDataAsync( persistentStorageService, document, avoidLoadingData : false, CancellationToken.None ) .ConfigureAwait(false); // store analysis result to active file state: var activeFileState = GetOrCreateActiveFileState(document.Id); activeFileState.Save( AnalysisKind.Syntax, new DocumentAnalysisData( result.Version, result.GetDocumentDiagnostics(document.Id, AnalysisKind.Syntax) ) ); activeFileState.Save( AnalysisKind.Semantic, new DocumentAnalysisData( result.Version, result.GetDocumentDiagnostics(document.Id, AnalysisKind.Semantic) ) ); return(true); }
public async Task <bool> SerializeAsync(IPersistentStorageService persistentService, Project project, Document?document, string key, ImmutableArray <DiagnosticData> items, CancellationToken cancellationToken) { Contract.ThrowIfFalse(document == null || document.Project == project); using var stream = SerializableBytes.CreateWritableStream(); using var writer = new ObjectWriter(stream, cancellationToken: cancellationToken); WriteDiagnosticData(writer, items, cancellationToken); using var storage = persistentService.GetStorage(project.Solution); stream.Position = 0; var writeTask = (document != null) ? storage.WriteStreamAsync(document, key, stream, cancellationToken) : storage.WriteStreamAsync(project, key, stream, cancellationToken); return(await writeTask.ConfigureAwait(false)); }
private async Task <bool> TryDeserializeDocumentDiagnosticsAsync(IPersistentStorageService persistentService, DiagnosticDataSerializer serializer, TextDocument document, Builder builder, CancellationToken cancellationToken) { var success = true; var project = document.Project; var documentId = document.Id; var diagnostics = await DeserializeDiagnosticsAsync(persistentService, serializer, project, document, documentId, _owner.SyntaxStateName, cancellationToken).ConfigureAwait(false); if (!diagnostics.IsDefault) { builder.AddSyntaxLocals(documentId, diagnostics); } else { success = false; } diagnostics = await DeserializeDiagnosticsAsync(persistentService, serializer, project, document, documentId, _owner.SemanticStateName, cancellationToken).ConfigureAwait(false); if (!diagnostics.IsDefault) { builder.AddSemanticLocals(documentId, diagnostics); } else { success = false; } diagnostics = await DeserializeDiagnosticsAsync(persistentService, serializer, project, document, documentId, _owner.NonLocalStateName, cancellationToken).ConfigureAwait(false); if (!diagnostics.IsDefault) { builder.AddNonLocals(documentId, diagnostics); } else { success = false; } return(success); }
public async Task <DiagnosticAnalysisResult> GetAnalysisDataAsync(IPersistentStorageService persistentService, TextDocument document, bool avoidLoadingData, CancellationToken cancellationToken) { // make a copy of last result. var lastResult = _lastResult; Contract.ThrowIfFalse(lastResult.ProjectId == document.Project.Id); if (lastResult.IsDefault) { return(await LoadInitialAnalysisDataAsync(persistentService, document, cancellationToken).ConfigureAwait(false)); } var version = await GetDiagnosticVersionAsync(document.Project, cancellationToken).ConfigureAwait(false); if (avoidLoadingData && lastResult.Version != version) { return(lastResult); } // if given document doesnt have any diagnostics, return empty. if (IsEmpty(lastResult, document.Id)) { return(DiagnosticAnalysisResult.CreateEmpty(lastResult.ProjectId, lastResult.Version)); } // loading data can be cancelled any time. var serializer = new DiagnosticDataSerializer(_owner.AnalyzerVersion, lastResult.Version); var builder = new Builder(document.Project, lastResult.Version); if (!await TryDeserializeDocumentDiagnosticsAsync(persistentService, serializer, document, builder, cancellationToken).ConfigureAwait(false)) { Debug.Assert(lastResult.Version == VersionStamp.Default); // this can happen if we merged back active file diagnostics back to project state but // project state didn't have diagnostics for the file yet. (since project state was staled) } return(builder.ToResult()); }
public async Task <DiagnosticAnalysisResult> GetProjectAnalysisDataAsync(IPersistentStorageService persistentService, Project project, bool avoidLoadingData, CancellationToken cancellationToken) { // make a copy of last result. var lastResult = _lastResult; Contract.ThrowIfFalse(lastResult.ProjectId == project.Id); if (lastResult.IsDefault) { return(await LoadInitialProjectAnalysisDataAsync(persistentService, project, cancellationToken).ConfigureAwait(false)); } var version = await GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false); if (avoidLoadingData && lastResult.Version != version) { return(lastResult); } // if given document doesnt have any diagnostics, return empty. if (lastResult.IsEmpty) { return(DiagnosticAnalysisResult.CreateEmpty(lastResult.ProjectId, lastResult.Version)); } // loading data can be cancelled any time. var serializer = new DiagnosticDataSerializer(_owner.AnalyzerVersion, lastResult.Version); var builder = new Builder(project, lastResult.Version); if (!await TryDeserializeProjectDiagnosticsAsync(persistentService, serializer, project, builder, cancellationToken).ConfigureAwait(false)) { // this can happen if SaveAsync is not yet called but active file merge happened. one of case is if user did build before the very first // analysis happened. } return(builder.ToResult()); }
public static async Task <ProjectAnalysisData> CreateAsync(IPersistentStorageService persistentService, Project project, IEnumerable <StateSet> stateSets, bool avoidLoadingData, CancellationToken cancellationToken) { VersionStamp?version = null; var builder = ImmutableDictionary.CreateBuilder <DiagnosticAnalyzer, DiagnosticAnalysisResult>(); foreach (var stateSet in stateSets) { var state = stateSet.GetOrCreateProjectState(project.Id); var result = await state.GetAnalysisDataAsync(persistentService, project, avoidLoadingData, cancellationToken).ConfigureAwait(false); Contract.ThrowIfFalse(project.Id == result.ProjectId); if (!version.HasValue) { version = result.Version; } else if (version.Value != VersionStamp.Default && version.Value != result.Version) { // if not all version is same, set version as default. // this can happen at the initial data loading or // when document is closed and we put active file state to project state version = VersionStamp.Default; } builder.Add(stateSet.Analyzer, result); } if (!version.HasValue) { // there is no saved data to return. return(new ProjectAnalysisData(project.Id, VersionStamp.Default, ImmutableDictionary <DiagnosticAnalyzer, DiagnosticAnalysisResult> .Empty)); } return(new ProjectAnalysisData(project.Id, version.Value, builder.ToImmutable())); }
protected AbstractDesignerAttributeIncrementalAnalyzer(Workspace workspace) { _storageService = workspace.Services.GetRequiredService <IPersistentStorageService>(); }
public ElementsController(ILogger <ElementsController> logger, IPersistentStorageService <CoreElementViewModel, CoreElement> persistentStorageService, HealthService healthService) { _logger = logger; _persistentStorageService = persistentStorageService; _healthService = healthService; }
public EnrollmentController(IPersistentStorageService persistantStorageService) { _persistantStorageService = persistantStorageService; }
public Task SaveAsync( IPersistentStorageService persistentService, Project project, DiagnosticAnalysisResult result ) => SaveCoreAsync(project, result, persistentService);
public RemoteDesignerAttributeIncrementalAnalyzer(Workspace workspace, RemoteEndPoint endPoint) { _endPoint = endPoint; _storageService = workspace.Services.GetRequiredService <IPersistentStorageService>(); }
public async Task <DiagnosticAnalysisResult> GetAnalysisDataAsync(IPersistentStorageService persistentService, Project project, bool avoidLoadingData, CancellationToken cancellationToken) { // make a copy of last result. var lastResult = _lastResult; Contract.ThrowIfFalse(lastResult.ProjectId == project.Id); if (lastResult.IsDefault) { return(await LoadInitialAnalysisDataAsync(persistentService, project, cancellationToken).ConfigureAwait(false)); } RoslynDebug.Assert(lastResult.DocumentIds != null); // PERF: avoid loading data if version is not right one. // avoid loading data flag is there as a strictly perf optimization. var version = await GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false); if (avoidLoadingData && lastResult.Version != version) { return(lastResult); } // if given project doesnt have any diagnostics, return empty. if (lastResult.IsEmpty) { return(DiagnosticAnalysisResult.CreateEmpty(lastResult.ProjectId, lastResult.Version)); } // loading data can be cancelled any time. var serializer = new DiagnosticDataSerializer(_owner.AnalyzerVersion, lastResult.Version); var builder = new Builder(project, lastResult.Version, lastResult.DocumentIds); foreach (var documentId in lastResult.DocumentIds) { cancellationToken.ThrowIfCancellationRequested(); var document = project.GetDocument(documentId); if (document == null) { continue; } if (!await TryDeserializeDocumentDiagnosticsAsync(persistentService, serializer, document, builder, cancellationToken).ConfigureAwait(false)) { Debug.Assert(lastResult.Version == VersionStamp.Default); // this can happen if we merged back active file diagnostics back to project state but // project state didn't have diagnostics for the file yet. (since project state was staled) continue; } } if (!await TryDeserializeProjectDiagnosticsAsync(persistentService, serializer, project, builder, cancellationToken).ConfigureAwait(false)) { // this can happen if SaveAsync is not yet called but active file merge happened. one of case is if user did build before the very first // analysis happened. } return(builder.ToResult()); }
public InventoryController(ILogger <InventoryController> logger, IPersistentStorageService <InventoryItemViewModel, InventoryItem> persistentStorageService, HealthService healthService) { _logger = logger; _persistentStorageService = persistentStorageService; _healthService = healthService; }