public void Test4() { ITableFilter theObj = DiskOperations.CreateTableFilterObj("TApplicationFilter.dll"); Assert.IsNotNull(theObj); Assert.IsTrue(theObj is TApplicationFilter.TApplicationFilter); }
private static ITableFilter CreateInstanceFromFile(string completeName, string simpleName) { Assembly theExpendAssembly = Assembly.LoadFile(completeName); string typeFullName = null; foreach (Type type in theExpendAssembly.GetTypes()) { Type[] theInterfaces = type.GetInterfaces(); if (theInterfaces != null) { foreach (Type anInterface in theInterfaces) { if (anInterface.Name.Equals(typeof(ITableFilter).Name) && type.Name.Equals(simpleName)) { typeFullName = type.FullName; } } } } if (string.IsNullOrEmpty(typeFullName)) { throw new ApplicationException(string.Format("{0}{1}", Utility._Error_InstanceCreation_Failed, completeName)); } ITableFilter retVal = theExpendAssembly.CreateInstance(typeFullName) as ITableFilter; if (retVal == null) { throw new ApplicationException(string.Format("{0}{1}", Utility._Error_InstanceCreation_Failed, completeName)); } return(retVal); }
public void WriteFile(string path, ITableFilter filter) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } IEnumerable <Table> tables; //If a filter exists, utilize only the tables that have not been filtered out if (filter != null) { tables = filter.GetTables(); } else { tables = _database.Tables; } //For each table that exists in the database, create ERD XML nodes IEnumerable <XElement> elements = tables.Select(t => CreateERDNode(t, true, true)); //Create edge elements for each table's relationship var edges = tables.Select(t => GetEdgeElements(_database, t)).ToArray(); //Create the entire .graphml document XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "no"), new XElement(GraphML.Namespace + "graphml", new XAttribute("xmlns", GraphML.Namespace), new XAttribute(XNamespace.Xmlns + "y", Namespace), new XComment("Created by yERD"), new XElement(GraphML.Namespace + "key", new XAttribute("for", "node"), new XAttribute("id", "d6"), new XAttribute("yfiles.type", "nodegraphics")), new XElement(GraphML.Namespace + "key", new XAttribute("for", "edge"), new XAttribute("id", "d10"), new XAttribute("yfiles.type", "edgegraphics")), new XElement(GraphML.Namespace + "graph", new XAttribute("edgedefault", "directed"), new XAttribute("id", "G"), //add all elements to the document elements, //add all edges to the document edges))); doc.Save(path); }
internal void Construct() { _TableFilter = string.IsNullOrEmpty(_TableFilterName) ? new NullTableFilter() : DiskOperations.CreateTableFilterObj(_TableFilterName); }
static void Main(string[] args) { string dataSource = null; string initialCatalog = null; string root = null; string outputFile = null; bool showType = true; string sType = ""; bool showRelation = true; string sRelation = ""; bool showHelp = false; var p = new OptionSet() { { "ds=", "the {DATA SOURCE} of the database to fetch ERD from.", (string ds) => dataSource = ds }, { "ic=", "the {INITIAL CATALOG} of the database to fetch ERD from.", (string ic) => initialCatalog = ic }, { "r|rootTable=", "a {ROOT TABLE} All tables output will have a descendent relation to this table.", (string r) => root = r }, { "st|showType=", "{Y/N} to indicate whether or not a column displaying attribute type is shown.", (string st) => sType = st }, { "sr|showRelation=", "{Y/N} to indicate whether or not PK/UX/IX/FK labels are displayed for each attribute.", (string sr) => sRelation = sr }, { "o|output=", "the {FILENAME} to output to.", (string o) => outputFile = o }, { "h|help", "show help.", h => showHelp = (h != null) } }; List <string> extra; try { extra = p.Parse(args); } catch (OptionException e) { Console.Write("yERD: "); Console.WriteLine(e.Message); Console.WriteLine("Try 'yERD --help' for more information."); return; } if (showHelp) { Console.WriteLine("Retrieve an ERD as a .graphml file!"); p.WriteOptionDescriptions(Console.Out); return; } if (dataSource == null || initialCatalog == null) { Console.Error.WriteLine("Both a data source and initial catalog must be supplied!. Try 'yERD --help' for more information."); return; } if (outputFile == null) { Console.Error.WriteLine("An output file must be specified!. Try '-yERD --help' for more information."); return; } showType = sType == "N" ? false : true; showRelation = sRelation == "N" ? false : true; Console.WriteLine("Fetching relationship data from the database..."); var schemaFetcher = new Fetch.SqlServerSchemaFetcher(); var connection = CreateConnectionString(dataSource, initialCatalog); var database = schemaFetcher.Fetch(connection); Console.WriteLine("Forming XML..."); string output = Path.Combine(Directory.GetCurrentDirectory(), Path.ChangeExtension(outputFile, ".graphml")); Console.WriteLine("Saving: " + output); var printer = new YWorksSchemaPrinter(database); ITableFilter filter = null; if (root != null) { var filterWithTable = database.Tables.FirstOrDefault(t => t.QualifiedName.ToLower() == root.ToLower()); filter = new RootTableFilter(database, filterWithTable); } printer.WriteFile(output, filter); Console.WriteLine("File '" + output + "' saved successfully!"); }