private void InitInstance(enLogFileStorageType logFileStorageType, string logFileConnectionString, enLogRetryQueueStorageType logRetryQueueStorageType, string logRetryQueueConnectionString) { _logFileStorageType = logFileStorageType; _logFileConnectionString = logFileConnectionString; _logRetryQueueStorageType = logRetryQueueStorageType; _logRetryQueueConnectionString = logRetryQueueConnectionString; if (File.Exists(_logFileConnectionString) == false) { FileStream fs = File.Create(_logFileConnectionString); fs.Close(); } if (File.Exists(_logRetryQueueConnectionString) == false) { //create the retry queue _logRetryQueue.SaveToXmlFile(_logRetryQueueConnectionString); } _logRetryQueue = PFList <PFLogMessage> .LoadFromXmlFile(_logRetryQueueConnectionString); }
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); }
//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
public void DatesAndTimesTest() { DataTable dt = new DataTable(); DataTableRandomizer dtr = new DataTableRandomizer(); PFList <DataTableRandomizerColumnSpec> colSpecs = new PFList <DataTableRandomizerColumnSpec>(); int maxOutputRows = 100; try { _msg.Length = 0; _msg.Append("DatesAndTimesTest started ...\r\n"); _messageLog.WriteLine(_msg.ToString()); DataColumn dc0 = new DataColumn("OrigDateTime", Type.GetType("System.DateTime")); DataColumn dc1 = new DataColumn("RandomDateUsingRange", Type.GetType("System.DateTime")); DataColumn dc2 = new DataColumn("RandomDateFromRange", Type.GetType("System.DateTime")); DataColumn dc3 = new DataColumn("RandomDateToRange", Type.GetType("System.DateTime")); DataColumn dc4 = new DataColumn("RandomTodayDate", Type.GetType("System.DateTime")); DataColumn dc5 = new DataColumn("RandomTodayDateOffset", Type.GetType("System.Int32")); DataColumn dc6 = new DataColumn("RandomDate", Type.GetType("System.DateTime")); DataColumn dc7 = new DataColumn("RandomDateOffset", Type.GetType("System.Int32")); dt.Columns.Add(dc0); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); dt.Columns.Add(dc5); dt.Columns.Add(dc6); dt.Columns.Add(dc7); colSpecs = dtr.GetInitColSpecListFromDataTable(dt); colSpecs[1].RandomDataType = enRandomDataType.RandomDatesAndTimes; colSpecs[1].RandomDataSource = "Years1930-1939.xml"; colSpecs[4].RandomDataType = enRandomDataType.RandomDatesAndTimes; colSpecs[4].RandomDataSource = "CurrentDateOffsetPlusMinus10Years.xml"; colSpecs[6].RandomDataType = enRandomDataType.RandomDatesAndTimes; colSpecs[6].RandomDataSource = "DatesOffsetPlusMinus10Years.xml"; string outputPath = Path.Combine(_defaultDataGridExportFolder, "DateTimeTestColSpecs.xml"); colSpecs.SaveToXmlFile(outputPath); for (int r = 0; r < maxOutputRows; r++) { DataRow dr = dt.NewRow(); dr[0] = Convert.ToDateTime("04/13/1948 00:00:01"); dr[1] = Convert.ToDateTime("04/13/1948 00:00:01"); dr[2] = Convert.ToDateTime("01/01/1930 00:00:00"); dr[3] = Convert.ToDateTime("12/31/1939 23:59:59"); dr[4] = DateTime.Now; dr[5] = (int)0; dr[6] = Convert.ToDateTime("04/13/1948 00:00:01"); dr[7] = (int)0; dt.Rows.Add(dr); } dtr.RandomizeDataTableValues(dt, colSpecs, 100); for (int r = 0; r < maxOutputRows; r++) { DataRow dr = dt.Rows[r]; DateTime newDateTime = (DateTime)dr[4]; TimeSpan ts = newDateTime.Subtract(DateTime.Now); dr[5] = (int)ts.TotalDays; newDateTime = (DateTime)dr[6]; ts = newDateTime.Subtract(Convert.ToDateTime("04/13/1948 00:00:01")); dr[7] = (int)ts.TotalDays; } dt.AcceptChanges(); OutputDataTableToGrid(dt); } catch (System.Exception ex) { _msg.Length = 0; _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); _messageLog.WriteLine(_msg.ToString()); AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog); } finally { _msg.Length = 0; _msg.Append("\r\n... DatesAndTimesTest finished."); _messageLog.WriteLine(_msg.ToString()); } }