private async Task<UserProfileResultMock> CreateProfileClientTestWorkerAsync(string input, CancellationToken ct = default(CancellationToken)) { string jsonResp = null; using (NamedPipeClientStream client = new NamedPipeClientStream("Microsoft.R.Host.UserProfile.Creator{b101cc2d-156e-472e-8d98-b9d999a93c7a}")) { await client.ConnectAsync(ct); byte[] data = Encoding.Unicode.GetBytes(input); await client.WriteAsync(data, 0, data.Length, ct); await client.FlushAsync(ct); byte[] responseRaw = new byte[1024]; var bytesRead = await client.ReadAsync(responseRaw, 0, responseRaw.Length, ct); jsonResp = Encoding.Unicode.GetString(responseRaw, 0, bytesRead); } return Json.DeserializeObject<UserProfileResultMock>(jsonResp); }
private async Task<RUserProfileServiceResponse> ProfileWorkerAsync(string name, string log, RUserProfileServiceRequest request, CancellationToken ct) { using (NamedPipeClientStream client = new NamedPipeClientStream(name)) { try { await client.ConnectAsync(ct); string jsonReq = JsonConvert.SerializeObject(request); byte[] data = Encoding.Unicode.GetBytes(jsonReq.ToString()); await client.WriteAsync(data, 0, data.Length, ct); await client.FlushAsync(ct); byte[] responseRaw = new byte[1024]; var bytesRead = await client.ReadAsync(responseRaw, 0, responseRaw.Length, ct); string jsonResp = Encoding.Unicode.GetString(responseRaw, 0, bytesRead); return Json.DeserializeObject<RUserProfileServiceResponse>(jsonResp); } catch (Exception ex) when (!ex.IsCriticalException()) { _logger.LogError(log, request.Username); return RUserProfileServiceResponse.Blank; } } }