private static void LoadServices(XmlReader reader, SsdpDevice device) { while (!reader.EOF && reader.NodeType != XmlNodeType.Element) { reader.Read(); } while (!reader.EOF) { while (!reader.EOF && reader.NodeType != XmlNodeType.Element && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "serviceList")) { reader.Read(); } if (reader.LocalName == "service") { var service = new SsdpService(reader.ReadOuterXml()); device.AddService(service); } else { break; } } }
private static void SetServiceTypePropertiesFromFullDeviceType(SsdpService service, string value) { if (String.IsNullOrEmpty(value) || !value.Contains(":")) { service.ServiceType = value; } else { var parts = value.Split(':'); if (parts.Length == 5) { int serviceVersion = 1; if (Int32.TryParse(parts[4], out serviceVersion)) { service.ServiceTypeNamespace = parts[1]; service.ServiceType = parts[3]; service.ServiceVersion = serviceVersion; } else { service.ServiceType = value; } } else { service.ServiceType = value; } } }
private bool SetPropertyFromReader(XmlReader reader, SsdpService service) { switch (reader.LocalName) { case "serviceType": SetServiceTypePropertiesFromFullDeviceType(service, reader.ReadElementContentAsString()); break; case "serviceId": SetServiceIdPropertiesFromFullServiceId(service, reader.ReadElementContentAsString()); break; case "SCPDURL": this.ScpdUrl = StringToUri(reader.ReadElementContentAsString()); break; case "controlURL": this.ControlUrl = StringToUri(reader.ReadElementContentAsString()); break; case "eventSubURL": this.EventSubUrl = StringToUri(reader.ReadElementContentAsString()); break; default: return(false); } return(true); }
/// <summary> /// Constructs a new instance for the specified <see cref="SsdpService"/>. /// </summary> /// <param name="service">The <see cref="SsdpService"/> associated with the event this argument class is being used for.</param> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="service"/> argument is null.</exception> public ServiceEventArgs(SsdpService service) { if (service == null) { throw new ArgumentNullException(nameof(service)); } _Service = service; }
/// <summary> /// Raises the <see cref="ServiceRemoved"/> event. /// </summary> /// <param name="service">The <see cref="SsdpService"/> instance removed from the <see cref="Services"/> collection.</param> /// <seealso cref="RemoveService"/> /// <see cref="ServiceRemoved"/> protected virtual void OnServiceRemoved(SsdpService service) { var handlers = this.ServiceRemoved; if (handlers != null) { handlers(this, new ServiceEventArgs(service)); } }
private static void WriteService(XmlWriter writer, SsdpService service) { writer.WriteStartElement("service"); WriteNodeIfNotEmpty(writer, "serviceType", service.FullServiceType); WriteNodeIfNotEmpty(writer, "serviceId", service.ServiceId); WriteNodeIfNotEmpty(writer, "SCPDURL", service.ScpdUrl); WriteNodeIfNotEmpty(writer, "controlURL", service.ControlUrl); WriteNodeIfNotEmpty(writer, "eventSubURL", service.EventSubUrl); writer.WriteEndElement(); }
private void LoadServiceProperties(XmlReader reader, SsdpService service) { ReadUntilServiceNode(reader); while (!reader.EOF) { if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "service") { reader.Read(); break; } if (!SetPropertyFromReader(reader, service)) { reader.Read(); } } }
private static void SetServiceIdPropertiesFromFullServiceId(SsdpService service, string value) { if (String.IsNullOrEmpty(value) || !value.Contains(":")) { service.ServiceType = value; } else { var parts = value.Split(':'); if (parts.Length == 4) { service.Uuid = parts[3]; } else { service.Uuid = value; } } }
/// <summary> /// Removes a service from the <see cref="Services"/> collection. /// </summary> /// <param name="service">The <see cref="SsdpService"/> instance to remove.</param> /// <remarks> /// <para>If the service is not a member of the <see cref="Services"/> collection, this method does nothing.</para> /// </remarks> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="service"/> argument is null.</exception> /// <seealso cref="ServiceRemoved"/> public void RemoveService(SsdpService service) { if (service == null) { throw new ArgumentNullException(nameof(service)); } bool wasRemoved = false; lock (_Services) { wasRemoved = _Services.Remove(service); } if (wasRemoved) { OnServiceRemoved(service); } }
/// <summary> /// Adds a service to the <see cref="Services"/> collection. /// </summary> /// <param name="service">The <see cref="SsdpService"/> instance to add.</param> /// <remarks> /// <para>If the service is already a member of the <see cref="Services"/> collection, this method does nothing.</para> /// <para>Services should be added to the device before it is added to a publisher.</para> /// </remarks> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="service"/> argument is null.</exception> /// <seealso cref="ServiceAdded"/> public void AddService(SsdpService service) { if (service == null) { throw new ArgumentNullException(nameof(service)); } bool wasAdded = false; lock (_Services) { if (!ChildServiceExists(service)) { _Services.Add(service); wasAdded = true; } } if (wasAdded) { OnServiceAdded(service); } }
private bool ChildServiceExists(SsdpService service) { return((from s in _Services where service.Uuid == s.Uuid select s).Any()); }