public static ArrayList GetServicesNamesFromAssembly(Assembly a) { var serviceContainer = new ArrayList(); if (a != null) { try { var types = GetTypesFromAssembly(a); var typeService = typeof(StiService); foreach (var type in types) { try { if (StiTypeFinder.FindType(type, typeService) && (!type.IsAbstract)) { serviceContainer.Add(GetStringFromService(type)); } } catch { } } } catch { } } return(serviceContainer); }
/// <summary> /// Returns services which are in the specified assembly. /// </summary> /// <param name="a">Assembly.</param> /// <returns>Services.</returns> public static StiServiceContainer GetServicesFromAssembly(Assembly a) { var serviceContainer = new StiServiceContainer(); if (a != null) { var types = GetTypesFromAssembly(a); Type typeService = typeof(StiService); foreach (Type type in types) { if (StiTypeFinder.FindType(type, typeService) && (!type.IsAbstract)) { try { var service = StiActivator.CreateObject(type) as StiService; if (service != null && service.ServiceType != null) { serviceContainer.Add(service); } } catch { } } } } return(serviceContainer); }
/// <summary> /// Loads container of services. /// </summary> /// <param name="tr">XmlReader.</param> public void Load(XmlReader tr) { var converter = new StiObjectStringConverter(); StiService service = null; tr.Read(); while (tr.Read()) { if (tr.IsStartElement()) { #region service if (tr.Name == "service") { string assembly = tr.GetAttribute("assembly"); string serviceType = tr.GetAttribute("type"); if (assemlyToSkip[assembly.ToLower(System.Globalization.CultureInfo.InvariantCulture)] == null) { try { service = CreateService(assembly, serviceType); if (service != null) { Add(service, false); } } catch { } } } #endregion #region property else if (tr.Name == "property" && service != null) { string propName = tr.GetAttribute("name"); string typeStr = tr.GetAttribute("type"); var propInfo = service.GetType().GetProperty(propName); if (propInfo != null) { if (tr.GetAttribute("isNull") != null) { propInfo.SetValue(service, null, null); } else if (tr.GetAttribute("isList") != null) { int count = int.Parse(tr.GetAttribute("count")); Type elementType = StiTypeFinder.GetType(typeStr); Array list = Array.CreateInstance(elementType, count); int index = 0; while (tr.Read()) { if (tr.IsStartElement()) { string nm = tr.Name; string valueStr = tr.ReadString(); object value = converter.StringToObject(valueStr, elementType); if (value != null) { list.SetValue(value, new int[] { index++ }); } if (index >= count) { break; } } } propInfo.SetValue(service, list, null); } else { string valueStr = tr.GetAttribute("value"); object value = converter.StringToObject(valueStr, StiTypeFinder.GetType(typeStr)); if (value != null) { propInfo.SetValue(service, value, null); } } } } #endregion } } }