示例#1
0
        /// <summary>
        /// Merges current list with the list of lists specified in the parameter.
        /// </summary>
        /// <param name="lists">Lists to merge with.</param>
        /// <returns>Merged list.</returns>
        public PFKeyValueListEx <TKey, TValue> Merge(PFListEx <PFKeyValueListEx <TKey, TValue> > lists)
        {
            PFKeyValueListEx <TKey, TValue> mergedList = new PFKeyValueListEx <TKey, TValue>();

            if (lists == null)
            {
                return(mergedList);
            }

            foreach (pfKeyValuePair <TKey, TValue> item in this)
            {
                mergedList.Add(item);
            }

            for (int listInx = 0; listInx < lists.Count; listInx++)
            {
                PFKeyValueListEx <TKey, TValue> tempList = lists[listInx];
                if (tempList != null)
                {
                    foreach (pfKeyValuePair <TKey, TValue> item in tempList)
                    {
                        mergedList.Add(item);
                    }
                }
            }

            return(mergedList);
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Converts PFKeyValueListExSorted object to PFKeyValueListEx object.
        /// </summary>
        /// <returns>PFKeyValueListEx object.</returns>
        public PFKeyValueListEx <K, V> ConvertThisToPFKeyValueListEx()
        {
            PFKeyValueListEx <K, V> kvlist = new PFKeyValueListEx <K, V>();

            IEnumerator <KeyValuePair <K, V> > enumerator = GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                pfKeyValuePair <K, V> keyValuePair = new pfKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                kvlist.Add(keyValuePair);
            }

            return(kvlist);
        }
示例#4
0
        /// <summary>
        /// Converts currentg instance to another PFKeyValueListEx object.
        /// </summary>
        /// <returns>PFKeyValueListEx object.</returns>
        public PFKeyValueListEx <TKey, TValue> CopyThisToPFKeyValueListEx()
        {
            PFKeyValueListEx <TKey, TValue> kvlist = new PFKeyValueListEx <TKey, TValue>();
            pfKeyValuePair <TKey, TValue>   kvp    = default(pfKeyValuePair <TKey, TValue>);

            if (this.Count > 0)
            {
                this.SetToBOF();
                kvp = this.FirstItem;
                while (this.EOF == false)
                {
                    kvlist.Add(new pfKeyValuePair <TKey, TValue>(kvp.Key, kvp.Value));
                    kvp = this.NextItem;
                }
            }

            return(kvlist);
        }
示例#5
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));
        }
示例#6
0
        /// <summary>
        /// Merges current list with the list specified in the parameter.
        /// </summary>
        /// <param name="list">List to merge with.</param>
        /// <returns>Merged list.</returns>
        public PFKeyValueListEx <TKey, TValue> Merge(PFKeyValueListEx <TKey, TValue> list)
        {
            PFKeyValueListEx <TKey, TValue> mergedList = new PFKeyValueListEx <TKey, TValue>();

            if (list == null)
            {
                return(mergedList);
            }

            foreach (pfKeyValuePair <TKey, TValue> item in this)
            {
                mergedList.Add(item);
            }

            foreach (pfKeyValuePair <TKey, TValue> item in list)
            {
                mergedList.Add(item);
            }

            return(mergedList);
        }
示例#7
0
        /// <summary>
        /// Routine that concatenates two or more lists into one list.
        /// </summary>
        /// <param name="lists">List of list objects to be concatenated.</param>
        /// <returns>Concatenated list.</returns>
        public static PFKeyValueListEx <TKey, TValue> ConcatenateLists(PFListEx <PFKeyValueListEx <TKey, TValue> > lists)
        {
            PFKeyValueListEx <TKey, TValue> concatenatedList = new PFKeyValueListEx <TKey, TValue>();

            if (lists == null)
            {
                return(concatenatedList);
            }

            for (int listInx = 0; listInx < lists.Count; listInx++)
            {
                PFKeyValueListEx <TKey, TValue> tempList = lists[listInx];
                if (tempList != null)
                {
                    foreach (pfKeyValuePair <TKey, TValue> item in tempList)
                    {
                        concatenatedList.Add(item);
                    }
                }
            }

            return(concatenatedList);
        }
