private PFList <string> GetCurrentRandomDataValues(PFList <DataTableRandomizerColumnSpec> colSpecs, PFList <PFList <string> > randomDataValueLists)
        {
            PFList <string> currentRandomDataValues = new PFList <string>();

            currentRandomDataValues.Clear();

            for (int valInx = 0; valInx < randomDataValueLists.Count; valInx++)
            {
                PFList <string> randDataValues  = randomDataValueLists[valInx];
                int             randNum         = _randNumber.GenerateRandomInt(0, randDataValues.Count - 1);
                string          randStringValue = randDataValues[randNum];
                currentRandomDataValues.Add(randStringValue);
            }

            for (int specInx = 0; specInx < colSpecs.Count; specInx++)
            {
                DataTableRandomizerColumnSpec spec = colSpecs[specInx];
                if (spec.RandomDataType == enRandomDataType.CustomRandomValues)
                {
                    spec.CurrentValueIndex = spec.RandomDataListIndex;
                }
            }

            return(currentRandomDataValues);
        }
Exemple #2
0
        private void InitializeInstance(string directoryPath, bool getDirectoryTree)
        {
            string dirPath = directoryPath;

            FileInfo[]      fileInfos;
            DirectoryInfo[] dirInfos;

            if (directoryPath.EndsWith(Path.DirectorySeparatorChar.ToString()) == false)
            {
                dirPath = dirPath + Path.DirectorySeparatorChar;
            }
            _dirInfo = new DirectoryInfo(dirPath);
            //fileInfos = _dirInfo.GetFiles();
            fileInfos = GetFiles(_warningMessages);
            if (fileInfos.Length > 0)
            {
                for (int i = 0; i < fileInfos.Length; i++)
                {
                    _files.Add(new PFFileEx(fileInfos[i]));
                }
            }
            GetDirectorySize();
            if (getDirectoryTree)
            {
                //dirInfos = _dirInfo.GetDirectories();
                dirInfos = GetSubdirectories(_warningMessages);
                if (dirInfos.Length > 0)
                {
                    for (int i = 0; i < dirInfos.Length; i++)
                    {
                        _subdirectories.Add(new PFDirectoryEx(dirInfos[i].FullName, true));
                    }
                }
            }
        }
        private PFList <RandomName> GetCurrentRandomNames(PFList <DataTableRandomizerColumnSpec> colSpecs, PFList <PFList <RandomName> > randomNameLists)
        {
            PFList <RandomName> currentRandomNames = new PFList <RandomName>();

            currentRandomNames.Clear();

            for (int nameInx = 0; nameInx < randomNameLists.Count; nameInx++)
            {
                PFList <RandomName> randNames = randomNameLists[nameInx];
                int        randNum            = _randNumber.GenerateRandomInt(0, randNames.Count - 1);
                RandomName randName           = randNames[randNum];
                currentRandomNames.Add(randName);
            }

            for (int specInx = 0; specInx < colSpecs.Count; specInx++)
            {
                DataTableRandomizerColumnSpec spec = colSpecs[specInx];
                //if (spec.RandomDataType == enRandomDataType.RandomNamesAndLocationsFile)
                //{
                //    spec.CurrentValueIndex = spec.RandomDataListIndex;
                //}
            }

            return(currentRandomNames);
        }
Exemple #4
0
        /// <summary>
        /// Method to convert table definitions from another database format to the data format supported by the destination database class.
        /// </summary>
        /// <param name="tableDefs">Object containing the list of table definitions to be converted.</param>
        /// <param name="destinationDatabase">Database object pointing to database that will define converted table definitions.</param>
        /// <param name="newSchemaName">Specify a new schema (owner) name for the tables when they are recreated in the database managed by the current instance.</param>
        /// <returns>Object containing the list of table definitions after they have been converted to match the data formats of the current instance.</returns>
        public PFList <PFTableDef> ConvertTableDefs(PFList <PFTableDef> tableDefs, IDatabaseProvider destinationDatabase, string newSchemaName)
        {
            PFList <PFTableDef> newTableDefs = new PFList <PFTableDef>();
            PFTableDef          tabDef       = null;
            string tabName            = string.Empty;
            string schemaName         = string.Empty;
            string tabCreateStatement = string.Empty;

            tableDefs.SetToBOF();

            while ((tabDef = tableDefs.NextItem) != null)
            {
                string     tabDefXmlString = tabDef.ToXmlString();
                PFTableDef newTabDef       = PFTableDef.LoadFromXmlString(tabDefXmlString);

                tabName    = destinationDatabase.RebuildFullTableName(tabDef, newSchemaName);
                schemaName = String.IsNullOrEmpty(newSchemaName) == false ? newSchemaName : tabDef.TableOwner;
                newTabDef.TableObject.TableName = tabName;
                tabCreateStatement             = destinationDatabase.BuildTableCreateStatement(newTabDef.TableObject);
                newTabDef.DbPlatform           = destinationDatabase.DbPlatform;
                newTabDef.DbConnectionString   = destinationDatabase.ConnectionString;
                newTabDef.TableOwner           = schemaName;
                newTabDef.TableFullName        = tabName;
                newTabDef.TableCreateStatement = tabCreateStatement;
                newTableDefs.Add(newTabDef);
            }

            return(newTableDefs);
        }
        private void InitSyntaxLists()
        {
            for (int i = 0; i < _sentenceSyntaxDefs.Length; i++)
            {
                for (int f = 0; f < _sentenceSyntaxDefs[i].Frequency; f++)
                {
                    _sentenceSyntaxList.Add(_sentenceSyntaxDefs[i].Syntax);
                }
            }

            for (int i = 0; i < _subordinateClauseDefs.Length; i++)
            {
                for (int f = 0; f < _subordinateClauseDefs[i].Frequency; f++)
                {
                    _subordinateClauseList.Add(_subordinateClauseDefs[i].Syntax);
                }
            }

            for (int i = 0; i < _nounPhraseSyntaxDefs.Length; i++)
            {
                for (int f = 0; f < _nounPhraseSyntaxDefs[i].Frequency; f++)
                {
                    _nounPhraseSyntaxList.Add(_nounPhraseSyntaxDefs[i].Syntax);
                }
            }

            for (int i = 0; i < _subjectSyntaxDefs.Length; i++)
            {
                for (int f = 0; f < _subjectSyntaxDefs[i].Frequency; f++)
                {
                    _subjectSyntaxList.Add(_subjectSyntaxDefs[i].Syntax);
                }
            }

            for (int i = 0; i < _verbPhraseSyntaxDefs.Length; i++)
            {
                for (int f = 0; f < _verbPhraseSyntaxDefs[i].Frequency; f++)
                {
                    _verbPhraseSyntaxList.Add(_verbPhraseSyntaxDefs[i].Syntax);
                }
            }

            for (int i = 0; i < _objectSyntaxDefs.Length; i++)
            {
                for (int f = 0; f < _objectSyntaxDefs[i].Frequency; f++)
                {
                    _objectSyntaxList.Add(_objectSyntaxDefs[i].Syntax);
                }
            }

            for (int i = 0; i < _sentenceTerminatorDefs.Length; i++)
            {
                for (int f = 0; f < _sentenceTerminatorDefs[i].Frequency; f++)
                {
                    _sentenceTerminatorList.Add(_sentenceTerminatorDefs[i].Syntax);
                }
            }
        }
