Exemplo n.º 1
0
        private void BuildRootSignature()
        {
            var texTable = new DescriptorRange(DescriptorRangeType.ShaderResourceView, 1, 0);

            var descriptor1 = new RootDescriptor(0, 0);
            var descriptor2 = new RootDescriptor(1, 0);
            var descriptor3 = new RootDescriptor(2, 0);

            // Root parameter can be a table, root descriptor or root constants.
            // Perfomance TIP: Order from most frequent to least frequent.
            var slotRootParameters = new[]
            {
                new RootParameter(ShaderVisibility.Pixel, texTable),
                new RootParameter(ShaderVisibility.Vertex, descriptor1, RootParameterType.ConstantBufferView),
                new RootParameter(ShaderVisibility.All, descriptor2, RootParameterType.ConstantBufferView),
                new RootParameter(ShaderVisibility.All, descriptor3, RootParameterType.ConstantBufferView)
            };

            // A root signature is an array of root parameters.
            var rootSigDesc = new RootSignatureDescription(
                RootSignatureFlags.AllowInputAssemblerInputLayout,
                slotRootParameters,
                GetStaticSamplers());

            _rootSignature = Device.CreateRootSignature(rootSigDesc.Serialize());
        }
Exemplo n.º 2
0
        public IDescriptorBase GetDir(string path, bool withFiles)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = ".";
            }

            FsoDescriptorBase res;

            if (_descriptors.TryGetValue(path, out res))
            {
                return(res);
            }

            if (string.IsNullOrEmpty(path) || path == ".")
            {
                res  = new RootDescriptor();
                path = ".";
            }
            else
            {
                res = new DirDescriptor(path, withFiles);
            }

            _descriptors.Add(path, res);
            return(res);
        }
Exemplo n.º 3
0
 internal DeviceDescriptor(RootDescriptor rootDescriptor, XPathNavigator deviceNavigator)
 {
     _rootDescriptor  = rootDescriptor;
     _deviceNavigator = deviceNavigator;
     _nsmgr           = new XmlNamespaceManager(_deviceNavigator.NameTable);
     _nsmgr.AddNamespace(DEVICE_DESCRIPTION_NAMESPACE_PREFIX, UPnPConsts.NS_DEVICE_DESCRIPTION);
 }