示例#8
0
        /// <summary>
        /// Converts instance of this class into an XML document.
        /// </summary>
        /// <returns>XmlDocument</returns>
        /// ///<remarks>XML Serialization and XmlDocument class are used for the transformation.</remarks>
        public XmlDocument ToXmlDocument()
        {
            PFKeyValueListEx <K, V> kvlist = ConvertThisToPFKeyValueListEx();

            return(kvlist.ToXmlDocument());
        }
示例#9
0
        /// <summary>
        /// Returns a string containing the contents of the object in XML format.
        /// </summary>
        /// <returns>String value in xml format.</returns>
        /// ///<remarks>XML Serialization is used for the transformation.</remarks>
        public string ToXmlString()
        {
            PFKeyValueListEx <K, V> kvlist = ConvertThisToPFKeyValueListEx();

            return(kvlist.ToXmlString());
        }
示例#10
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 PFKeyValueListExSorted <K, V> LoadFromDatabase(string connectionString, string listName)
        {
            PFKeyValueListEx <K, V> kvlist = PFKeyValueListEx <K, V> .LoadFromDatabase(connectionString, listName);

            return(ConvertPFKeyValueListExToSortedList(kvlist));
        }
示例#11
0
        /// <summary>
        /// Creates and initializes an instance of the class by loading a serialized version of the instance from a file.
        /// </summary>
        /// <param name="filePath">Full path for the input file.</param>
        /// <returns>An instance of PFKeyValueListEx.</returns>
        public static PFKeyValueListExSorted <K, V> LoadFromXmlFile(string filePath)
        {
            PFKeyValueListEx <K, V> kvlist = PFKeyValueListEx <K, V> .LoadFromXmlFile(filePath);

            return(ConvertPFKeyValueListExToSortedList(kvlist));
        }
示例#12
0
        /// <summary>
        /// Saves the public property values contained in the current instance to the database specified by the connection string.
        /// </summary>
        /// <param name="connectionString">Contains information needed to open the database.</param>
        /// <param name="listName">Name to give list in the database.</param>
        public void SaveToDatabase(string connectionString, string listName)
        {
            PFKeyValueListEx <K, V> kvlist = ConvertThisToPFKeyValueListEx();

            kvlist.SaveToDatabase(connectionString, listName);
        }
示例#13
0
        /// <summary>
        /// Saves the public property values contained in the current instance to the specified file. Serialization is used for the save.
        /// </summary>
        /// <param name="filePath">Full path for output file.</param>
        public void SaveToXmlFile(string filePath)
        {
            PFKeyValueListEx <K, V> kvlist = ConvertThisToPFKeyValueListEx();

            kvlist.SaveToXmlFile(filePath);
        }
示例#14
0
        /// <summary>
        /// Converts PFKeyValueListEx object to PFKeyValueListExSorted object.
        /// </summary>
        /// <param name="kvlist"></param>
        /// <returns>PFKeyValueListExSorted object.</returns>
        public static PFKeyValueListExSorted <K, V> ConvertPFKeyValueListExToSortedList(PFKeyValueListEx <K, V> kvlist)
        {
            PFKeyValueListExSorted <K, V> kvlistSorted = new PFKeyValueListExSorted <K, V>();

            kvlist.SetToBOF();
            pfKeyValuePair <K, V> pfKeyValuePair = kvlist.FirstItem;

            while (!kvlist.EOF)
            {
                kvlistSorted.Add(pfKeyValuePair.Key, pfKeyValuePair.Value);
                pfKeyValuePair = kvlist.NextItem;
            }
            return(kvlistSorted);
        }