Exemple #6
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());
            }
        }
Exemple #7
0
        private PFList <PFTask> GetTaskListXML()
        {
            PFList <PFTask> taskList = new PFList <PFTask>();

            string[] taskFiles = null;


            taskFiles = Directory.GetFiles(this.ConnectionString, "*.xml", SearchOption.TopDirectoryOnly);

            if (taskFiles != null)
            {
                for (int i = 0; i < taskFiles.Length; i++)
                {
                    PFTask task = PFTask.LoadFromXmlFile(taskFiles[i]);
                    taskList.Add(task);
                }
            }

            return(taskList);
        }
Exemple #8
0
        private PFList <PFSchedule> GetScheduleListXML()
        {
            PFList <PFSchedule> scheduleList = new PFList <PFSchedule>();

            string[] scheduleFiles = null;


            scheduleFiles = Directory.GetFiles(this.ConnectionString, "*.xml", SearchOption.TopDirectoryOnly);

            if (scheduleFiles != null)
            {
                for (int i = 0; i < scheduleFiles.Length; i++)
                {
                    PFSchedule schedule = PFSchedule.LoadFromXmlFile(scheduleFiles[i]);
                    scheduleList.Add(schedule);
                }
            }

            return(scheduleList);
        }
Exemple #9
0
        private PFList <PFTaskHistoryEntry> GetTaskListDatabase(string taskName)
        {
            PFList <PFTaskHistoryEntry> taskHistoryEntryList = new PFList <PFTaskHistoryEntry>();
            PFDatabase db      = null;
            string     sqlStmt = string.Empty;

            try
            {
                db = new PFDatabase(DatabasePlatform.SQLServerCE35);
                db.ConnectionString = this.ConnectionString;
                db.OpenConnection();

                sqlStmt = _taskHistoryDefinitionsSelectTaskSQL.Replace("<taskname>", taskName);
                DbDataReader rdr = db.RunQueryDataReader(sqlStmt, System.Data.CommandType.Text);

                while (rdr.Read())
                {
                    string             str = rdr["TaskHistoryObject"].ToString();
                    PFTaskHistoryEntry the = PFTaskHistoryEntry.LoadFromXmlString(str);
                    taskHistoryEntryList.Add(the);
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    if (db.IsConnected)
                    {
                        db.CloseConnection();
                    }
                }
            }



            return(taskHistoryEntryList);
        }
Exemple #10
0
        private PFList <PFTaskHistoryEntry> GetTaskListXML(string taskName)
        {
            PFList <PFTaskHistoryEntry> taskHistoryEntryList = new PFList <PFTaskHistoryEntry>();

            string[] taskHistoryEntryFiles = null;
            string   searchPattern         = taskName + "*.xml";


            taskHistoryEntryFiles = Directory.GetFiles(this.ConnectionString, searchPattern, SearchOption.TopDirectoryOnly);

            if (taskHistoryEntryFiles != null)
            {
                for (int i = 0; i < taskHistoryEntryFiles.Length; i++)
                {
                    PFTaskHistoryEntry the = PFTaskHistoryEntry.LoadFromXmlFile(taskHistoryEntryFiles[i]);
                    taskHistoryEntryList.Add(the);
                }
            }

            return(taskHistoryEntryList);
        }
Exemple #11
0
        private PFList <PFSchedule> GetScheduleListDatabase()
        {
            PFList <PFSchedule> scheduleList = new PFList <PFSchedule>();
            PFDatabase          db           = null;

            try
            {
                db = new PFDatabase(DatabasePlatform.SQLServerCE35);
                db.ConnectionString = this.ConnectionString;
                db.OpenConnection();

                DbDataReader rdr = db.RunQueryDataReader(_scheduleDefinitionsSelectAllSQL, System.Data.CommandType.Text);

                while (rdr.Read())
                {
                    string     str      = rdr["ScheduleObject"].ToString();
                    PFSchedule schedule = PFSchedule.LoadFromXmlString(str);
                    scheduleList.Add(schedule);
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    if (db.IsConnected)
                    {
                        db.CloseConnection();
                    }
                }
            }



            return(scheduleList);
        }
        /// <summary>
        /// Routine to use column definitions in a DataTable to initialize a DataTableRandomizerColumnSpec list.
        /// </summary>
        /// <param name="dt">DataTable object containing columns to include in the column specification list.</param>
        /// <returns>List of DataTableRandomizerColumnSpec objects.</returns>
        public PFList <DataTableRandomizerColumnSpec> GetInitColSpecListFromDataTable(DataTable dt)
        {
            PFList <DataTableRandomizerColumnSpec> colSpecs = new PFList <DataTableRandomizerColumnSpec>();

            if (dt == null)
            {
                _msg.Length = 0;
                _msg.Append("DataTable is null. You must specify an instance of a DataTable in order to get a list of column specs.");
                throw new System.Exception(_msg.ToString());
            }

            for (int colInx = 0; colInx < dt.Columns.Count; colInx++)
            {
                DataColumn dc = dt.Columns[colInx];
                DataTableRandomizerColumnSpec colSpec = new DataTableRandomizerColumnSpec();
                colSpec.DataTableColumnName     = dc.ColumnName;
                colSpec.DataTableColumnDataType = dc.DataType.FullName;
                //remainder of properties are left at their default values: to be filled in by application using the column specs.
                colSpecs.Add(colSpec);
            }

            return(colSpecs);
        }