Exemplo n.º 4
0
 internal DeviceDescriptor(RootDescriptor rootDescriptor, XPathNavigator deviceNavigator)
 {
   _rootDescriptor = rootDescriptor;
   _deviceNavigator = deviceNavigator;
   _nsmgr = new XmlNamespaceManager(_deviceNavigator.NameTable);
   _nsmgr.AddNamespace(DEVICE_DESCRIPTION_NAMESPACE_PREFIX, UPnPConsts.NS_DEVICE_DESCRIPTION);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a <see cref="DeviceDescriptor"/> for the root device from the device description of the given
 /// <paramref name="rootDescriptor"/>.
 /// </summary>
 /// <param name="rootDescriptor">Descriptor for whose root device the <see cref="DeviceDescriptor"/> should be built.</param>
 /// <returns>Device descriptor or <c>null</c>, if the given <paramref name="rootDescriptor"/> doesn't contain a device description
 /// (e.g. if it is erroneous).</returns>
 public static DeviceDescriptor CreateRootDeviceDescriptor(RootDescriptor rootDescriptor)
 {
   XPathDocument xmlDeviceDescription = rootDescriptor.DeviceDescription;
   if (xmlDeviceDescription == null)
     return null;
   XPathNavigator nav = xmlDeviceDescription.CreateNavigator();
   nav.MoveToChild(XPathNodeType.Element);
   XPathNodeIterator rootDeviceIt = nav.SelectChildren("device", "urn:schemas-upnp-org:device-1-0");
   return rootDeviceIt.MoveNext() ? new DeviceDescriptor(rootDescriptor, rootDeviceIt.Current) : null;
 }
Exemplo n.º 6
0
 internal ServiceDescriptor(RootDescriptor rootDescriptor, string serviceType, int serviceTypeVersion, string serviceId,
                            string descriptionURL, string controlURL, string eventSubURL)
 {
     _rootDescriptor     = rootDescriptor;
     _serviceType        = serviceType;
     _serviceTypeVersion = serviceTypeVersion;
     _serviceId          = serviceId;
     _descriptionURL     = descriptionURL;
     _controlURL         = controlURL;
     _eventSubURL        = eventSubURL;
 }
Exemplo n.º 7
0
 internal ServiceDescriptor(RootDescriptor rootDescriptor, string serviceType, int serviceTypeVersion, string serviceId,
     string descriptionURL, string controlURL, string eventSubURL)
 {
   _rootDescriptor = rootDescriptor;
   _serviceType = serviceType;
   _serviceTypeVersion = serviceTypeVersion;
   _serviceId = serviceId;
   _descriptionURL = descriptionURL;
   _controlURL = controlURL;
   _eventSubURL = eventSubURL;
 }
Exemplo n.º 8
0
        protected IResourceInformationService TryGetResourceInformationService(RootDescriptor rootDescriptor)
        {
            DeviceConnection connection;

            using (_networkTracker.SharedControlPointData.Lock.EnterRead())
            {
                object service;
                if (rootDescriptor.SSDPRootEntry.ClientProperties.TryGetValue(KEY_RESOURCE_INFORMATION_SERVICE, out service))
                {
                    return(service as IResourceInformationService);
                }
            }

            DeviceDescriptor rootDevice           = DeviceDescriptor.CreateRootDeviceDescriptor(rootDescriptor);
            DeviceDescriptor frontendServerDevice = rootDevice.FindFirstDevice(
                UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION) ??
                                                    rootDevice.FindFirstDevice(UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE_VERSION);

            if (frontendServerDevice == null)
            {
                return(null);
            }
            string deviceUuid = frontendServerDevice.DeviceUUID;

            try
            {
                connection = _controlPoint.Connect(rootDescriptor, deviceUuid, UPnPExtendedDataTypes.ResolveDataType);
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("Error connecting to UPnP MP2 device '{0}'", e, deviceUuid);
                return(null);
            }
            try
            {
                CpService rasStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.RESOURCE_INFORMATION_SERVICE_ID);
                if (rasStub == null)
                {
                    throw new InvalidDataException("ResourceAccess service not found in device '{0}'", deviceUuid);
                }
                IResourceInformationService ris = new UPnPResourceInformationServiceProxy(rasStub);
                using (_networkTracker.SharedControlPointData.Lock.EnterWrite())
                    rootDescriptor.SSDPRootEntry.ClientProperties[KEY_RESOURCE_INFORMATION_SERVICE] = ris;
                return(ris);
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("Error connecting to services of UPnP MP2 device '{0}'", e, deviceUuid);
                _controlPoint.Disconnect(deviceUuid);
                return(null);
            }
        }
