Exemplo n.º 1
0
        private void GetDeviceInfoClick(object sender, RoutedEventArgs e)
        {
            MSEDevice mseDevice = new MSEDevice() { Identifier = SendToTextBox.Text };

            mseMultiSurface.Locator.Locate(mseDevice, delegate(MSEDevice device) {
                if (device != null)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        DataTextBlock.Text += device.ToString() + "\n\n";
                    }));

                }
                else
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        DataTextBlock.Text += "No Device Found \n\n";
                    }));

                }

            }, delegate(Exception exception) {
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    DataTextBlock.Text = exception.ToString();
                }));
            });
        }
Exemplo n.º 2
0
        public void Parser_EmptyFile()
        {
            MSEMultiSurface target = new MSEMultiSurface(0.0, 0.0, false);

            // Testing empty file
            string[] emptyFile = { };
            MSEDevice ownDevice = new MSEDevice();
            target.ParseConfigurationFile(emptyFile, ownDevice);

            Assert.IsTrue(!ownDevice.Location.HasValue);
            Assert.IsTrue(!ownDevice.Orientation.HasValue);
        }
Exemplo n.º 3
0
        public void Parser_GarbageValue()
        {
            MSEMultiSurface target = new MSEMultiSurface(0.0, 0.0, false);

            // Testing garbage
            string[] garbageValue = { "ASDAWDSD ASCAASASSSFVRSDFFSEFSEFSEFSFSEF;';';AASDASD>AS:>DPASDPA<S?><./,>?A<S?>D,/.,./?A>S<d  as.d,./sd ,as/.", "ASD##@$?>?SDF{++_#_@$)#+_)+_V VV   S FDF SDF location", "location: d233 2aSDASd,/.,/.as,d/.as,das][[[=--=[=-[=-[" };
            MSEDevice ownDevice = new MSEDevice();
            target.ParseConfigurationFile(garbageValue, ownDevice);

            Assert.IsTrue(!ownDevice.Location.HasValue);
            Assert.IsTrue(!ownDevice.Orientation.HasValue);
        }
Exemplo n.º 4
0
        public void Parser_CorrectInput()
        {
            MSEMultiSurface target = new MSEMultiSurface(0.0, 0.0, false);

            // Testing Correct Input
            string[] correctInput = { "location:2.0 2.0", "orientation:90.0" };
            MSEDevice ownDevice = new MSEDevice();
            target.ParseConfigurationFile(correctInput, ownDevice);

            Assert.AreEqual(ownDevice.Orientation.Value, 90.0);
            Assert.AreEqual(ownDevice.Location.Value.ToString(), new Point(2.0, 2.0).ToString());
        }
Exemplo n.º 5
0
        private void setupDataRoute()
        {
            //Setup Data Route
            this.intAirAct.Route(Routes.DataRoute, delegate(IARequest request, IAResponse response)
            {
                //Retrieves the data from the request
                byte[] data = request.Body;

                //Retrieve Device from Request
                MSEDevice originDevice = new MSEDevice();

                // If the sending device disconnects as soon as it sends the message, it will be null here
                if (request.Origin != null)
                {
                    originDevice.Identifier = request.Origin.Name;
                    originDevice.setupNetworkDevice(this.IntAirAct);
                }

                if (originDevice.NetworkDevice == null)
                {
                    logger.TraceEvent(TraceEventType.Error, 0, "MSE Error - A device " + originDevice.Identifier + " has sent data but is not now visible to MSE");
                    originDevice = null;
                }

                //Error Handling
                if (data == null)
                {
                    logger.TraceEvent(TraceEventType.Error, 0, "Received data request did not contain valid data");
                }

                lock (originDevice.threadLock)
                {
                    originDevice.intersectionPoint["x"] = Convert.ToDouble(request.Parameters["x"]);
                    originDevice.intersectionPoint["y"] = Convert.ToDouble(request.Parameters["y"]);

                    //Run Handlers
                    foreach (MSEReceivedDataHandler handler in ReceivedDataHandlers)
                    {
                        handler(data, originDevice, null);
                    }
                }

            });
        }
