Пример #1
0
 public void OnPairingStateChanged(PairablePerson pairablePerson)
 {
     //Dispatch Brush Change to Main Thread
     Application.Current.Dispatcher.BeginInvoke(new Action(() => {
         //Set Color of Ellipse to Appropriate Color
         PersonEllipse.Stroke = DrawingResources.GetBrushFromPairingState(pairablePerson.PairingState);
     }));
 }
Пример #2
0
 void personRemoved(PersonManager personManager, PairablePerson pairablePerson)
 {
     this.Dispatcher.Invoke(new Action(delegate()
     {
         if (PersonControlDictionary.ContainsKey(pairablePerson))
         {
             canvas.Children.Remove(PersonControlDictionary[pairablePerson]);
             PersonControlDictionary.Remove(pairablePerson);
         }
     }));
 }
Пример #3
0
 void personAdded(PersonManager personManager, PairablePerson pairablePerson)
 {
     this.Dispatcher.Invoke(new Action(delegate()
     {
         if (!PersonControlDictionary.ContainsKey(pairablePerson))
         {
             PersonControlDictionary[pairablePerson] = new PersonControl(pairablePerson);
             canvas.Children.Add(PersonControlDictionary[pairablePerson]);
         }
     }));
 }
Пример #4
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        // #region Process Persons Tests

        internal PairablePerson CreateTestPerson(int newId, int?holdsId = null)
        {
            PairablePerson person = new PairablePerson
            {
                Identifier           = newId.ToString(),
                HeldDeviceIdentifier = holdsId.ToString() ?? null,
                Location             = null,
                Orientation          = null,
                PairingState         = PairingState.NotPaired
            };

            return(person);
        }
        public void GetOffsetAngleTest()
        {
            Setup();

            // Create a person and device, paired and positioned
            PairablePerson person = new PairablePerson
            {
                PairingState         = PairingState.Paired,
                Identifier           = "Bob",
                Location             = new Point(1, 1),
                HeldDeviceIdentifier = "myPad"
            };

            PairableDevice device = new PairableDevice
            {
                HeldByPersonIdentifier = "Bob",
                Identifier             = "myPad",
                Location     = new Point(1, 1),
                PairingState = PairingState.Paired
            };

            // Position the tracker
            //Server.PersonManager.Tracker.Location = new Point(0, 2);
            //Server.PersonManager.Tracker.Orientation = 270;
            Server.Locator.Devices.Add(device);
            Server.Locator.Persons.Add(person);

            Server.Start();
            Client.Start();
            WaitForConnections();

            IARequest request = new IARequest(Routes.GetOffsetAngleRoute);

            request.Parameters["identifier"] = "myPad";

            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception exception)
            {
                double offsetOrientation = double.Parse(response.BodyAsString());
                // The angle between the device and the tracker should be 135 degrees
                Assert.AreEqual(135, offsetOrientation, 0.01);
            });


            Teardown();
        }
        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();
        }
Пример #7
0
        public PersonControl(PairablePerson pairablePerson)
        {
            InitializeComponent();

            person = pairablePerson;

            //Setup Events
            pairablePerson.LocationChanged         += OnLocationChanged;
            pairablePerson.OrientationChanged      += OnOrientationChanged;
            pairablePerson.PairingStateChanged     += OnPairingStateChanged;
            pairablePerson.CalibrationStateChanged += onCalibrationStateChanged;

            //Setup the person's 'dot'
            PersonEllipse.StrokeThickness = DrawingResources.STROKE_WIDTH;
            PersonEllipse.Stroke          = DrawingResources.unpairedBrush;

            // Assuming people have a diameter of about 0.5m
            double personWidth = 0.5 * MainWindow.SharedCanvas.ActualWidth / DrawingResources.ROOM_WIDTH;

            PersonEllipse.Width  = personWidth;
            PersonEllipse.Height = personWidth;


            //Setup the person's identifier
            IdentifierLabel.Content = "ID: " + pairablePerson.Identifier;
            IdentifierLabel.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
            IdentifierLabel.Width = 100;
            Canvas.SetTop(IdentifierLabel, 130);
            Canvas.SetLeft(IdentifierLabel, -5);

            //Setup the person's identifier
            CoordinatesLabel.Content = pairablePerson.Identifier;
            CoordinatesLabel.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
            CoordinatesLabel.Width = 300;
            Canvas.SetTop(CoordinatesLabel, 150);
            Canvas.SetLeft(CoordinatesLabel, -150);
        }
        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();
        }