コード例 #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 PFList <T> LoadFromDatabase(string connectionString, string listName)
        {
            string       sqlStmt        = string.Empty;
            PFList <T>   objectInstance = null;
            PFDatabase   db             = new PFDatabase(DatabasePlatform.SQLServerCE35);
            DbDataReader rdr            = null;
            string       pfKeyListExXml = string.Empty;

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

            sqlStmt = _listsSelectSQL.Replace("<listname>", listName);
            rdr     = db.RunQueryDataReader(sqlStmt, CommandType.Text);
            while (rdr.Read())
            {
                pfKeyListExXml = rdr.GetString(0);
                objectInstance = PFList <T> .LoadFromXmlString(pfKeyListExXml);

                break;  //should be only one record
            }

            db.CloseConnection();
            db = null;


            if (objectInstance == null)
            {
                objectInstance = new PFList <T>();
            }

            return(objectInstance);
        }
コード例 #2
0
        public void ToXmlTest()
        {
            PFList <string> testList = new PFList <string>();

            try
            {
                _msg.Length = 0;
                _msg.Append("ToXmlTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                testList.Add("First item");
                testList.Add("Second item");
                testList.Add("Third item");

                string          xmlString = testList.ToXmlString();
                XmlDocument     xmlDoc    = testList.ToXmlDocument();
                PFList <string> testList2 = PFList <string> .LoadFromXmlString(xmlString);

                _msg.Length = 0;
                _msg.Append("\r\n\r\n");
                _msg.Append(xmlString);
                _msg.Append("\r\n\r\n");
                _msg.Append(xmlDoc.OuterXml);
                _msg.Append("\r\n\r\n");
                _msg.Append(testList2.ToString());
                _msg.Append("\r\n\r\n");
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... ToXmlTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }