private void ProcessFile() { DataRow fileContentRow = null; DataTable fileContentShell = null; // Load the file into the readers file object. Logger.WriteLine("BaseFileReader.OnProcess", " OPENING: " + FileName, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Open(this, new EventArgs()); // Load the file into the readers CompleteFileContents data table. Load(this, new EventArgs()); fileContentShell = CompleteFileContents.Clone(); fileContentShell.TableName = Name; // Add the cloned table to the shared data as the modul's output table. SharedData.Add(fileContentShell); if (EndRow == 0 || EndRow > CompleteFileContents.Rows.Count) { EndRow = CompleteFileContents.Rows.Count; } if (StartRow <= CompleteFileContents.Rows.Count) { // Loop through the CompleteFileContents.Rows until we reach EndRow. for (int i = (StartRow - 1); i <= EndRow - 1; i++) { // Copy the file's row contents to the reader's output table. fileContentRow = GlobalOutputTable.NewRow(); fileContentRow.ItemArray = CompleteFileContents.Rows[i].ItemArray; GlobalOutputTable.Rows.Add(fileContentRow); } Logger.WriteLine("BaseFileReader.OnProcess", " ", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("BaseFileReader.OnProcess", " STATUS: SUCCESSFULL", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("BaseFileReader.OnProcess", " ROWCOUNT: " + GlobalOutputTable.Rows.Count, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); } else { Logger.WriteLine("BaseFileReader.OnProcess", " ", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("BaseFileReader.OnProcess", " STATUS: NO DATA", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); } Close(this, new EventArgs()); }
protected void CreateResultsTable() { string results_table_name; try { if (Method.ToLower() == "disk" || Method.ToLower() == "stream") { // Parse the destination table name for commands. results_table_name = TextParser.Parse(DestinationDataTable.Name, DrivingData, SharedData, ModuleCommands); // Check to see if the destination table has already been created and added to the global dataset. if (!SharedData.Data.Contains(results_table_name)) { // Make sure the memory management column exist in the destination table. if (!DestinationDataTable.CacheColumnCollection.Contains("_Memory_Management_")) { DestinationDataTable.CacheColumnCollection.Add("_Memory_Management_", "STRING", Method.ToLower()); } // If We are streaming the report from memory, make sure the raw report column exists in the destination table. if (Method.ToLower() == "stream" && !DestinationDataTable.CacheColumnCollection.Contains("_Raw_Report_")) { DestinationDataTable.CacheColumnCollection.Add("_Raw_Report_", "BYTE()", "%RawReport%"); } // Add the destination table to the cache. SharedData.Add(results_table_name, DestinationDataTable); } } else { throw new Exception("Method[" + Method + "] is not recognized."); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Drop handler /// </summary> /// <param name="data">shared data</param> /// <param name="pasteType">verbs one of {Copy | Move}</param> /// <param name="status">synchronous status for updating the console</param> /// <returns>true for success</returns> protected override bool OnPaste(SharedData data, DragAndDropVerb pasteType, SyncStatus status) { string displayName = ""; // get pasted name data.Add(new SharedDataItem("DisplayName")); try { displayName = Encoding.Unicode.GetString(data.GetItem("DisplayName").GetData()); } catch (Microsoft.ManagementConsole.Advanced.PrimarySnapInDataException) { return(false); } // find string in buffer displayName = displayName.Substring(0, displayName.IndexOf("\0")); // update pasted on node to show the drop this.SelectedNodes[0].DisplayName += " ( " + displayName + " Dropped)"; return(true); }
/// <summary> /// Drop handler /// </summary> /// <param name="data">shared data</param> /// <param name="pasteType">verbs one of {Copy | Move}</param> /// <param name="status">synchronous status for updating the console</param> /// <returns>true for success</returns> protected override bool OnPaste(SharedData data, DragAndDropVerb pasteType, SyncStatus status) { string displayName = ""; // get pasted name data.Add(new SharedDataItem("DisplayName")); try { displayName = Encoding.Unicode.GetString(data.GetItem("DisplayName").GetData()); } catch (Microsoft.ManagementConsole.Advanced.PrimarySnapInDataException) { return false; } // find string in buffer displayName = displayName.Substring(0, displayName.IndexOf("\0")); // update pasted on node to show the drop this.SelectedNodes[0].DisplayName += " ( " + displayName + " Dropped)"; return true; }
private static void LoadDataBySheetName(string fileName, string sheetName, TestDataType type) { FileStream stream = null; IExcelDataReader excelReader = null; try { FileInfo fileInfo = new FileInfo(fileName); var ext = fileInfo.Extension; stream = File.Open(fileName, FileMode.Open, FileAccess.Read); if (ext.Equals(".xls", StringComparison.CurrentCultureIgnoreCase)) { excelReader = ExcelReaderFactory.CreateBinaryReader(stream); } else if (ext.Equals(".csv", StringComparison.CurrentCultureIgnoreCase)) { excelReader = ExcelReaderFactory.CreateCsvReader(stream); } else { excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); } var rows = excelReader.AsDataSet().Tables[sheetName].Rows; //==test plan if (type == TestDataType.TestPlan) { for (int i = 0; i < rows.Count; i++) { var key = rows[i].ItemArray.GetValue(0).ToString(); var value = rows[i].ItemArray.GetValue(1).ToString(); TestPlanData.Add(new TestDataModel { Key = key, Value = value }); } return; } else if (type == TestDataType.Share) //==share data --> skip the 1st row for header { for (int i = 1; i < rows.Count; i++) { var key = rows[i].ItemArray.GetValue(0).ToString(); var value = rows[i].ItemArray.GetValue(1).ToString(); SharedData.Add(new TestDataModel { Key = key, Value = value }); } return; } else if (type == TestDataType.TestSuite)//==test suite { TestCaseDataModel testCaseData = null; TestDataExtraModel extraData = null; for (int i = 0; i < rows.Count; i++) { extraData = null; var key = rows[i].ItemArray.GetValue(0).ToString(); if (string.IsNullOrEmpty(key)) { continue; } var value = rows[i].ItemArray.GetValue(1) == null ? string.Empty : rows[i].ItemArray.GetValue(1).ToString(); if (key.EqualsText(TestCaseNameKey, true)) { if (testCaseData == null) //==begin a test case { testCaseData = new TestCaseDataModel(); } else//next test case { if (TestSuitData.TestCaseDataList == null) { TestSuitData.TestCaseDataList = new List <TestCaseDataModel>(); } TestSuitData.TestCaseDataList.Add(testCaseData.Clone() as TestCaseDataModel); testCaseData = new TestCaseDataModel(); continue; } } else if (key.Contains(ExtraDataKey)) { if (string.IsNullOrEmpty(value)) { continue; } string extraSheetName = value.Split('!').ToList().FirstOrDefault(); extraData = new TestDataExtraModel { Key = key, DataExtend = excelReader.AsDataSet().Tables[extraSheetName] }; if (testCaseData.DataExtendList == null) { testCaseData.DataExtendList = new List <TestDataExtraModel>(); } testCaseData.DataExtendList.Add(extraData.Clone() as TestDataExtraModel); extraData = null; continue; } if (testCaseData == null && string.IsNullOrEmpty(TestSuitData.TestSuiteId)) //==test suite info { if (key.EqualsText(TestSuiteIdKey, true)) { TestSuitData.TestSuiteId = value; } if (TestSuitData.DataList == null) { TestSuitData.DataList = new List <TestDataModel>(); } TestSuitData.DataList.Add(new TestDataModel { Key = key, Value = value }); } else if (testCaseData != null) { if (testCaseData.DataList == null) { testCaseData.DataList = new List <TestDataModel>(); } if (key.EqualsText(TestCaseIdKey, true)) { testCaseData.TestCaseId = value; } testCaseData.DataList.Add(new TestDataModel { Key = key, Value = value }); } } //the latest test case if (testCaseData != null && testCaseData.TestCaseId != string.Empty) { if (TestSuitData.TestCaseDataList == null) { TestSuitData.TestCaseDataList = new List <TestCaseDataModel>(); } TestSuitData.TestCaseDataList.Add(testCaseData); } return; } } catch (Exception ex) { throw ex; } finally { excelReader.Close(); stream.Close(); } }
private DataTable PerformJoin(DataTable source_table) { DataTable table_to_join = new DataTable(); DataTable new_source_table = new DataTable(); DataRow nRow = null; if (Join != null) { // Get the table that will be joined with the source table from the global cacheset. table_to_join = SharedData.Data.Tables(Join.DataTable.Name); // Add each column in the source table to the new table. foreach (DataColumn source_column in source_table.Columns) { new_source_table.Columns.Add(new DataColumn { ColumnName = source_column.ColumnName, DataType = source_column.DataType, DefaultValue = source_column.DefaultValue }); } // Add each column in the table to join that is not the Fkey to the new source table. foreach (DataColumn join_column in table_to_join.Columns) { // Make sure the column is not the key column and that the column was not already // added from the source table. if (join_column.ColumnName != Join.ForeignKey && !new_source_table.Columns.Contains(join_column.ColumnName)) { // See if only certain columns are specified in the configuration. if (Join.DataTable.CacheColumnCollection != null) { // Make sure the column is listed in the configuration. if (Join.DataTable.CacheColumnCollection.Contains(join_column.ColumnName)) { new_source_table.Columns.Add(new DataColumn { ColumnName = join_column.ColumnName, DataType = join_column.DataType, DefaultValue = join_column.DefaultValue }); } } else { new_source_table.Columns.Add(new DataColumn { ColumnName = join_column.ColumnName, DataType = join_column.DataType, DefaultValue = System.DBNull.Value }); } } } // Grab each row in table to join. foreach (DataRow jRow in table_to_join.Rows) { // Grab each row in the source table. foreach (DataRow sRow in source_table.Rows) { // See if the PKey column in the source table matches the Fkey column in the table // to join column. if (sRow[Join.PrimaryKey].ToString() == jRow[Join.ForeignKey].ToString()) { // Create a new row for the new data source table. nRow = new_source_table.NewRow(); foreach (DataColumn sCol in source_table.Columns) { // Copy the value of each column in the old source table's row to the // new source table's row. if (!string.IsNullOrEmpty(sRow[sCol.ColumnName].ToString())) { nRow[sCol.ColumnName] = sRow[sCol.ColumnName].ToString(); } } foreach (DataColumn jCol in table_to_join.Columns) { // Make sure the current column is not the key column. if (jCol.ColumnName == Join.ForeignKey) { // Copy the value of each column in the table to join's row to the // new source table's row. if (!string.IsNullOrEmpty(jRow[jCol.ColumnName].ToString())) { nRow[jCol.ColumnName] = jRow[jCol.ColumnName].ToString(); } } } // Add the new row to the new source table. new_source_table.Rows.Add(nRow); break; } } } // Name the source table. new_source_table.TableName = Join.NewTableName; // Add the new source table to the global dataset. SharedData.Add(new_source_table); return(new_source_table); } return(source_table); }