Exemplo n.º 6
0
        private void LoadConfigurationFile(MSEDevice ownDevice)
        {
            if (!Directory.Exists(CONFIGFILEDIRECTORY))
            {
                Directory.CreateDirectory(CONFIGFILEDIRECTORY);
            }

            if (!File.Exists(CONFIGFILELOCATION))
            {
                System.IO.File.Create(CONFIGFILELOCATION);
            }
            else
            {
                string[] lines = File.ReadAllLines(CONFIGFILELOCATION);
                ParseConfigurationFile(lines, ownDevice);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Parses the configuration file and sets the values in ownDevice
        /// </summary>
        /// <param name="lines">Input strings</param>
        /// <param name="ownDevice">Device to have the values modified</param>
        internal void ParseConfigurationFile(string[] lines, MSEDevice ownDevice)
        {
            foreach (string line in lines)
            {
                string[] s = line.Split(':');

                if (s.Length == 2)
                {
                    switch (s[0])
                    {
                        case "location":

                            // Split on space to get multiple parameters per line
                            string[] location = s[1].Split(' ');

                            try
                            {
                                if (location.Length == 2)
                                {
                                    ownDevice.Location = new System.Windows.Point(Convert.ToDouble(location[0]), Convert.ToDouble(location[1]));
                                }
                            }
                            catch
                            {
                                logger.TraceEvent(TraceEventType.Error, 0, "Configuration File has invalid data for Location field");
                            }

                            break;
                        case "orientation":
                            try
                            {
                                ownDevice.Orientation = Convert.ToDouble(s[1]);
                            }
                            catch
                            {
                                logger.TraceEvent(TraceEventType.Error, 0, "Configuration File has invalid data for Orientation field");
                            }
                            break;
                    }
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Send an image to a target device
 /// </summary>
 /// <param name="image">The image to send</param>
 /// <param name="imageName">The name of the image</param>
 /// <param name="targetDevice">The target device (NOTE - targetDevice.NetworkDevice must not be null)</param>
 /// <param name="gesture">The Gesture used to send the image</param>
 public void SendImage(Image image, String imageName, MSEDevice targetDevice, MSEGesture gesture)
 {
     SendImage(image, imageName, targetDevice.intersectionPoint, targetDevice.NetworkDevice, gesture);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Send a Dictionary to another device
 /// </summary>
 /// <param name="dictionary">The dictionary to send</param>
 /// <param name="dictionaryType">The dictionary type. This is shown on the receiving end and so you can just it to differentiate dictionaries</param>
 /// <param name="targetDevice">The target device (NOTE - targetDevice.NetworkDevice must not be null)</param>
 /// <param name="gesture">The Gesture used to send the image</param>
 public void SendDictionary(Dictionary<string, string> dictionary, String dictionaryType, MSEDevice targetDevice, MSEGesture gesture)
 {
     SendDictionary(dictionary, dictionaryType, targetDevice.intersectionPoint, targetDevice.NetworkDevice, gesture);
 }
Exemplo n.º 10
0
 void mseMultiSurface_Ready(MSEDevice ownDevice)
 {
     Console.WriteLine("Device Ready Url {0}:{1} \n Supported Routes {2}",
         ownDevice.NetworkDevice.Host, ownDevice.NetworkDevice.Port, ownDevice.NetworkDevice.SupportedRoutes);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Notify the server of the device's current Location. Intended for use with stationary devices, since mobile devices can't
        /// determine their own location in the room.
        /// </summary>
        /// <param name="device">The Identifier and Location properties of this MSEDevice will be used for the update.</param>
        /// <param name="success"></param>
        /// <param name="failure"></param>
        public void UpdateDeviceLocation(MSEDevice device, MSESuccessHandler success, MSEErrorHandler failure)
        {
            IARequest updateRequest = new IARequest(Routes.SetLocationRoute);
            updateRequest.SetBodyWith(new IntermediatePoint(device.Location.Value));
            updateRequest.Parameters["identifier"] = device.Identifier;

            IEnumerable devicesSupportingRoutes = this.intAirAct.DevicesSupportingRoute(Routes.SetLocationRoute);
            foreach (IADevice iaDevice in devicesSupportingRoutes)
            {
                this.intAirAct.SendRequest(updateRequest, iaDevice, delegate(IAResponse response, Exception exception)
                {
                    if (exception != null)
                    {
                        failure(exception);
                        return;
                    }
                    else
                    {
                        success();
                    }
                });

                // Break, so that we only send the update to one server
                // How our system should function if there are multiple servers is undefined ...
                break;
            }
        }
Exemplo n.º 12
0
        public MSEMultiSurface(double screenWidthInCm, double screenHeightInCm, bool isMobile)
        {
            this.ScreenWidth = screenWidthInCm;
            this.ScreenHeight = screenHeightInCm;

            //Setup Logging
            logger = new TraceSource("MSEMultiSurface");

            this.isRunning = false;

            //Initialize Our Arrays of Handlers
            this.ReceivedImageHandlers = new List<MSEReceivedImageHandler>();
            this.ReceivedDataHandlers = new List<MSEReceivedDataHandler>();
            this.ReceivedDictionaryHandlers = new List<MSEReceivedDictionaryHandler>();

            //Setup IntAirAct
            this.intAirAct = IAIntAirAct.New();

            this.ownDevice = new MSEDevice();

            LoadConfigurationFile(this.ownDevice);

            //Setup Locator
            this.locator = new MSELocator(IntAirAct);

            //Setup MSE Standard Routes
            this.setupRoutes();

            // Pairing Setup
            if (!isMobile)
            {
                // If we have a location set, we should send it to any server that connencts
                this.IntAirAct.Route(Routes.GetLocationRoute, delegate(IARequest request, IAResponse response)
                {
                    if (!this.OwnDevice().Location.HasValue)
                    {
                        response.StatusCode = 404; // Location not found
                    }
                    else
                    {
                        response.SetBodyWith(new IntermediatePoint(this.OwnDevice().Location.Value));
                    }
                });
            }

            else
            {
                this.setupPairingRoutes();
            }

            // If the server sends us an updated location, we should update our location here
            this.IntAirAct.Route(Routes.SetLocationRoute, delegate(IARequest request, IAResponse response)
            {
                IntermediatePoint p = request.BodyAs<IntermediatePoint>();
                UpdateConfigFileLocation(p);
            });

            // Setup handler for when device is found so we can trigger the Ready Event
            this.IntAirAct.DeviceFound += (delegate(IADevice device, bool ownDevice)
            {
                // If the device we find is ourself, then we are ready and fire the event
                if (ownDevice)
                {
                    if (Ready != null)
                    {
                        this.ownDevice.Identifier = device.Name;
                        this.ownDevice.setupNetworkDevice(this.IntAirAct);
                        Ready(this.ownDevice);
                    }
                }
            });
        }
Exemplo n.º 13
0
        private void setupDictionaryRoute()
        {
            this.IntAirAct.Route(Routes.DictionaryRoute, delegate(IARequest request, IAResponse response)
            {
                //Retrieve the dictionary data
                String dictionaryType = request.Parameters["dictionarytype"];
                Dictionary<string, string> dictionary = request.BodyAs<Dictionary<string, string>>();

                //Retrieve Device from Request
                MSEDevice originDevice = new MSEDevice();

                // If the sending device disconnects as soon as it sends the message, it will be null here
                if (request.Origin != null)
                {
                    originDevice.Identifier = request.Origin.Name;
                    originDevice.setupNetworkDevice(this.IntAirAct);
                }

                //It's possible for a device to post a message and then immediately become disconnected, if this happens we warn and do not provide the device to the handlers
                if (originDevice.NetworkDevice == null)
                {
                    logger.TraceEvent(TraceEventType.Error, 0, "MSE Error - A device has sent a dictionary but is not now visible to MSE");
                    originDevice = null;
                }

                lock (originDevice.threadLock)
                {
                    originDevice.intersectionPoint["x"] = Convert.ToDouble(request.Parameters["x"]);
                    originDevice.intersectionPoint["y"] = Convert.ToDouble(request.Parameters["y"]);

                    //Run Handlers
                    foreach (MSEReceivedDictionaryHandler handler in ReceivedDictionaryHandlers)
                    {
                        handler(dictionary, dictionaryType, originDevice, null);
                    }
                }
            });
        }
Exemplo n.º 14
0
        public void Parser_SlightlyOffValue()
        {
            MSEMultiSurface target = new MSEMultiSurface(0.0, 0.0, false);

            // Testing slightly off formatting that should be acceptable
            string[] slightlyOffValue = { "location: \t2.0    2", "orientation:    \t 90.0" };
            MSEDevice ownDevice = new MSEDevice();
            target.ParseConfigurationFile(slightlyOffValue, ownDevice);

            //         Assert.AreEqual(ownDevice.Orientation.Value, 90.0);
            //         Assert.AreEqual(ownDevice.Location.Value.ToString(), new Point(2.0, 2.0).ToString());
        }
Exemplo n.º 15
0
        public void Parser_SingleLocationValue()
        {
            MSEMultiSurface target = new MSEMultiSurface(0.0, 0.0, false);

            // Testing single value for location
            string[] singleValue = { "location:20.0", "orientation:90.0" };
            MSEDevice ownDevice = new MSEDevice();
            target.ParseConfigurationFile(singleValue, ownDevice);

            Assert.IsTrue(!ownDevice.Location.HasValue);
            Assert.AreEqual(ownDevice.Orientation.Value, 90.0);
        }
Exemplo n.º 16
0
        public void Parser_NegativeValue()
        {
            MSEMultiSurface target = new MSEMultiSurface(0.0, 0.0, false);

            // Testing negative values
            string[] negativeValue = { "location:" + Double.MinValue.ToString("R") + " " + Double.MinValue.ToString("R"), "orientation:" + Double.MinValue.ToString("R") };
            MSEDevice ownDevice = new MSEDevice();
            target.ParseConfigurationFile(negativeValue, ownDevice);

            Assert.AreEqual(ownDevice.Location.Value.ToString(), new Point(Double.MinValue, Double.MinValue).ToString());
            Assert.AreEqual(ownDevice.Orientation.Value, Double.MinValue);
        }
Exemplo n.º 17
0
        public void Parser_LargeValue()
        {
            MSEMultiSurface target = new MSEMultiSurface(0.0, 0.0, false);

            // Testing large values. toString("R") prevents weird rounding that causes overflow
            string[] largeValue = { "location:" + Double.MaxValue.ToString("R") + " " + Double.MaxValue.ToString("R"), "orientation:" + Double.MaxValue.ToString("R") };
            MSEDevice ownDevice = new MSEDevice();
            target.ParseConfigurationFile(largeValue, ownDevice);

            Assert.AreEqual(ownDevice.Location.Value.ToString(), new Point(Double.MaxValue, Double.MaxValue).ToString());
            Assert.AreEqual(ownDevice.Orientation.Value, Double.MaxValue);
        }
Exemplo n.º 18
0
        public void Parser_InvalidRightSide()
        {
            MSEMultiSurface target = new MSEMultiSurface(0.0, 0.0, false);

            // Testing a non double value
            string[] nonDoubleValue = { "location:POTATO POTATO", "orientation:HELLOWORLD" };
            MSEDevice ownDevice = new MSEDevice();
            target.ParseConfigurationFile(nonDoubleValue, ownDevice);

            Assert.IsTrue(!ownDevice.Location.HasValue);
            Assert.IsTrue(!ownDevice.Orientation.HasValue);
        }
Exemplo n.º 19
0
        private void setupImageRoute()
        {
            //Setup Image Route
            this.intAirAct.Route(Routes.ImageRoute, delegate(IARequest request, IAResponse response)
            {
                //Retrieve the name of the image
                string imageName = request.Parameters["imagename"];

                Image image;

                using (MemoryStream stream = new MemoryStream(request.Body))
                {
                    // Saves the image from the RequestBody into a Image
                    image = Image.FromStream(stream);
                }

                //Retrieve Device from Request
                MSEDevice originDevice = new MSEDevice();

                // If the sending device disconnects as soon as it sends the message, it will be null here
                if (request.Origin != null)
                {
                    originDevice.Identifier = request.Origin.Name;
                    originDevice.setupNetworkDevice(this.IntAirAct);
                }

                //It's possible for a device to post a message and then immediately become disconnected, if this happens we warn and do not provide the device to the handlers
                if (originDevice.NetworkDevice == null)
                {
                    logger.TraceEvent(TraceEventType.Error, 0, "MSE Error - A device has sent a dictionary but is not now visible to MSE");
                    originDevice = null;
                }

                lock (originDevice.threadLock)
                {
                    originDevice.intersectionPoint["x"] = Convert.ToDouble(request.Parameters["x"]);
                    originDevice.intersectionPoint["y"] = Convert.ToDouble(request.Parameters["y"]);

                    //Run Handlers
                    foreach (MSEReceivedImageHandler handler in ReceivedImageHandlers)
                    {
                        handler(image, imageName, originDevice, null);
                    }
                }
            });
        }
Exemplo n.º 20
0
        public void Parser_InvalidLeftSide()
        {
            MSEMultiSurface target = new MSEMultiSurface(0.0, 0.0, false);

            // Testing invalid left side
            string[] invalidLeftValue = { "funk rating:20.0", "value:off the charts" };
            MSEDevice ownDevice = new MSEDevice();
            target.ParseConfigurationFile(invalidLeftValue, ownDevice);

            Assert.IsTrue(!ownDevice.Location.HasValue);
            Assert.IsTrue(!ownDevice.Orientation.HasValue);
        }
Exemplo n.º 21
0
        /// <summary>
        /// This method takes an MSEDevice object and 'locates' it. This could be used if the MSEDevice did not have an initial location (i.e. the location and orientation values are nil. Or if the device has become stale and requires an update
        /// </summary>
        /// <param name="device">Device to be located</param>
        /// <param name="success">Success Handler</param>
        /// <param name="failure">Failure Handler</param>
        public void Locate(MSEDevice device, MSESingleDeviceHandler success, MSEErrorHandler failure)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("identifier", this.intAirAct.OwnDevice.Name);

            CallIntAirActRoute(Routes.GetDeviceInfoRoute, parameters, success, failure);
        }
Exemplo n.º 22
0
 /// <summary>
 /// Send Data to another Device
 /// </summary>
 /// <param name="data">The data to send</param>
 /// <param name="targetDevice">The target device (NOTE - targetDevice.NetworkDevice must not be null)</param>
 /// <param name="gesture">The Gesture used to send the image</param>
 public void SendData(byte[] data, MSEDevice targetDevice, MSEGesture gesture)
 {
     SendData(data, targetDevice.intersectionPoint, targetDevice.NetworkDevice, gesture);
 }
Exemplo n.º 23
0
        public void UpdateDeviceOrientation(MSEDevice device, MSESuccessHandler success, MSEErrorHandler failure)
        {
            IARequest request = new IARequest(Routes.SetOrientationRoute);
            request.SetBodyWithString(device.Orientation.Value.ToString());
            request.Parameters["identifier"] = device.Identifier;

            IEnumerable devicesSupportingRoutes = this.intAirAct.DevicesSupportingRoute(Routes.SetOrientationRoute);
            foreach (IADevice iaDevice in devicesSupportingRoutes)
            {
                this.intAirAct.SendRequest(request, iaDevice, delegate(IAResponse response, Exception exception)
                {
                    if (exception != null)
                    {
                        failure(exception);
                        return;
                    }
                    else
                    {
                        success();
                    }
                });

                break;
            }
        }
Exemplo n.º 24
0
 /// <summary>
 /// Searches for IADevice from IntAirAct and assigns it to device. Updates the LastUpdated property
 /// </summary>
 /// <param name="device">Device to be updated</param>
 /// <param name="intAirAct">Instance of IntAirAct</param>
 public static void CompleteDeviceInformation(MSEDevice device, IAIntAirAct intAirAct)
 {
     device.setupNetworkDevice(intAirAct);
     device.LastUpdated = DateTime.Now;
 }