/// <summary>
        /// Creates a new resource, given a contentUri and a protocolInfo.
        /// </summary>
        /// <param name="contentUri"></param>
        /// <param name="protocolInfo"></param>
        /// <returns></returns>
        public static DvMediaResource CreateResource(string contentUri, string protocolInfo)
        {
            ResourceBuilder.ResourceAttributes attribs = new ResourceBuilder.ResourceAttributes();
            attribs.contentUri = contentUri;
            attribs.protocolInfo = new ProtocolInfoString(protocolInfo);

            return DvResourceBuilder.CreateResource(attribs, false);
        }
        /// <summary>
        /// Creates a new resource, given a contentUri and a protocolInfo.
        /// </summary>
        /// <param name="contentUri"></param>
        /// <param name="protocolInfo"></param>
        /// <returns></returns>
        public static CpMediaResource CreateResource(string contentUri, string protocolInfo)
        {
            ResourceBuilder.ResourceAttributes attribs = new ResourceBuilder.ResourceAttributes();
            attribs.contentUri = contentUri;
            attribs.protocolInfo = new ProtocolInfoString(protocolInfo);

            CpMediaResource newRes = new CpMediaResource();
            ResourceBuilder.SetCommonAttributes(newRes, attribs);

            return newRes;
        }
        protected MediaResource[] BuildResources(string Interface, IDictionaryEnumerator en)
        {
            ArrayList a = new ArrayList();
            while(en.MoveNext())
            {
                FileInfo f = (FileInfo)en.Value;
                MediaResource mr;

                ResourceBuilder.ResourceAttributes resInfo = new ResourceBuilder.ResourceAttributes();
                resInfo.contentUri = "file://" + f.FullName;
                resInfo.protocolInfo = ProtocolInfoString.CreateHttpGetProtocolInfoString(f);

                mr = ResourceBuilder.CreateResource(resInfo);
                OpenSource.UPnP.AV.Extensions.MetaData.Finder.PopulateMetaData(mr,f);

                a.Add(mr);
            }
            return((MediaResource[])a.ToArray(typeof(MediaResource)));
        }
        private void ajax_OnReceive(HTTPSession sender, HTTPMessage msg)
        {
            string query = "";
            HTTPMessage r;

            if (msg.Directive.ToUpper() == "GET" && msg.DirectiveObj.StartsWith("/Query?"))
            {
                query = msg.DirectiveObj.Substring(msg.DirectiveObj.IndexOf("?") + 1);
                if (query == "-1")
                {
                    r = new HTTPMessage("1.1");
                    r.StatusCode = 200;
                    r.StatusData = "OK";
                    r.StringBuffer = ScrapeUI();
                    sender.Send(r);
                }
                if (query == "-2")
                {
                    r = new HTTPMessage("1.1");
                    r.StatusCode = 205;
                    r.StatusData = "OK";
                    sender.Send(r);
                    if (CurrentConnection != null)
                    {
                        CurrentConnection.Play();
                    }
                }
                if (query == "-3")
                {
                    r = new HTTPMessage("1.1");
                    r.StatusCode = 205;
                    r.StatusData = "OK";
                    sender.Send(r);
                    if (CurrentConnection != null)
                    {
                        CurrentConnection.Stop();
                    }
                }
                if (query == "-4")
                {
                    r = new HTTPMessage("1.1");
                    r.StatusCode = 205;
                    r.StatusData = "OK";
                    sender.Send(r);
                    if (CurrentConnection != null)
                    {
                        CurrentConnection.Pause();
                    }
                }
                if (query == "-5")
                {
                    //
                    // Event
                    //
                    lock (SessionQ)
                    {
                        SessionQ.Enqueue(sender);
                    }
                }
                if (query == "-6" || query == "-7")
                {
                    AVRenderer[] Rs = (AVRenderer[])RendererList.ToArray(typeof(AVRenderer));
                    int i = 0;

                    foreach (AVRenderer cr in Rs)
                    {
                        if (cr.UniqueDeviceName == CurrentRenderer.UniqueDeviceName)
                        {
                            break;
                        }
                        ++i;
                    }
                    if (query == "-6")
                    {
                        if (i != 0)
                        {
                            CurrentRenderer = Rs[i - 1];
                            CurrentConnection = (AVConnection)CurrentRenderer.Connections[0];
                            ShowRenderer();
                        }
                    }
                    else
                    {
                        if (i != Rs.Length - 1)
                        {
                            CurrentRenderer = Rs[i + 1];
                            CurrentConnection = (AVConnection)CurrentRenderer.Connections[0];
                            ShowRenderer();
                        }
                    }
                    r = new HTTPMessage("1.1");
                    r.StatusCode = 200;
                    r.StatusData = "OK";
                    r.StringBuffer = ScrapeUI();
                    sender.Send(r);
                }

                if (query.StartsWith("http://"))
                {
                    r = new HTTPMessage("1.1");
                    r.StatusCode = 205;
                    r.StatusData = "OK";
                    sender.Send(r);
                    if (CurrentRenderer != null)
                    {
                        ResourceBuilder.ResourceAttributes resInfo = new ResourceBuilder.ResourceAttributes();
                        resInfo.contentUri = query;
                        resInfo.protocolInfo = new ProtocolInfoString("http-get:*:*:*");
                        CurrentRenderer.OnCreateConnection += new AVRenderer.ConnectionHandler(CreateConnectionSink);
                        CurrentRenderer.OnRecycledConnection += new AVRenderer.ConnectionHandler(CreateConnectionSink);
                        CurrentRenderer.CreateConnection(new MediaResource[1] { ResourceBuilder.CreateResource(resInfo) }, true);
                    }
                }
            }
        }