Beispiel #1
0
        /// <summary>
        /// Creates and initializes an instance of the class by loading a serialized version of the instance from a database record.
        /// </summary>
        /// <param name="connectionString">Connection parameters for the database.</param>
        /// <param name="listName">Name of the list in the database.</param>
        /// <returns>PFListEx object.</returns>
        public static PFKeyValueListEx <TKey, TValue> LoadFromDatabase(string connectionString, string listName)
        {
            string sqlStmt = string.Empty;
            PFKeyValueListEx <TKey, TValue> objectInstance     = null;
            PFKeyValueListEx <TKey, TValue> tempObjectInstance = new PFKeyValueListEx <TKey, TValue>();
            PFDatabase   db  = new PFDatabase(DatabasePlatform.SQLServerCE35);
            DbDataReader rdr = null;
            string       pfKeyValueListExXml = string.Empty;

            db.ConnectionString = connectionString;
            db.OpenConnection();

            sqlStmt = tempObjectInstance._listsSelectSQL.Replace("<listname>", listName);
            rdr     = db.RunQueryDataReader(sqlStmt, CommandType.Text);
            while (rdr.Read())
            {
                pfKeyValueListExXml = rdr.GetString(0);
                objectInstance      = PFKeyValueListEx <TKey, TValue> .LoadFromXmlString(pfKeyValueListExXml);

                break;  //should be only one record
            }

            db.CloseConnection();
            db = null;

            return(objectInstance);
        }
Beispiel #2
0
        /// <summary>
        /// Creates and initializes an instance of the class by loading a serialized version of the instance stored as a xml formatted string.
        /// </summary>
        /// <param name="xmlString">String containing the xml formatted representation of an instance of this class.</param>
        /// <returns>An instance of PFKeyValueListEx.</returns>
        public static PFKeyValueListExSorted <K, V> LoadFromXmlString(string xmlString)
        {
            PFKeyValueListEx <K, V> kvlist = default(PFKeyValueListEx <K, V>);

            try
            {
                kvlist = PFKeyValueListEx <K, V> .LoadFromXmlString(xmlString);
            }
            catch (System.Exception ex)
            {
                StringBuilder errMsg = new StringBuilder();
                errMsg.Length = 0;
                errMsg.Append("Error while loading xml string:");
                errMsg.Append(Environment.NewLine);
                errMsg.Append(ex.Message);
                errMsg.Append(Environment.NewLine);
                errMsg.Append("XML must contain definition for a PFKeyValueListEx object. That object will be converted into a PFKeyValueListExSorted object.");
                throw new System.Exception(errMsg.ToString());
            }
            return(ConvertPFKeyValueListExToSortedList(kvlist));
        }