protected ServiceHubServiceBase(IServiceProvider serviceProvider, Stream stream) { InstanceId = Interlocked.Add(ref s_instanceId, 1); _disposed = false; // in unit test, service provider will return asset storage, otherwise, use the default one AssetStorage = (AssetStorage)serviceProvider.GetService(typeof(AssetStorage)) ?? AssetStorage.Default; Logger = (TraceSource)serviceProvider.GetService(typeof(TraceSource)); Logger.TraceInformation($"{DebugInstanceString} Service instance created"); _shutdownCancellationSource = new CancellationTokenSource(); ShutdownCancellationToken = _shutdownCancellationSource.Token; // due to this issue - https://github.com/dotnet/roslyn/issues/16900#issuecomment-277378950 // all sub type must explicitly start JsonRpc once everything is // setup _rpc = new JsonRpc(new JsonRpcMessageHandler(stream, stream), this); _rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance); _rpc.Disconnected += OnRpcDisconnected; // we do this since we want to mark Rpc as obsolete but want to set its value for // partner teams until they move. we can't use Rpc directly since we will get // obsolete error and we can't suppress it since it is an error this.GetType().GetField("Rpc", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, _rpc); }
public void InitializeGlobalState(string host, int uiCultureLCID, int cultureLCID, string?serializedSession, CancellationToken cancellationToken) { RunService(() => { // initialize global asset storage AssetStorage.Initialize(this); // serializedSession may be null for testing if (serializedSession != null) { SetGlobalContext(uiCultureLCID, cultureLCID, serializedSession); } // log telemetry that service hub started RoslynLogger.Log(FunctionId.RemoteHost_Connect, KeyValueLogMessage.Create(m => { m["Host"] = host; m["InstanceId"] = InstanceId; })); if (serializedSession != null) { // Set this process's priority BelowNormal. // this should let us to freely try to use all resources possible without worrying about affecting // host's work such as responsiveness or build. Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; } }, cancellationToken); }
public async Task SynchronizeGlobalAssetsAsync(Checksum[] checksums) { using (RoslynLogger.LogBlock(FunctionId.RemoteHostService_SynchronizeGlobalAssetsAsync, Checksum.GetChecksumsLogInfo, checksums, CancellationToken)) { try { var assets = await RoslynServices.AssetService.GetAssetsAsync <object>(checksums, CancellationToken).ConfigureAwait(false); foreach (var asset in assets) { AssetStorage.TryAddGlobalAsset(asset.Item1, asset.Item2); } } catch (IOException) { // stream to send over assets has closed before we // had chance to check cancellation } catch (OperationCanceledException) { // rpc connection has closed. // this can happen if client side cancelled the // operation } } }
protected AssetSource(AssetStorage assetStorage, int sessionId) { _assetStorage = assetStorage; _sessionId = sessionId; _assetStorage.RegisterAssetSource(_sessionId, this); }
public RoslynServices(int scopeId, AssetStorage storage, HostServices hostServices) { _scopeId = scopeId; AssetService = new AssetService(_scopeId, storage, SolutionService.PrimaryWorkspace); SolutionService = new SolutionService(AssetService); CompilationService = new CompilationService(SolutionService); }
public RoslynServices(int scopeId, AssetStorage storage) { _scopeId = scopeId; AssetService = new AssetService(_scopeId, storage); SolutionService = new SolutionService(AssetService); CompilationService = new CompilationService(SolutionService); }
public async Task SynchronizeGlobalAssetsAsync(Checksum[] checksums, CancellationToken cancellationToken) { using (RoslynLogger.LogBlock(FunctionId.RemoteHostService_SynchronizeGlobalAssetsAsync, Checksum.GetChecksumsLogInfo, checksums, cancellationToken)) { var assets = await RoslynServices.AssetService.GetAssetsAsync <object>(checksums, cancellationToken).ConfigureAwait(false); foreach (var asset in assets) { AssetStorage.TryAddGlobalAsset(asset.Item1, asset.Item2); } } }
public RoslynServices(int scopeId, AssetStorage storage, HostServices hostServices) { _scopeId = scopeId; var mefHostExportProvider = (IMefHostExportProvider)hostServices; var primaryWorkspace = mefHostExportProvider.GetExports <PrimaryWorkspace>().Single().Value; var workspace = (RemoteWorkspace)primaryWorkspace.Workspace ?? new RemoteWorkspace(); AssetService = new AssetService(_scopeId, storage, workspace); SolutionService = new SolutionService(AssetService); CompilationService = new CompilationService(SolutionService); }
protected ServiceBase(IServiceProvider serviceProvider, Stream stream, IEnumerable <JsonConverter>?jsonConverters = null) { InstanceId = Interlocked.Add(ref s_instanceId, 1); // in unit test, service provider will return asset storage, otherwise, use the default one AssetStorage = (AssetStorage)serviceProvider.GetService(typeof(AssetStorage)) ?? AssetStorage.Default; Logger = (TraceSource)serviceProvider.GetService(typeof(TraceSource)); Log(TraceEventType.Information, "Service instance created"); // invoke all calls incoming over the stream on this service instance: EndPoint = new RemoteEndPoint(stream, Logger, incomingCallTarget: this, jsonConverters); }
public void InitializeGlobalState(int uiCultureLCID, int cultureLCID, CancellationToken cancellationToken) { RunService(() => { // initialize global asset storage AssetStorage.Initialize(this); if (uiCultureLCID != 0) { EnsureCulture(uiCultureLCID, cultureLCID); } }, cancellationToken); }
public Task SynchronizeGlobalAssetsAsync(PinnedSolutionInfo solutionInfo, Checksum[] checksums, CancellationToken cancellationToken) { return(RunServiceAsync(async() => { using (RoslynLogger.LogBlock(FunctionId.RemoteHostService_SynchronizeGlobalAssetsAsync, Checksum.GetChecksumsLogInfo, checksums, cancellationToken)) { var assetProvider = SolutionService.CreateAssetProvider(solutionInfo, AssetStorage); var assets = await assetProvider.GetAssetsAsync <object>(checksums, cancellationToken).ConfigureAwait(false); foreach (var(checksum, value) in assets) { AssetStorage.TryAddGlobalAsset(checksum, value); } } }, cancellationToken)); }
protected ServiceHubServiceBase(Stream stream, IServiceProvider serviceProvider) { _instanceId = Interlocked.Add(ref s_instanceId, 1); // in unit test, service provider will return asset storage, otherwise, use the default one AssetStorage = (AssetStorage)serviceProvider.GetService(typeof(AssetStorage)) ?? AssetStorage.Default; Logger = (TraceSource)serviceProvider.GetService(typeof(TraceSource)); Logger.TraceInformation($"{DebugInstanceString} Service instance created"); _cancellationTokenSource = new CancellationTokenSource(); CancellationToken = _cancellationTokenSource.Token; Rpc = JsonRpc.Attach(stream, this); Rpc.Disconnected += OnRpcDisconnected; }
protected ServiceHubServiceBase(IServiceProvider serviceProvider, Stream stream) { _instanceId = Interlocked.Add(ref s_instanceId, 1); // in unit test, service provider will return asset storage, otherwise, use the default one AssetStorage = (AssetStorage)serviceProvider.GetService(typeof(AssetStorage)) ?? AssetStorage.Default; Logger = (TraceSource)serviceProvider.GetService(typeof(TraceSource)); Logger.TraceInformation($"{DebugInstanceString} Service instance created"); _cancellationTokenSource = new CancellationTokenSource(); CancellationToken = _cancellationTokenSource.Token; // due to this issue - https://github.com/dotnet/roslyn/issues/16900#issuecomment-277378950 // all sub type must explicitly start JsonRpc once everything is // setup Rpc = new JsonRpc(stream, stream, this); Rpc.Disconnected += OnRpcDisconnected; }
public string Connect(string host, int uiCultureLCID, int cultureLCID, string?serializedSession, CancellationToken cancellationToken) { return(RunService(() => { cancellationToken.ThrowIfCancellationRequested(); // initialize global assert storage AssetStorage.Initialize(this); _primaryInstance = InstanceId; var existing = Interlocked.CompareExchange(ref _host, host, null); // serializedSession may be null for testing if (serializedSession != null) { SetGlobalContext(uiCultureLCID, cultureLCID, serializedSession); } if (existing != null && existing != host) { Log(TraceEventType.Error, $"{host} is given for {existing}"); } // log telemetry that service hub started RoslynLogger.Log(FunctionId.RemoteHost_Connect, KeyValueLogMessage.Create(SetSessionInfo)); if (serializedSession != null) { // Set this process's priority BelowNormal. // this should let us to freely try to use all resources possible without worrying about affecting // host's work such as responsiveness or build. Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; } return _host; }, cancellationToken)); }
protected ServiceBase(IServiceProvider serviceProvider, Stream stream, IEnumerable <JsonConverter> jsonConverters) { InstanceId = Interlocked.Add(ref s_instanceId, 1); _disposed = false; // in unit test, service provider will return asset storage, otherwise, use the default one AssetStorage = (AssetStorage)serviceProvider.GetService(typeof(AssetStorage)) ?? AssetStorage.Default; Logger = (TraceSource)serviceProvider.GetService(typeof(TraceSource)); Logger.TraceInformation($"{DebugInstanceString} Service instance created"); // due to this issue - https://github.com/dotnet/roslyn/issues/16900#issuecomment-277378950 // all sub type must explicitly start JsonRpc once everything is // setup. // we also wires given json converters when creating JsonRpc so that razor or SBD can register // their own converter when they create their own service _rpc = stream.CreateStreamJsonRpc(target: this, Logger, jsonConverters); _rpc.Disconnected += OnRpcDisconnected; // we do this since we want to mark Rpc as obsolete but want to set its value for // partner teams until they move. we can't use Rpc directly since we will get // obsolete error and we can't suppress it since it is an error this.GetType().GetField("Rpc", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, _rpc); }
public AssetService(int scopeId, AssetStorage assetStorage) { _scopeId = scopeId; _assetStorage = assetStorage; }
public Task SynchronizeTextAsync(DocumentId documentId, Checksum baseTextChecksum, IEnumerable <TextChange> textChanges, CancellationToken cancellationToken) { return(RunServiceAsync(async() => { using (RoslynLogger.LogBlock(FunctionId.RemoteHostService_SynchronizeTextAsync, Checksum.GetChecksumLogInfo, baseTextChecksum, cancellationToken)) { var service = SolutionService.PrimaryWorkspace.Services.GetService <ISerializerService>(); if (service == null) { return; } var text = await TryGetSourceTextAsync().ConfigureAwait(false); if (text == null) { // it won't bring in base text if it is not there already. // text needed will be pulled in when there is request return; } var newText = new WrappedText(text.WithChanges(textChanges)); var newChecksum = service.CreateChecksum(newText, cancellationToken); // save new text in the cache so that when asked, the data is most likely already there // // this cache is very short live. and new text created above is ChangedText which share // text data with original text except the changes. // so memory wise, this doesn't put too much pressure on the cache. it will not duplicates // same text multiple times. // // also, once the changes are picked up and put into Workspace, normal Workspace // caching logic will take care of the text AssetStorage.TryAddAsset(newChecksum, newText); } async Task <SourceText?> TryGetSourceTextAsync() { // check the cheap and fast one first. // see if the cache has the source text if (AssetStorage.TryGetAsset <SourceText>(baseTextChecksum, out var sourceText)) { return sourceText; } // do slower one // check whether existing solution has it var document = SolutionService.PrimaryWorkspace.CurrentSolution.GetDocument(documentId); if (document == null) { return null; } // check checksum whether it is there. // since we lazily synchronize whole solution (SynchronizePrimaryWorkspaceAsync) when things are idle, // soon or later this will get hit even if text changes got out of sync due to issues in VS side // such as file is first opened and there is no SourceText in memory yet. if (!document.State.TryGetStateChecksums(out var state) || !state.Text.Equals(baseTextChecksum)) { return null; } return await document.GetTextAsync(cancellationToken).ConfigureAwait(false); } }, cancellationToken)); }
public RemoteHostTestData(AssetStorage assetStorage, RemoteWorkspaceManager workspaceManager, bool isInProc) { AssetStorage = assetStorage; WorkspaceManager = workspaceManager; IsInProc = isInProc; }
public AssetService(int sessionId, AssetStorage assetStorage) { _sessionId = sessionId; _assetStorage = assetStorage; }
public AssetProvider CreateAssetProvider(PinnedSolutionInfo solutionInfo, AssetStorage assetStorage) { var serializerService = Services.GetRequiredService <ISerializerService>(); return(new AssetProvider(solutionInfo.ScopeId, assetStorage, serializerService)); }
public AssetProvider(int scopeId, AssetStorage assetStorage, ISerializerService serializerService) { _scopeId = scopeId; _assetStorage = assetStorage; _serializerService = serializerService; }
protected AssetSource(AssetStorage assetStorage) { _assetStorage = assetStorage; _assetStorage.SetAssetSource(this); }
public static AssetService CreateAssetProvider(PinnedSolutionInfo solutionInfo, AssetStorage assetStorage) { var serializerService = PrimaryWorkspace.Services.GetRequiredService <ISerializerService>(); return(new AssetService(solutionInfo.ScopeId, assetStorage, serializerService)); }
public AssetService(int scopeId, AssetStorage assetStorage, RemoteWorkspace remoteWorkspace) { _serializerService = remoteWorkspace.Services.GetService <ISerializerService>(); _scopeId = scopeId; _assetStorage = assetStorage; }