public static void Seed(InheritanceContext context) { var animals = InheritanceData.CreateAnimals(); var countries = InheritanceData.CreateCountries(); var drinks = InheritanceData.CreateDrinks(); var plants = InheritanceData.CreatePlants(); InheritanceData.WireUp(animals, countries); context.Animals.AddRange(animals); context.Countries.AddRange(countries); context.Drinks.AddRange(drinks); context.Plants.AddRange(plants); context.SaveChanges(); }
static void printAncestor(StreamWriter sr, InheritanceData ih, ref string tabs) { if (ih.ancestor >= 0) { printAncestor(sr, inheritanceGraph[ih.ancestor], ref tabs); } if (ih.refid == null)//class not tracked { sr.WriteLine(tabs + "- `{0}`", ih.name); } else { sr.WriteLine(tabs + "- [`{0}`]({1})", ih.name, compounds[ih.refid].FullName); } tabs += " "; }
public virtual ISetSource GetFilteredExpectedData(DbContext context) { if (_expectedDataCache.TryGetValue(EnableFilters, out var cachedResult)) { return(cachedResult); } var expectedData = new InheritanceData(); if (EnableFilters) { var animals = expectedData.Animals.Where(a => a.CountryId == 1).ToList(); var animalQueries = expectedData.AnimalQueries.Where(a => a.CountryId == 1).ToList(); expectedData = new InheritanceData(animals, animalQueries, expectedData.Countries, expectedData.Drinks, expectedData.Plants); } _expectedDataCache[EnableFilters] = expectedData; return(expectedData); }
public static void process(string input, string output) { inheritanceGraph = new Dictionary <int, InheritanceData>(); compounds = new Dictionary <string, Compound>(); Directory.CreateDirectory(output); string[] infiles = Directory.GetFiles(input, "*.xml"); foreach (string infile in infiles) { Compound c = new Compound(); XmlDocument doc = new XmlDocument(); using (Stream ins = new FileStream(infile, FileMode.Open)){ doc.Load(ins); } XmlNode comps = doc.SelectSingleNode("/doxygen/compounddef"); if (comps == null) { continue; } c.id = comps.Attributes["id"].Value; c.compKind = (Kind)Enum.Parse(typeof(Kind), comps.Attributes["kind"]?.Value, true); foreach (XmlNode xn in comps.ChildNodes) { switch (xn.Name) { case "compoundname": c.FullName = xn.InnerText.Replace("::", "."); if (c.compKind != Kind.File) { c.ShortName = c.GetSimpleName; if (c.ShortName.Length < c.FullName.Length - 1) { c.nameSpace = c.FullName.Remove(c.FullName.Length - c.ShortName.Length - 1); } } break; case "basecompoundref": c.baseComps.Add(xn.InnerText); break; case "derivedcompoundref": c.derivedComps.Add(xn.InnerText); break; case "briefdescription": c.shortDesc = processDesciption(xn); break; case "detaileddescription": c.longDesc = processDesciption(xn); break; case "inheritancegraph": foreach (XmlNode node in xn.ChildNodes) { InheritanceData ih = new InheritanceData(); ih.id = int.Parse(node.Attributes["id"].Value); ih.name = node["label"].InnerText?.Split('.').LastOrDefault(); ih.refid = node["link"]?.Attributes["refid"]?.Value; if (node["childnode"] == null) { ih.ancestor = -1; } else { ih.ancestor = int.Parse(node["childnode"].Attributes["refid"].Value); } if (inheritanceGraph.ContainsKey(ih.id)) { if (inheritanceGraph[ih.id].ancestor < 0) { inheritanceGraph[ih.id].ancestor = ih.ancestor; } } else { inheritanceGraph[ih.id] = ih; } } break; case "sectiondef": foreach (XmlNode memb in xn.ChildNodes) { Compound p = new Compound(); p.compKind = (Kind)Enum.Parse(typeof(Kind), memb.Attributes["kind"].Value, true); if (memb.Attributes["prot"]?.Value != "public") { continue; } p.id = memb.Attributes["id"].Value; foreach (XmlNode membAtts in memb.ChildNodes) { switch (membAtts.Name) { case "type": p.type = membAtts.InnerText?.Split(' ').LastOrDefault(); break; case "definition": p.definition = membAtts.InnerText; break; case "name": p.FullName = membAtts.InnerText; break; case "argsstring": p.argsstring = membAtts.InnerText; break; case "location": p.location = Path.Combine("../blob/master", membAtts.Attributes["file"].Value); int tmp = 0; if (int.TryParse(membAtts.Attributes["bodystart"]?.Value, out tmp)) { p.bodyStart = tmp; } if (int.TryParse(membAtts.Attributes["bodyend"]?.Value, out tmp)) { p.bodyEnd = tmp; } break; case "briefdescription": p.shortDesc = processDesciption(membAtts); break; case "detaileddescription": p.longDesc = processDesciption(membAtts); break; } } c.memberIds.Add(p.id); compounds[p.id] = p; } break; } } compounds[c.id] = c; } foreach (KeyValuePair <string, Compound> kc in compounds.Where(cp => cp.Value.compKind == Kind.Class)) { Compound c = kc.Value; using (Stream os = new FileStream(Path.Combine(output, c.FullName) + ".md", FileMode.Create)) { using (StreamWriter sr = new StreamWriter(os)) { sr.WriteLine(c.shortDesc); sr.WriteLine(); sr.WriteLine(c.longDesc); sr.WriteLine(); sr.WriteLine("**namespace**: `{0}`\n\n", c.nameSpace); sr.WriteLine("#### Inheritance Hierarchy\n"); //if (c.className == "ComboBox") //System.Diagnostics.Debugger.Break(); string tabs = ""; InheritanceData igThis = inheritanceGraph.Values.FirstOrDefault(nd => nd.refid == c.id); if (igThis?.ancestor >= 0) { printAncestor(sr, inheritanceGraph[igThis.ancestor], ref tabs); } sr.WriteLine(tabs + "- `{0}`", c.ShortName); tabs += " "; Compound baseClass = findBaseClass(c); foreach (string s in c.derivedComps) { Compound deriv = findCompoundByName(s); if (deriv == null) { continue; } sr.WriteLine(tabs + "- [`{0}`]({1})", deriv.ShortName, deriv.FullName); } sr.WriteLine("#### Syntax\n"); sr.WriteLine("```csharp"); sr.Write("public class {0}", c.ShortName); Compound[] ifaces = findIFaces(c); int ifaceIdx = 0; if (baseClass != null) { sr.Write(" : {0}", baseClass.ShortName); } else if (ifaces.Length > 0) { sr.Write(" : {0}", ifaces[0].ShortName); ifaceIdx = 1; } while (ifaceIdx < ifaces.Length) { sr.Write(", {0}", ifaces[ifaceIdx].ShortName); ifaceIdx++; } List <Compound> pubCTORs = new List <Compound>(); List <Compound> pubMethods = new List <Compound>(); List <Compound> pubProperties = new List <Compound>(); List <Compound> pubEvents = new List <Compound>(); foreach (string memId in c.memberIds) { Compound m = compounds[memId]; switch (m.compKind) { case Kind.Function: if (m.FullName == c.ShortName) { pubCTORs.Add(m); } else { pubMethods.Add(m); } break; case Kind.Property: pubProperties.Add(m); break; case Kind.Event: pubEvents.Add(m); break; } } sr.WriteLine(""); sr.WriteLine("```"); sr.WriteLine("#### Constructors\n"); sr.WriteLine("| :white_large_square: | prototype | description"); sr.WriteLine("| --- | --- | --- |"); foreach (Compound prop in pubCTORs) { sr.WriteLine("| method | `{0} {1} {2}` | _{3}_", prop.type, prop.FullName?.Trim(), prop.argsstring, prop.shortDesc?.Trim()); } sr.WriteLine("#### Properties\n"); sr.WriteLine("| :white_large_square: | name | description |"); sr.WriteLine("| --- | --- | --- |"); foreach (Compound cp in pubProperties.OrderBy(mbb => mbb.FullName)) { sr.WriteLine("| property | `{0}` | _{1}_ |", cp.FullName?.Trim(), cp.shortDesc?.Trim()); } sr.WriteLine("#### Methods\n"); sr.WriteLine("| :white_large_square: | prototype | description |"); sr.WriteLine("| --- | --- | --- |"); foreach (Compound cp in pubMethods.OrderBy(mbb => mbb.FullName)) { sr.WriteLine("| method | `{0} {1}{2}` | _{3}_ |", cp.type, cp.FullName?.Trim(), cp.argsstring, cp.shortDesc?.Trim()); } sr.WriteLine("#### Events\n"); sr.WriteLine("| :white_large_square: | name | description |"); sr.WriteLine("| --- | --- | --- |"); foreach (Compound cp in pubEvents.OrderBy(mbb => mbb.FullName)) { sr.WriteLine("| event | `{0}` | _{1}_ |", cp.FullName?.Trim(), cp.shortDesc?.Trim()); } } } } using (Stream os = new FileStream(Path.Combine(output, "Home.md"), FileMode.Create)) { using (StreamWriter sr = new StreamWriter(os)) { foreach (IGrouping <string, KeyValuePair <string, Compound> > nkc in compounds.Where(cp => cp.Value.compKind == Kind.Class).GroupBy(cpp => cpp.Value.nameSpace)) { sr.WriteLine("## `{0}` namespace\n", nkc.Key); sr.WriteLine("| class | description |"); sr.WriteLine("| --- | --- |"); foreach (KeyValuePair <string, Compound> kc in nkc) { Compound c = kc.Value; sr.WriteLine("| [`{0}`]({1}) | _{2}_ |", c.ShortName, c.FullName, c.shortDesc?.Trim()); } } } } }