private bool ExtractExcelTriggers(Workbook xlWorkbook) { log.Log("Extract Triggers to local variables - start"); //THIS IS NEW PROCESSING TO USE XLS INSTEAD OF TXT FORMAT _Worksheet sheet = xlWorkbook.Sheets[1]; Range xlRange = sheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; log.Log("Importing Triggers - start"); try { //iterate through all columns/rows in xls for (int i = 2; i != rowCount + 1; i++) { TriggerDefinition trigger = new TriggerDefinition(); int count = 3; trigger.Name = sheet.Cells[i, count].Value2.ToString(); count++; trigger.Type = sheet.Cells[i, count].Value2.ToString(); count++; trigger.TriggeringEvent = sheet.Cells[i, count].Value2.ToString(); count++; count++; trigger.BaseObjectType = sheet.Cells[i, count].Value2.ToString(); count++; trigger.TableName = sheet.Cells[i, count].Value2.ToString(); count++; count++; count++; trigger.WhenClause = sheet.Cells[i, count].Value2.ToString(); count++; count++; count++; count++; trigger.Body = sheet.Cells[i, count].Value2.ToString(); //trigger.Unit = bucketSheet.Cells[i, count].Value2.ToString(); //write processing output to same line log.Log(String.Format("Reading trigger {0} \r", trigger.Name)); _triggers.Add(trigger); } log.Log("Extract Triggers to local variables - complete"); } catch (Exception e) { log.Log(string.Format("Error reading trigger file: {0}", e)); return false; } return true; }
private bool ExtractTriggers() { string triggerFile = ""; string line; int lineNo = 0; int triggerCount = 0; log.Log("Extract Triggers to local variables - start"); if (File.Exists(triggerFile)) { StreamReader triggersFile = new StreamReader(triggerFile); try { while ((line = triggersFile.ReadLine()) != null) // loop through all extract lines { lineNo++; if (lineNo > Common.Constants.triggerLinesToSkip) { triggerCount++; TriggerDefinition trigger = new TriggerDefinition(); trigger.TableName = line.Substring(Common.Constants.posTriggerTableName, Common.Constants.posTriggerRuleName - Common.Constants.posTriggerTableName).Trim(); trigger.RuleName = line.Substring(Common.Constants.posTriggerRuleName, Common.Constants.lenTriggerRuleName).Trim(); trigger.Access = line.Substring(Common.Constants.posTriggerAccess).Trim(); foreach (TableDefinition table in _tables) { if (table.Name.Equals(trigger.TableName.ToString())) { trigger.TableSourceId = table.Id; trigger.Unit = table.Unit; } } foreach (RuleDefinition rule in _rules) { if (rule.Name.Equals(trigger.RuleName.ToString())) { trigger.RuleSourceId = rule.Id; break; } } //write processing output to same line log.Log(string.Format("Reading trigger for {0} \r", trigger.TableName)); _triggers.Add(trigger); } } triggersFile.Close(); log.Log("Extract Triggers to local variables - complete"); } catch (Exception e) { triggersFile.Close(); log.Log(string.Format("Incorrect format of the Triggers file. Error:{0}", e.Message)); return false; } } else { log.Log("Triggers Data file is missing"); return false; } return true; }