/// <summary>
        /// Creates a programmer-friendly object for using a device
        /// that happens implement a MediaServer.
        /// </summary>
        /// <param name="device"></param>
        public CpMediaServer(UPnPDevice device)
        {
            UPnPService sCM = device.GetServices(CpConnectionManager.SERVICE_NAME)[0];
            UPnPService sCD = device.GetServices(CpContentDirectory.SERVICE_NAME)[0];

            CpConnectionManager cpCM = new CpConnectionManager(sCM);
            CpContentDirectory  cpCD = new CpContentDirectory(sCD);

            UDN = device.UniqueDeviceName;

            if (
                (cpCD.HasAction_GetSearchCapabilities == false) ||
                (cpCD.HasAction_GetSortCapabilities == false) ||
                (cpCD.HasAction_GetSystemUpdateID == false) ||
                (cpCD.HasAction_Browse == false)
                )
            {
                throw new UPnPCustomException(0, "MediaServer does not implement minimum features.");
            }

            this.m_ConnectionManager = cpCM;
            this.m_ContentDirectory  = cpCD;

            //create a virtualized root container with the desired settings
            m_Root     = new CpRootContainer(this);
            m_Root.UDN = device.UniqueDeviceName;
        }
Ejemplo n.º 2
0
        internal void AddRootContainer(CpRootContainer root)
        {
            lock (this.m_Roots)
            {
                if (root.Parent != null)
                {
                    throw new Error_MediaObjectHasParent(root);
                }
                this.m_Roots.Add(root);
                root.SetParent(this);
            }

            IList spiders = this.GetActiveSpiders();

            if (spiders != null)
            {
                Hashtable table   = new Hashtable(spiders.Count);
                ArrayList addThis = new ArrayList(1);
                addThis.Add(root);
                foreach (CdsSpider spider in spiders)
                {
                    if (spider.IsMatch(root))
                    {
                        root.IncrementSpiderMatches();
                        table[spider] = addThis;
                    }
                }

                this.NotifySpidersAdd(table);
            }
        }
        /// <summary>
        /// Used by
        /// <see cref="CpMediaBuilder"/>
        /// to instantiate a root container.
        /// </summary>
        /// <param name="info">metadata information for the container</param>
        /// <returns>the new root container</returns>
        internal static CpRootContainer CreateRoot(MediaBuilder.container info)
        {
            info.ID        = "0";
            info.IdIsValid = true;
            CpRootContainer root = new CpRootContainer();

            MediaBuilder.SetObjectProperties(root, info);
            return(root);
        }
Ejemplo n.º 4
0
        private bool SetContainerContext(ContextInfo ci, IMediaContainer context)
        {
            bool retVal = false;
            bool fwd = false, bk = false;

            // check against forward contexts
            fwd = IsValidContext(context, ci.ForwardContexts, false);

            // check against current/entire context
            if (fwd == false)
            {
                bk = IsValidContext(context, ci.EntireContext, false);
            }

            // if selecting a valid context...
            if (fwd)
            {
                // going forward, so push the desired context
                // to our stack context
                lock (this)
                {
                    ci.m_Context.Push(context);

                    // if new context is a root container, set the server context
                    if ((context.IsRootContainer) && (!(context is CpRootCollectionContainer)))
                    {
                        CpRootContainer root = context as CpRootContainer;
                        if (root != null)
                        {
                            ci.m_ServerContext = root.Server;
                        }
                    }
                }
                retVal = true;
            }
            else if (bk)
            {
                lock (this)
                {
                    // going back, so pop the stack until
                    // we get to the desired context
                    // and then refresh
                    while ((this.CurrentContext != context) && (this.m_Context.m_Context.Count > 1))
                    {
                        this.m_Context.m_Context.Pop();
                    }
                    if (this.m_Context.m_Context.Count == 1)
                    {
                        this.m_Context.m_ServerContext = null;
                    }
                }
                retVal = true;
            }

            return(retVal);
        }
