protected virtual void InitAppPlugins() { var types = ShReflectionUtils.GetTypesFromAssemblies <IPlugin>(AppPluginsAssemblies); foreach (var type in types.OrderByDescending(a => a.Name)) { try { if (!AppDataServices.Any(t => t.GetType() == type)) { var instance = Activator.CreateInstance(type) as IPlugin; instance.Init(); AppPlugins.Add(instance); } } catch (System.Exception e) { // TODO throw; } } }
protected virtual void InitAppDataServices() { var types = ShReflectionUtils.GetTypesFromAssemblies <ShAppDataServiceBase>(AppDataServiceAssemblies) .ToList(); // special init for event hub var eventDataService = types.First(t => typeof(IAppEventService).IsAssignableFrom(t)); AppDataServices.Add(Activator.CreateInstance(eventDataService) as ShAppDataServiceBase); types.Remove(eventDataService); // the rest foreach (var type in types.OrderByDescending(a => a.Name)) { try { if (!AppDataServices.Any(t => t.GetType() == type)) { var instance = Activator.CreateInstance(type) as ShAppDataServiceBase; instance.Init(); AppDataServices.Add(instance); } } catch (Exception e) { // TODO throw; } } }
protected virtual void CreateAppUIServices() { var types = ShReflectionUtils.GetTypesFromAssemblies <ShAppUIServiceBase>(AppUIServiceAssemblies); foreach (var type in types.OrderByDescending(a => a.Name)) { try { if (!AppDataServices.Any(t => t.GetType() == type)) { var instance = Activator.CreateInstance(type) as ShAppUIServiceBase; AppUIServices.Add(instance); } } catch (Exception e) { // TODO throw; } } }
public static Type GetUIComponentType(Type targetType, Type fallbackType) { if (!hasInitedAssemblies) { InitAssemblies(); hasInitedAssemblies = true; } Type result = null; var allTypes = ShReflectionUtils.GetTypesFromAssemblies(targetType, uiAssemblies) .Where(t => typeof(ShUserControlBase).IsAssignableFrom(t) && !t.IsAbstract); if (allTypes.Count() == 0) { throw new ShAppException("Can't find implementation for type: " + targetType.Name); } if (allTypes.Count() == 1) { return(allTypes.First()); } if (fallbackType != null) { var implType = allTypes.FirstOrDefault(t => t != fallbackType); if (implType != null) { return(implType); } return(fallbackType); } throw new ShAppException("Can't find fallback type for type: " + targetType.Name); }