//Instantiates a list of SQL rules stored in the user_defined_rules.xml file //The config for each rule (containing the actual SQL code) is stored in the config file and is handled elsewhere private static IEnumerable <SQLRule> LoadSQLRules() { if (!File.Exists(sqlRulesXMLFile)) { return(new List <SQLRule>()); } IEnumerable <String> SQLRuleNames = new List <String>(); lock (sqlRulesXMLFile) { FileStream fs = new FileStream(sqlRulesXMLFile, FileMode.Open); XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()); DataContractSerializer ser = new DataContractSerializer(typeof(IEnumerable <String>)); SQLRuleNames = (IEnumerable <String>)ser.ReadObject(reader, true); reader.Close(); fs.Close(); } IList <SQLRule> returnValue = new List <SQLRule>(); foreach (String ruleName in SQLRuleNames) { SQLRule rule = new SQLRule(); rule.RuleName.Value = ruleName; rule.RuleName.DefaultValue = ruleName; returnValue.Add(rule); } return(returnValue); }
/// <summary> /// Adds an SQL rule to the rule collection using default parameters and persist the updated sql rule set /// </summary> /// <param name="ruleName">Name of the rule to be created</param> /// <returns>The created rule</returns> public static SQLRule AddSQLRule(String ruleName) { SQLRule newRule = new SQLRule(); newRule.RuleName.Value = ruleName; rules.Add(newRule); saveSQLRules(); return(newRule); }
public IEnumerable <SQLRule> GetSQLRules() { var sqlRules = new List <SQLRule>(); if (this.XMLConfig.UserDefinedRules != null) { foreach (string ruleName in this.XMLConfig.UserDefinedRules) { SQLRule rule = new SQLRule(); rule.RuleName.Value = ruleName; rule.RuleName.DefaultValue = ruleName; this.ConfigureRule(rule); sqlRules.Add(rule); } } return(sqlRules); }
private void runExecutable(Object executableObject) { ExecutionUnit unit = (ExecutionUnit)executableObject; var executable = unit.Executable; if (unit.Finalize) { ((IDataExecutable)executable).Finalize(this.database, this.providerCollection); if (executable.IsProvider()) { this.providerCollection.AddProvider((IProvider)executable); } return; } if (executable.IsData() && unit.Table != null && unit.Table != this.currentTable) { this.currentTable = unit.Table; CurrentTableChanged(unit.Table); //Console.WriteLine("Finished: " + unit.Table.TableName); } var table = (DataTable)unit.Table; Stopwatch clock = new Stopwatch(); clock.Start(); FinishedStatus finishedStatus; //Execute (executables have different execute signatures) #if !DEBUG try { #endif if (executable.IsSchemaRule()) { ISchemaRule rule = (ISchemaRule)executable; rule.Execute(this.database, this.issueCollector, this.providerCollection); } else if (executable.IsSQLRule()) { SQLRule rule = (SQLRule)executable; rule.Execute(this.database, this.issueCollector); } else if (executable.IsDataRule()) { IDataRule rule = (IDataRule)executable; rule.Execute(table, this.issueCollector, this.providerCollection); } else if (executable.IsSchemaProvider()) { ISchemaProvider prov = (ISchemaProvider)executable; prov.Execute(this.database, this.providerCollection); } else if (executable.IsDataProvider()) { IDataProvider prov = (IDataProvider)executable; prov.Execute(table, this.providerCollection); } if (executable is IProvider && executable.IsSchema()) { this.providerCollection.AddProvider((IProvider)executable); } finishedStatus = FinishedStatus.Success; #if !DEBUG } catch (Exception e) { Console.WriteLine(e.StackTrace); finishedStatus = FinishedStatus.Failed; } #endif clock.Stop(); executionSummaryLock.EnterWriteLock(); if (executable.IsSchemaRule() || executable.IsSQLRule()) { var issues = this.issueCollector.GetIssues((IRule)executable); RuleSummary summary = new RuleSummary((IRule)executable, issues, finishedStatus, clock.Elapsed); this.executionSummary.AddRuleSummary(summary); } else if (executable.IsDataRule()) { IRule rule = (IRule)executable; var issues = this.issueCollector.GetIssues(rule); var sum = executionSummary.GetSummary(rule); if (sum == null) { sum = new RuleSummary(rule, null, finishedStatus, new TimeSpan()); this.executionSummary.AddRuleSummary(sum); } sum.ExecutionTime.Add(clock.Elapsed); sum.Issues = issues; } int pbefore = this.progressTracker.Progress; this.progressTracker.UpdateProgress(executable, table); this.ProgressUpdated(this.progressTracker.Progress); int pafter = this.progressTracker.Progress; //if (pbefore != pafter) // Console.WriteLine(pafter); executionSummaryLock.ExitWriteLock(); }