public void StoreModule(IndexBase.Module module) { var mentity = new ModuleEntity { ModuleHeader = JsonConvert.SerializeObject(module), Id = module.FullName.GenerateGuid(), FullName = module.FullName }; var filter = Builders <ModuleEntity> .Filter.Where(w => w.Id == mentity.Id); var replaceResult = modules.ReplaceOne(filter, mentity, new UpdateOptions { IsUpsert = true }); }
private IEnumerable <IndexBase.Module> ExtractModule(TypeDefinition moduleType, AssemblyDefinition assDef, CustomAttribute modAttr) { var res = new IndexBase.Module(); res.Assembly = assDef.Name.Name; res.Description = moduleType.GetDescription(); res.FullName = moduleType.FullName + " [Lease]"; res.Tags = new[] { "Lease" }; bool isAgar = false; if (modAttr != null) { res.Significance = (Nailhang.Significance)modAttr.Properties.Where(w => w.Name == "Significance").Select(w => (int)w.Argument.Value).FirstOrDefault(); } else { res.Significance = Significance.Low; } var types = new List <Mono.Cecil.TypeReference>(); foreach (var meth in moduleType.Methods .Where(w => w.Body != null)) { if (meth.Name == "Load") { var methBody = meth.Body; foreach (var i in methBody.Instructions) { var op = i.Operand as Mono.Cecil.TypeReference; if (op != null && op.FullName != "Ninject.Modules.INinjectModule" && op.FullName != "System.Type") { types.Add(op); } var mr = i.Operand as Mono.Cecil.MethodReference; if (mr != null) { if (mr.DeclaringType.FullName == "Alda.MultiVox.Base.Agar.Base.AgarModule") { isAgar = true; } } } } } if (isAgar) { if (types.Any(q => q.FullName == "Alda.MultiVox.Base.Agar.Base.CellInfo")) { yield break; } res.ModuleBinds = types.Select(q => q.ToIndexBaseTypeReference()).ToArray(); yield return(res); } }
private IEnumerable <IndexBase.Module> ExtractModule(TypeDefinition moduleType, AssemblyDefinition assDef, CustomAttribute modAttr) { var res = new IndexBase.Module(); res.Assembly = assDef.Name.Name; res.Description = moduleType.GetDescription(); res.FullName = moduleType.FullName; if (modAttr != null) { res.Significance = (Significance)modAttr.Properties.Where(w => w.Name == "Significance").Select(w => (int)w.Argument.Value).FirstOrDefault(); } else { res.Significance = Significance.Low; } var moduleTypeRefs = ModuleBinds(moduleType).ToArray(); var activatesTypes = ModuleActivates(moduleType) .ToDefs() .ToArray(); activatesTypes = activatesTypes .Concat(moduleTypeRefs.ToDefs()) .Concat(activatesTypes.SelectMany(w => w.GetConstructorTypes()).ToDefs()) .Distinct() .ToArray(); var moduleTypes = activatesTypes; res.ModuleBinds = ModuleBinds(moduleType) .Select(w => w.ToIndexBaseTypeReference()) .ToArray(); res.Interfaces = moduleTypes .Where(w => w.Namespace.StartsWith(moduleType.Namespace)) .CreateInterfaces(); res.Objects = moduleTypes .Where(w => w.Namespace.StartsWith(moduleType.Namespace)) .CreateObjects(true); var moduleReferences = moduleTypes .FilterObjects(false) .GetDependencies() .ToDefs(); res.InterfaceDependencies = moduleReferences .FilterInterfaces() .Select(w => w.ToIndexBaseTypeReference()) .ToArray(); res.ObjectDependencies = moduleReferences .FilterObjects(true) .Select(w => w.ToIndexBaseTypeReference()) .ToArray(); if (res.InterfaceDependencies.Any() || res.Interfaces.Any() || res.ModuleBinds.Any() || res.ObjectDependencies.Any() || res.Objects.Any()) { yield return(res); } }