private BsonDocument persistRep(TopLevelDocumentable rep) { JObject json = rep.getJson(); string jsonText = json.ToString(); //Debug.WriteLine(jsonText); BsonDocument doc = BsonDocument.Parse(jsonText); return(doc); }
/// <summary> /// reflects on a Type object (class, enum, struct or interface) (the ones that can be top level /// </summary> /// <param name="type"></param> /// <returns>A representation of that type</returns> public static TopLevelDocumentable reflectTopOrNested(Type type) { if (type.IsGenericType) { Debug.WriteLine("Generic type found"); foreach (Type arg in type.GetGenericArguments()) { Debug.WriteLine(arg.ToString()); } } TopLevelDocumentable rep = null; if (type.IsEnum) { rep = new EnumRepresentation(type.FullName); reflectEnum((EnumRepresentation)rep, type); } else if (type.IsClass) { ObjectType ot = ObjectType.toObjectType(type); rep = new ClassRepresentation(ot.typeName); ((ClassRepresentation)rep).varargs = ot.varargs; new ClassReflector().reflectClass((ClassRepresentation)rep, type); } else if (type.IsInterface) { ObjectType ot = ObjectType.toObjectType(type); rep = new ClassRepresentation(ot.typeName); rep.objectType.typeName = "interface"; ((ClassRepresentation)rep).varargs = ot.varargs; new ClassReflector().reflectClass((ClassRepresentation)rep, type); } else if (type.IsValueType) { ObjectType ot = ObjectType.toObjectType(type); rep = new ClassRepresentation(ot.typeName); rep.objectType.typeName = "struct"; ((ClassRepresentation)rep).varargs = ot.varargs; new ClassReflector().reflectClass((ClassRepresentation)rep, type); } else { return(null); } //TypeInfo ti = type..GetTypeInfo(); rep.userGenerated = false; rep.namespaceName = type.Namespace; rep.assemblyName = type.Assembly.GetName().Name; convert(rep.modifiers, type); return(rep); }
private void reflectSubtypes(ClassRepresentation rep, Type type) { foreach (Type t in type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { if (t.IsNestedPrivate) { continue; } TopLevelDocumentable td = APIReflector.reflectTopOrNested(t); rep.nested.Add(td); } }
public void storeClass(TopLevelDocumentable rep) { if (batchSize >= 100) { Task task = database.GetCollection <BsonDocument>(collectionName).InsertManyAsync(reps); task.ContinueWith(tasking => { Debug.WriteLine("Completed a batch"); return(""); }); Debug.WriteLine("Persisting batch"); allTasks.Add(task); batchSize = 0; reps = new List <BsonDocument>(); } BsonDocument doc = persistRep(rep); reps.Add(doc); count++; batchSize++; }
public void reflectClasses(CLOptions options) { String assemblyFile = options.assemblyFile; Assembly ksp = null; if (assemblyFile == null) { ksp = typeof(GameEvents).Assembly; } else { ksp = Assembly.LoadFrom(assemblyFile); } foreach (Type type in ksp.GetExportedTypes()) { Debug.WriteLine("reflecting " + type.FullName); TopLevelDocumentable rep = reflectTop(type); if (rep != null) { classStore.storeClass(rep); } } ksp = typeof(ConfigNode).Assembly; foreach (Type type in ksp.GetExportedTypes()) { Debug.WriteLine("reflecting " + type.FullName); TopLevelDocumentable rep = reflectTop(type); if (rep != null) { classStore.storeClass(rep); } } ksp = typeof(PQSOrbit).Assembly; foreach (Type type in ksp.GetExportedTypes()) { Debug.WriteLine("reflecting " + type.FullName); TopLevelDocumentable rep = reflectTop(type); if (rep != null) { classStore.storeClass(rep); } } ksp = typeof(KSPAssets.AssetDefinition).Assembly; foreach (Type type in ksp.GetExportedTypes()) { Debug.WriteLine("reflecting " + type.FullName); TopLevelDocumentable rep = reflectTop(type); if (rep != null) { classStore.storeClass(rep); } } int count = classStore.await(); Debug.WriteLine("inserted =" + count); }
public void storeClass(TopLevelDocumentable doc) { list.Add(doc); }