Exemple #13
0
        private void OutputRandomDataFile(RandomCustomValuesDataRequest dataRequest, ref DataTable dt, string sqlStatement, int valueInx, int frequencyInx, int adjustedFrequencyInx, int adjustmentNumberInx)
        {
            string          randomDataFileName         = Path.Combine(dataRequest.ListFolder, dataRequest.ListName + ".xml");
            string          randomDataSummaryFile      = Path.Combine(dataRequest.ListFolder, dataRequest.ListName + ".clistsum");
            string          randomDataDefinition       = Path.Combine(dataRequest.ListFolder, dataRequest.ListName + ".clistdef");
            string          randomDataSQLStatementFile = Path.Combine(dataRequest.ListFolder, dataRequest.ListName + ".sql");
            PFList <string> randomDataList             = new PFList <string>();
            int             frequency = 0;

            dt.WriteXml(randomDataSummaryFile, XmlWriteMode.WriteSchema);
            dataRequest.SaveToXmlFile(randomDataDefinition);
            System.IO.File.WriteAllText(randomDataSQLStatementFile, sqlStatement);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                frequency = Convert.ToInt32(dt.Rows[i][adjustedFrequencyInx].ToString());
                for (int k = 0; k < frequency; k++)
                {
                    randomDataList.Add(dt.Rows[i][valueInx].ToString());
                }
            }

            randomDataList.SaveToXmlFile(randomDataFileName);
        }