Exemplo n.º 9
0
        public static ServerDescriptor GetMPBackendServerDescriptor(RootDescriptor uPnPRootDescriptor)
        {
            DeviceDescriptor rootDescriptor = DeviceDescriptor.CreateRootDeviceDescriptor(uPnPRootDescriptor);

            if (rootDescriptor == null)
            {
                return(null);
            }
            DeviceDescriptor serverDeviceDescriptor = rootDescriptor.FindFirstDevice(
                UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);

            return(serverDeviceDescriptor == null ? null : new ServerDescriptor(serverDeviceDescriptor));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Reads information about default character set and collation for schema.
        /// </summary>
        private void ReadDefaulCharacterSetAndCollationForSchema()
        {
            // Read schema aditional information
            DataTable table = RootDescriptor.Enumerate(this, null);

            // Exctract default character set and collation names
            if (table != null && table.Rows.Count > 0 &&
                table.Columns.Contains(RootDescriptor.Attributes.DefaultCharset) &&
                table.Columns.Contains(RootDescriptor.Attributes.DefaultCollation))
            {
                defaultCharacterSetVal = DataInterpreter.GetString(table.Rows[0], RootDescriptor.Attributes.DefaultCharset);
                defaultCollationVal    = DataInterpreter.GetString(table.Rows[0], RootDescriptor.Attributes.DefaultCollation);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a <see cref="DeviceDescriptor"/> for the root device from the device description of the given
        /// <paramref name="rootDescriptor"/>.
        /// </summary>
        /// <param name="rootDescriptor">Descriptor for whose root device the <see cref="DeviceDescriptor"/> should be built.</param>
        /// <returns>Device descriptor or <c>null</c>, if the given <paramref name="rootDescriptor"/> doesn't contain a device description
        /// (e.g. if it is erroneous).</returns>
        public static DeviceDescriptor CreateRootDeviceDescriptor(RootDescriptor rootDescriptor)
        {
            XPathDocument xmlDeviceDescription = rootDescriptor.DeviceDescription;

            if (xmlDeviceDescription == null)
            {
                return(null);
            }
            XPathNavigator nav = xmlDeviceDescription.CreateNavigator();

            nav.MoveToChild(XPathNodeType.Element);
            XPathNodeIterator rootDeviceIt = nav.SelectChildren("device", "urn:schemas-upnp-org:device-1-0");

            return(rootDeviceIt.MoveNext() ? new DeviceDescriptor(rootDescriptor, rootDeviceIt.Current) : null);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Given an XML &lt;service&gt; element containing a service description, this method extracts the returned
        /// <see cref="ServiceDescriptor"/>.
        /// </summary>
        /// <param name="rd">Root descriptor of the service descriptor to be built.</param>
        /// <param name="serviceNav">XPath navigator pointing to an XML &lt;service&gt; element containing the service
        /// description.</param>
        /// <returns>Extracted service descriptor.</returns>
        protected ServiceDescriptor ExtractServiceDescriptor(RootDescriptor rd, XPathNavigator serviceNav)
        {
            string descriptionURL = ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":SCPDURL/text()", _nsmgr);
            string serviceType;
            int    serviceTypeVersion;

            if (!ParserHelper.TryParseTypeVersion_URN(ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":serviceType/text()", _nsmgr),
                                                      out serviceType, out serviceTypeVersion))
            {
                throw new ArgumentException("'serviceType' content has the wrong format");
            }
            string controlURL  = ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":controlURL", _nsmgr);
            string eventSubURL = ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":eventSubURL", _nsmgr);

            return(new ServiceDescriptor(rd, serviceType, serviceTypeVersion,
                                         ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":serviceId/text()", _nsmgr), descriptionURL, controlURL, eventSubURL));
        }
        void OnUPnPRootDeviceAdded(RootDescriptor rootDescriptor)
        {
            ClientDescriptor clientDescriptor;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                clientDescriptor = ClientDescriptor.GetMPFrontendServerDescriptor(rootDescriptor);
                if (clientDescriptor == null || _availableClients.Contains(clientDescriptor))
                {
                    return;
                }
                ServiceRegistration.Get <ILogger>().Debug("UPnPServerControlPoint: Found MP 2 client '{0}' (system ID '{1}') at host '{2}' ({3})",
                                                          clientDescriptor.ClientName, clientDescriptor.MPFrontendServerUUID, clientDescriptor.System.HostName,
                                                          _attachedClientSystemIds.Contains(clientDescriptor.MPFrontendServerUUID) ? "attached" : "not attached");
                _availableClients.Add(clientDescriptor);
            }
            InvokeClientAvailable(clientDescriptor);
            CheckConnect(clientDescriptor);
        }
        void OnUPnPRootDeviceRemoved(RootDescriptor rootDescriptor)
        {
            ClientDescriptor clientDescriptor;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                clientDescriptor = ClientDescriptor.GetMPFrontendServerDescriptor(rootDescriptor);
                if (clientDescriptor == null || !_availableClients.Contains(clientDescriptor))
                {
                    return;
                }
                ServiceRegistration.Get <ILogger>().Debug("UPnPServerControlPoint: MP 2 client '{0}' (system ID '{1}') at host '{2}' was removed from the network",
                                                          clientDescriptor.ClientName, clientDescriptor.MPFrontendServerUUID, clientDescriptor.System.HostName);
                _availableClients.Remove(clientDescriptor);
            }
            InvokeClientUnavailable(clientDescriptor);
            // The client connection has its own event handler for disconnects - it will trigger method OnClientDisconnected
            // as result of disconnection, this will remove the client connection from the _clientConnections collection
        }
