Beispiel #1
0
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            try
            {
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                PFKeyValueList <string, string> dbPlatformProperties = conndef.DbPlatformConnectionStringProperties;
                //stKeyValuePair<string, string> keyval = default(stKeyValuePair<string, string>);

                this.txtDsnName.Text    = dbPlatformProperties.Find("Dsn").Value;
                this.txtDriverName.Text = dbPlatformProperties.Find("Driver").Value;

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
        /// <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 PFKeyValueListSorted <K, V> LoadFromDatabase(string connectionString, string listName)
        {
            PFDBKeyValueListProcessor <K, V> listProcessor = new PFDBKeyValueListProcessor <K, V>();
            PFKeyValueList <K, V>            kvlist        = listProcessor.LoadFromDatabase(connectionString, listName);

            return(ConvertPFKeyValueListToSortedList(kvlist));
        }
Beispiel #3
0
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            try
            {
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                PFKeyValueList <string, string> dbPlatformProperties = conndef.DbPlatformConnectionStringProperties;

                this.txtServerName.Text               = dbPlatformProperties.Find("ServerName").Value;
                this.txtDatabaseName.Text             = dbPlatformProperties.Find("DatabaseName").Value;
                this.txtUsername.Text                 = dbPlatformProperties.Find("Username").Value;
                this.txtPassword.Text                 = dbPlatformProperties.Find("Password").Value;
                this.txtApplicationName.Text          = dbPlatformProperties.Find("ApplicationName").Value;
                this.txtWorkstationId.Text            = dbPlatformProperties.Find("WorkstationId").Value;
                this.chkUseIntegratedSecurity.Checked = PFTextProcessor.ConvertStringToBoolean(dbPlatformProperties.Find("UseIntegratedSecurity").Value, "false");
                this.chkUseAsyncProcessing.Checked    = PFTextProcessor.ConvertStringToBoolean(dbPlatformProperties.Find("AsynchronousProcessing").Value, "false");

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
Beispiel #4
0
        //properties

        //methods

        /// <summary>
        /// Saves the public property values contained in the current instance to the database specified by the connection string.
        /// </summary>
        /// <param name="kvlist">Key/Value list object to be saved to a database.</param>
        /// <param name="connectionString">Contains information needed to open the database.</param>
        /// <param name="listName">Name of the list in the database.</param>
        public void SaveToDatabase(PFKeyValueList <K, V> kvlist, string connectionString, string listName)
        {
            string     sqlStmt         = string.Empty;
            PFDatabase db              = new PFDatabase(DatabasePlatform.SQLServerCE35);
            int        numRecsAffected = 0;
            DateTime   currdate        = DateTime.Now;
            string     currBatchId     = string.Empty;
            string     listObject      = string.Empty;

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

            //create batch id for this list
            currBatchId = "'" + Guid.NewGuid().ToString().Trim() + "'";

            listObject = kvlist.ToXmlString().Replace("'", "");      //get rid of any single quotes in the object. they will mess up the sql syntax e.g. values(1, 'two' ,'this is the 'object'')

            //insert current list to the database
            sqlStmt         = _listsInsertSQL.Replace("<listname>", listName).Replace("<id>", currBatchId).Replace("<listobject>", listObject);
            numRecsAffected = db.RunNonQuery(sqlStmt, CommandType.Text);

            //get rid of any previous PFListEx objects in the database
            sqlStmt         = _listsDeleteOldSQL.Replace("<listname>", listName).Replace("<id>", currBatchId);
            numRecsAffected = db.RunNonQuery(sqlStmt, CommandType.Text);


            db.CloseConnection();
            db = null;
        }
Beispiel #5
0
        private void InitDatabaseTypesDropdown()
        {
            bool showInstalledDatabaseProvidersOnly = true;
            PFConnectionManager connMgr             = new PFConnectionManager();
            PFKeyValueList <string, PFProviderDefinition> provDefs = connMgr.GetListOfProviderDefinitions();

            this.cboDatabaseTypeForOutputTables.Items.Clear();
            foreach (stKeyValuePair <string, PFProviderDefinition> provDef in provDefs)
            {
                if (showInstalledDatabaseProvidersOnly)
                {
                    if (provDef.Value.InstallationStatus == enProviderInstallationStatus.IsInstalled)
                    {
                        this.cboDatabaseTypeForOutputTables.Items.Add(provDef.Key);
                    }
                    else
                    {
                        ;
                    }
                }
                else
                {
                    this.cboDatabaseTypeForOutputTables.Items.Add(provDef.Key);
                }
            }
        }
Beispiel #6
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 PFKeyValueList <K, V> LoadFromDatabase(string connectionString, string listName)
        {
            string sqlStmt = string.Empty;
            PFKeyValueList <K, V> objectInstance = null;
            PFDatabase            db             = new PFDatabase(DatabasePlatform.SQLServerCE35);
            DbDataReader          rdr            = null;
            string pfKeyValueListExXml           = string.Empty;

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

            sqlStmt = _listsSelectSQL.Replace("<listname>", listName);
            rdr     = db.RunQueryDataReader(sqlStmt, CommandType.Text);
            while (rdr.Read())
            {
                pfKeyValueListExXml = rdr.GetString(0);
                objectInstance      = PFKeyValueList <K, V> .LoadFromXmlString(pfKeyValueListExXml);

                break;  //should be only one record
            }

            db.CloseConnection();
            db = null;

            if (objectInstance == null)
            {
                objectInstance = new PFKeyValueList <K, V>();
            }

            return(objectInstance);
        }
        /// <summary>
        /// Saves the public property values contained in the current instance to the database specified by the connection string.
        /// </summary>
        /// <param name="kvlistSorted">Sorted key value list to be saved to database.</param>
        /// <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(PFKeyValueListSorted <K, V> kvlistSorted, string connectionString, string listName)
        {
            PFKeyValueList <K, V> kvlist = ConvertPFKeyValueListSortedToPFKeyValueList(kvlistSorted);

            PFDBKeyValueListProcessor <K, V> listProcessor = new PFDBKeyValueListProcessor <K, V>();

            listProcessor.SaveToDatabase(kvlist, connectionString, listName);
        }
        private void InitFormValues()
        {
            bool showInstalledDatabaseProvidersOnly = this.ShowInstalledDatabaseProvidersOnly;
            PFConnectionManager connMgr             = new PFConnectionManager();
            PFKeyValueList <string, PFProviderDefinition> provDefs = connMgr.GetListOfProviderDefinitions();

            if (provDefs.Count == 0)
            {
                connMgr.CreateProviderDefinitions();
            }
            else
            {
                connMgr.UpdateAllProvidersInstallationStatus();
            }
            provDefs = connMgr.GetListOfProviderDefinitions();

            this.cboDatabaseTypeForOutputTable.Items.Clear();
            foreach (stKeyValuePair <string, PFProviderDefinition> provDef in provDefs)
            {
                if (showInstalledDatabaseProvidersOnly)
                {
                    if (provDef.Value.InstallationStatus == enProviderInstallationStatus.IsInstalled)
                    {
                        //this.cboDatabaseTypeForOutputTable.Items.Add(provDef.Key);
                        if (provDef.Value.AvailableForSelection)
                        {
                            this.cboDatabaseTypeForOutputTable.Items.Add(provDef.Key);
                        }
                        else
                        {
                            ;
                        }
                    }
                    else
                    {
                        ;
                    }
                }
                else
                {
                    this.cboDatabaseTypeForOutputTable.Items.Add(provDef.Key);
                }
            }

            SetOutputDatabaseProvider();
            SetOutputConnectionString();
            if (this.cboDatabaseTypeForOutputTable.Text.Trim().Length > 0)
            {
                SetOutputTableName();
                SetOutputBatchSizeForDbPlatform();
            }
            else
            {
                this.txtOutputTableName.Text = string.Empty;
                this.txtOutputBatchSize.Text = AppConfig.GetStringValueFromConfigFile("DefaultOutputDatabaseBatchSize", "120");;
            }
            this.chkReplaceExistingTable.Checked = AppConfig.GetBooleanValueFromConfigFile("ReplaceOutputTableIfExists", "False");
        }
        private void InitDefaultDatabaseType(ComboBox cboDatabaseType, TextBox txtDefaultDatabseConnectionString)
        {
            bool showInstalledDatabaseProvidersOnly = pfDataViewerCP.Properties.Settings.Default.ShowInstalledDatabaseProvidersOnly;
            PFConnectionManager connMgr             = new PFConnectionManager();
            PFKeyValueList <string, PFProviderDefinition> provDefs = connMgr.GetListOfProviderDefinitions();

            cboDatabaseType.Items.Clear();
            foreach (stKeyValuePair <string, PFProviderDefinition> provDef in provDefs)
            {
                if (showInstalledDatabaseProvidersOnly)
                {
                    if (provDef.Value.InstallationStatus == enProviderInstallationStatus.IsInstalled)
                    {
                        if (provDef.Value.AvailableForSelection)
                        {
                            cboDatabaseType.Items.Add(provDef.Key);
                        }
                        else
                        {
                            ;
                        }
                    }
                    else
                    {
                        ;
                    }
                }
                else
                {
                    if (provDef.Value.AvailableForSelection)
                    {
                        cboDatabaseType.Items.Add(provDef.Key);
                    }
                    else
                    {
                        ;
                    }
                }
            }

            if (DatabaseTypeIsInList(cboDatabaseType) == false)
            {
                //database type no longer in the list of database types available for use
                cboDatabaseType.Text = string.Empty;
                txtDefaultDatabseConnectionString.Text = string.Empty;
            }
            else
            {
                //database type is still in the list: do nothing
                ;
            }
        }
        /// <summary>
        /// Converts PFKeyValueList object to PFKeyValueListSorted object.
        /// </summary>
        /// <param name="kvlist"></param>
        /// <returns>PFKeyValueListSorted object.</returns>
        public static PFKeyValueListSorted <K, V> ConvertPFKeyValueListToSortedList(PFKeyValueList <K, V> kvlist)
        {
            PFKeyValueListSorted <K, V> kvlistSorted = new PFKeyValueListSorted <K, V>();

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

            while (!kvlist.EOF)
            {
                kvlistSorted.Add(pfKeyValuePair.Key, pfKeyValuePair.Value);
                pfKeyValuePair = kvlist.NextItem;
            }
            return(kvlistSorted);
        }
        private void VerifyProviderLists()
        {
            PFKeyValueList <string, PFProviderDefinition> provDefs = _connMgr.GetListOfProviderDefinitions();

            if (provDefs.Count == 0)
            {
                _connMgr.CreateProviderDefinitions();
            }
            else
            {
                _connMgr.UpdateAllProvidersInstallationStatus();
            }
            //provDefs = _connMgr.GetListOfProviderDefinitions();
        }
        private int GetRandomDataValueListIndex(DataTableRandomizerColumnSpec spec, PFKeyValueList <string, int> randomDataValueListIndexes)
        {
            int listInx = -1;

            for (int inx = 0; inx < randomDataValueListIndexes.Count; inx++)
            {
                if (spec.RandomDataFileName == randomDataValueListIndexes[inx].Key)
                {
                    listInx = randomDataValueListIndexes[inx].Value;
                    break;
                }
            }

            return(listInx);
        }
        //properties

        //methods

        /// <summary>
        /// Converts PFKeyValueListSorted object to PFKeyValueList object.
        /// </summary>
        /// <returns>PFKeyValueList object.</returns>
        public PFKeyValueList <K, V> ConvertPFKeyValueListSortedToPFKeyValueList(PFKeyValueListSorted <K, V> sortedKvList)
        {
            PFKeyValueList <K, V> kvlist = new PFKeyValueList <K, V>();

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

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

            return(kvlist);
        }
Beispiel #14
0
        public void RandomizeListsTest()
        {
            PFList <string> list1 = new PFList <string>();
            PFKeyValueList <int, string>       kvlist2   = new PFKeyValueList <int, string>();
            PFKeyValueListSorted <int, string> sortlist3 = new PFKeyValueListSorted <int, string>();

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

                list1.Add("First");
                list1.Add("Second");
                list1.Add("Third");
                list1.Add("fourth");
                list1.Add("fifth");
                list1.Add("sixth");
                list1.Add("Seventh");
                list1.Add("Eighth");
                list1.Add("Ninth");
                list1.Add("Tenth");

                PFList <string> randomizedList = list1.Randomize();

                _msg.Length = 0;
                _msg.Append("randomizedList: ");
                _msg.Append(Environment.NewLine);
                _msg.Append(randomizedList.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());

                kvlist2.Add(new stKeyValuePair <int, string>(1, "First"));
                kvlist2.Add(new stKeyValuePair <int, string>(2, "Second"));
                kvlist2.Add(new stKeyValuePair <int, string>(3, "Third"));
                kvlist2.Add(new stKeyValuePair <int, string>(4, "fourth"));
                kvlist2.Add(new stKeyValuePair <int, string>(5, "fifth"));
                kvlist2.Add(new stKeyValuePair <int, string>(6, "sixth"));
                kvlist2.Add(new stKeyValuePair <int, string>(7, "Seventh"));
                kvlist2.Add(new stKeyValuePair <int, string>(8, "Eighth"));
                kvlist2.Add(new stKeyValuePair <int, string>(9, "Ninth"));
                kvlist2.Add(new stKeyValuePair <int, string>(10, "Tenth"));

                PFKeyValueList <int, string> randomizedKvList = kvlist2.Randomize();

                _msg.Length = 0;
                _msg.Append("randomizedKvList: ");
                _msg.Append(Environment.NewLine);
                _msg.Append(randomizedKvList.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());

                sortlist3.Add(1, "First");
                sortlist3.Add(2, "Second");
                sortlist3.Add(3, "Third");
                sortlist3.Add(4, "fourth");
                sortlist3.Add(5, "fifth");
                sortlist3.Add(6, "sixth");
                sortlist3.Add(7, "Seventh");
                sortlist3.Add(8, "Eighth");
                sortlist3.Add(9, "Ninth");
                sortlist3.Add(10, "Tenth");

                PFKeyValueList <int, string> randomizedSortList = sortlist3.Randomize();

                _msg.Length = 0;
                _msg.Append("randomizedSortList: ");
                _msg.Append(Environment.NewLine);
                _msg.Append(randomizedSortList.ToXmlString());
                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... RandomizeListsTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
Beispiel #15
0
        public void KeyValueListMergeTest()
        {
            PFKeyValueList <int, string> list1 = new PFKeyValueList <int, string>();
            PFKeyValueList <int, string> list2 = new PFKeyValueList <int, string>();
            PFKeyValueList <int, string> list3 = new PFKeyValueList <int, string>();

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

                list1.Add(new stKeyValuePair <int, string>(1, "First"));
                list1.Add(new stKeyValuePair <int, string>(2, "Second"));
                list1.Add(new stKeyValuePair <int, string>(3, "Third"));

                list2.Add(new stKeyValuePair <int, string>(4, "fourth"));
                list2.Add(new stKeyValuePair <int, string>(5, "fifth"));
                list2.Add(new stKeyValuePair <int, string>(6, "sixth"));

                list3.Add(new stKeyValuePair <int, string>(7, "Seventh"));
                list3.Add(new stKeyValuePair <int, string>(8, "Eighth"));
                list3.Add(new stKeyValuePair <int, string>(9, "Ninth"));
                list3.Add(new stKeyValuePair <int, string>(10, "Tenth"));

                PFKeyValueList <int, string>[]         listArray   = { list1, list2, list3 };
                PFList <PFKeyValueList <int, string> > listOfLists = new PFList <PFKeyValueList <int, string> >();
                listOfLists.Add(list1);
                listOfLists.Add(list2);
                listOfLists.Add(list3);

                PFKeyValueList <int, string> concatListFromArray = PFKeyValueList <int, string> .ConcatenateLists(listArray);

                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Concatenated list from Array");
                _msg.Append(Environment.NewLine);
                _msg.Append(concatListFromArray.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());


                PFKeyValueList <int, string> concatListFromList = PFKeyValueList <int, string> .ConcatenateLists(listOfLists);

                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Concatenated list from List");
                _msg.Append(Environment.NewLine);
                _msg.Append(concatListFromList.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());

                PFKeyValueList <int, string> mergedList = list1.Merge(list2);
                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Merged list");
                _msg.Append(Environment.NewLine);
                _msg.Append(mergedList.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());

                mergedList.Clear();
                mergedList = list3.Merge(new PFKeyValueList <int, string>[2] {
                    list1, list2
                });
                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Merged list from Array");
                _msg.Append(Environment.NewLine);
                _msg.Append(mergedList.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());

                mergedList.Clear();
                mergedList = list3.Merge(new PFList <PFKeyValueList <int, string> > {
                    list2, list1
                });
                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Merged list from List");
                _msg.Append(Environment.NewLine);
                _msg.Append(mergedList.ToXmlString());
                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... KeyValueListMergeTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
Beispiel #16
0
        }//end GenericListTest

        public void GenericKeyValueListTest()
        {
            PFKeyValueList <int, string> kvlist  = new PFKeyValueList <int, string>();
            PFKeyValueList <int, string> kvlist3 = new PFKeyValueList <int, string>();
            string kvlistFilename   = @"c:\temp\testkvlist.xml";
            string connectionString = string.Empty;
            string configValue      = string.Empty;
            PFDBKeyValueListProcessor <int, string> kvlistProcessor = new PFDBKeyValueListProcessor <int, string>();

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

                configValue = AppConfig.GetStringValueFromConfigFile("ListsDatabaseFile", string.Empty);
                if (configValue.Length > 0)
                {
                    connectionString = configValue;
                }
                else
                {
                    connectionString = _listsDatabaseConnectionString;
                }

                Program._messageLog.WriteLine(Environment.NewLine);

                kvlist.Add(new stKeyValuePair <int, string>(1, "First value"));
                kvlist.Add(new stKeyValuePair <int, string>(2, "Second value"));
                kvlist.Add(new stKeyValuePair <int, string>(3, "Third value"));
                kvlist.Add(new stKeyValuePair <int, string>(4, "Fourth value is just this"));
                kvlist.Add(new stKeyValuePair <int, string>(5, "First value is whatever comes here"));

                kvlist.SaveToXmlFile(kvlistFilename);

                PFKeyValueList <int, string> kvlist2 = PFKeyValueList <int, string> .LoadFromXmlFile(kvlistFilename);

                kvlist2.SetToBOF();
                stKeyValuePair <int, string> kvp = kvlist2.FirstItem;
                while (!kvlist2.EOF)
                {
                    _msg.Length = 0;
                    _msg.Append(kvp.Key.ToString());
                    _msg.Append(", ");
                    _msg.Append(kvp.Value);
                    Program._messageLog.WriteLine(_msg.ToString());
                    kvp = kvlist2.NextItem;
                }

                kvlistProcessor.SaveToDatabase(kvlist, connectionString, "TestprogCollections_kvlist");

                kvlist3 = kvlistProcessor.LoadFromDatabase(connectionString, "TestprogCollections_kvlist");

                if (kvlist3 != null)
                {
                    _msg.Length = 0;
                    _msg.Append("kvlist3 ToXmlString Test: ");
                    Program._messageLog.WriteLine(_msg.ToString());
                    _msg.Length = 0;
                    _msg.Append(kvlist3.ToXmlString());
                    _msg.Append(Environment.NewLine);
                    _msg.Append("+++ kvlist3 retrieved. +++");
                    Program._messageLog.WriteLine(_msg.ToString());
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("kvlist3 ToXmlString Test: ");
                    Program._messageLog.WriteLine(_msg.ToString());
                    _msg.Length = 0;
                    _msg.Append("*** KVLIST3 IS NULL ***");
                    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
            {
                kvlistProcessor = null;
                _msg.Length     = 0;
                _msg.Append("\r\n... GenericKeyValueListTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
Beispiel #17
0
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            int numValue = 0;

            try
            {
                NewConnectionDefinition();
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                _db.ConnectionString  = conndef.ConnectionString;

                PFKeyValueList <string, string> dbPlatformProperties = conndef.DbPlatformConnectionStringProperties;

                //TODO (DONE)
                this.txtDataSource.Text      = _db.GetPropertyValue("DatabasePath").ToString();
                this.txtPassword.Text        = _db.GetPropertyValue("DatabasePassword").ToString();
                this.chkEncryptionOn.Checked = (bool)_db.GetPropertyValue("EncryptionOn");
                this.cboEncryptionMode.Text  = _db.GetPropertyValue("EncryptionMode").ToString();
                numValue = (int)_db.GetPropertyValue("MaxDatabaseSize");
                if (numValue != (int)enSQLCE40Defaults.MaxDatabaseSize)
                {
                    this.txtMaxDatabaseSize.Text = numValue.ToString();
                }
                else
                {
                    this.txtMaxDatabaseSize.Text = string.Empty;
                }
                numValue = (int)_db.GetPropertyValue("MaxBufferSize");
                if (numValue != (int)enSQLCE40Defaults.MaxBufferSize)
                {
                    this.txtMaxBufferSize.Text = numValue.ToString();
                }
                else
                {
                    this.txtMaxBufferSize.Text = string.Empty;
                }
                numValue = (int)_db.GetPropertyValue("MaxTempFileSize");
                if (numValue != (int)enSQLCE40Defaults.MaxTempFileSize)
                {
                    this.txtMaxTempFileSize.Text = numValue.ToString();
                }
                else
                {
                    this.txtMaxTempFileSize.Text = string.Empty;
                }
                //END TODO

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
        /// <summary>
        /// Main routine for inserting random values into a data table.
        /// </summary>
        /// <param name="dt">DataTable object containing data to be randomized.</param>
        /// <param name="colSpecs">List of specifications for which columns to randomize and values to use in the randomizing.</param>
        /// <param name="nameSpecs">Object containing various criteria for determining types of random names and locations to include.</param>
        public void RandomizeDataTableValues(DataTable dt, PFList <DataTableRandomizerColumnSpec> colSpecs, RandomNamesAndLocationsDataRequest nameSpecs)
        {
            PFList <PFList <RandomName> > randomNameLists            = new PFList <PFList <RandomName> >();
            PFList <PFList <string> >     randomDataValueLists       = new PFList <PFList <string> >();
            PFKeyValueList <string, int>  randomNamesListIndexes     = new PFKeyValueList <string, int>();
            PFKeyValueList <string, int>  randomDataValueListIndexes = new PFKeyValueList <string, int>();
            PFList <RandomName>           currentRandomNames         = null;
            PFList <string> currentRandomDataValues = null;

            PFList <RandomName> generatedRandomNamesList   = null;
            RandomName          currentGeneratedRandomName = null;
            bool generatedRandomNameRequested = false;
            int  generatedRandomNameIndex     = this.BatchSizeForGeneratedRandomNames;

            RandomDataProcessor rdp = null;

            if (dt == null || colSpecs == null || nameSpecs == null)
            {
                _msg.Length = 0;
                _msg.Append("You must specify a non-null value for following parameter(s): ");
                if (dt == null)
                {
                    _msg.Append("dt, ");
                }
                if (colSpecs == null)
                {
                    _msg.Append("colSpecs, ");
                }
                if (nameSpecs == null)
                {
                    _msg.Append("nameSpecs, ");
                }
                char[] charsToTrim = { ',', ' ' };
                throw new System.Exception(_msg.ToString().TrimEnd(charsToTrim) + ".");
            }

            if (dt.Rows.Count < 1 || colSpecs.Count == 0)
            {
                _msg.Length = 0;
                _msg.Append("You must specify non-empty collections for following parameter(s): ");
                if (dt.Rows.Count < 1)
                {
                    _msg.Append("dt, ");
                }
                if (colSpecs.Count == 0)
                {
                    _msg.Append("colSpecs, ");
                }
                char[] charsToTrim = { ',', ' ' };
                throw new System.Exception(_msg.ToString().TrimEnd(charsToTrim) + ".");
            }

            if (this.BatchSizeForGeneratedRandomNames == _defaultBatchSizeForGeneratedRandomNumbers)
            {
                if (dt.Rows.Count > 0)
                {
                    this.BatchSizeForGeneratedRandomNames = dt.Rows.Count;
                }
            }
            if (this.BatchSizeForGeneratedRandomNames > _defaultMaxBatchSizeForGeneratedRandomNumbers)
            {
                this.BatchSizeForGeneratedRandomNames = _defaultMaxBatchSizeForGeneratedRandomNumbers;
            }


            //test
            int    numDups                   = 0;
            string prevAddressLine1          = string.Empty;
            string prevGeneratedAddressLine1 = string.Empty;

            //end test

            this.DataTableToRandomize  = dt;
            this.RandomizerColumnSpecs = colSpecs;
            this.RandomizerNameSpecs   = nameSpecs;

            if (colSpecs == null || dt == null)
            {
                _msg.Length = 0;
                _msg.Append("You must specify both the data table to be randomized and the list of column randomizer specifications in order to run OLD_RandomizeDataTableValues method.");
                throw new System.Exception(_msg.ToString());
            }

            if (dt.Rows.Count < 1 || colSpecs.Count == 0)
            {
                //no changes nee3d to be made;
                return;
            }


            try
            {
                for (int inx = 0; inx < colSpecs.Count; inx++)
                {
                    DataTableRandomizerColumnSpec spec = colSpecs[inx];
                    spec.DataTableColumnIndex = GetDataTableColumnIndex(dt, spec);
                    if (spec.DataTableColumnIndex != -1)
                    {
                        if (spec.RandomDataType == enRandomDataType.RandomNamesAndLocations)
                        {
                            generatedRandomNameRequested = true;
                            spec.RandomDataFileName      = string.Empty;
                            spec.RandomDataListIndex     = -1;
                            spec.CurrentValueIndex       = -1;
                            if (generatedRandomNamesList == null)
                            {
                                rdp = new RandomDataProcessor(nameSpecs.DatabaseFilePath, nameSpecs.DatabasePassword, nameSpecs.RandomDataXmlFilesFolder);
                                rdp.CountryRandomDataSpec = nameSpecs;
                                generatedRandomNamesList  = rdp.GenerateRandomNameList(this.BatchSizeForGeneratedRandomNames);
                            }
                        }
                        else if (spec.RandomDataType == enRandomDataType.CustomRandomValues)
                        {
                            if (RandomListAlreadyStored(spec, inx, colSpecs) == false)
                            {
                                PFList <string> randomDataValueList;
                                randomDataValueList = PFList <string> .LoadFromXmlFile(spec.RandomDataFileName);

                                randomDataValueLists.Add(randomDataValueList);
                                spec.RandomDataListIndex = randomDataValueLists.Count - 1;
                                randomDataValueListIndexes.Add(new stKeyValuePair <string, int>(spec.RandomDataFileName, spec.RandomDataListIndex));
                            }
                            else
                            {
                                spec.RandomDataListIndex = GetRandomDataValueListIndex(spec, randomDataValueListIndexes);
                            }
                        }
                        else
                        {
                            _msg.Length = 0;
                            _msg.Append("Invalid or not specified random data file type detected: ");
                            _msg.Append(spec.RandomDataType.ToString());
                            throw new System.Exception(_msg.ToString());
                        }
                    }
                    else
                    {
                        _msg.Length = 0;
                        _msg.Append("Invalid or missing column name detected: ");
                        _msg.Append(spec.DataTableColumnName);
                        _msg.Append(" Column name not found in DataTable.");
                        throw new System.Exception(_msg.ToString());
                    }
                }//end for

                generatedRandomNameIndex = -1;

                for (int rowInx = 0; rowInx < dt.Rows.Count; rowInx++)
                {
                    //test********************************************
                    if (currentRandomNames != null)
                    {
                        if (currentRandomNames.Count > 0)
                        {
                            if (rowInx > 0)
                            {
                                prevAddressLine1 = currentRandomNames[0].AddressLine1;
                            }
                            else
                            {
                                prevAddressLine1 = string.Empty;
                            }
                        }
                    }
                    if (generatedRandomNameRequested)
                    {
                        if (currentGeneratedRandomName != null)
                        {
                            if (rowInx > 0)
                            {
                                prevGeneratedAddressLine1 = currentGeneratedRandomName.AddressLine1;
                            }
                            else
                            {
                                prevGeneratedAddressLine1 = string.Empty;
                            }
                        }
                    }
                    //end test****************************************

                    if (generatedRandomNameRequested)
                    {
                        generatedRandomNameIndex++;
                        if (generatedRandomNameIndex >= this.BatchSizeForGeneratedRandomNames)
                        {
                            generatedRandomNamesList.Clear();
                            generatedRandomNamesList = null;
                            generatedRandomNamesList = rdp.GenerateRandomNameList(this.BatchSizeForGeneratedRandomNames);
                            generatedRandomNameIndex = 0;
                        }
                        currentGeneratedRandomName = generatedRandomNamesList[generatedRandomNameIndex];
                    }
                    currentRandomNames      = GetCurrentRandomNames(colSpecs, randomNameLists);
                    currentRandomDataValues = GetCurrentRandomDataValues(colSpecs, randomDataValueLists);

                    //test***********************************************
                    if (currentRandomNames.Count > 0)
                    {
                        if (currentRandomNames[0].AddressLine1 == prevAddressLine1)
                        {
                            numDups++;
                        }
                    }
                    if (generatedRandomNameRequested)
                    {
                        if (currentGeneratedRandomName.AddressLine1 == prevGeneratedAddressLine1)
                        {
                            numDups++;
                        }
                    }
                    //end test******************************************

                    for (int specInx = 0; specInx < colSpecs.Count; specInx++)
                    {
                        DataTableRandomizerColumnSpec spec = colSpecs[specInx];
                        DataRow dr  = dt.Rows[rowInx];
                        string  val = string.Empty;

                        try
                        {
                            if (spec.RandomDataType == enRandomDataType.RandomNamesAndLocations)
                            {
                                val = currentGeneratedRandomName.GetPropertyValue(spec.RandomDataFieldName).ToString();
                            }
                            else
                            {
                                val = currentRandomDataValues[spec.CurrentValueIndex];
                            }
                            if (dt.Columns[spec.DataTableColumnIndex].DataType == Type.GetType("System.String"))
                            {
                                dr[spec.DataTableColumnIndex] = val;
                            }
                            else
                            {
                                dr[spec.DataTableColumnIndex] = Convert.ChangeType(val, dt.Columns[spec.DataTableColumnIndex].DataType);
                            }
                        }
                        catch (System.Exception ex)
                        {
                            _msg.Length = 0;
                            _msg.Append("Unable to randomize data for ");
                            _msg.Append(spec.DataTableColumnName);
                            if (spec.DataTableColumnIndex < dt.Columns.Count)
                            {
                                _msg.Append(" Randomized value is of type System.String. DataTable column type is ");
                                _msg.Append(dt.Columns[spec.DataTableColumnIndex].DataType.FullName);
                                if (spec.RandomDataType == enRandomDataType.RandomNamesAndLocations)
                                {
                                    _msg.Append(".");
                                    _msg.Append(" Random  field is ");
                                    _msg.Append(spec.RandomDataFieldName);
                                }
                                _msg.Append(".");
                            }
                            else
                            {
                                _msg.Append("Invalid column index. Column with index of ");
                                _msg.Append(spec.DataTableColumnIndex.ToString());
                                _msg.Append(" does not exit. Thre are ");
                                _msg.Append(dt.Columns.Count.ToString());
                                _msg.Append(" columns in the DataTable with indexes from 0 to ");
                                _msg.Append((dt.Columns.Count - 1).ToString());
                                _msg.Append(".");
                            }
                            _msg.Append(Environment.NewLine);
                            _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                            throw new System.Exception(_msg.ToString());
                        }
                    } // end for loop on colSpecs
                }     // end for loop on dt.rows

                dt.AcceptChanges(); //commit changes
            }//end try
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("Number of dup persons or businesses: ");
                _msg.Append(numDups.ToString("#,##0"));
                //Console.WriteLine(_msg.ToString());
                DllMessageLogExt.WriteLine(_msg.ToString());
            }
        }//end method