async void Hookup() { var deviceName = ConfigurationManager.AppSettings["DeviceName"]; CurrentDevice = PTZDevice.GetDevice(deviceName, PTZType.Relative); var url = ConfigurationManager.AppSettings["relayServerUrl"]; var remoteGroup = Environment.MachineName; //They have to hardcode the group, but for us it's our machine name var connection = new HubConnection(url); var proxy = connection.CreateHubProxy("RelayHub"); proxy.On<int, int>("Move", (x, y) => { Console.WriteLine("Move({0},{1})", x, y); BoxContext.Log.DebugFormat("Move({0},{1})", x, y); CurrentDevice.Move(x, y); }); proxy.On<int>("Zoom", (z) => { Console.WriteLine("Zoom ({0})", z); BoxContext.Log.DebugFormat("Zoom ({0})", z); CurrentDevice.Zoom(z); }); try { await connection.Start(); BoxContext.Log.DebugFormat("After connection.Start()"); await proxy.Invoke("JoinRelay", remoteGroup); BoxContext.Log.DebugFormat("After JoinRelay"); BoxContext.Log.DebugFormat("Joined remote group - " + remoteGroup); } catch (Exception pants) { BoxContext.Log.ErrorFormat(pants.GetError().ToString()); throw; } }
private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { var deviceName = ConfigurationManager.AppSettings["DeviceName"]; device = PTZDevice.GetDevice(deviceName, PTZType.Relative); url = ConfigurationManager.AppSettings["relayServerUrl"]; remoteGroup = Environment.MachineName; //They have to hardcode the group, but for us it's our machine name connection = new HubConnection(url); proxy = connection.CreateHubProxy("RelayHub"); connection.TraceLevel = TraceLevels.StateChanges | TraceLevels.Events; connection.TraceWriter = new PTZRemoteTraceWriter(Log); //Can't do this here because DirectShow has to be on the UI thread! // This would cause an obscure COM casting error with no clue what's up. So, um, ya. //proxy.On<int, int>("Move",(x,y) => device.Move(x, y)); //proxy.On<int>("Zoom", (z) => device.Zoom(z)); magic = SynchronizationContext.Current; proxy.On<int, int>("Move", (x, y) => { //Toss this over the fence from this background thread to the UI thread magic.Post((_) => { Log(String.Format("Move({0},{1})", x,y)); device.Move(x, y); }, null); }); proxy.On<int>("Zoom", (z) => { magic.Post((_) => { Log(String.Format("Zoom({0})", z)); device.Zoom(z); }, null); }); try { await connection.Start(); Log("After connection.Start()"); await proxy.Invoke("JoinRelay", remoteGroup); Log("After JoinRelay"); } catch (Exception pants) { Log(pants.GetError().ToString()); throw; } }
private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { var deviceName = ConfigurationManager.AppSettings["DeviceName"]; device = PTZDevice.GetDevice(deviceName, PTZType.Relative); url = ConfigurationManager.AppSettings["relayServerUrl"]; remoteGroup = Environment.MachineName; //They have to hardcode the group, but for us it's our machine name connection = new HubConnection(url); proxy = connection.CreateHubProxy("RelayHub"); connection.TraceLevel = TraceLevels.StateChanges | TraceLevels.Events; connection.TraceWriter = new PTZRemoteTraceWriter(Log); magic = SynchronizationContext.Current; proxy.On<int, int>("Move", (x, y) => magic.Post((_) => { Log(String.Format("Move({0},{1})", x, y)); device.Move(x, y); }, null)); proxy.On<int>("Zoom", (z) => magic.Post((_) => { Log(String.Format("Zoom({0})", z)); device.Zoom(z); }, null)); try { await connection.Start(); Log("After connection.Start()"); await proxy.Invoke("JoinRelay", remoteGroup); Log("After JoinRelay"); Log("Joined remote group - " + remoteGroup); } catch (Exception pants) { Log(pants.GetError().ToString()); throw; } }
public CameraController() { _myCamera = PTZDevice.GetDevice(DeviceName, PTZType.Relative); }