Exemplo n.º 15
0
        void OnUPnPRootDeviceAdded(RootDescriptor rootDescriptor)
        {
            ICollection <ServerDescriptor> availableServers;

            using (_networkTracker.SharedControlPointData.Lock.EnterWrite())
            {
                ServerDescriptor serverDescriptor = ServerDescriptor.GetMPBackendServerDescriptor(rootDescriptor);
                if (serverDescriptor == null || _availableServers.Contains(serverDescriptor))
                {
                    return;
                }
                SystemName preferredLink = serverDescriptor.GetPreferredLink();
                ServiceRegistration.Get <ILogger>().Debug("UPnPServerWatcher: Found MediaPortal 2 BackendServer '{0}' at host '{1}' (IP address: '{2}')",
                                                          serverDescriptor.ServerName, preferredLink.HostName, preferredLink.Address);
                _availableServers.Add(serverDescriptor);
                availableServers = _availableServers;
            }
            InvokeAvailableBackendServersChanged(availableServers, true);
        }
Exemplo n.º 16
0
        void OnUPnPRootDeviceRemoved(RootDescriptor rootDescriptor)
        {
            ICollection <ServerDescriptor> availableServers;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                ServerDescriptor serverDescriptor = ServerDescriptor.GetMPBackendServerDescriptor(rootDescriptor);
                if (serverDescriptor == null || !_availableServers.Contains(serverDescriptor))
                {
                    return;
                }
                SystemName preferredLink = serverDescriptor.GetPreferredLink();
                ServiceRegistration.Get <ILogger>().Debug("UPnPServerWatcher: MediaPortal 2 BackendServer '{0}' at host '{1}' (IP address: '{2}') was removed from the network",
                                                          serverDescriptor.ServerName, preferredLink.HostName, preferredLink.Address);
                _availableServers.Remove(serverDescriptor);
                availableServers = _availableServers;
            }
            InvokeAvailableBackendServersChanged(availableServers, false);
        }
Exemplo n.º 17
0
        private void OnUpnpRootDeviceRemoved(RootDescriptor rootDescriptor)
        {
            if (rootDescriptor == null || rootDescriptor.SSDPRootEntry == null || rootDescriptor.SSDPRootEntry.RootDeviceUUID == null)
            {
                return;
            }

            string remoteHost = new Uri(rootDescriptor.SSDPRootEntry.PreferredLink.DescriptionLocation).Host;
            string uuid       = rootDescriptor.SSDPRootEntry.RootDeviceUUID;

            if (KnownUpnpRootDevices.ContainsKey(uuid))
            {
                Logger.Info("Media Server - Remove Rootdevice: {0}", rootDescriptor.SSDPRootEntry.RootDeviceUUID);
                TrackedDevice value;
                if (!KnownUpnpRootDevices.TryRemove(uuid, out value))
                {
                    Logger.Error("Media Server: Failed to remove Rootdevice");
                }
            }
        }
Exemplo n.º 18
0
        private void OnUpnpRootDeviceAdded(RootDescriptor rootDescriptor)
        {
            if (rootDescriptor == null || rootDescriptor.State != RootDescriptorState.Ready || _knownUpnpDevices.Contains(rootDescriptor.SSDPRootEntry.RootDeviceUUID))
            {
                return;
            }

            _knownUpnpDevices.Add(rootDescriptor.SSDPRootEntry.RootDeviceUUID);
            DeviceDescriptor          deviceDescriptor = DeviceDescriptor.CreateRootDeviceDescriptor(rootDescriptor);
            IEnumerator <DeviceEntry> childDeviceEn    = rootDescriptor.SSDPRootEntry.Devices.Values.GetEnumerator();
            bool isFirst = true;

            while (childDeviceEn.MoveNext())
            {
                foreach (string serviceUrn in childDeviceEn.Current.Services)
                {
                    // Supported device?
                    if (serviceUrn.Equals("urn:schemas-opencable-com:service:Tuner:1"))
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                            Log.Log.Info("Detected new OCUR/DRI device {0}", deviceDescriptor.FriendlyName);
                        }

                        // Find the corresponding DeviceDescriptor.
                        IEnumerator <DeviceDescriptor> childDeviceDescriptorEn = deviceDescriptor.ChildDevices.GetEnumerator();
                        while (childDeviceDescriptorEn.MoveNext())
                        {
                            if (childDeviceDescriptorEn.Current.DeviceUUID == childDeviceEn.Current.UUID)
                            {
                                break;
                            }
                        }
                        Log.Log.Info("  add {0} {1}", childDeviceDescriptorEn.Current.FriendlyName, childDeviceDescriptorEn.Current.DeviceUDN);
                        _deviceEventListener.OnDeviceAdded(new TunerDri(childDeviceDescriptorEn.Current, _upnpControlPoint));
                        break;
                    }
                }
            }
        }
