private static void LoadTree() { var loaded = AppDomain.CurrentDomain.GetAssemblies(); lock (Loaded) { Loaded.UnionWith(loaded); } var msgAssemblies = new List <Assembly>(); var rootName = IMessageType.Assembly.GetName(); for (int i = 0; i < loaded.Length; i++) { AssemblyName[] refs = loaded[i].GetReferencedAssemblies(); for (int j = 0; j < refs.Length; j++) { if (AssemblyName.ReferenceMatchesDefinition(refs[j], rootName)) { msgAssemblies.Add(loaded[i]); break; } } } lock (Processed) { Processed.UnionWith(msgAssemblies); } var types = new HashSet <Type>(); for (int i = 0; i < msgAssemblies.Count; i++) { types.UnionWith(msgAssemblies[i].GetLoadableTypes().Where(t => IMessageType.IsAssignableFrom(t) && !t.IsInterface)); } TypeTree.AddToTypeTree(types); }
public static IEnumerable <Type> DescendantsAndSelf(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } return(TypeTree.DescendantsAndSelf(type)); }
private static void RebuildMessageTree() { var addedTypes = GetTypesDerivedFrom(typeof(Message)); // Update lookups for name and fullnames addedTypes.ForEach(t => nameToType[t.Name] = t); addedTypes.ForEach(t => fullNameToType[t.FullName] = t); if (addedTypes.FirstOrDefault() != null) { TypeTree.AddToTypeTree(addedTypes); MessageTypesAdded(null, null); } }
static MessageHierarchy() { // Get the all of the types in the Assembly that are derived from Message and then build a // backing TypeTree. // TODO: Put in timing logging var derivedTypes = GetTypesDerivedFrom(typeof(Message)); // Create lookups for name and fullnames derivedTypes.ForEach(t => nameToType[t.Name] = t); derivedTypes.ForEach(t => fullNameToType[t.FullName] = t); TypeTree.BuildTree(derivedTypes); AppDomain.CurrentDomain.AssemblyLoad += AssemblyLoadEventHandler; }
static MessageHierarchy() { // Get the all of the types in the Assembly that are derived from Message and then build a // backing TypeTree. //Load Root var types = new HashSet <Type>(IMessageType.Assembly.GetLoadableTypes().Where(t => IMessageType.IsAssignableFrom(t) && !t.IsInterface)); TypeTree.AddToTypeTree(types); Processed.Add(IMessageType.Assembly); var sw = Stopwatch.StartNew(); LoadTree(); sw.Stop(); InitialLoadTime = sw.Elapsed; TotalLoadTime = sw.Elapsed; }
public static Type GetTypeByFullName(string fullName) { if (fullName == null) { throw new ArgumentNullException(nameof(fullName)); } if (TypeTree.TryGetTypeByFullName(fullName, out Type result)) { return(result); } ExpandTree(); if (TypeTree.TryGetTypeByFullName(fullName, out result)) { return(result); } throw new UnregisteredMessageTypeNameException(fullName); }
public static List <Type> DescendantsAndSelf(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (type != IMessageType && !IMessageType.IsAssignableFrom(type) && type != typeof(object)) { throw new MessagingException($"{type.FullName} does not implement {IMessageType.FullName}"); } if (TypeTree.TryGetDescendantsAndSelf(type, out var types)) { return(types); } ExpandTree(); if (!TypeTree.TryGetDescendantsAndSelf(type, out types)) { throw new UnregisteredMessageTypeNameException(type.FullName); } return(types); }
private static void LoadAssembly(Assembly assembly) { TypeTree.AddToTypeTree(new HashSet <Type>(assembly.GetLoadableTypes().Where(t => IMessageType.IsAssignableFrom(t) && !t.IsInterface))); }