internal BfNamespace method_13(BfType bfType_0) { BfNamespace bfNamespace = null; string text = null; BfNamespace result; try { text = BfCache.smethod_4(bfType_0.method_2().FullName); if (!this.sortedDictionary_1.ContainsKey(text)) { bfNamespace = new BfNamespace(this, text); this.sortedDictionary_1.Add(text, bfNamespace); this.namespaceCollection_0.method_1(bfNamespace); } else { bfNamespace = this.sortedDictionary_1[text]; } if (bfNamespace.Types == null) { Logger.LogError("BfNamespace: '" + bfNamespace.FullName + "' had null collection - " + bfType_0.FullName); bfNamespace.Types = new TypeCollection(); } bfNamespace.Types.method_1(bfType_0); result = bfNamespace; } catch (Exception) { Builder builder = new Builder("\r\n"); try { builder.Append("type == null => " + (bfType_0 == null)); builder.Append("type = " + bfType_0.ToString()); } catch { } try { builder.Append("type.Assembly = " + bfType_0.Assembly.ToString()); } catch { } try { builder.Append("type.TypeDef.Name = " + bfType_0.method_2().Name); } catch { } try { builder.Append("type.TypeDef == null => " + (bfType_0.method_2() == null)); builder.Append("type.TypeDef = " + bfType_0.method_2().ToString()); } catch { } try { builder.Append("type.TypeDef.FullName == null => " + (bfType_0.method_2().FullName == null)); builder.Append("type.TypeDef.FullName = " + bfType_0.method_2().FullName.ToString()); } catch { } try { builder.Append("myNamespace == null => " + (text == null)); builder.Append("myNamespace = " + text.ToString()); } catch { } try { builder.Append("_namespaceDictionary == null => " + (this.sortedDictionary_1 == null)); builder.Append("_namespaceDictionary = " + this.sortedDictionary_1.Count<KeyValuePair<string, BfNamespace>>()); } catch { } try { builder.Append("_namespaces == null => " + (this.namespaceCollection_0 == null)); builder.Append("_namespaces = " + this.namespaceCollection_0.Count<BfNamespace>()); } catch { } try { builder.Append("bfNamespace == null => " + (bfNamespace == null)); builder.Append("bfNamespace = " + bfNamespace); } catch { } try { builder.Append("bfNamespace.Types == null => " + (bfNamespace.Types == null)); builder.Append("bfNamespace.Types = " + bfNamespace.Types.Count<BfType>()); } catch { } throw new NitriqException("NamespaceProblems", builder.ToString()); } return result; }
internal void method_14(Rule rule_1, bool bool_4) { if (rule_1 != null) { rule_1.QueryResults.Problems = new ObservableCollection<Problem>(); rule_1.QueryResults.Output = ""; string code = rule_1.Code; List<string> list = new List<string> { "CodeDom", "IO", "Net", "Media", "Reflection", "Runtime", "Security", "Threading", "Web", "Windows" }; Builder builder = new Builder("|"); foreach (string current in list) { builder.Append(string.Concat(new string[] { "^(?<namespace>System\\.", current, ")\\.|[\\s;:!{}()[\\]](?<namespace>System\\.", current, ")\\." })); } MatchCollection matchCollection = Regex.Matches(code, builder.ToString()); if (matchCollection.Count > 0) { string description = "It looks like you're trying to use a class in the \"" + matchCollection[0].Groups["namespace"].Value + "\" namespace.\r\nWe can't let you complete the query because of security concerns, sorry.\r\nIf you believe you've received this message erroneously please contact [email protected] with the text of your query"; ObservableCollection<Problem> observableCollection = new ObservableCollection<Problem>(); observableCollection.Add(new Problem { Description = description, ProblemType = RuleStatus.CompileError }); rule_1.QueryResults.Problems = observableCollection; rule_1.QueryResults.Results = null; rule_1.QueryResults.Description = "The query \"" + rule_1.Name + "\" had a compile time error"; } else { string text = "\r\n\t\t\t\t using System;\r\n\t\t\t\t using System.Collections; \r\n using System.Collections.Generic; \r\n\t\t\t\t using System.Linq;\r\n\t\t\t\t using System.Text;\r\n\t\t\t\t using System.Text.RegularExpressions;\r\n\t\t\t\t using Nitriq.Analysis.Models;\r\n\t\t\t\t \r\n\t\t\t\t namespace Runner\r\n\t\t\t\t {\r\n\t\t\t\t public static class ExtensionMethods\r\n\t\t\t\t {\r\n\t\t\t\t public static int Count(this IEnumerable enumerable)\r\n\t\t\t\t {\r\n\t\t\t\t if (enumerable == null)\r\n\t\t\t\t return 0;\r\n\r\n\t\t\t\t int count = 0;\r\n\r\n\t\t\t\t foreach (object obj in enumerable)\r\n\t\t\t\t count++;\r\n\r\n\t\t\t\t return count;\r\n\t\t\t\t }\r\n\r\n public static List<object> ToList(this IEnumerable enumerable)\r\n {\r\n List<object> list = new List<object>();\r\n foreach (object obj in enumerable)\r\n {\r\n list.Add(obj);\r\n }\r\n return list;\r\n }\r\n\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public class RunnerClass\r\n\t\t\t\t {\r\n\t\t\t\t //public BfCache _cache;\r\n\t\t\t\t \r\n\t\t\t\t public void ConsoleWrite(object message)\r\n\t\t\t\t {\r\n\t\t\t\t ConsoleWrite(message.ToString());\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public void ConsoleWriteLine(object message)\r\n\t\t\t\t {\r\n\t\t\t\t ConsoleWriteLine(message.ToString());\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public void ConsoleWrite(string message)\r\n\t\t\t\t {\r\n\t\t\t\t _debug(message);\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public void ConsoleWriteLine(string message)\r\n\t\t\t\t {\r\n\t\t\t\t _debug(message + \"\\r\\n\");\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public void Warn(bool condition, string message)\r\n\t\t\t\t {\r\n\t\t\t\t if (condition)\r\n\t\t\t\t _warn(message);\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public void Error(bool condition, string message)\r\n\t\t\t\t {\r\n\t\t\t\t if (condition)\r\n\t\t\t\t _error(message);\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public void Warn(IEnumerable results, int resultsCount)\r\n\t\t\t\t {\r\n\t\t\t\t if (results.Count() > resultsCount)\r\n\t\t\t\t _warn(\"More than \" + resultsCount + \" results were returned\");\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public void Error(IEnumerable results, int resultsCount)\r\n\t\t\t\t {\r\n\t\t\t\t if (results.Count() > resultsCount)\r\n\t\t\t\t _error(\"More than \" + resultsCount + \" results were returned\");\r\n\t\t\t\t }\r\n\r\n /*\r\n\t\t\t\t public void Warn(bool condition)\r\n\t\t\t\t {\r\n\t\t\t\t if (condition)\r\n\t\t\t\t _warnNoMsg();\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public void Error(bool condition)\r\n\t\t\t\t {\r\n\t\t\t\t if (condition)\r\n\t\t\t\t _errorNoMsg();\r\n\t\t\t\t }\r\n */\r\n\r\n\t\t\t\t Action<string> _debug;\r\n\t\t\t\t Action<string> _warn;\r\n\t\t\t\t Action<string> _error;\r\n\t\t\t\t Action _warnNoMsg;\r\n\t\t\t\t Action _errorNoMsg;\r\n\r\n\t\t\t\t public RunnerClass(BfCache cache, Action<string> debug, Action<string> warn, Action<string> error, Action warnNoMsg, Action errorNoMsg)\r\n\t\t\t\t {\r\n\t\t\t\t //_cache = cache;\r\n\t\t\t\t _assemblies = cache.Assemblies;\r\n\t\t\t\t _namespaces = cache.Namespaces;\r\n\t\t\t\t _types = cache.Types;\r\n\t\t\t\t _methods = cache.Methods;\r\n\t\t\t\t _fields = cache.Fields;\r\n\t\t\t\t _events = cache.Events;\r\n\r\n\t\t\t\t _debug = debug;\r\n\t\t\t\t _warn = warn;\r\n\t\t\t\t _error = error;\r\n\t\t\t\t _warnNoMsg = warnNoMsg; \r\n\t\t\t\t _errorNoMsg = errorNoMsg;\r\n\t\t\t\t } \r\n\r\n\r\n\t\t\t\t private AssemblyCollection _assemblies;\r\n\t\t\t\t public AssemblyCollection Assemblies\r\n\t\t\t\t {\r\n\t\t\t\t get { return _assemblies; }\r\n\t\t\t\t set { _assemblies = value; }\r\n\t\t\t\t }\r\n\r\n\t\t\t\t private NamespaceCollection _namespaces;\r\n\t\t\t\t public NamespaceCollection Namespaces\r\n\t\t\t\t {\r\n\t\t\t\t get { return _namespaces; }\r\n\t\t\t\t set { _namespaces = value; }\r\n\t\t\t\t }\r\n\t\t\t\t \r\n\t\t\t\t private TypeCollection _types;\r\n\t\t\t\t public TypeCollection Types\r\n\t\t\t\t {\r\n\t\t\t\t get { return _types; }\r\n\t\t\t\t set { _types = value; }\r\n\t\t\t\t }\r\n\r\n\t\t\t\t private MethodCollection _methods;\r\n\t\t\t\t public MethodCollection Methods\r\n\t\t\t\t {\r\n\t\t\t\t get { return _methods; }\r\n\t\t\t\t set { _methods = value; }\r\n\t\t\t\t }\r\n\r\n\t\t\t\t private FieldCollection _fields;\r\n\t\t\t\t public FieldCollection Fields\r\n\t\t\t\t {\r\n\t\t\t\t get { return _fields; }\r\n\t\t\t\t set { _fields = value; }\r\n\t\t\t\t }\r\n\r\n\t\t\t\t private EventCollection _events;\r\n\t\t\t\t public EventCollection Events\r\n\t\t\t\t {\r\n\t\t\t\t get { return _events; }\r\n\t\t\t\t set { _events = value; }\r\n\t\t\t\t }\r\n\r\n\t\t\t\t public object RunMethod()\r\n\t\t\t\t {\r\n\t\t\t\t \r\n\t\t\t\t "; int count = Regex.Matches(text, "\\r\\n").Count; string text2 = text + code + "\r\n\t\t\t\t \r\n return results.ToList();\r\n \r\n\t\t\t\t }\r\n\t\t\t\t }\r\n\t\t\t\t }\r\n\r\n\t\t\t\t "; CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider(new Dictionary<string, string> { { "CompilerVersion", "v3.5" } }); CompilerParameters compilerParameters = new CompilerParameters(); compilerParameters.ReferencedAssemblies.Add(MainViewModelBase.string_0); compilerParameters.ReferencedAssemblies.Add("System.dll"); compilerParameters.ReferencedAssemblies.Add("System.Data.Linq.dll"); compilerParameters.ReferencedAssemblies.Add("System.Core.dll"); compilerParameters.ReferencedAssemblies.Add("WindowsBase.dll"); compilerParameters.ReferencedAssemblies.Add("PresentationCore.dll"); compilerParameters.ReferencedAssemblies.Add("PresentationFramework.dll"); Stopwatch stopwatch = Stopwatch.StartNew(); CompilerResults compilerResults = cSharpCodeProvider.CompileAssemblyFromSource(compilerParameters, new string[] { text2 }); stopwatch.Stop(); if (compilerResults.Errors.Count != 0) { rule_1.QueryResults.Problems = this.method_18(compilerResults.Errors, count); rule_1.QueryResults.Results = null; rule_1.Status = RuleStatus.CompileError; if (!bool_4) { this.Status = string.Concat(new object[] { "The query \"", rule_1.Name, "\" had ", rule_1.QueryResults.Problems, " compilation errors" }); this.method_17(new LightWrapper(rule_1.QueryResults.Results, this.bfCache_0)); } this.method_11(false); } else { stopwatch = Stopwatch.StartNew(); Assembly compiledAssembly = compilerResults.CompiledAssembly; Type type = compiledAssembly.GetType("Runner.RunnerClass"); string text3 = "You don't have any analyzed assemblies loaded"; try { ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(BfCache), typeof(Action<string>), typeof(Action<string>), typeof(Action<string>), typeof(Action), typeof(Action) }); Action<string> action = delegate(string message) { QueryResults expr_0B = rule_1.QueryResults; expr_0B.Output += message; }; Action<string> action2 = delegate(string message) { rule_1.QueryResults.Problems.Add(new Problem { Description = message, ProblemType = RuleStatus.Warning }); }; Action<string> action3 = delegate(string message) { rule_1.QueryResults.Problems.Add(new Problem { Description = message, ProblemType = RuleStatus.Error }); }; Action action4 = delegate { rule_1.QueryResults.Problems.Add(new Problem { Description = string.Concat(new object[] { "\"", rule_1.Name, "\" returned ", rule_1.QueryResults.Results.Count(), " results" }), ProblemType = RuleStatus.Warning }); }; Action action5 = delegate { rule_1.QueryResults.Problems.Add(new Problem { Description = string.Concat(new object[] { "\"", rule_1.Name, "\" returned ", rule_1.QueryResults.Results.Count(), " results" }), ProblemType = RuleStatus.RuntimeError }); }; if (this.bfCache_0 == null) { throw new Exception(text3); } object obj = constructor.Invoke(new object[] { this.bfCache_0, action, action2, action3, action4, action5 }); MethodInfo method = type.GetMethod("RunMethod"); rule_1.QueryResults.Results = (IEnumerable)method.Invoke(obj, null); if (rule_1.QueryResults.ResultCount != 0 && rule_1.QueryResults.IdPropertyName == null) { rule_1.QueryResults.Problems.Add(new Problem { ProblemType = RuleStatus.Warning, Description = "This query's results type does not contain a TypeId, MethodId, FieldId, EventId, AssemblyId or NamespaceId.\r\nWithout one of these fields, Nitriq is unable to generate the CodeTree, nor is it able to highlight the results in the TreeMap" }); } if (!bool_4) { this.method_17(new LightWrapper(rule_1.QueryResults.Results, this.bfCache_0)); } rule_1.QueryResults.Description = string.Concat(new object[] { "The query \"", rule_1.Name, "\" has a successfully completed with ", rule_1.QueryResults.Results.Cast<object>().Count(), " items" }); if (rule_1 == this.CurrentRule) { this.method_11(true); } } catch (Exception ex) { ObservableCollection<Problem> observableCollection = new ObservableCollection<Problem>(); Problem problem = new Problem { Description = ex.ToString(), ProblemType = RuleStatus.RuntimeError }; if (ex.Message == text3) { problem.Description = text3; } observableCollection.Add(problem); rule_1.QueryResults.Problems = observableCollection; rule_1.QueryResults.Results = null; rule_1.QueryResults.Description = "The query \"" + rule_1.Name + "\" had a runtime error"; if (rule_1 == this.CurrentRule) { this.method_11(false); } } rule_1.CalculateStatus(); this.FirePropertyChanged("CurrentRule"); if (!bool_4) { this.Status = rule_1.QueryResults.Description; } stopwatch.Stop(); } } } }