protected static void PopulateDeviceStructs(CodeProcessor cs, UPnPDevice d)
        {
            foreach(UPnPDevice ed in d.EmbeddedDevices)
            {
                PopulateDeviceStructs(cs,ed);
            }
            cs.Append("struct UPnP_Device_"+d.User2.ToString()+" UPnP_Device_"+d.User2.ToString()+"_Impl = "+cs.NewLine);
            cs.Append("{"+cs.NewLine);
            foreach(UPnPService s in d.Services)
            {
                cs.Append("	&UPnP_Service_"+((ServiceGenerator.ServiceConfiguration)s.User).Name+"_Impl,"+cs.NewLine);
            }
            cs.Append(cs.NewLine);
            foreach(UPnPDevice ed in d.EmbeddedDevices)
            {
                cs.Append("	&UPnP_Device_"+ed.User2.ToString()+"_Impl,"+cs.NewLine);
            }
            cs.Append("	NULL,"+cs.NewLine); // Friendly
            if (d.ParentDevice==null)
            {
                cs.Append("	NULL,"+cs.NewLine+"	NULL,"+cs.NewLine); //UDN, Serial
            }
            cs.Append(" NULL,"+cs.NewLine); //Manufacturer
            cs.Append(" NULL,"+cs.NewLine); //ManufacturerURL
            cs.Append(" NULL,"+cs.NewLine); //ModelDescription
            cs.Append(" NULL,"+cs.NewLine); //ModelName
            cs.Append(" NULL,"+cs.NewLine); //ModelNumber
            cs.Append(" NULL,"+cs.NewLine); //ModelURL
            cs.Append(" NULL,"+cs.NewLine); //Product Code

            UPnPDevice[] embeddedDevices = d.EmbeddedDevices;
            UPnPService[] services = d.Services;

            d.EmbeddedDevices = new UPnPDevice[0];
            d.Services = new UPnPService[0];

            string xmlString;

            if (d.ParentDevice==null)
                {byte[] xml;
                xml = d.GetRootDeviceXML(null);
                xmlString = (new UTF8Encoding()).GetString(xml);
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                StringWriter SW = new StringWriter(sb);
                XmlTextWriter XDoc = new XmlTextWriter(SW);
                (new UPnPDebugObject(d)).InvokeNonStaticMethod("GetNonRootDeviceXML",new object[2]{null,XDoc});
                SW.Flush();
                xmlString = sb.ToString();
            }
            string stringX;
            int stringXLen;
            InjectCompressedString(out stringX,out stringXLen,xmlString,cs.NewLine);

            cs.Append("	"+stringX+","+cs.NewLine);
            cs.Append("	"+stringXLen.ToString()+","+cs.NewLine);
            cs.Append("	"+xmlString.Length.ToString()+","+cs.NewLine);
            if (d.ParentDevice==null)
            {
                cs.Append("	NULL,"+cs.NewLine);
            }
            cs.Append("	NULL"+cs.NewLine);
            cs.Append("};"+cs.NewLine);

            d.EmbeddedDevices = embeddedDevices;
            d.Services = services;
        }
        protected static void BuildDeviceStructs(CodeProcessor cs, UPnPDevice d)
        {
            foreach(UPnPDevice ed in d.EmbeddedDevices)
            {
                BuildDeviceStructs(cs,ed);
            }
            cs.Append("struct UPnP_Device_"+d.User2.ToString()+cs.NewLine);
            cs.Append("{"+cs.NewLine);
            foreach(UPnPService s in d.Services)
            {
                cs.Append("	struct UPnP_Service_"+((ServiceGenerator.ServiceConfiguration)s.User).Name+" *"+((ServiceGenerator.ServiceConfiguration)s.User).Name+";"+cs.NewLine);
            }
            cs.Append(cs.NewLine);
            foreach(UPnPDevice ed in d.EmbeddedDevices)
            {
                cs.Append("	struct UPnP_Device_"+ed.User2.ToString()+" *UPnP_Device_"+ed.User2.ToString()+";"+cs.NewLine);
            }
            cs.Append("	const char *FriendlyName;"+cs.NewLine);
            if (d.ParentDevice==null)
            {
                cs.Append("	const char *UDN;"+cs.NewLine);
                cs.Append("	const char *Serial;"+cs.NewLine);
            }
            cs.Append(" const char *Manufacturer;"+cs.NewLine);
            cs.Append(" const char *ManufacturerURL;"+cs.NewLine);
            cs.Append(" const char *ModelDescription;"+cs.NewLine);
            cs.Append(" const char *ModelName;"+cs.NewLine);
            cs.Append(" const char *ModelNumber;"+cs.NewLine);
            cs.Append(" const char *ModelURL;"+cs.NewLine);
            cs.Append("	const char *ProductCode;"+cs.NewLine);

            UPnPDevice[] embeddedDevices = d.EmbeddedDevices;
            UPnPService[] services = d.Services;

            d.EmbeddedDevices = new UPnPDevice[0];
            d.Services = new UPnPService[0];

            byte[] xml;
            if (d.Root)
            {
                xml = d.GetRootDeviceXML(null);
            }
            else
            {
                xml = (byte[])(new UPnPDebugObject(d)).InvokeNonStaticMethod("GetRootDeviceXML",new object[1]{null});
            }
            UTF8Encoding U = new UTF8Encoding();
            string xmlString = U.GetString(xml);
            string stringX;
            int stringXLen;
            InjectCompressedString(out stringX,out stringXLen,xmlString,cs.NewLine);
            d.EmbeddedDevices = embeddedDevices;
            d.Services = services;

            cs.Append("	char Reserved["+stringXLen.ToString()+"];"+cs.NewLine);
            cs.Append("	int ReservedXL;"+cs.NewLine);
            cs.Append("	int ReservedUXL;"+cs.NewLine);

            cs.Append("	void *User;"+cs.NewLine);
            if (d.ParentDevice==null)
            {
                cs.Append("	void *MicrostackToken;"+cs.NewLine);
            }
            cs.Append("};"+cs.NewLine);
        }
        private void BuildDeviceDescription(CodeProcessor cs, UPnPDevice device)
        {
            UTF8Encoding U = new UTF8Encoding();
            string deviceDescription = (new UTF8Encoding().GetString(device.GetRootDeviceXML(new IPEndPoint(new IPAddress(0x0100007F), 80))));

            for (int i = 0; i < 40; i++) deviceDescription = deviceDescription.Replace("\r\n ", "\r\n");
            deviceDescription = deviceDescription.Replace("\r\n", "");
            //deviceDescription = deviceDescription;

            //			if (this.BasicHTTP)
            //			{
            //				deviceDescription = "HTTP/1.0 200  OK\r\nCONTENT-TYPE:  text/xml\r\nServer: " + UseSystem + ", UPnP/1.0, MicroStack/" + UseVersion + "\r\n\r\n" + deviceDescription;
            //			}

            byte[] deviceDescriptionX = OpenSource.Utilities.StringCompressor.CompressString(deviceDescription);

            cs.Append("const int " + this.pc_methodPrefix + "DeviceDescriptionTemplateLengthUX = " + U.GetByteCount(deviceDescription).ToString() + ";" + cl);
            cs.Append("const int " + this.pc_methodPrefix + "DeviceDescriptionTemplateLength = " + deviceDescriptionX.Length.ToString() + ";" + cl);
            cs.Append("const char " + this.pc_methodPrefix + "DeviceDescriptionTemplate[" + deviceDescriptionX.Length.ToString() + "]={" + cl);
            bool _first = true;
            int _ctr = 0;
            foreach (byte b in deviceDescriptionX)
            {
                if (_first == false)
                {
                    cs.Append(",");
                }
                else
                {
                    _first = false;
                }
                string hx = b.ToString("X");
                cs.Append("0x");
                if (hx.Length == 1) { cs.Append("0"); }
                cs.Append(hx);

                ++_ctr;
                if (_ctr % 20 == 0)
                {
                    cs.Append("\r\n");
                }
            }
            cs.Append("};\r\n");
        }