예제 #1
0
        public UpnpDevice()
        {
            this.server = new UpnpServer(this);

            this.asyncStartDel = new Action(OnStart);
            this.asyncStopDel  = new Action(OnStop);
        }
예제 #2
0
 public ContentDirectoryService(MediaServerDevice device, UpnpServer server) : base(server,
                                                                                    "urn:schemas-upnp-org:service:ContentDirectory:1", "urn:upnp-org:serviceId:ContentDirectory", "/ContentDirectory.control",
                                                                                    "/ContentDirectory.event", "/ContentDirectory.xml")
 {
     this.device = device;
 }
예제 #3
0
 public HttpServer(UpnpServer upnpServer)
 {
     this.upnpServer = upnpServer;
 }
예제 #4
0
 public ConnectionManagerService(MediaServerDevice device, UpnpServer server) : base(server,
                                                                                     "urn:schemas-upnp-org:service:ConnectionManager:1", "urn:upnp-org:serviceId:ConnectionManager", "/ConnectionManager.control",
                                                                                     "/ConnectionManager.event", "/ConnectionManager.xml")
 {
     this.device = device;
 }
예제 #5
0
        public UpnpService(UpnpServer server, string serviceType, string serviceId, string controlUrl, string eventSubUrl, string SCPDURL)
        {
            this.server = server;

            this.serviceType = serviceType;
            this.serviceId   = serviceId;
            this.controlUrl  = controlUrl;
            this.eventSubUrl = eventSubUrl;
            this.SCPDURL     = SCPDURL;

            MemoryStream memStream = new MemoryStream();

            using (XmlTextWriter descWriter = new XmlTextWriter(memStream, new UTF8Encoding(false)))
            {
                descWriter.Formatting = Formatting.Indented;
                descWriter.WriteRaw("<?xml version=\"1.0\"?>");

                descWriter.WriteStartElement("scpd", "urn:schemas-upnp-org:service-1-0");

                descWriter.WriteStartElement("specVersion");
                descWriter.WriteElementString("major", "1");
                descWriter.WriteElementString("minor", "0");
                descWriter.WriteEndElement();

                descWriter.WriteStartElement("actionList");

                MethodInfo[] methods = GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
                foreach (MethodInfo method in methods)
                {
                    IEnumerable <UpnpServiceArgument> methAttribs = method.GetCustomAttributes(typeof(UpnpServiceArgument), true).Cast <UpnpServiceArgument>();
                    ParameterInfo[] parameters = method.GetParameters();

                    if (methAttribs.Count() > 0 || parameters.Any(a => a.GetCustomAttributes(typeof(UpnpServiceArgument), true).Length > 0))
                    {
                        descWriter.WriteStartElement("action");
                        descWriter.WriteElementString("name", method.Name);
                        descWriter.WriteStartElement("argumentList");

                        //Zapisanie vstupnych parametrov
                        foreach (ParameterInfo parameter in parameters)
                        {
                            UpnpServiceArgument paramAttrib = parameter.GetCustomAttributes(typeof(UpnpServiceArgument), true).FirstOrDefault() as UpnpServiceArgument;
                            if (paramAttrib != null)
                            {
                                descWriter.WriteStartElement("argument");
                                descWriter.WriteElementString("name", parameter.Name);
                                descWriter.WriteElementString("direction", "in");
                                descWriter.WriteElementString("relatedStateVariable", paramAttrib.RelatedStateVariable);
                                descWriter.WriteEndElement();
                            }
                        }

                        //Zapisanie vystupnych parametrov
                        foreach (UpnpServiceArgument methAttrib in methAttribs.OrderBy(a => a.Index))
                        {
                            descWriter.WriteStartElement("argument");
                            descWriter.WriteElementString("name", methAttrib.Name);
                            descWriter.WriteElementString("direction", "out");
                            descWriter.WriteElementString("relatedStateVariable", methAttrib.RelatedStateVariable);
                            descWriter.WriteEndElement();
                        }

                        descWriter.WriteEndElement();
                        descWriter.WriteEndElement();
                    }
                }

                descWriter.WriteEndElement();
                descWriter.WriteStartElement("serviceStateTable");

                //Zapisanie premennych
                foreach (UpnpServiceVariable variable in GetType().GetCustomAttributes(typeof(UpnpServiceVariable), true).Cast <UpnpServiceVariable>())
                {
                    descWriter.WriteStartElement("stateVariable");
                    descWriter.WriteAttributeString("sendEvents", variable.SendEvents ? "yes" : "no");
                    descWriter.WriteElementString("name", variable.Name);
                    descWriter.WriteElementString("dataType", variable.DataType);
                    if (variable.AllowedValue.Length > 0)
                    {
                        descWriter.WriteStartElement("allowedValueList");
                        foreach (string value in variable.AllowedValue)
                        {
                            descWriter.WriteElementString("allowedValue", value);
                        }
                        descWriter.WriteEndElement();
                    }
                    descWriter.WriteEndElement();
                }

                descWriter.WriteEndElement();

                descWriter.WriteEndElement();

                descWriter.Flush();
                this.descArray = memStream.ToArray();
            }

            server.HttpServer.AddRoute("GET", SCPDURL, new HttpRouteDelegate(GetDescription));
            server.HttpServer.AddRoute("POST", controlUrl, new HttpRouteDelegate(ProceedControl));
            server.HttpServer.AddRoute("SUBSCRIBE", eventSubUrl, new HttpRouteDelegate(ProceedEventSub));
            server.HttpServer.AddRoute("UNSUBSCRIBE", eventSubUrl, new HttpRouteDelegate(ProceedEventUnsub));
        }
예제 #6
0
        public SsdpServer(UpnpServer upnpServer)
        {
            this.upnpServer = upnpServer;

            NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
        }
예제 #7
0
 public MediaReceiverRegistrarService(MediaServerDevice device, UpnpServer server) : base(server,
                                                                                          "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1", "urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar",
                                                                                          "/X_MS_MediaReceiverRegistrar.control", "/X_MS_MediaReceiverRegistrar.event", "/X_MS_MediaReceiverRegistrar.xml")
 {
     this.device = device;
 }