public SQLDatabaseSettingsProvider(SettingsSection settings) : base(settings)
        {
            this.dbs = settings.ConnectionString;

            this.conn = new SqlConnection(dbs);
            xmlHelper = new SqlXmlHelper(conn);
        }
Пример #2
0
        /// <summary>Reads object data from an XML file.</summary>
        /// <param name="file">XML file name.</param>
        /// <returns>T instance initialized from XML data in the file supplied.</returns>
        public static T ReadFile <T>(string file)
        {
            string xml = string.Empty;

            try
            {
                SqlXmlHelper serializer = new SqlXmlHelper();
                using (StreamReader reader = new StreamReader(file))
                {
                    xml = reader.ReadToEnd();
                }
                return(serializer.Deserialize <T>(xml));
            }
            catch { }
            return(default(T));
        }
Пример #3
0
        /// <summary>Writes object data to an XML file.</summary>
        /// <param name="file">XML file name.</param>
        /// <param name="config">Object to serialize.</param>
        /// <returns>Boolean success.</returns>
        public static bool WriteFile <T>(string file, T obj)
        {
            bool         ok         = false;
            SqlXmlHelper serializer = new SqlXmlHelper();

            try
            {
                string xml = serializer.Serialize(obj).OuterXml;
                using (StreamWriter writer = new StreamWriter(file, false))
                {
                    writer.Write(xml.Trim());
                    writer.Flush();
                }
                ok = true;
            }
            catch { }
            return(ok);
        }