Exemplo n.º 19
0
        private void OnUpnpRootDeviceRemoved(RootDescriptor rootDescriptor)
        {
            if (rootDescriptor == null)
            {
                return;
            }

            _knownUpnpDevices.Remove(rootDescriptor.SSDPRootEntry.RootDeviceUUID);
            DeviceDescriptor          deviceDescriptor = DeviceDescriptor.CreateRootDeviceDescriptor(rootDescriptor);
            IEnumerator <DeviceEntry> childDeviceEn    = rootDescriptor.SSDPRootEntry.Devices.Values.GetEnumerator();
            bool isFirst = true;

            while (childDeviceEn.MoveNext())
            {
                foreach (string serviceUrn in childDeviceEn.Current.Services)
                {
                    if (serviceUrn.Equals("urn:schemas-opencable-com:service:Tuner:1"))
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                            Log.Log.Info("UPnP device {0} removed", deviceDescriptor.FriendlyName);
                        }

                        IEnumerator <DeviceDescriptor> childDeviceDescriptorEn = deviceDescriptor.ChildDevices.GetEnumerator();
                        while (childDeviceDescriptorEn.MoveNext())
                        {
                            if (childDeviceDescriptorEn.Current.DeviceUUID == childDeviceEn.Current.UUID)
                            {
                                break;
                            }
                        }
                        Log.Log.Info("  remove {0} {1}", childDeviceDescriptorEn.Current.FriendlyName, childDeviceDescriptorEn.Current.DeviceUDN);
                        _deviceEventListener.OnDeviceRemoved(childDeviceDescriptorEn.Current.DeviceUDN);
                        break;
                    }
                }
            }
        }
Exemplo n.º 20
0
        private void BuildRootSignature()
        {
            var descriptor1 = new RootDescriptor(0, 0);
            var descriptor2 = new RootDescriptor(1, 0);
            var descriptor3 = new RootDescriptor(2, 0);

            // Root parameter can be a table, root descriptor or root constants.
            var slotRootParameters = new[]
            {
                new RootParameter(ShaderVisibility.Vertex, descriptor1, RootParameterType.ConstantBufferView),
                new RootParameter(ShaderVisibility.Pixel, descriptor2, RootParameterType.ConstantBufferView),
                new RootParameter(ShaderVisibility.All, descriptor3, RootParameterType.ConstantBufferView)
            };

            // A root signature is an array of root parameters.
            var rootSigDesc = new RootSignatureDescription(
                RootSignatureFlags.AllowInputAssemblerInputLayout,
                slotRootParameters);

            // Create a root signature with a single slot which points to a descriptor range consisting of a single constant buffer.
            _rootSignature = Device.CreateRootSignature(rootSigDesc.Serialize());
        }
Exemplo n.º 21
0
        private string RootDescriptorToString(RootDescriptor param)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("{0}({1}{2}",
                            param.ParameterType.GetDescription(),
                            param.ParameterType.GetRegisterName(),
                            param.ShaderRegister);
            if (param.RegisterSpace != 0)
            {
                sb.AppendFormat(", space={0}", param.RegisterSpace);
            }
            if (param.Flags != RootDescriptorFlags.None)
            {
                sb.AppendFormat(", flags={0}", FormatFlags(param.Flags));
            }
            if (param.ShaderVisibility != ShaderVisibility.All)
            {
                sb.AppendFormat(", visibility={0}", param.ShaderVisibility.GetDescription());
            }
            sb.Append(")");
            return(sb.ToString());
        }
