Example #1
0
        public static XmlDocument GetItems(IUPnPService svc, string containerID, string criteria, string filter, int startItem, int count)
        {
            XmlDocument doc = new XmlDocument();

            object results;
            object retVal;
            int    hr = svc.InvokeAction("Browse", new object[] { containerID, criteria, filter, startItem, count, "" }, out results, out retVal);

            if (hr == 0)
            {
                doc.LoadXml(((object[])results)[0].ToString());
            }
            return(doc);
        }
Example #2
0
        // Checks if device supports Content Directory service and opens a browser on it
        private void BrowseDevice(IUPnPDevice device)
        {
            // Get service enumerator
            IntPtr       pE    = device.Services._NewEnum;
            IEnumUnknown pEnum = (IEnumUnknown)Marshal.GetObjectForIUnknown(pE);

            Marshal.Release(pE);

            // Enumerate services. Look for one that has ContentDirectory in its description
            uint         cItems;
            IUPnPService svc         = null;
            IUPnPService svcContent  = null;
            bool         couldBrowse = false;

            while (pEnum.Next(1, out pE, out cItems) == 0 && cItems == 1)
            {
                svc = (IUPnPService)Marshal.GetObjectForIUnknown(pE);
                Marshal.Release(pE);

                object results;// = new object[3];
                object retVal;
                if (svc.ServiceTypeIdentifier.IndexOf("ContentDirectory", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    // Check if the service supports Browse verb
                    // This is not really neccessary, but just a precaution
                    svcContent = svc;
                    int hr = svc.InvokeAction("Browse", new object[] { "0", "BrowseDirectChildren", "*", 0, 0, "" }, out results, out retVal);
                    if (hr == 0)
                    {
                        couldBrowse = true;
                    }
                    hr = 0;
                }
            }

            if (!couldBrowse || svcContent == null)
            {
                MessageBox.Show("Found no browsable content");
            }
            else
            {
                // We have found the Content Directory
                Browser browser = new Browser(svcContent);
                browser.ShowDialog();
            }
        }
Example #3
0
        /// <summary>
        /// Invokes an action.
        /// </summary>
        /// <param name="name">The name of the action.</param>
        /// <param name="inParams">The in parameters for the action.</param>
        /// <returns>An array of objects representing the out parameters for the action.</returns>
        /// <exception cref="UPnPException"></exception>
        /// <exception cref="MissingMethodException">Action not found or failed.</exception>
        /// <exception cref="NotSupportedException">Underlying native service is null.</exception>
        public object[] InvokeAction(string name, params object[] inParams)
        {
            try
            {
                if (msCOMService != null)
                {
                    object[] laIn = inParams;
                    if (laIn == null)
                    {
                        laIn = new object[] { }
                    }
                    ;

                    object loOut = null;

                    object loResult = msCOMService.InvokeAction(name, laIn, ref loOut);

                    if (loResult != null)
                    {
                        throw new MissingMethodException(
                                  string.Format(
                                      "({0}) => {1} failed with {2} result",
                                      msCOMService.ServiceTypeIdentifier, name, loResult));
                    }

                    return((object[])loOut);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            catch (COMException loE)
            {
                throw new UPnPException(loE);
            }
        }