public static List <IGSASenderDictionary> GetAssembliesSenderDictionaries() { var assemblies = SpeckleInitializer.GetAssemblies().Where(a => a.GetTypes().Any(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)))); var staticObjects = new List <IGSASenderDictionary>(); //Now obtain the serialised (inheriting from SpeckleObject) objects foreach (var ass in assemblies) { var types = ass.GetTypes(); try { var gsaStatic = types.FirstOrDefault(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)) && t.GetProperties().Any(p => p.PropertyType == typeof(IGSACacheForKit))); if (gsaStatic != null) { var dict = (IGSASenderDictionary)gsaStatic.GetProperties().FirstOrDefault(p => p.PropertyType == typeof(IGSASenderDictionary)).GetValue(null); //This is how SpeckleGSA finds the objects in the GSASenderObjects dictionary - by finding the first property in ISpeckleInitializer which is of the specific dictionary type staticObjects.Add(dict); } } catch (Exception e) { } } return(staticObjects); }
public static bool SetAssembliesSenderDictionaries() { var assemblies = SpeckleInitializer.GetAssemblies().Where(a => a.GetTypes().Any(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)))); senderDictionaries = new List <IGSASenderDictionary>(); //Now obtain the serialised (inheriting from SpeckleObject) objects foreach (var ass in assemblies) { var types = ass.GetTypes(); try { var gsaStatic = types.FirstOrDefault(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)) && t.GetProperties().Any(p => p.PropertyType == typeof(IGSACacheForKit))); if (gsaStatic != null) { var dict = (IGSASenderDictionary)gsaStatic.GetProperties().FirstOrDefault(p => p.PropertyType == typeof(IGSASenderDictionary)).GetValue(null); //This is how SpeckleGSA finds the objects in the GSASenderObjects dictionary - by finding the first property in ISpeckleInitializer which is of the specific dictionary type senderDictionaries.Add(dict); } } catch (FileNotFoundException) { //Swallow as it is likely to be an application SDK that a kit's conversion code references which isn't installed } catch (Exception e) { return(false); } } return(true); }
private List <Type> GetAssembliesTypes() { // Grab GSA interface type var interfaceType = typeof(IGSASpeckleContainer); var assemblies = SpeckleInitializer.GetAssemblies(); var objTypes = new List <Type>(); foreach (var ass in assemblies) { var types = ass.GetTypes(); objTypes.AddRange(types.Where(t => interfaceType.IsAssignableFrom(t) && t != interfaceType)); } return(objTypes); }
private static void InitialiseKits(out List <string> statusMessages) { statusMessages = new List <string>(); var attributeType = typeof(GSAObject); var interfaceType = typeof(IGSASpeckleContainer); SpeckleInitializer.Initialize(); // Run initialize receiver method in interfacer var assemblies = SpeckleInitializer.GetAssemblies().Where(a => a.GetTypes().Any(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)))); var speckleTypes = new List <Type>(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var t in types) { if (typeof(SpeckleObject).IsAssignableFrom(t)) { speckleTypes.Add(t); } } } var mappableTypes = new List <Type>(); foreach (var ass in assemblies) { var types = ass.GetTypes(); Type gsaStatic; try { gsaStatic = types.FirstOrDefault(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)) && t.GetProperties().Any(p => p.PropertyType == typeof(IGSACacheForKit))); if (gsaStatic == null) { continue; } } catch { //The kits could throw an exception due to an app-specific library not being linked in (e.g.: the Revit SDK). These libraries aren't of the kind that //would contain the static properties searched for anyway, so just continue. continue; } try { gsaStatic.GetProperty("Interface").SetValue(null, gsaProxy); gsaStatic.GetProperty("Settings").SetValue(null, Settings); gsaStatic.GetProperty("Cache").SetValue(null, gsaCache); gsaStatic.GetProperty("AppUI").SetValue(null, appUi); } catch { Status.AddError($"Unable to fully connect to {ass.GetName().Name}.dll. Please check the versions of the kit you have installed."); } var objTypes = types.Where(t => interfaceType.IsAssignableFrom(t) && t != interfaceType).ToList(); objTypes = objTypes.Distinct().ToList(); foreach (var t in objTypes) { var prereq = t.GetAttribute("WritePrerequisite"); WriteTypePrereqs[t] = (prereq != null) ? ((Type[])prereq).ToList() : new List <Type>(); prereq = t.GetAttribute("ReadPrerequisite"); ReadTypePrereqs[t] = (prereq != null) ? ((Type[])prereq).ToList() : new List <Type>(); } foreach (var t in speckleTypes) { var methods = Helper.GetExtensionMethods(ass, t, "ToNative"); if (methods != null && methods.Count() > 0 && !mappableTypes.Contains(t)) { mappableTypes.Add(t); if (t.BaseType != null && t.BaseType != typeof(SpeckleObject)) { if (!mappableTypes.Contains(t.BaseType)) { mappableTypes.Add(t.BaseType); } } } } } Merger.Initialise(mappableTypes); }