public static async Task<RemoteHostClient> CreateAsync( Workspace workspace, CancellationToken cancellationToken) { using (Logger.LogBlock(FunctionId.ServiceHubRemoteHostClient_CreateAsync, cancellationToken)) { var primary = new HubClient("ManagedLanguage.IDE.RemoteHostClient"); var remoteHostStream = await primary.RequestServiceAsync(WellKnownRemoteHostServices.RemoteHostService, cancellationToken).ConfigureAwait(false); var instance = new ServiceHubRemoteHostClient(workspace, primary, remoteHostStream); // make sure connection is done right var current = $"VS ({Process.GetCurrentProcess().Id})"; var host = await instance._rpc.InvokeAsync<string>(WellKnownRemoteHostServices.RemoteHostService_Connect, current).ConfigureAwait(false); // TODO: change this to non fatal watson and make VS to use inproc implementation Contract.ThrowIfFalse(host == current.ToString()); instance.Connected(); // Create a workspace host to hear about workspace changes. We'll // remote those changes over to the remote side when they happen. RegisterWorkspaceHost(workspace, instance); // return instance return instance; } }
private ServiceHubRemoteHostClient(Workspace workspace, HubClient hubClient, Stream stream) : base(workspace) { _hubClient = hubClient; _rpc = JsonRpc.Attach(stream, target: this); // handle disconnected situation _rpc.Disconnected += OnRpcDisconnected; }
private ServiceHubRemoteHostClient( Workspace workspace, HubClient hubClient, HostGroup hostGroup, Stream stream) : base(workspace) { _hubClient = hubClient; _hostGroup = hostGroup; _rpc = JsonRpc.Attach(stream, target: this); _rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance); // handle disconnected situation _rpc.Disconnected += OnRpcDisconnected; }
public static async Task<RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken) { var primary = new HubClient("ManagedLanguage.IDE.RemoteHostClient"); var remoteHostStream = await primary.RequestServiceAsync(WellKnownServiceHubServices.RemoteHostService, cancellationToken).ConfigureAwait(false); var instance = new ServiceHubRemoteHostClient(workspace, primary, remoteHostStream); // make sure connection is done right var current = $"VS ({Process.GetCurrentProcess().Id})"; var host = await instance._rpc.InvokeAsync<string>(WellKnownServiceHubServices.RemoteHostService_Connect, current).ConfigureAwait(false); // TODO: change this to non fatal watson and make VS to use inproc implementation Contract.ThrowIfFalse(host == current.ToString()); instance.Connected(); // return instance return instance; }
/// <summary> /// Gets the number of <see cref="ReportMeasurements"/> in the report. /// </summary> public int GetCount() => HubClient.GetCount();
/// <summary> /// Gets the <see cref="ReportMeasurements"/> for a given page (and sorted by a given Field). /// </summary> /// <param name="ascending"> If the data should be sorted Ascending or Descending</param> /// <param name="page"> the (1 based) pageIndex</param> /// <param name="pageSize"> The number of records in a single page. </param> /// <param name="sortField">The Field by which the data is sorted. </param> public IEnumerable <ReportMeasurements> GetData(string sortField, bool ascending, int page, int pageSize) => HubClient.GetData(sortField, ascending, page, pageSize);
public IEnumerable <StatusLight> GetLights() { return(HubClient.GetStatusLights()); }
public static async Task <ServiceHubRemoteHostClient> CreateWorkerAsync(Workspace workspace, HubClient primary, TimeSpan timeout, CancellationToken cancellationToken) { ServiceHubRemoteHostClient client = null; try { // let each client to have unique id so that we can distinguish different clients when service is restarted var current = CreateClientId(Process.GetCurrentProcess().Id.ToString()); var hostGroup = new HostGroup(current); // Create the RemotableDataJsonRpc before we create the remote host: this call implicitly sets up the remote IExperimentationService so that will be available for later calls var remotableDataRpc = new RemotableDataJsonRpc( workspace, primary.Logger, await Connections.RequestServiceAsync(workspace, primary, WellKnownServiceHubServices.SnapshotService, hostGroup, timeout, cancellationToken).ConfigureAwait(false)); var remoteHostStream = await Connections.RequestServiceAsync(workspace, primary, WellKnownRemoteHostServices.RemoteHostService, hostGroup, timeout, cancellationToken).ConfigureAwait(false); var enableConnectionPool = workspace.Options.GetOption(RemoteHostOptions.EnableConnectionPool); var maxConnection = workspace.Options.GetOption(RemoteHostOptions.MaxPoolConnection); var connectionManager = new ConnectionManager(primary, hostGroup, enableConnectionPool, maxConnection, timeout, new ReferenceCountedDisposable <RemotableDataJsonRpc>(remotableDataRpc)); client = new ServiceHubRemoteHostClient(workspace, primary.Logger, connectionManager, remoteHostStream); var uiCultureLCID = CultureInfo.CurrentUICulture.LCID; var cultureLCID = CultureInfo.CurrentCulture.LCID; // make sure connection is done right var host = await client._rpc.InvokeWithCancellationAsync <string>( nameof(IRemoteHostService.Connect), new object[] { current, uiCultureLCID, cultureLCID, TelemetryService.DefaultSession.SerializeSettings() }, cancellationToken).ConfigureAwait(false); return(client); } catch (ConnectionLostException ex) { RemoteHostCrashInfoBar.ShowInfoBar(workspace, ex); Shutdown(client, ex, cancellationToken); // dont crash VS because OOP is failed to start. we will show info bar telling users to restart // but never physically crash VS. throw new SoftCrashException("Connection Lost", ex, cancellationToken); } catch (Exception ex) { Shutdown(client, ex, cancellationToken); throw; }
public void TerminateSubscriptions() { HubClient.TerminateSubscriptions(); }
public void StatSubscribe(string filterExpression) { HubClient.UpdateStatisticsDataSubscription(filterExpression); }
public string DeriveString(ushort[] values) { return(HubClient.DeriveString(values)); }
public IEnumerable <SchemaVersion> GetSchemaVersion() { return(HubClient.GetSchemaVersion()); }
public Task WriteCoils(ushort startAddress, bool[] data) { return(HubClient.WriteCoils(startAddress, data)); }
public Task WriteHoldingRegisters(ushort startAddress, ushort[] data) { return(HubClient.WriteHoldingRegisters(startAddress, data)); }
public Task <ushort[]> ReadHoldingRegisters(ushort startAddress, ushort pointCount) { return(HubClient.ReadHoldingRegisters(startAddress, pointCount)); }
public Task <bool[]> ReadCoils(ushort startAddress, ushort pointCount) { return(HubClient.ReadCoils(startAddress, pointCount)); }
private static async Task<Stream> RequestServiceAsync(HubClient client, string serviceName, string hostGroup, CancellationToken cancellationToken = default(CancellationToken)) { const int max_retry = 10; const int retry_delayInMS = 50; // call to get service can fail due to this bug - devdiv#288961 // until root cause is fixed, we decide to have retry rather than fail right away for (var i = 0; i < max_retry; i++) { cancellationToken.ThrowIfCancellationRequested(); try { var descriptor = new ServiceDescriptor(serviceName) { HostGroup = new HostGroup(hostGroup) }; return await client.RequestServiceAsync(descriptor, cancellationToken).ConfigureAwait(false); } catch (RemoteInvocationException ex) { // RequestServiceAsync should never fail unless service itself is actually broken. // right now, we know only 1 case where it can randomly fail. but there might be more cases so // adding non fatal watson here. FatalError.ReportWithoutCrash(ex); } // wait for retry_delayInMS before next try await Task.Delay(retry_delayInMS, cancellationToken).ConfigureAwait(false); } return Contract.FailWithReturn<Stream>("Fail to get service. look FatalError.s_reportedException for more detail"); }
/// <summary> /// Sends a service command. /// </summary> /// <param name="command">Command string.</param> public void SendCommand(string command) => HubClient.SendCommand(command);
public float DeriveSingle(ushort highValue, ushort lowValue) { return(HubClient.DeriveSingle(highValue, lowValue)); }
public void GivenAHubIsListeningAtHttpLocalhostPublish(string url) { var hubClient = new HubClient(url); ScenarioContext.Current.Add("HubClient", hubClient); }
public double DeriveDouble(ushort b3, ushort b2, ushort b1, ushort b0) { return(HubClient.DeriveDouble(b3, b2, b1, b0)); }
public void InitializeSubscriptions() { HubClient.InitializeSubscriptions(); }
public uint DeriveUInt32(ushort highValue, ushort lowValue) { return(HubClient.DeriveUInt32(highValue, lowValue)); }
public void UpdateFilters(string filterExpression) { HubClient.UpdatePrimaryDataSubscription(filterExpression); }
public ulong DeriveUInt64(ushort b3, ushort b2, ushort b1, ushort b0) { return(HubClient.DeriveUInt64(b3, b2, b1, b0)); }
public IEnumerable <MeasurementValue> GetStats() { return(HubClient.GetStatistics()); }
public Task <bool> ModbusConnect(string connectionString) { return(HubClient.Connect(connectionString)); }
public IEnumerable <DeviceDetail> GetDeviceDetails() { return(HubClient.GetDeviceDetails()); }
public void ModbusDisconnect() { HubClient.Disconnect(); }
public static async Task <Stream> RequestServiceAsync( Workspace workspace, HubClient client, string serviceName, HostGroup hostGroup, TimeSpan timeout, CancellationToken cancellationToken) { const int max_retry = 10; const int retry_delayInMS = 50; RemoteInvocationException lastException = null; var descriptor = new ServiceDescriptor(serviceName) { HostGroup = hostGroup }; // call to get service can fail due to this bug - devdiv#288961 or more. // until root cause is fixed, we decide to have retry rather than fail right away for (var i = 0; i < max_retry; i++) { try { // we are wrapping HubClient.RequestServiceAsync since we can't control its internal timeout value ourselves. // we have bug opened to track the issue. // https://devdiv.visualstudio.com/DefaultCollection/DevDiv/Editor/_workitems?id=378757&fullScreen=false&_a=edit // retry on cancellation token since HubClient will throw its own cancellation token // when it couldn't connect to service hub service for some reasons // (ex, OOP process GC blocked and not responding to request) // // we have double re-try here. we have these 2 seperated since 2 retries are for different problems. // as noted by 2 different issues above at the start of each 2 different retries. // first retry most likely deal with real issue on servicehub, second retry (cancellation) is to deal with // by design servicehub behavior we don't want to use. return(await RetryRemoteCallAsync <OperationCanceledException, Stream>( workspace, () => client.RequestServiceAsync(descriptor, cancellationToken), timeout, cancellationToken).ConfigureAwait(false)); } catch (RemoteInvocationException ex) { // save info only if it failed with different issue than before. if (lastException?.Message != ex.Message) { // RequestServiceAsync should never fail unless service itself is actually broken. // So far, we catched multiple issues from this NFW. so we will keep this NFW. ex.ReportServiceHubNFW("RequestServiceAsync Failed"); lastException = ex; } } // wait for retry_delayInMS before next try await Task.Delay(retry_delayInMS, cancellationToken).ConfigureAwait(false); } RemoteHostCrashInfoBar.ShowInfoBar(workspace, lastException); // raise soft crash exception rather than doing hard crash. // we had enough feedback from users not to crash VS on servicehub failure throw new SoftCrashException("RequestServiceAsync Failed", lastException, cancellationToken); }
private static async Task<Stream> RequestServiceAsync(HubClient client, string serviceName, string hostGroup, CancellationToken cancellationToken = default(CancellationToken)) { // we can remove these once whole system moved to new servicehub API try { var descriptor = new ServiceDescriptor(serviceName) { HostGroup = new HostGroup(hostGroup) }; return await client.RequestServiceAsync(descriptor, cancellationToken).ConfigureAwait(false); } catch { return await client.RequestServiceAsync(serviceName, cancellationToken).ConfigureAwait(false); } }
/// <summary> /// Gets Progress of current Report. /// </summary> public double GetReportProgress() => HubClient.GetReportProgress();
public IEnumerable <MeasurementDetail> GetMeasurementDetails() { return(HubClient.GetMeasurementDetails()); }
/// <summary> /// Updates the Report Data Source. /// </summary> /// <param name="startDate">Start date of the Report.</param> /// <param name="endDate">End date of the Report.</param> /// <param name="reportType"> Type of Report <see cref="ReportType"/>.</param> /// <param name="reportCriteria"> Crtieria to use for Report <see cref="ReportCriteria"/>.</param> /// <param name="number">Number of records included 0 for all records.</param> /// <param name="dataContext">DataContext from which the available reportingParameters are pulled <see cref="DataContext"/>.</param> public void UpdateReportSource(DateTime startDate, DateTime endDate, ReportCriteria reportCriteria, ReportType reportType, int number, DataContext dataContext) { HubClient.UpdateReportSource(startDate, endDate, reportCriteria, reportType, number, dataContext); }
public IEnumerable <PhasorDetail> GetPhasorDetails() { return(HubClient.GetPhasorDetails()); }
public Task <bool[]> ReadDiscreteInputs(ushort startAddress, ushort pointCount) { return(HubClient.ReadDiscreteInputs(startAddress, pointCount)); }
public static async Task <ServiceHubRemoteHostClient> CreateWorkerAsync(Workspace workspace, HubClient primary, TimeSpan timeout, CancellationToken cancellationToken) { ServiceHubRemoteHostClient client = null; try { // let each client to have unique id so that we can distinguish different clients when service is restarted var current = CreateClientId(Process.GetCurrentProcess().Id.ToString()); var hostGroup = new HostGroup(current); var remoteHostStream = await Connections.RequestServiceAsync(workspace, primary, WellKnownRemoteHostServices.RemoteHostService, hostGroup, timeout, cancellationToken).ConfigureAwait(false); var remotableDataRpc = new RemotableDataJsonRpc( workspace, primary.Logger, await Connections.RequestServiceAsync(workspace, primary, WellKnownServiceHubServices.SnapshotService, hostGroup, timeout, cancellationToken).ConfigureAwait(false)); var enableConnectionPool = workspace.Options.GetOption(RemoteHostOptions.EnableConnectionPool); var maxConnection = workspace.Options.GetOption(RemoteHostOptions.MaxPoolConnection); var connectionManager = new ConnectionManager(primary, hostGroup, enableConnectionPool, maxConnection, timeout, new ReferenceCountedDisposable <RemotableDataJsonRpc>(remotableDataRpc)); client = new ServiceHubRemoteHostClient(workspace, connectionManager, remoteHostStream); var uiCultureLCID = CultureInfo.CurrentUICulture.LCID; var cultureLCID = CultureInfo.CurrentCulture.LCID; // make sure connection is done right var host = await client._rpc.InvokeWithCancellationAsync <string>( nameof(IRemoteHostService.Connect), new object[] { current, uiCultureLCID, cultureLCID, TelemetryService.DefaultSession.SerializeSettings() }, cancellationToken).ConfigureAwait(false); return(client); } catch (Exception ex) { // make sure we shutdown client if initializing client has failed. client?.Shutdown(); // translate to our own cancellation if it is raised. cancellationToken.ThrowIfCancellationRequested(); // otherwise, report watson and throw original exception ex.ReportServiceHubNFW("ServiceHub creation failed"); throw; } }