private void ConnectOrReconnect() { try { // Close active connections (if restarting) headTrackingService?.Dispose(); controllerService?.Dispose(); broadcastProxy?.Dispose(); // Give it some time to clean up Thread.Sleep(10); // Connect to the services headTrackingService = new TrackingService(apiClient.CreateProxy <HeadTrackingProxy>()); controllerService = new ControllerService(apiClient.CreateProxy <ControllerProxy>()); broadcastProxy = apiClient.CreateProxy <BroadcastProxy>(); broadcastProxy.HapticPulseReceived += OnHapticFeedbackReceived; headTrackingService.ChangeStatus(IsControllingHeadTracking); } catch (Exception x) { MessageBox.Show(x.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void ConnectOrReconnect() { try { // Connect to the services headTrackingService = new TrackingService(apiClient.CreateProxy <HeadTrackingProxy>()); controllerService = new ControllerService(apiClient.CreateProxy <ControllerProxy>()); controllerService2 = new ControllerService(apiClient.CreateProxy <ControllerProxy>()); //controllerService3 = new ControllerService(apiClient.CreateProxy<ControllerProxy>()); //controllerService4 = new ControllerService(apiClient.CreateProxy<ControllerProxy>()); broadcastProxy = apiClient.CreateProxy <BroadcastProxy>(); headTrackingService.ChangeStatus(true); } catch (Exception e) { Console.WriteLine(e.Message); } }
// Sets up connection and returns true if all links are established. private bool TrySettingUpConnection() { lastConnectionAttempt = DateTime.Now; // Make sure API server is alive var status = api.GetStatus(timeoutThresholdMs); if (status == null) { return(false); } // Reset current connections, if exist DisconnectAllEndpoints(); try { if (capabilities.HasFlag(Capabilities.HeadTracking)) { var endpointStatus = status.Endpoints.FirstOrDefault(x => x.Name == EndpointNames.HeadTracking); if (endpointStatus == null || endpointStatus.Code != (int)ControlResponseCode.OK) { return(false); } head = new HeadRemote(api.CreateProxy <HeadTrackingProxy>()); } if (capabilities.HasFlag(Capabilities.Controllers)) { var endpointStatus = status.Endpoints.FirstOrDefault(x => x.Name == EndpointNames.Controller); if (endpointStatus == null || endpointStatus.Code != (int)ControlResponseCode.OK) { return(false); } controller = new ControllerRemote(api.CreateProxy <ControllerProxy>()); } // Subscribe to haptic pulse broadcasts, if controller proxy is in use if (controller != null) { broadcasts = api.CreateProxy <BroadcastProxy>(); // Forward the events to long-lived event so API user doesn't // have to resubscribe on reconnect broadcasts.HapticPulseReceived += (s, e) => HapticPulse?.Invoke(this, e); } return(true); } catch (Exception x) { Logger.Error("Error during API connection: " + x); // Cleanup possibly connected endpoints DisconnectAllEndpoints(); } return(false); }