Exemplo n.º 22
0
        private void OnUpnpRootDeviceAdded(RootDescriptor rootDescriptor)
        {
            if (rootDescriptor == null || rootDescriptor.SSDPRootEntry == null || rootDescriptor.SSDPRootEntry.RootDeviceUUID == null || rootDescriptor.State != RootDescriptorState.Ready)
            {
                return;
            }

            string remoteHost = new Uri(rootDescriptor.SSDPRootEntry.PreferredLink.DescriptionLocation).Host;
            string uuid       = rootDescriptor.SSDPRootEntry.RootDeviceUUID;

            if (!KnownUpnpRootDevices.ContainsKey(uuid))
            {
                Logger.Info("Media Server - Adding Rootdevice: {0}", uuid);

                TrackedDevice trackedDevice = new TrackedDevice
                {
                    RootDescriptor = rootDescriptor,
                    RemoteHost     = IPAddress.Parse(remoteHost)
                };

                XPathNavigator navigator = rootDescriptor.DeviceDescription.CreateNavigator();
                XmlTextReader  reader    = new XmlTextReader(new StringReader(navigator.InnerXml));
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Element && reader.NodeType != XmlNodeType.EndElement)
                    {
                        continue;
                    }
                    string nodeName = reader.Name;

                    if (nodeName == "device" && reader.NodeType == XmlNodeType.Element)
                    {
                        while (reader.Read()) // Read the attributes.
                        {
                            if (reader.NodeType != XmlNodeType.Element)
                            {
                                continue;
                            }

                            switch (reader.Name)
                            {
                            case "deviceType":
                                trackedDevice.DeviceType = reader.ReadElementContentAsString();
                                break;

                            case "friendlyName":
                                trackedDevice.FriendlyName = reader.ReadElementContentAsString();
                                break;

                            case "manufacturer":
                                trackedDevice.Manufacturer = reader.ReadElementContentAsString();
                                break;

                            case "manufacturerURL":
                                trackedDevice.ManufacturerUrl = reader.ReadElementContentAsString();
                                break;

                            case "modelDescription":
                                trackedDevice.ModelDescription = reader.ReadElementContentAsString();
                                break;

                            case "modelName":
                                trackedDevice.ModelName = reader.ReadElementContentAsString();
                                break;

                            case "modelNumber":
                                trackedDevice.ModelNumber = reader.ReadElementContentAsString();
                                break;

                            case "modelURL":
                                trackedDevice.ModelUrl = reader.ReadElementContentAsString();
                                break;

                            case "ProductNumber":
                                trackedDevice.ProductNumber = reader.ReadElementContentAsString();
                                break;

                            case "Server":
                                trackedDevice.Server = reader.ReadElementContentAsString();
                                break;

                            case "UDN":
                                trackedDevice.Udn = reader.ReadElementContentAsString();
                                break;
                            }
                        }
                    }
                }

                Logger.Info("Media Server - Tracked Device: {0}", trackedDevice.ToString());

                if (!KnownUpnpRootDevices.TryAdd(uuid, trackedDevice))
                {
                    Logger.Error("Media Server: Failed to add Rootdevice {0}", rootDescriptor.SSDPRootEntry.RootDeviceUUID);
                }
            }
        }