Exemple #14
0
        public void SortedKeyValueListMergeTest()
        {
            PFKeyValueListSorted <int, string> list1 = new PFKeyValueListSorted <int, string>();
            PFKeyValueListSorted <int, string> list2 = new PFKeyValueListSorted <int, string>();
            PFKeyValueListSorted <int, string> list3 = new PFKeyValueListSorted <int, string>();

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

                list1.Add(1, "First");
                list1.Add(2, "Second");
                list1.Add(3, "Third");

                list2.Add(4, "fourth");
                list2.Add(5, "fifth");
                list2.Add(6, "sixth");

                list3.Add(7, "Seventh");
                list3.Add(8, "Eighth");
                list3.Add(9, "Ninth");
                list3.Add(10, "Tenth");

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

                PFKeyValueListSorted <int, string> concatListFromArray = PFKeyValueListSorted <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());


                PFKeyValueListSorted <int, string> concatListFromList = PFKeyValueListSorted <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());

                PFKeyValueListSorted <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 PFKeyValueListSorted <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 <PFKeyValueListSorted <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());

                PFKeyValueListSorted <int, string> copyOfList = list2.Copy();
                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append("Copy of list");
                _msg.Append(Environment.NewLine);
                _msg.Append(copyOfList.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... SortedKeyValueListMergeTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
        /// <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
Exemple #16
0
        //tests
        public void GenericListTest()
        {
            PFList <string>            testList         = new PFList <string>();
            PFList <string>            testList2        = new PFList <string>();
            PFList <string>            testList3        = new PFList <string>();
            PFList <string>            testList4        = new PFList <string>();
            string                     testListXmlFile  = @"c:\temp\testlist.xml";
            string                     connectionString = string.Empty;
            string                     configValue      = string.Empty;
            PFDBListProcessor <string> listProcessor    = new PFDBListProcessor <string>();

            try
            {
                _msg.Length = 0;
                _msg.Append("GenericListTest started ...");
                Program._messageLog.WriteLine(_msg.ToString());

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


                _msg.Length = 0;
                _msg.Append("First = ");
                _msg.Append(testList.FirstItem == null ? "<null>" : testList.FirstItem);
                Program._messageLog.WriteLine(_msg.ToString());

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

                _msg.Length = 0;
                _msg.Append("Number of items in list: ");
                Program._messageLog.WriteLine(_msg.ToString());

                foreach (string s in testList)
                {
                    _msg.Length = 0;
                    _msg.Append(s);
                    Program._messageLog.WriteLine(_msg.ToString());
                }

                _msg.Length = 0;
                _msg.Append("First = ");
                _msg.Append(testList.FirstItem);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Last = ");
                _msg.Append(testList.LastItem);
                Program._messageLog.WriteLine(_msg.ToString());


                _msg.Length = 0;
                _msg.Append("NextItem loop: ");
                Program._messageLog.WriteLine(_msg.ToString());

                string res = testList.FirstItem;
                while (!testList.EOF)
                {
                    _msg.Length = 0;
                    _msg.Append(res);
                    Program._messageLog.WriteLine(_msg.ToString());
                    res = testList.NextItem;
                }

                _msg.Length = 0;
                _msg.Append("PrevItem loop: ");
                Program._messageLog.WriteLine(_msg.ToString());

                res = testList.LastItem;
                while (!testList.EOF)
                {
                    _msg.Length = 0;
                    _msg.Append(res);
                    Program._messageLog.WriteLine(_msg.ToString());
                    res = testList.PrevItem;
                }

                _msg.Length = 0;
                _msg.Append("ToString Test: ");
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append(testList.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("SaveToXmlFile Test: ");
                _msg.Append(testListXmlFile);
                Program._messageLog.WriteLine(_msg.ToString());

                testList.SaveToXmlFile(testListXmlFile);

                _msg.Length = 0;
                _msg.Append("LoadFromXmlFile Test: ");
                _msg.Append(testListXmlFile);
                Program._messageLog.WriteLine(_msg.ToString());

                testList2 = PFList <string> .LoadFromXmlFile(testListXmlFile);

                _msg.Length = 0;
                _msg.Append("testList2 ToString Test: ");
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append(testList2.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                //save and read to database tests next
                listProcessor.SaveToDatabase(testList, connectionString, "TestprogCollections_testList");

                testList3 = listProcessor.LoadFromDatabase(connectionString, "TestprogCollections_testList");

                if (testList3 != null)
                {
                    _msg.Length = 0;
                    _msg.Append("testList3 ToXmlString Test: ");
                    Program._messageLog.WriteLine(_msg.ToString());
                    _msg.Length = 0;
                    _msg.Append(testList3.ToXmlString());
                    _msg.Append(Environment.NewLine);
                    _msg.Append("+++ testlist3 retrieved. +++");
                    Program._messageLog.WriteLine(_msg.ToString());
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("testList3 ToXmlString Test: ");
                    Program._messageLog.WriteLine(_msg.ToString());
                    _msg.Length = 0;
                    _msg.Append("*** TESTLIST3 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
            {
                listProcessor = null;
                _msg.Length   = 0;
                _msg.Append("... GenericListTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }//end GenericListTest
Exemple #17
0
        private FileInfo[] GetFiles(PFList <string> warningMessages)
        {
            List <string>   files     = null;
            List <FileInfo> fileInfos = new List <FileInfo>();

            try
            {
                files = new List <string>(Directory.EnumerateFiles(this.FullName));
            }
            catch (UnauthorizedAccessException UAEx)
            {
                _msg.Length = 0;
                _msg.Append("Access denied: Unable to retrieve file information list. Permissions exception: ");
                _msg.Append(this.FullName);
                _msg.Append(" Error message: ");
                _msg.Append(AppMessages.FormatErrorMessage(UAEx));
                _msg.Append("\r\n");
                warningMessages.Add(_msg.ToString());
            }
            catch (PathTooLongException PathEx)
            {
                _msg.Length = 0;
                _msg.Append("Access denied: Unable to retrieve file information list. Path too long exception: ");
                _msg.Append(this.FullName);
                _msg.Append(" Error message: ");
                _msg.Append(AppMessages.FormatErrorMessage(PathEx));
                _msg.Append("\r\n");
                warningMessages.Add(_msg.ToString());
            }

            if (files != null)
            {
                foreach (var fileItem in files)
                {
                    try
                    {
                        FileInfo file = new FileInfo(fileItem);
                        fileInfos.Add(file);
                    }
                    catch (UnauthorizedAccessException UAEx)
                    {
                        _msg.Length = 0;
                        _msg.Append("Access denied: Permissions exception: ");
                        _msg.Append(fileItem);
                        _msg.Append(" Error message: ");
                        _msg.Append(AppMessages.FormatErrorMessage(UAEx));
                        _msg.Append("\r\n");
                        warningMessages.Add(_msg.ToString());
                    }
                    catch (PathTooLongException PathEx)
                    {
                        _msg.Length = 0;
                        _msg.Append("Access denied: Path too long exception: ");
                        _msg.Append(fileItem);
                        _msg.Append(" Error message: ");
                        _msg.Append(AppMessages.FormatErrorMessage(PathEx));
                        _msg.Append("\r\n");
                        warningMessages.Add(_msg.ToString());
                    }
                    catch (System.Exception ex)
                    {
                        _msg.Length = 0;
                        _msg.Append("Unable to process: ");
                        _msg.Append(fileItem);
                        _msg.Append(" Error message: ");
                        _msg.Append(AppMessages.FormatErrorMessage(ex));
                        _msg.Append("\r\n");
                        warningMessages.Add(_msg.ToString());
                    }
                }
            }

            return(fileInfos.ToArray());
        }
        private void SaveLogMessageToRetryQueue(PFLogMessage logMessage)
        {
            _logRetryQueue.Add(logMessage);

            SaveRetryQueue();
        }
        private void InitInstance(IDatabaseProvider db, string schemaName, string tableName, bool dropOldTable)
        {
            _db           = db;
            _schemaName   = schemaName;
            _dropOldTable = dropOldTable;
            if (tableName.Trim().Length > 0)
            {
                _tableName = tableName;
            }
            else
            {
                _tableName = "TestTable01";
            }

            if (_db.IsConnected == false)
            {
                _msg.Length = 0;
                _msg.Append("Database connection is closed. It must be open before passing it to this instance of PFUnitTestDataTable class.");
                throw new System.Exception(_msg.ToString());
            }

            TableColumn k1 = new TableColumn("K1", "System.Int32", "1", -1, true, false, false);
            TableColumn f1 = new TableColumn("F1", "System.String", "Short string value", 50, true, false, true);
            //TableColumn f1a = new TableColumn("F1A", "System.String", "Much longer string value goes into this field", 50000, true, false, true);
            TableColumn f2  = new TableColumn("F2", "System.Int32", "1123456789", -1, true, false, true);
            TableColumn f2a = new TableColumn("F2A", "System.UInt32", "3123456789", -1, true, false, true);
            TableColumn f3  = new TableColumn("F3", "System.Int64", "23123456789", -1, true, false, true);
            TableColumn f3a = new TableColumn("F3A", "System.UInt64", "8881234567889", -1, true, false, true);
            TableColumn f4  = new TableColumn("F4", "System.Int16", "11123", -1, true, false, true);
            TableColumn f4a = new TableColumn("F4A", "System.UInt16", "52432", -1, true, false, true);
            TableColumn f5  = new TableColumn("F5", "System.Double", "123456.7654", -1, true, false, true);
            TableColumn f6  = new TableColumn("F6", "System.Single", "321.234", -1, true, false, true);
            TableColumn f7  = new TableColumn("F7", "System.Decimal", "2123456789.22", -1, true, false, true);
            TableColumn f8  = new TableColumn("F8", "System.Char", "A", -1, true, false, true);
            TableColumn f8a = new TableColumn("F8A", "System.Char[]", "ABCDEFGH", -1, true, false, true);
            TableColumn f9  = new TableColumn("F9", "System.Byte", "254", -1, true, false, true);
            TableColumn f9a = new TableColumn("F9A", "System.SByte", "125", -1, true, false, true);
            TableColumn f9b = new TableColumn("F9B", "System.Byte[]", "UVWZYZ)", -1, true, false, true);
            TableColumn f10 = new TableColumn("F10", "System.Boolean", "true", -1, true, false, true);
            TableColumn f11 = new TableColumn("F11", "System.Object", "This is an object: be careful!", -1, true, false, true);
            TableColumn f12 = new TableColumn("F12", "System.DateTime", "5/31/2013 13:54:25", -1, true, false, true);
            TableColumn f13 = new TableColumn("F13", "System.Guid", "58a4a08d-6101-4393-86dc-b2a8db46ec0f", -1, true, false, true);


            _tableColumns.Add(k1);
            _tableColumns.Add(f1);
            _tableColumns.Add(f2);
            _tableColumns.Add(f2a);
            _tableColumns.Add(f3);
            _tableColumns.Add(f3a);
            _tableColumns.Add(f4);
            _tableColumns.Add(f4a);
            _tableColumns.Add(f5);
            _tableColumns.Add(f6);
            _tableColumns.Add(f7);
            _tableColumns.Add(f8);
            _tableColumns.Add(f8a);
            _tableColumns.Add(f9);
            _tableColumns.Add(f9a);
            _tableColumns.Add(f9b);
            _tableColumns.Add(f10);
            _tableColumns.Add(f11);
            _tableColumns.Add(f12);
            _tableColumns.Add(f13);
        }
Exemple #20
0
        private DirectoryInfo[] GetSubdirectories(PFList <string> warningMessages)
        {
            List <string>        dirs     = null;
            List <DirectoryInfo> dirInfos = new List <DirectoryInfo>();

            try
            {
                dirs = new List <string>(Directory.EnumerateDirectories(this.FullName));
            }
            catch (UnauthorizedAccessException UAEx)
            {
                _msg.Length = 0;
                _msg.Append("Access denied: Unable to retrieve directory information list. Permissions exception: ");
                _msg.Append(this.FullName);
                _msg.Append(" Error message: ");
                _msg.Append(AppMessages.FormatErrorMessage(UAEx));
                _msg.Append("\r\n");
                warningMessages.Add(_msg.ToString());
            }
            catch (PathTooLongException PathEx)
            {
                _msg.Length = 0;
                _msg.Append("Access denied: Unable to retrieve directory information list. Path too long exception: ");
                _msg.Append(this.FullName);
                _msg.Append(" Error message: ");
                _msg.Append(AppMessages.FormatErrorMessage(PathEx));
                _msg.Append("\r\n");
                warningMessages.Add(_msg.ToString());
            }
            catch (DirectoryNotFoundException NotFoundEx)
            {
                _msg.Length = 0;
                _msg.Append("Directory does not exist: ");
                _msg.Append(this.FullName);
                _msg.Append(" Error message: ");
                _msg.Append(AppMessages.FormatErrorMessage(NotFoundEx));
                _msg.Append("\r\n");
                warningMessages.Add(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Unable to process: ");
                _msg.Append(this.FullName);
                _msg.Append(" Error message: ");
                _msg.Append(AppMessages.FormatErrorMessage(ex));
                _msg.Append("\r\n");
                warningMessages.Add(_msg.ToString());
            }

            if (dirs != null)
            {
                foreach (var subdirItem in dirs)
                {
                    try
                    {
                        DirectoryInfo subdir = new DirectoryInfo(subdirItem);
                        dirInfos.Add(subdir);
                    }
                    catch (UnauthorizedAccessException UAEx)
                    {
                        _msg.Length = 0;
                        _msg.Append("Access denied: Permissions exception: ");
                        _msg.Append(subdirItem);
                        _msg.Append(" Error message: ");
                        _msg.Append(AppMessages.FormatErrorMessage(UAEx));
                        _msg.Append("\r\n");
                        warningMessages.Add(_msg.ToString());
                    }
                    catch (PathTooLongException PathEx)
                    {
                        _msg.Length = 0;
                        _msg.Append("Access denied: Path too long exception: ");
                        _msg.Append(subdirItem);
                        _msg.Append(" Error message: ");
                        _msg.Append(AppMessages.FormatErrorMessage(PathEx));
                        _msg.Append("\r\n");
                        warningMessages.Add(_msg.ToString());
                    }
                    catch (System.Exception ex)
                    {
                        _msg.Length = 0;
                        _msg.Append("Unable to process: ");
                        _msg.Append(subdirItem);
                        _msg.Append(" Error message: ");
                        _msg.Append(AppMessages.FormatErrorMessage(ex));
                        _msg.Append("\r\n");
                        warningMessages.Add(_msg.ToString());
                    }
                }
            }

            return(dirInfos.ToArray());
        }
Exemple #21
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());
            }
        }
Exemple #22
0
        private void FillConnectionStringsList()
        {
            _connectionStrings.Add(@"MSSQLServer" + @"|" + @"Data Source=PROFASTWS3; Initial Catalog=AdventureWorksDW2008R2; Integrated Security=True; Application Name=TestprogTableDefs; Workstation ID=PROFASTWS5;");
            _connectionStrings.Add(@"MSSQLServer" + @"|" + @"Data Source=PROFASTSV2; Initial Catalog=AdventureWorksDW2008R2; Integrated Security=True; Application Name=TestprogTableDefs; Workstation ID=PROFASTWS5;");
            _connectionStrings.Add(@"MSSQLServer" + @"|" + @"Data Source=PROFASTSV2; Initial Catalog=AWTest; Integrated Security=True; Application Name=TestprogTableDefs; Workstation ID=PROFASTWS5;");
            _connectionStrings.Add(@"MSSQLServer" + @"|" + @"Data Source=PROFASTWS3; Initial Catalog=Namelists; Integrated Security=True; Application Name=TestprogTableDefs; Workstation ID=PROFASTWS5;");
            _connectionStrings.Add(@"MSOracle" + @"|" + @"Data Source=PROFASTSV4ORA;User ID=SYSTEM;Password=ORA1992;");
            _connectionStrings.Add(@"OracleNative" + @"|" + @"Data Source=PROFASTSV4ORA;User ID=SYSTEM;Password=ORA1992;");
            _connectionStrings.Add(@"DB2" + @"|" + @"Database=SAMPLE;User ID=MIKE;Password=MIKE92;Server=PROFASTSV4DB2:50000;");
            _connectionStrings.Add(@"MySQL" + @"|" + @"server=PROFASTSV4MYSQL; port=3306; database=SAKILA;User Id=Mike; password=MIKE92;");
            _connectionStrings.Add(@"Sybase|Data Source=PROFASTSV2SYB;Port=5000;Database=AdventureWorks;Uid=SA;Pwd=SA1992;");
            _connectionStrings.Add(@"SQLAnywhere" + @"|" + @"UserID=DBA;Password=sql;DatabaseName=AdventureWorks;DatabaseFile=C:\Testdata\SQLAnywhere\AdventureWorks.Db;ServerName=AdventureWorks");
            _connectionStrings.Add(@"SQLAnywhere" + @"|" + @"UserID=DBA;Password=sql;DatabaseFile=C:\Temp\newSQL.Db;ServerName=newSQL");
            _connectionStrings.Add(@"SQLAnywhere" + @"|" + @"UserID=DBA;Password=sql;DatabaseFile=C:\Users\Public\Documents\SQL Anywhere 12\Samples\demo.db;ServerName=demo12");
            _connectionStrings.Add(@"SQLAnywhere" + @"|" + @"UserID=DBA;Password=sql;DatabaseFile=C:\Users\Public\Documents\SQL Anywhere 12\Samples\ultralite\custdb\custdb.db;ServerName=custdb");
            _connectionStrings.Add(@"SQLAnywhereUltraLite" + @"|" + @"nt_file=C:\Testdata\SQLAnywhere\Test1.udb;dbn=Test1;uid=DBA;pwd=sql");
            _connectionStrings.Add(@"SQLServerCE40" + @"|" + @"data source='c:\SQLData\nametestV4.sdf';");
            _connectionStrings.Add(@"SQLServerCE35" + @"|" + @"data source='c:\SQLData\nametestV4_35.sdf';");
            _connectionStrings.Add(@"MSAccess" + @"|" + @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Testdata\Access\AdventureWorksDW.accdb;User Id=admin;Password=;Jet OLEDB:Engine Type=6;");
            _connectionStrings.Add(@"MSAccess" + @"|" + @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Testdata\Access\AdventureWorksDW.mdb;User Id=admin;Password=;Jet OLEDB:Engine Type=5;");

            _connectionStrings.Add(@"ODBC" + @"|" + @"Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\Testdata\Access\AdventureWorksDW.accdb;Uid=Admin;Pwd=;");
            _connectionStrings.Add(@"ODBC" + "|" + @"Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\Testdata\Access\AdventureWorksDW.mdb;Uid=Admin;Pwd=;");
            _connectionStrings.Add(@"ODBC" + "|" + @"Driver={SQL Server Native Client 10.0};Server=profastws3;Database=AdventureWorksDW2008R2;Trusted_Connection=yes;");
            _connectionStrings.Add(@"ODBC" + "|" + @"Driver={SQL Server Native Client 10.0};Server=profastws3;Database=Namelists;Trusted_Connection=yes;");
            _connectionStrings.Add(@"ODBC" + "|" + @"Driver={Oracle in OraClient11g_home1};Dbq=ORASV4;Uid=SYSTEM;Pwd=ORA1992;");
            _connectionStrings.Add(@"ODBC" + "|" + @"Driver={Microsoft ODBC for Oracle};Server=ORASV4;Uid=SYSTEM;Pwd=ORA1992;");
            _connectionStrings.Add(@"ODBC" + "|" + @"Driver={IBM DB2 ODBC DRIVER};Database=sample;Hostname=profastsv4db2;Port=50000;Protocol=TCPIP;Uid=Mike;Pwd=MIKE92;");
            _connectionStrings.Add(@"ODBC" + "|" + @"Driver={MySQL ODBC 5.2w Driver};Server=profastsv4mysql;Database=SAKILA;User=Mike;Password=MIKE92;Option=3;");
            _connectionStrings.Add(@"ODBC" + "|" + @"Driver={Adaptive Server Enterprise};server=profastsv2syb;port=5000;sourceDb=AdventureWorks;uid=SA;Pwd=SA1992;");
            _connectionStrings.Add(@"ODBC" + "|" + @"Driver={SQL Anywhere 12};Uid=DBA;Pwd=sql;DBF=C:\Testdata\SQLAnywhere\AdventureWorks.sourceDb;");

            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Testdata\Access\AdventureWorksDW.accdb;User Id=admin;Password=;Jet OLEDB:Engine Type=6");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Testdata\Access\AdventureWorksDW.mdb;User Id=admin;Password=;Jet OLEDB:Engine Type=6;");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Testdata\Access\AdventureWorksDW.mdb;User Id=admin;Password=;Jet OLEDB:Engine Type=5;");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=SQLOLEDB;Data Source=PROFASTWS3;Initial Catalog=AdventureWorksDW2008R2;Integrated Security=SSPI;");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=SQLOLEDB;Data Source=PROFASTWS3;Initial Catalog=Namelists;Integrated Security=SSPI;");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\SQLData\nametest.sdf;");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=msdaora;Data Source=ORASV4;User Id=SYSTEM;Password=ORA1992;");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=OraOLEDB.Oracle;Data Source=ORASV4;User Id=SYSTEM;Password=ORA1992;");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=IBMDADB2;Database=sample;Hostname=profastsv4db2;Port=50000;Protocol=TCPIP;Uid=Mike;Pwd=MIKE92;");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=ASEOLEDB;Data Source=PROFASTSV2SYB:5000;Initial Catalog=AdventureWorks;User Id=SA;Password=SA1992;");
            _connectionStrings.Add(@"OLEDB" + "|" + @"Provider=SAOLEDB;Data Source=SQLAnywhere_AdventureWorks;Initial Catalog=AdventureWorks;User Id=DBA;Password=sql;");
        }
Exemple #23
0
        /// <summary>
        /// Retrieves list of tables and their associated schema information contained in the database pointed to by the current connection.
        /// </summary>
        /// <param name="sourceDatabase">Database from which the table list will be retrieved.</param>
        /// <param name="includePatterns">Wildard pattern to use when selecting which tables to include. Specify * or null or empty string for pattern to include all tables.</param>
        /// <param name="excludePatterns">Wildard pattern to use when selecting which tables to exclude. Specify * for pattern to exclude all tables. Specify null or empty string to exclude no tables.</param>
        /// <returns>Object containing the list of table definitions.</returns>
        public PFList <PFTableDef> GetTableList(IDatabaseProvider sourceDatabase, string[] includePatterns, string[] excludePatterns)
        {
            PFList <PFTableDef> tableDefs = new PFList <PFTableDef>();
            DataTable           dt        = null;
            string sqlSelect = "select * from <tableName> where 1=0";

            PFSearchPattern[] regexInclude = null;
            PFSearchPattern[] regexExclude = null;

            regexInclude = GetSearchPatternRegexObjects(includePatterns, "*");
            regexExclude = GetSearchPatternRegexObjects(excludePatterns, string.Empty);

            if (sourceDatabase.IsConnected == false)
            {
                _msg.Length = 0;
                _msg.Append("You must be connected to a database to run GetTableList method.");
                throw new System.Exception(_msg.ToString());
            }

            dt = sourceDatabase.Connection.GetSchema("Tables");

            foreach (DataRow dr in dt.Rows)
            {
                if (sourceDatabase.TypeIsUserTable(dr))
                {
                    string tabName = sourceDatabase.GetFullTableName(dr);
                    if (IsMatchToPattern(regexInclude, tabName) && IsMatchToPattern(regexExclude, tabName) == false)
                    {
                        string sql = sqlSelect.Replace("<tableName>", tabName);
                        try
                        {
                            dt = sourceDatabase.RunQueryDataTable(sql, CommandType.Text);
                        }
                        catch
                        {
                            dt = new DataTable(tabName);
                        }
                        string tabCreateStatement = string.Empty;
                        dt.TableName = tabName;
                        try
                        {
                            tabCreateStatement = sourceDatabase.BuildTableCreateStatement(dt);
                        }
                        catch
                        {
                            tabCreateStatement = "Unable to build create statement. Error occurred in BuildTableCreateStatement.";
                        }
                        PFTableDef tabDef = new PFTableDef();
                        tabDef.DbPlatform           = sourceDatabase.DbPlatform;
                        tabDef.DbConnectionString   = sourceDatabase.ConnectionString;
                        tabDef.TableCreateStatement = tabCreateStatement;
                        tabDef.TableObject          = dt;
                        tabDef.TableFullName        = tabName;
                        TableNameQualifiers tnq = sourceDatabase.GetTableNameQualifiers(dr);
                        tabDef.TableCatalog = tnq.TableCatalog;
                        tabDef.TableOwner   = tnq.TableSchema;
                        tabDef.TableName    = tnq.TableName;
                        tableDefs.Add(tabDef);
                    }
                }
            }

            return(tableDefs);
        }
        /// <summary>
        /// Synchronizes the list of column specifications with the current query definition.
        /// </summary>
        /// <param name="queryDef">File containing the current query definitiion.</param>
        /// <param name="colSpecs">List containing the existing column specifications.</param>
        /// <remarks>This routine is used to catch any changes made to a query after a set of column specifications were generated.</remarks>
        public void SyncColSpecsWithDataSchema(pfQueryDef queryDef, ref PFList <DataTableRandomizerColumnSpec> colSpecs)
        {
            PFList <DataTableRandomizerColumnSpec> newColSpecs = new PFList <DataTableRandomizerColumnSpec>();
            DataTable dt = null;

            if (colSpecs == null || queryDef.RandomizerColSpecs == null)
            {
                return;
            }

            try
            {
                dt = GetQueryDefSchema(queryDef);

                if (dt == null)
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to retrieve query schema in SyncColSpecsWithDataSchema routine for ");
                    _msg.Append(queryDef.QueryName);
                    _msg.Append(".");
                    WriteMessageToLog(_msg.ToString());
                    AppMessages.DisplayErrorMessage(_msg.ToString());
                    return;
                }
                else if (dt.Columns == null)
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to retrieve query schema column list in SyncColSpecsWithDataSchema routine for ");
                    _msg.Append(queryDef.QueryName);
                    _msg.Append(".");
                    WriteMessageToLog(_msg.ToString());
                    AppMessages.DisplayErrorMessage(_msg.ToString());
                    return;
                }
                else if (dt.Columns.Count == 0)
                {
                    _msg.Length = 0;
                    _msg.Append("Query text must specify one or more data columns for SyncColSpecsWithDataSchema routine.");
                    WriteMessageToLog(_msg.ToString());
                    AppMessages.DisplayErrorMessage(_msg.ToString());
                    return;
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("SyncColSpecsWithDataSchema will process queryDef ");
                    _msg.Append(queryDef.QueryName);
                    WriteMessageToLog(_msg.ToString());
                }

                for (int dtColInx = 0; dtColInx < dt.Columns.Count; dtColInx++)
                {
                    DataTableRandomizerColumnSpec newColSpec = new DataTableRandomizerColumnSpec();
                    for (int colSpecsInx = 0; colSpecsInx < colSpecs.Count; colSpecsInx++)
                    {
                        if (dt.Columns[dtColInx].ColumnName.ToLower() == colSpecs[colSpecsInx].DataTableColumnName.ToLower())
                        {
                            newColSpec.DataTableColumnName           = colSpecs[colSpecsInx].DataTableColumnName;
                            newColSpec.DataTableColumnIndex          = colSpecs[colSpecsInx].DataTableColumnIndex;
                            newColSpec.DataTableColumnDataType       = colSpecs[colSpecsInx].DataTableColumnDataType;
                            newColSpec.CurrentValueIndex             = colSpecs[colSpecsInx].CurrentValueIndex;
                            newColSpec.RandomDataFieldColumnIndex    = colSpecs[colSpecsInx].RandomDataFieldColumnIndex;
                            newColSpec.RandomDataFieldName           = colSpecs[colSpecsInx].RandomDataFieldName;
                            newColSpec.RandomDataFileName            = colSpecs[colSpecsInx].RandomDataFileName;
                            newColSpec.RandomDataListIndex           = colSpecs[colSpecsInx].RandomDataListIndex;
                            newColSpec.RandomDataSource              = colSpecs[colSpecsInx].RandomDataSource;
                            newColSpec.RandomDataType                = colSpecs[colSpecsInx].RandomDataType;
                            newColSpec.RandomDataTypeProcessorIndex  = colSpecs[colSpecsInx].RandomDataTypeProcessorIndex;
                            newColSpec.RandomNamesAndLocationsNumber = colSpecs[colSpecsInx].RandomNamesAndLocationsNumber;
                            break;
                        }
                    } //end for loop colSpecInx
                    newColSpecs.Add(newColSpec);
                }     //end for loop dtColInx

                if (dt.Columns.Count != newColSpecs.Count)
                {
                    _msg.Length = 0;
                    _msg.Append("SyncColSpecsWithDataSchema has failed: DataTable column count does not match count for new column specs list.");
                    _msg.Append(Environment.NewLine);
                    _msg.Append("Data Table Column count:       ");
                    _msg.Append(dt.Columns.Count.ToString());
                    _msg.Append(Environment.NewLine);
                    _msg.Append("New Column Specs Column count: ");
                    _msg.Append(newColSpecs.Count.ToString());
                    _msg.Append(Environment.NewLine);
                    _msg.Append("Query Definition Name:         ");
                    _msg.Append(queryDef.QueryName);
                    WriteMessageToLog(_msg.ToString());
                    throw new System.Exception(_msg.ToString());
                }

                colSpecs = newColSpecs;
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                WriteMessageToLog(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                ;
            }
        } //end method
Exemple #25
0
        /// <summary>
        /// Runs the table create statements contained in the provided tableDefs object.
        /// </summary>
        /// <param name="sourceDatabase">Database containing source tables..</param>
        /// <param name="tableIncludePatterns">Wildard pattern to use when selecting which tables to include. Specify * or null or empty string for pattern to include all tables.</param>
        /// <param name="tableExcludePatterns">Wildard pattern to use when selecting which tables to exclude. Specify * for pattern to exclude all tables. Specify null or empty string to exclude no tables.</param>
        /// <param name="destinationDatabase">Database were data will be copied to..</param>
        /// <param name="newSchemaName">Schema to use for identifying the destination tables.</param>
        /// <param name="dropBeforeCreate">If true and table already exists, table will be dropped and then recreated using the table definition in the supplied PFTableDefs list. If false, table create step is bypassed if table already exists.</param>
        /// <returns>Number of tables created.</returns>
        /// <remarks>Include and exclude patterns are the same as Windows File wildcards. * specifies zero or more characters. ? specifies one character.</remarks>
        public PFList <TableCopyDetails> CopyTableDataFromTableDefs(IDatabaseProvider sourceDatabase, string[] tableIncludePatterns, string[] tableExcludePatterns,
                                                                    IDatabaseProvider destinationDatabase, string newSchemaName, bool dropBeforeCreate)
        {
            PFList <TableCopyDetails> tableCopyLog = new PFList <TableCopyDetails>();
            PFTableDef td              = null;
            string     sqlStatement    = string.Empty;
            string     selectStatement = "select * from <TableName>";
            string     newTableName    = string.Empty;
            string     tdToXml         = string.Empty;
            PFTableDef newTd           = null;

            PFList <PFTableDef> tableDefs  = sourceDatabase.GetTableList(tableIncludePatterns, tableExcludePatterns);
            DataTable           sourceData = null;

            tableDefs.SetToBOF();

            while ((td = tableDefs.NextItem) != null)
            {
                newTableName = td.TableName;
                tdToXml      = td.ToXmlString();
                newTd        = PFTableDef.LoadFromXmlString(tdToXml);

                if (newSchemaName.Trim().Length > 0)
                {
                    newTd.TableObject.TableName = newSchemaName + "." + newTableName;
                }
                else
                {
                    newTd.TableObject.TableName = newTableName;
                }
                newTd.TableFullName = newTd.TableObject.TableName;
                newTd.TableOwner    = newSchemaName;
                newTd.TableName     = newTableName;

                if (destinationDatabase.TableExists(newSchemaName, newTableName) && dropBeforeCreate)
                {
                    destinationDatabase.DropTable(newSchemaName, newTableName);
                }

                if (destinationDatabase.TableExists(newSchemaName, newTableName) == false)
                {
                    sqlStatement = destinationDatabase.BuildTableCreateStatement(newTd.TableObject);
                    destinationDatabase.RunNonQuery(sqlStatement, CommandType.Text);
                }

                TableCopyDetails tcdetails = new TableCopyDetails();
                tcdetails.sourceTableName      = td.TableFullName;
                tcdetails.destinationTableName = newTd.TableFullName;
                tcdetails.numSourceRows        = -1;
                tcdetails.numRowsCopied        = -1;
                try
                {
                    sqlStatement            = selectStatement.Replace("<TableName>", td.TableObject.TableName);
                    sourceData              = sourceDatabase.RunQueryDataTable(sqlStatement, CommandType.Text);
                    sourceData.TableName    = newTd.TableObject.TableName;
                    tcdetails.numSourceRows = sourceData.Rows.Count;
                    if (sourceData.Rows.Count > 0)
                    {
                        destinationDatabase.ImportDataFromDataTable(sourceData);
                        tcdetails.numRowsCopied = sourceData.Rows.Count;
                        tcdetails.result        = TableCopyResult.Success;
                        tcdetails.messages      = string.Empty;
                    }
                    else
                    {
                        tcdetails.numRowsCopied = 0;
                        tcdetails.result        = TableCopyResult.Alert;
                        tcdetails.messages      = "The were no rows in the source table.";
                    }
                }
                catch (System.Exception ex)
                {
                    _msg.Length = 0;
                    _msg.Append("Attempt to copy ");
                    _msg.Append(td.TableFullName);
                    _msg.Append(" to ");
                    _msg.Append(newTd.TableFullName);
                    _msg.Append(" failed. Error message: ");
                    _msg.Append(PFTextObjects.PFTextProcessor.FormatErrorMessage(ex));
                    tcdetails.messages      = _msg.ToString();
                    tcdetails.numRowsCopied = -1;
                    tcdetails.result        = TableCopyResult.Failure;
                }

                tableCopyLog.Add(tcdetails);


                newTd      = null;
                sourceData = null;
            }

            return(tableCopyLog);
        }