예제 #1
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);
                    }
                }
            });
        }
예제 #2
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);
                    }
                }

            });
        }
예제 #3
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);
                    }
                }
            });
        }
예제 #4
0
파일: Util.cs 프로젝트: ase-lab/MSEAPI-CS
 /// <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;
 }