Esempio n. 1
0
        /// <summary>
        /// Deserialize a XML file on disk to an instance of OWOfficeConfiguration.
        /// </summary>
        /// <param name="configurationFilePath">Full file path for the XML file to be read and deserialized.</param>
        /// <returns>A deserialized OWOfficeConfiguration instance.</returns>
        public static OWC DeserializeFromXml(string xmlData)
        {
            OWC owc = null;

            System.IO.StringReader sr = null;
            try
            {
                sr = new System.IO.StringReader(xmlData);

                XmlSerializer serializer = new XmlSerializer(typeof(OWC));
                owc = (OWC)serializer.Deserialize(sr);
            }
            catch (Exception ex)
            {
                ex = ex;
            }
            finally
            {
                // Clean up memory
                if (sr != null)
                {
                    sr.Close();
                }
            }
            return(owc);
        }
Esempio n. 2
0
        /// <summary>
        /// Serialize an OWOfficeConfiguration instance to a XML file on disk.
        /// </summary>
        /// <param name="configuration">An OWOfficeConfiguration instance to serialize.</param>
        /// <param name="configurationFilePath">Full file path for the XML file to be created/saved.</param>
        public static void Serialize(OWC owc, string configurationFilePath)
        {
            XmlTextWriter writer = null;

            // Checks permissions before proceeding
            CheckFilePermissions(configurationFilePath);
            writer = new XmlTextWriter(configurationFilePath, Encoding.UTF8);
            XmlSerializer serializer = new XmlSerializer(typeof(OWC));

            serializer.Serialize(writer, owc);
            // Clean up memory
            if (writer != null)
            {
                writer.Close();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Loads an OWOfficeConfiguration instance with settings stored in a XML file.
        /// </summary>
        /// <param name="configurationData">OWOffice configuration file path to use when loading settings.</param>
        public void Read(string configurationData)
        {
            OWC owc = new OWC();

            //Test if it is a xml document
            if (configurationData.IndexOf("<?xml") != -1)
            {
                owc = Serializer.DeserializeFromXml(configurationData);
            }
            else            //else is a xml file
            {
                owc = Serializer.Deserialize(configurationData, out this.owcXMLData);
            }

            // As this method could be called at runtime, this call ensures data is actual
            this.Refresh(owc);
        }
Esempio n. 4
0
 /// <summary>
 /// Keeps instance data settings synchronized with XML file data values
 /// </summary>
 /// <param name="configuration">An OWC instance to keep synchronized with the XML configuration file.</param>
 private void Refresh(OWC owc)
 {
     this.WebServerUrl      = owc.WebServerUrl;
     this.TempDirectoryPath = owc.TempDirectoryPath;
     this.Templates         = owc.Templates;
 }