public static void LoadImportingPageTypes() { TypesLoader typesLoader = new TypesLoader("LoadingModulesConfig.xml"); var types = typesLoader.LoadImportingPageTypes( t => t.CustomAttributes.Any(a => a.AttributeType == typeof(Navigator.NavigationAttribute.NavigationPageAttribute))); Navigator.Navigation.NavigationManager.InitializePageTypes(types); }
private static void Main() { var assemblyPaths = new[] { @".\OpenSoftware.DgmlBuilder.dll" }; var excludeFilters = new IExcludeFilter[] { new ExcludeByNameSpace(x => x.Contains("OpenSoftware") == false), new ExcludeByNameSpace(x => x.EndsWith(".Annotations")), new ExcludeByCustomAttribute <CompilerGeneratedAttribute>() }; using (var loader = new TypesLoader(assemblyPaths, excludeFilters)) { var types = loader.Load().ToArray(); var graph = TypesVisualizer.Types2Dgml(types); graph.WriteToFile(@"../../class-diagram.dgml"); } }
/// <summary> /// Initializes the inventory engine by loading available assemblies in the installation folder (top directory only). /// </summary> private static void Initialize() { string Folder = Path.GetDirectoryName(typeof(Gateway).GetTypeInfo().Assembly.Location); Directory.SetCurrentDirectory(Folder); TypesLoader.Initialize(Folder, (FileName) => { FileName = Path.GetFileName(FileName).ToLower(); if (FileName.StartsWith("api-ms-win-") || FileName.StartsWith("system.") || FileName.StartsWith("microsoft.") || FileName.StartsWith("waher.client.") || FileName.StartsWith("waher.utility.")) { return(false); } switch (FileName) { case "clrcompression.dll": case "clretwrc.dll": case "clrjit.dll": case "coreclr.dll": case "dbgshim.dll": case "hostpolicy.dll": case "hostfxr.dll": case "libskiasharp.dll": case "mscordaccore.dll": case "mscordaccore_x86_x86_4.6.00001.0.dll": case "mscordbi.dll": case "mscorlib.dll": case "mscorrc.debug.dll": case "mscorrc.dll": case "netstandard.dll": case "sos.dll": case "sos.netcore.dll": case "sos_x86_x86_4.6.00001.0.dll": case "ucrtbase.dll": case "windowsbase.dll": return(false); } return(true); }); }
private async Task _init(string connectionString) { JsonSerializer.SetDefaultResolver(StandardResolver.AllowPrivateCamelCase); _connection = new NpgsqlConnection(connectionString); await _connection.OpenAsync(); DatabaseName = _databaseName(); SchemaEntities = SchemasLoader.Load(_connection).ToImmutableArray(); RelationEntities = RelationsLoader.Load(_connection).ToImmutableArray(); ColumnEntities = ColumnsLoader.Load(_connection).ToImmutableArray(); ForeignKeyEntities = ForeignKeysLoader.Load(_connection).ToImmutableArray(); UniqueIndexEntities = UniqueIndexesLoader.Load(_connection).ToImmutableArray(); TypeEntities = TypesLoader.Load(_connection).ToImmutableDictionary(); SchemaRelations = GetRelationSchemas(); UsingNamespaces = _usingNamespaces().ToImmutableArray(); TypeMap = _typesMap().ToImmutableDictionary(); Keywords = _keywords().ToImmutableSortedSet(); }
static void Main(string[] args) { TypesLoader.Initialise(AppDomain.CurrentDomain.GetAssemblies()); PCPlatform.Start(); Framework.Start(); Console.WriteLine("type anything and press Enter to call Sample Service"); string input = Console.ReadLine(); while (input != "quit") { if (!string.IsNullOrEmpty(input)) { Process(input); } input = Console.ReadLine(); } Framework.Stop(); }
private static void Main() { var assemblyPaths = new[] { @"OpenSoftware.DgmlBuilder.dll" }; var excludeFilters = new IExcludeFilter[] { new ExcludeByNameSpace(x => x.Contains("OpenSoftware") == false), new ExcludeByNameSpace(x => x.EndsWith(".Annotations")), new ExcludeByCustomAttribute <CompilerGeneratedAttribute>() }; using var loader = new TypesLoader(assemblyPaths, excludeFilters); var types = loader.Load().ToArray(); var graph = TypesVisualizer.Types2Dgml(types); //graph.GraphDirection = GraphDirection.LeftToRight; //graph.Layout = Layout.Sugiyama; //graph.NeighborhoodDistance = 1; graph.WriteToFile(@"../../../class-diagram.dgml"); }
static int Main(string[] args) { try { StringBuilder CommandLine = new StringBuilder("ComSim.exe"); LinkedList <string> Master = new LinkedList <string>(); LinkedList <string> Css = new LinkedList <string>(); LinkedList <string> AssemblyFolders = new LinkedList <string>(); Encoding Encoding = Encoding.UTF8; XmlDocument Model = null; string ProgramDataFolder = null; string SnifferFolder = null; string LogFileName = null; string LogTransformFileName = null; string SnifferTransformFileName = null; string XmlOutputFileName = null; string MarkdownOutputFileName = null; int i; int c = args.Length; int BlockSize = 8192; int BlobBlockSize = 8192; bool Encryption = false; string s; bool Help = args.Length == 0; bool LogConsole = false; bool Quote; for (i = 0; i < c; i++) { CommandLine.Append(' '); s = args[i]; Quote = s.IndexOf(' ') >= 0; if (Quote) { CommandLine.Append('"'); } CommandLine.Append(s); if (Quote) { CommandLine.Append('"'); } } i = 0; while (i < c) { s = args[i++].ToLower(); s = s.ToLower(); if (s.StartsWith("/")) { s = "-" + s.Substring(1); } switch (s) { case "-i": if (i >= c) { throw new Exception("Expected model filename."); } s = args[i++]; if (!File.Exists(s)) { throw new Exception("File not found: " + s); } Model = new XmlDocument(); Model.Load(s); break; case "-l": if (i >= c) { throw new Exception("Missing log file name."); } if (string.IsNullOrEmpty(LogFileName)) { LogFileName = args[i++]; } else { throw new Exception("Only one log file name allowed."); } break; case "-lt": if (i >= c) { throw new Exception("Missing log transform file name."); } if (string.IsNullOrEmpty(LogTransformFileName)) { LogTransformFileName = args[i++]; } else { throw new Exception("Only one log transform file name allowed."); } break; case "-lc": LogConsole = true; break; case "-s": if (i >= c) { throw new Exception("Missing sniffer folder."); } if (string.IsNullOrEmpty(SnifferFolder)) { SnifferFolder = args[i++]; } else { throw new Exception("Only one sniffer folder allowed."); } break; case "-st": if (i >= c) { throw new Exception("Missing sniffer transform file name."); } if (string.IsNullOrEmpty(SnifferTransformFileName)) { SnifferTransformFileName = args[i++]; } else { throw new Exception("Only one sniffer transform file name allowed."); } break; case "-d": if (i >= c) { throw new Exception("Missing program data folder."); } if (string.IsNullOrEmpty(ProgramDataFolder)) { ProgramDataFolder = args[i++]; } else { throw new Exception("Only one program data folder allowed."); } break; case "-bs": if (i >= c) { throw new Exception("Block size missing."); } if (!int.TryParse(args[i++], out BlockSize)) { throw new Exception("Invalid block size"); } break; case "-bbs": if (i >= c) { throw new Exception("Blob Block size missing."); } if (!int.TryParse(args[i++], out BlobBlockSize)) { throw new Exception("Invalid blob block size"); } break; case "-enc": if (i >= c) { throw new Exception("Text encoding missing."); } Encoding = Encoding.GetEncoding(args[i++]); break; case "-e": Encryption = true; break; case "-mr": if (i >= c) { throw new Exception("Missing markdown report file name."); } if (string.IsNullOrEmpty(MarkdownOutputFileName)) { MarkdownOutputFileName = args[i++]; } else { throw new Exception("Only one markdown report file name allowed."); } break; case "-xr": if (i >= c) { throw new Exception("Missing XML report file name."); } if (string.IsNullOrEmpty(XmlOutputFileName)) { XmlOutputFileName = args[i++]; } else { throw new Exception("Only one XML report file name allowed."); } break; case "-master": if (i >= c) { throw new Exception("Missing master file name."); } Master.AddLast(args[i++]); break; case "-css": if (i >= c) { throw new Exception("Missing CSS file name."); } Css.AddLast(args[i++]); break; case "-ik": if (i >= c) { throw new Exception("Missing key name."); } string KeyName = args[i++]; if (i >= c) { throw new Exception("Missing CSV filename."); } string CsvFileName = args[i++]; string Csv = File.ReadAllText(CsvFileName); Dictionary <string, string> Lookup; if (!importedKeys.TryGetValue(KeyName, out Lookup)) { Lookup = new Dictionary <string, string>(); importedKeys[KeyName] = Lookup; } string[][] Records = CSV.Parse(Csv); foreach (string[] Record in Records) { if (Record.Length != 2) { throw new Exception("CSV file must contain records with two columns: Lookup, and value."); } Lookup[Record[0]] = Record[1]; } break; case "-af": if (i >= c) { throw new Exception("Missing Assembly folder."); } AssemblyFolders.AddLast(args[i++]); break; case "-?": Help = true; break; default: throw new Exception("Unrecognized switch: " + s); } } if (Help) { Console.Out.WriteLine("The TAG Network Communication Simulator (or TAG ComSim) is a white-label console"); Console.Out.WriteLine("utility application written in C# provided by Trust Anchor Group (TAG for short)."); Console.Out.WriteLine("It can be used to simulate network communication traffic in large-scale networks."); Console.Out.WriteLine(); Console.Out.WriteLine("Command-line arguments:"); Console.Out.WriteLine(); Console.Out.WriteLine("-i FILENAME Specifies the filename of the model to use during simulation."); Console.Out.WriteLine(" The file must be an XML file that conforms to the"); Console.Out.WriteLine(" http://trustanchorgroup.com/Schema/ComSim.xsd namespace."); Console.Out.WriteLine(" Schema is available at Schema/ComSim.xsd in the repository."); Console.Out.WriteLine("-l LOG_FILENAME Redirects logged events to a log file."); Console.Out.WriteLine("-lt LOG_TRANSFORM File name of optional XSLT transform for use with log file."); Console.Out.WriteLine("-lc Log events to the console."); Console.Out.WriteLine("-s SNIFFER_FOLDER Optional folder for storing network sniff files."); Console.Out.WriteLine("-st SNIFFER_TRANSFORM File name of optional XSLT transform for use with sniffers."); Console.Out.WriteLine("-d APP_DATA_FOLDER Points to the application data folder. Required if storage"); Console.Out.WriteLine(" of data in a local database is necessary for the"); Console.Out.WriteLine(" simulation. (Storage can include generated user credentials"); Console.Out.WriteLine(" so that the same user identities can be used across"); Console.Out.WriteLine(" simulations.)"); Console.Out.WriteLine("-af FOLDER Adds an assembly folder. Assemblies can be loaded from this"); Console.Out.WriteLine(" folder."); Console.Out.WriteLine("-e If encryption is used by the database. Default=no encryption."); Console.Out.WriteLine("-bs BLOCK_SIZE Block size, in bytes. Default=8192."); Console.Out.WriteLine("-bbs BLOB_BLOCK_SIZE BLOB block size, in bytes. Default=8192."); Console.Out.WriteLine("-enc ENCODING Text encoding. Default=UTF-8"); Console.Out.WriteLine("-mr FILENAME Generates a Markdown Report file after simulation."); Console.Out.WriteLine("-xr FILENAME Generates an XML report file after simulation."); Console.Out.WriteLine("-master RELNAME Adds a Master file declaration to the top of markdown"); Console.Out.WriteLine(" reports. The reference must be relative to the generated"); Console.Out.WriteLine(" report file."); Console.Out.WriteLine("-css RELNAME Adds a CSS file declaration to the top of markdown"); Console.Out.WriteLine(" reports. The reference must be relative to the generated"); Console.Out.WriteLine(" report file."); Console.Out.WriteLine("-ik KEYNAME FILENAME Import keys from a CSV file. The CSV file must consist of"); Console.Out.WriteLine(" two columns. The first, contains lookup values, the second,"); Console.Out.WriteLine(" the key values corresponding to the lookup values. The"); Console.Out.WriteLine(" KEYNAME argument defines the key name to which the keys"); Console.Out.WriteLine(" are associated. FILENAME must point to a CSV file."); Console.Out.WriteLine("-? Displays command-line help."); Console.Out.WriteLine(); if (args.Length <= 1) { return(1); } } if (Model is null) { throw new Exception("No simulation model specified."); } if (string.IsNullOrEmpty(ProgramDataFolder)) { throw new Exception("No program data folder set"); } Console.Out.WriteLine("Loading modules."); foreach (XmlNode N in Model.DocumentElement.ChildNodes) { if (N is XmlElement E && E.LocalName == "Assemblies") { Dictionary <string, Assembly> Loaded = new Dictionary <string, Assembly>(); foreach (Assembly A in AppDomain.CurrentDomain.GetAssemblies()) { Loaded[A.GetName().Name] = A; } foreach (XmlNode N2 in E.ChildNodes) { if (N2 is XmlElement E2 && E2.LocalName == "Assembly") { string FileName = XML.Attribute(E2, "fileName"); if (!File.Exists(FileName)) { string FileName2 = null; foreach (string Folder in AssemblyFolders) { FileName2 = Path.Combine(Folder, FileName); if (File.Exists(FileName2)) { break; } else { FileName2 = null; } } if (FileName2 is null) { throw new Exception("File not found: " + FileName); } else { FileName = FileName2; } } LinkedList <string> ToLoad = new LinkedList <string>(); ToLoad.AddLast(FileName); while (!string.IsNullOrEmpty(FileName = ToLoad.First?.Value)) { ToLoad.RemoveFirst(); Console.Out.WriteLine("Loading " + FileName); byte[] Bin = File.ReadAllBytes(FileName); try { Assembly A = AppDomain.CurrentDomain.Load(Bin); Loaded[A.GetName().Name] = A; AssemblyName[] Referenced = A.GetReferencedAssemblies(); foreach (AssemblyName AN in Referenced) { if (Loaded.ContainsKey(AN.Name)) { continue; } string RefFileName = Path.Combine(Path.GetDirectoryName(FileName), AN.Name + ".dll"); if (!File.Exists(RefFileName)) { continue; } if (!ToLoad.Contains(RefFileName)) { ToLoad.AddLast(RefFileName); } } } catch (BadImageFormatException) { // Ignore } } } } } } if (!string.IsNullOrEmpty(SnifferFolder)) { if (!Directory.Exists(SnifferFolder)) { Directory.CreateDirectory(SnifferFolder); } foreach (string FileName in Directory.GetFiles(SnifferFolder, "*.xml", SearchOption.TopDirectoryOnly)) { File.Delete(FileName); } } if (!Directory.Exists(ProgramDataFolder)) { Directory.CreateDirectory(ProgramDataFolder); } Console.Out.WriteLine("Initializing runtime inventory."); TypesLoader.Initialize(); Factory.Initialize(); Console.Out.WriteLine("Validating model."); Dictionary <string, XmlSchema> Schemas = new Dictionary <string, XmlSchema>(); LinkedList <XmlElement> ToProcess = new LinkedList <XmlElement>(); XmlElement Loop; string Last = null; ToProcess.AddLast(Model.DocumentElement); while (!((Loop = ToProcess.First?.Value) is null)) { ToProcess.RemoveFirst(); foreach (XmlNode N in Loop.ChildNodes) { if (N is XmlElement E) { ToProcess.AddLast(E); } } s = Loop.NamespaceURI; if (s != Last) { Last = s; if (!Schemas.ContainsKey(s)) { if (Factory.TryGetSchemaResource(s, out KeyValuePair <string, Assembly> P)) { Schemas[s] = XSL.LoadSchema(P.Key, P.Value); } } } } XmlSchema[] Schemas2 = new XmlSchema[Schemas.Count]; Schemas.Values.CopyTo(Schemas2, 0); XSL.Validate("Model", Model, "Model", TAG.Simulator.Model.ComSimNamespace, Schemas2); if (!string.IsNullOrEmpty(LogFileName)) { if (File.Exists(LogFileName)) { File.Delete(LogFileName); } Log.Register(new XmlFileEventSink("XmlEventSink", LogFileName, LogTransformFileName, int.MaxValue)); } if (LogConsole) { Log.Register(new ConsoleEventSink(false)); } TaskCompletionSource <bool> Done = new TaskCompletionSource <bool>(false); try { SetConsoleCtrlHandler((ControlType) => { switch (ControlType) { case CtrlTypes.CTRL_BREAK_EVENT: case CtrlTypes.CTRL_CLOSE_EVENT: case CtrlTypes.CTRL_C_EVENT: case CtrlTypes.CTRL_SHUTDOWN_EVENT: Done.TrySetResult(false); break; case CtrlTypes.CTRL_LOGOFF_EVENT: break; } return(true); }, true); } catch (Exception) { Log.Error("Unable to register CTRL-C control handler."); } Console.Out.WriteLine("Initializing database."); bool Result = Run(Model, Done, SnifferFolder, SnifferTransformFileName, MarkdownOutputFileName, XmlOutputFileName, CommandLine.ToString(), Master, Css, !LogConsole, ProgramDataFolder, BlockSize, BlobBlockSize, Encoding, Encryption).Result; if (Result) { Console.Out.WriteLine("Simulation completed."); return(0); } else { WriteLine("Simulation aborted.", ConsoleColor.White, ConsoleColor.Red); return(1); } } catch (AggregateException ex) { foreach (Exception ex2 in ex.InnerExceptions) { WriteLine(ex2.Message, ConsoleColor.White, ConsoleColor.Red); } return(1); } catch (Exception ex) { WriteLine(ex.Message, ConsoleColor.White, ConsoleColor.Red); return(1); } }