Exemplo n.º 23
0
 private void networkTracker_RootDeviceRemoved(RootDescriptor rootdescriptor)
 {
     ExecuteInUIThread(UpdateTreeView);
 }
        protected void TryConnect(RootDescriptor rootDescriptor)
        {
            DeviceConnection connection;
            string           deviceUuid;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                if (_connection != null)
                {
                    return;
                }
                DeviceDescriptor rootDeviceDescriptor    = DeviceDescriptor.CreateRootDeviceDescriptor(rootDescriptor);
                DeviceDescriptor backendServerDescriptor = rootDeviceDescriptor.FindFirstDevice(
                    UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
                if (backendServerDescriptor == null)
                {
                    return;
                }
                deviceUuid = backendServerDescriptor.DeviceUUID;
                string     friendlyName = backendServerDescriptor.FriendlyName;
                SystemName system       = new SystemName(new Uri(rootDescriptor.SSDPRootEntry.PreferredLink.DescriptionLocation).Host);
                if (deviceUuid == _homeServerSystemId)
                {
                    ServiceRegistration.Get <ILogger>().Debug("UPnPClientControlPoint: Found MP2 home server '{0}' (system ID '{1}') at host '{2}' (IP address: '{3}')",
                                                              friendlyName, deviceUuid, system.HostName, system.Address);
                }
                else
                {
                    ServiceRegistration.Get <ILogger>().Debug("UPnPClientControlPoint: Found foreign MP2 server '{0}' (system ID '{1}') at host '{2}' (IP address: '{3}')",
                                                              friendlyName, deviceUuid, system.HostName, system.Address);
                    return;
                }
                try
                {
                    connection = _connection = _controlPoint.Connect(rootDescriptor, deviceUuid, UPnPExtendedDataTypes.ResolveDataType);
                }
                catch (Exception e)
                {
                    ServiceRegistration.Get <ILogger>().Warn("UPnPClientControlPoint: Error connecting to UPnP MP2 backend server '{0}'", e, deviceUuid);
                    return;
                }
            }
            connection.DeviceDisconnected += OnUPnPDeviceDisconnected;
            try
            {
                CpService cdsStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.CONTENT_DIRECTORY_SERVICE_ID);
                if (cdsStub == null)
                {
                    throw new InvalidDataException("ContentDirectory service not found in device '{0}' of type '{1}:{2}'",
                                                   deviceUuid, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
                }
                CpService risStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.RESOURCE_INFORMATION_SERVICE_ID);
                if (risStub == null)
                {
                    throw new InvalidDataException("ResourceAccess service not found in device '{0}' of type '{1}:{2}'",
                                                   deviceUuid, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
                }
                CpService scsStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.SERVER_CONTROLLER_SERVICE_ID);
                if (scsStub == null)
                {
                    throw new InvalidDataException("ServerController service not found in device '{0}' of type '{1}:{2}'",
                                                   deviceUuid, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
                }
                CpService updmStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.USER_PROFILE_DATA_MANAGEMENT_SERVICE_ID);
                if (updmStub == null)
                {
                    throw new InvalidDataException("UserProfileDataManagement service not found in device '{0}' of type '{1}:{2}'",
                                                   deviceUuid, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
                }
                lock (_networkTracker.SharedControlPointData.SyncObj)
                {
                    _contentDirectoryService          = new UPnPContentDirectoryServiceProxy(cdsStub);
                    _resourceInformationService       = new UPnPResourceInformationServiceProxy(risStub);
                    _serverControllerService          = new UPnPServerControllerServiceProxy(scsStub);
                    _userProfileDataManagementService = new UPnPUserProfileDataManagementServiceProxy(updmStub);
                }

                ICollection <UPnPServiceProxyBase> additionalServices = new List <UPnPServiceProxyBase>();
                foreach (AdditionalServiceRegisterDlgt additionalServiceRegistration in _additionalServiceRegistrations)
                {
                    try
                    {
                        additionalServices.Add(additionalServiceRegistration(connection));
                    }
                    catch (Exception e)
                    {
                        ServiceRegistration.Get <ILogger>().Warn("UPnPClientControlPoint: Error registering user service for UPnP MP2 backend server '{0}'", e, deviceUuid);
                    }
                }
                lock (_networkTracker.SharedControlPointData.SyncObj)
                    _additionalServices = additionalServices;
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("UPnPClientControlPoint: Error connecting to services of UPnP MP2 backend server '{0}'", e, deviceUuid);
                connection.DeviceDisconnected -= OnUPnPDeviceDisconnected;
                _controlPoint.Disconnect(deviceUuid);
                return;
            }
            InvokeBackendServerDeviceConnected(connection);
        }
 void OnUPnPRootDeviceAdded(RootDescriptor rootDescriptor)
 {
     TryConnect(rootDescriptor);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Given an XML &lt;service&gt; element containing a service description, this method extracts the returned
 /// <see cref="ServiceDescriptor"/>.
 /// </summary>
 /// <param name="rd">Root descriptor of the service descriptor to be built.</param>
 /// <param name="serviceNav">XPath navigator pointing to an XML &lt;service&gt; element containing the service
 /// description.</param>
 /// <returns>Extracted service descriptor.</returns>
 protected ServiceDescriptor ExtractServiceDescriptor(RootDescriptor rd, XPathNavigator serviceNav)
 {
   string descriptionURL = ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":SCPDURL/text()", _nsmgr);
   string serviceType;
   int serviceTypeVersion;
   if (!ParserHelper.TryParseTypeVersion_URN(ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":serviceType/text()", _nsmgr),
       out serviceType, out serviceTypeVersion))
     throw new ArgumentException("'serviceType' content has the wrong format");
   string controlURL = ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":controlURL", _nsmgr);
   string eventSubURL = ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":eventSubURL", _nsmgr);
   return new ServiceDescriptor(rd, serviceType, serviceTypeVersion,
       ParserHelper.SelectText(serviceNav, DEVICE_DESCRIPTION_NAMESPACE_PREFIX + ":serviceId/text()", _nsmgr), descriptionURL, controlURL, eventSubURL);
 }