Example #1
0
        /// <summary>
        ///     ''' Set an entire device profile from an XML encoded string
        ///     ''' </summary>
        ///     ''' <param name="DriverId">The ProgID of the device</param>
        ///     ''' <param name="XmlProfile">An XML encoding of the profile</param>
        ///     ''' <remarks>Please see the code examples in this help file for a description of how to use this method. See GetProfileXML for a
        ///     ''' description of the XML format.</remarks>
        public void SetProfileXML(string DriverId, string XmlProfile)
        {
            ASCOMProfile NewProfileContents;

            byte[]        XMLProfileBytes;
            XmlSerializer XMLSer = new XmlSerializer(typeof(ASCOMProfile));
            UTF8Encoding  UTF8   = new UTF8Encoding();

            TL.LogMessageCrLf("SetProfileXML", "Driver: " + DriverId + Constants.vbCrLf + XmlProfile);
            CheckRegistered(DriverId);

            XMLProfileBytes = UTF8.GetBytes(XmlProfile);                          // Convert the UTF8 XML string into a byte array
            using (MemoryStream MemStream = new MemoryStream(XMLProfileBytes))    // Present the UTF8 string byte array as a memory stream
            {
                NewProfileContents = (ASCOMProfile)XMLSer.Deserialize(MemStream); // De-serialise the stream to a ProfileKey object holding the new set of values
            }

            ProfileStore.SetProfile(MakeKey(DriverId, ""), NewProfileContents);
            TL.LogMessage("  SetProfileXML", "  Complete");
        }