public void Pair(PairableDevice pairingDevice, PairablePerson pairingPerson) { //Change the Pairing State pairingDevice.PairingState = PairingState.Paired; pairingPerson.PairingState = PairingState.Paired; //Create a Holds-Device and Held-By-Person Relationship pairingPerson.HeldDeviceIdentifier = pairingDevice.Identifier; pairingDevice.HeldByPersonIdentifier = pairingPerson.Identifier; List <IADevice> devices = intAirAct.Devices; IADevice device = devices.Find(d => d.Name == pairingDevice.Identifier); if (device != null) { IARequest request = new IARequest(Routes.BecomePairedRoute); intAirAct.SendRequest(request, device, delegate(IAResponse response, Exception exception) { logger.TraceEvent(TraceEventType.Information, 0, "Error notifying Device {0} that it became paired.", pairingDevice.Identifier, pairingPerson.Identifier); }); } logger.TraceEvent(TraceEventType.Information, 0, "Pairing Succeeded with Device {0} and Person {1}", pairingDevice.Identifier, pairingPerson.Identifier); }
public void SuccessfulPairingTest() { Setup(); // Setup the 'became paired' route on the client. Client.Route(Routes.BecomePairedRoute, delegate(IARequest request, IAResponse response) { // In response to receiving 'became paired', we test some properties on the server // Find the mock pairable person we created, test their pairing state PairablePerson person = (PairablePerson)Server.Locator.Persons.Find(x => x.Identifier.Equals("Bob")); Assert.AreEqual(PairingState.Paired, person.PairingState); // Find the Client's IADevice on the server, test its pariing state PairableDevice device = (PairableDevice)Server.Locator.Devices.Find(x => x.Identifier.Equals(Client.OwnDevice.Name)); Assert.AreEqual(PairingState.Paired, device.PairingState); // Test that the two were paired with each other Assert.AreEqual(person.HeldDeviceIdentifier, device.Identifier); Assert.AreEqual(device.HeldByPersonIdentifier, person.Identifier); doneWaitingForResponse = true; }); Server.Start(); Client.Start(); WaitForConnections(); // Create a person on the server, who is attempting to pair their device // NB: Setting PairingAttempt on a person begins a 3 second timer, after which it resets to NotPaired // The test should always complete before then, though Server.Locator.Persons.Add(new PairablePerson() { Identifier = "Bob", Location = new System.Windows.Point(1, 1), PairingState = PairingState.PairingAttempt }); // Notify the server that the client wants to be paired Client.SendRequest(new IARequest(Routes.RequestPairingRoute), Server.IntAirAct.OwnDevice); WaitForResponse(); Teardown(); }
public void SuccessfulPairingTest() { Setup(); // We would like to be able to test the round trip communication, sending 'request pairing' on the client to the server, to sending // 'become paired' from server to client. // But internally, tinyIOC registers things by type, so only the first instance of intairact's server adapter gets retrieved. // All routes are handled by the same IAA instance, which is obviously a problem when we have two in the system that we would like to have talk to each other. // So, at present this part of the test cannot work //Client.Route(Routes.BecomePairedRoute, delegate(IARequest request, IAResponse response) //{ // doneWaitingForResponse = true; //}); Server.Start(); Client.Start(); WaitForConnections(); // Create a person on the server, who is attempting to pair their device // NB: Setting PairingAttempt on a Person begins a 3 second timer, after which their pairing state resets to NotPaired // The test should always complete before then, but if mysterious failures start appearing, it could be time related Server.Locator.Persons.Add(new PairablePerson() { Identifier = "Bob", Location = new System.Windows.Point(1, 1), PairingState = PairingState.PairingAttempt }); // Notify the server that the client wants to be paired IARequest pairingRequest = new IARequest(Routes.RequestPairingRoute); pairingRequest.Origin = Client.OwnDevice; pairingRequest.Parameters["identifier"] = Client.OwnDevice.Name; Client.SendRequest(pairingRequest, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception exception) { if (exception != null) { System.Diagnostics.Debug.WriteLine(exception.Message); Assert.Fail(); } // In response to the return of the request, we test some properties on the server // Find the mock pairable person we created, test their pairing state PairablePerson person = (PairablePerson)Server.Locator.Persons.Find(x => x.Identifier.Equals("Bob")); Assert.AreEqual(PairingState.Paired, person.PairingState); // Find the Client's IADevice on the server, test its pariing state PairableDevice device = (PairableDevice)Server.Locator.Devices.Find(x => x.Identifier.Equals(Client.OwnDevice.Name)); Assert.AreEqual(PairingState.Paired, device.PairingState); // Test that the two were paired with each other Assert.AreEqual(person.HeldDeviceIdentifier, device.Identifier); Assert.AreEqual(device.HeldByPersonIdentifier, person.Identifier); doneWaitingForResponse = true; }); WaitForResponse(); Teardown(); }
private void RemoveOldPeople(List <Skeleton> skeletons, List <PairablePerson> pairablePersons, List <PairableDevice> pairableDevices, String kinectID) { // If a person has dissappeared, remove the kinect ID from they TrackIDwithSkeletonID dictionary List <PairablePerson> vanishedPersons = new List <PairablePerson>(); foreach (PairablePerson person in pairablePersons) { foreach (KeyValuePair <string, string> entry in person.TrackerIDwithSkeletonID.ToList()) { if (entry.Key != null && entry.Key.Equals(kinectID)) { bool found = false; foreach (Skeleton skeleton in skeletons) { if (entry.Value.Equals(skeleton.TrackingId.ToString())) { found = true; } } if (!found) { // Remove from the dictionary person.TrackerIDwithSkeletonID.Remove(kinectID); } } } //If that person is not tracked by anyone then make them an occluded person. if (person.TrackerIDwithSkeletonID.Count == 0) { //Remove Held-By-Person Identifier PairableDevice device = pairableDevices.Find(x => x.Identifier.Equals(person.HeldDeviceIdentifier)); // If the person was not paired to a device, we can remove them immediately if (device == null) { RemovePerson(vanishedPersons, person); } // If the person was paired, then we allow a grace period for them to reappear, to avoid immediately unpairing them else { if (person.PairingState == PairingState.Paired) { person.PairingState = PairingState.PairedButOccluded; person.Identifier = null; } // The person will remain with PairingState == PairedButOccluded for a few seconds, after which it will mark itself NotPaired // If this happens, we remove the person for good, and unpair their device else if (person.PairingState == PairingState.NotPaired) { device.HeldByPersonIdentifier = null; device.PairingState = PairingState.NotPaired; // Dispatch a message to the device IARequest request = new IARequest(Routes.BecomeUnpairedRoute); // Find the IntAirAct device matching the current device. IADevice iaDevice = intAirAct.Devices.Find(d => d.Name == device.Identifier); intAirAct.SendRequest(request, iaDevice); System.Diagnostics.Debug.WriteLine(iaDevice.Name + " " + iaDevice.Host); RemovePerson(vanishedPersons, person); } } } } foreach (PairablePerson person in vanishedPersons) { pairablePersons.Remove(person); } }