private static void HandleLocation(DeviceInformation device)
        {
            using (WebClient wc = new WebClient())
            {
                try
                {
                    string xmlData = wc.DownloadString(device.Location);

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(xmlData);
                    if (xmlDoc.DocumentElement != null)
                    {
                        XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
                        nsmgr.AddNamespace("dev", xmlDoc.DocumentElement.NamespaceURI);
                        var name = xmlDoc.SelectSingleNode("/dev:root/dev:device/dev:friendlyName", nsmgr);
                        var presentationUrl = xmlDoc.SelectSingleNode("/dev:root/dev:device/dev:presentationURL", nsmgr);
                        var modelName = xmlDoc.SelectSingleNode("/dev:root/dev:device/dev:modelName", nsmgr);
                        var modelDesc = xmlDoc.SelectSingleNode("/dev:root/dev:device/dev:modelDescription", nsmgr);

                        device.FriendlyName = name?.InnerText;
                        device.PresentationUrl = presentationUrl?.InnerText;
                        device.ModelName = modelName?.InnerText;
                        device.ModelDescription = modelDesc?.InnerText;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
        public DeviceInformation Collect(Message message)
        {
            var device = new DeviceInformation();

            if (message.Headers.ContainsKey("USN"))
            {
                device.UniqueId = message.Headers["USN"];
            }

            if (message.Headers.ContainsKey("LOCATION"))
            {
                device.Location = message.Headers["LOCATION"];
                Regex regex = new Regex(@"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)");
                if (regex.IsMatch(device.Location))
                {
                    var m = regex.Match(device.Location);
                    device.HostAddress = m.Groups[0].Value;
                }

                HandleLocation(device);
            }

            if (message.Headers.ContainsKey("SERVER"))
            {
                device.PlatformName = message.Headers["SERVER"];
            }

            return device;
        }
Exemplo n.º 3
0
 private static void LogDevice(DeviceInformation d)
 {
     Log.InfoFormat("Discovered a new device:");
     Log.InfoFormat("FriendlyName  : {0}", d.FriendlyName);
     Log.InfoFormat("ModelName     : {0}", d.ModelName);
     Log.InfoFormat("ModelDesc     : {0}", d.ModelDescription);
     Log.InfoFormat("HostAddress   : {0}", d.HostAddress);
     Log.InfoFormat("Location      : {0}", d.Location);
     Log.InfoFormat("UniqueId      : {0}", d.UniqueId);
     Log.InfoFormat("Platform      : {0}", d.PlatformName);
 }
Exemplo n.º 4
0
        public static void AddOrUpdate(DeviceInformation deviceInformation)
        {
            deviceInformation.LastSeen = DateTime.Now;
            if (Devices.ContainsKey(deviceInformation.UniqueId))
            {
                Devices[deviceInformation.UniqueId] = deviceInformation;
                return;
            }

            Devices.Add(deviceInformation.UniqueId, deviceInformation);

            LogDevice(deviceInformation);
        }
Exemplo n.º 5
0
 public ResponseFactory(DeviceInformation deviceInformation, IMessageParser messageParser)
 {
     _deviceInformation = deviceInformation;
     _messageParser = messageParser;
 }