Ejemplo n.º 5
0
        internal void RemoveRootContainer(CpRootContainer root)
        {
            lock (this.m_Roots)
            {
                this.m_Roots.Remove(root);
                root.SetParent(null);
                root.NotifySpidersOfGoneContainer();
            }

            IList spiders = this.GetActiveSpiders();

            if (spiders != null)
            {
                ArrayList removeThese = new ArrayList(1);
                removeThese.Add(root);

                this.NotifySpidersRemove(spiders, removeThese);
            }
        }
        private void ContainerChangedSink(CpRootContainer sender, CpMediaContainer thisChanged)
        {
            if (InvokeRequired) { this.Invoke(new CpRootContainer.Delegate_OnContainerChanged(ContainerChangedSink), sender, thisChanged); return; }

            // Update the tree view
            this.GetSpider(thisChanged);

            // Throw spiders on every child container
            foreach (CpMediaContainer cpc in thisChanged.Containers)
            {
                this.GetSpider(cpc);
            }

            try
            {
                lock (this.m_ContainerToSpider)
                {

                    TreeNode node = NodeTagSearch(cdsRootNode,thisChanged);
                    if (node == null)
                    {
                        //Update on unknown node
                        Event("Container " + thisChanged.Title,"Unknown Container Changed");
                    }
                    else
                    {
                        Event("Container " + thisChanged.Title,"Changed");

                        // get the curren listing of child containers for the
                        // container reporting the change
                        IList newcontainers = thisChanged.Containers;
                        if (newcontainers != null)
                        {
                            ArrayList noderemovelist = new ArrayList();
                            ArrayList existingcontainers = new ArrayList();

                            // iterate through the treeview's representation
                            // of the last known set of child containers
                            foreach (TreeNode n in node.Nodes)
                            {
                                // get the container associated with the node
                                CpMediaContainer c = (CpMediaContainer) n.Tag;

                                if (newcontainers.Contains(c) == false)
                                {
                                    // If the node's container is no longer associated
                                    // with the container, then the node should be removed.
                                    noderemovelist.Add(n);
                                }
                                else
                                {
                                    // If the node's container is still associated with
                                    // the container, then the container and node
                                    // should remain.
                                    existingcontainers.Add(c);
                                }
                            }

                            foreach (TreeNode n in noderemovelist)
                            {
                                this.CleanupRemovedNode(n);

                                // Remove the subtree of tree nodes.
                                // For some reason, we need to remove
                                // all of the nodes after we clean up.
                                // I had memory leaks when the nodes
                                // were removed from within the code
                                // for CleanupRemovedNode()
                                n.Remove();
                            }

                            foreach (CpMediaContainer c in newcontainers)
                            {
                                // Iterate through the new list of containers, but recurse
                                // and update the treeview only with containers that
                                // are brand new.
                                if (existingcontainers.Contains(c) == false)
                                {
                                    TreeNode cNode;
                                    // Depending on the type of container, ensure
                                    // that we use the right icon in the treeview.
                                    if (c.GetType() == typeof(CpRootContainer))
                                    {
                                        cNode = new TreeNode(c.Title,1,1);
                                    }
                                    else
                                    {
                                        cNode = new TreeNode(c.Title,2,3);
                                    }
                                    cNode.Tag = c;
                                    node.Nodes.Add(cNode);
                                    ContainerChangedSink(null,c);
                                }
                            }
                        }
                    }

                    cdsRootNode.Expand();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a programmer-friendly object for using a device
        /// that happens implement a MediaServer.
        /// </summary>
        /// <param name="device"></param>
        public CpMediaServer(UPnPDevice device)
        {
            UPnPService sCM = device.GetServices(CpConnectionManager.SERVICE_NAME)[0];
            UPnPService sCD = device.GetServices(CpContentDirectory.SERVICE_NAME)[0];

            CpConnectionManager cpCM = new CpConnectionManager(sCM);
            CpContentDirectory cpCD = new CpContentDirectory(sCD);

            UDN = device.UniqueDeviceName;

            if (
                (cpCD.HasAction_GetSearchCapabilities == false) ||
                (cpCD.HasAction_GetSortCapabilities == false) ||
                (cpCD.HasAction_GetSystemUpdateID == false) ||
                (cpCD.HasAction_Browse == false)
                )
            {
                throw new UPnPCustomException(0, "MediaServer does not implement minimum features.");
            }

            this.m_ConnectionManager = cpCM;
            this.m_ContentDirectory = cpCD;

            //create a virtualized root container with the desired settings
            m_Root = new CpRootContainer(this);
            m_Root.UDN = device.UniqueDeviceName;
        }
 /// <summary>
 /// Used by 
 /// <see cref="CpMediaBuilder"/>
 /// to instantiate a root container. 
 /// </summary>
 /// <param name="info">metadata information for the container</param>
 /// <returns>the new root container</returns>
 internal static CpRootContainer CreateRoot(MediaBuilder.container info)
 {
     info.ID = "0";
     info.IdIsValid = true;
     CpRootContainer root = new CpRootContainer();
     MediaBuilder.SetObjectProperties(root, info);
     return root;
 }
        internal void RemoveRootContainer(CpRootContainer root)
        {
            lock (this.m_Roots)
            {
                this.m_Roots.Remove(root);
                root.SetParent (null);
                root.NotifySpidersOfGoneContainer();
            }

            IList spiders = this.GetActiveSpiders();
            if (spiders != null)
            {
                ArrayList removeThese = new ArrayList(1);
                removeThese.Add(root);

                this.NotifySpidersRemove(spiders, removeThese);
            }
        }
        internal void AddRootContainer(CpRootContainer root)
        {
            lock (this.m_Roots)
            {
                if (root.Parent != null)
                {
                    throw new Error_MediaObjectHasParent(root);
                }
                this.m_Roots.Add(root);
                root.SetParent(this);
            }

            IList spiders = this.GetActiveSpiders();
            if (spiders != null)
            {
                Hashtable table = new Hashtable(spiders.Count);
                ArrayList addThis = new ArrayList(1);
                addThis.Add(root);
                foreach (CdsSpider spider in spiders)
                {
                    if (spider.IsMatch(root))
                    {
                        root.IncrementSpiderMatches();
                        table[spider] = addThis;
                    }
                }

                this.NotifySpidersAdd(table);
            }
        }
Ejemplo n.º 11
0
 private void OnAllRootsContainerChanged(CpRootContainer sender, CpMediaContainer thisChanged)
 {
     IncrementalFillMediaList();
 }