/// <summary> /// Returns the assembly information for the LobSystems. /// </summary> /// <param name="featurePropertyCollection">Collection of LobSystem Properties.</param> /// <param name="featureFolder">Feature folder.</param> /// <returns>Collection of assembly information for the LobSystems.</returns> private Dictionary<string, LobSystemAssemblies> GetLobSystemAssemblies(SPFeaturePropertyCollection featurePropertyCollection, string featureFolder) { //Get a list of all lobSystems defined by the model. XmlNodeList lobSystemList = this.modelDocument.GetElementsByTagName("LobSystem"); Dictionary<string, string> lobSystemProperties = new Dictionary<string, string>(lobSystemList.Count); foreach (XmlNode node in lobSystemList) { XmlAttribute lobSystemNameAttribute = node.Attributes["Name"]; //If lobSystem does not have a Name, import will fail with XSD validation. if (lobSystemNameAttribute != null) { string lobSystemName = lobSystemNameAttribute.Value; if (featurePropertyCollection[lobSystemName] != null && !String.IsNullOrEmpty(featurePropertyCollection[lobSystemName].Value)) { string lobSystemProperty = featurePropertyCollection[lobSystemName].Value; lobSystemProperties.Add(lobSystemName, lobSystemProperty); } } } Dictionary<string, LobSystemAssemblies> lobSystemAssemblies = new Dictionary<string, LobSystemAssemblies>(); foreach (string lobSystemName in lobSystemProperties.Keys) { string[] assembliesPath = ParseSemicolonDelimitedNames(lobSystemProperties[lobSystemName]); LobSystemAssemblies assemblies = new LobSystemAssemblies(); //Add full path to assembly names and load them. for (int i = 0; i < assembliesPath.Length; i++) { try { assembliesPath[i] = Path.Combine(featureFolder, assembliesPath[i]); } catch (ArgumentException ex) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Feature property '{0}' has invalid value. Feature activation failed with the following message: {1}", lobSystemName, ex.Message)); } if (File.Exists(assembliesPath[i]) == false) { throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, "Assembly file '{0}' does not exist.", assembliesPath[i])); } // First assembly is the main assembly if (i == 0) { assemblies.MainAssembly = GetAssemblyBytes(assembliesPath[0]); } else { if (assemblies.DependentAssemblies == null) { assemblies.DependentAssemblies = new List<byte[]>(assembliesPath.Length - 1); } assemblies.DependentAssemblies.Add(GetAssemblyBytes(assembliesPath[i])); } } lobSystemAssemblies.Add(lobSystemName, assemblies); } return lobSystemAssemblies; }
/// <summary> /// Export the lobSystems of the model. /// </summary> /// <param name="model">the model</param> /// <returns>lob systems</returns> private static Dictionary<string, LobSystemAssemblies> ExportLobSystem(Model model) { LobSystemCollection collection = model.OwnedReferencedLobSystems; Dictionary<string, LobSystemAssemblies> exportedLobSystems = new Dictionary<string, LobSystemAssemblies>(); foreach (LobSystem lobSystem in collection) { if (lobSystem.HasProxyAssembly) { LobSystemAssemblies assemblies = new LobSystemAssemblies(); IList<byte[]> allAssemblies = lobSystem.GetAllAssemblies(); if (allAssemblies != null && allAssemblies.Count > 0) { assemblies.MainAssembly = allAssemblies[0]; if (allAssemblies.Count > 1) { allAssemblies.RemoveAt(0); assemblies.DependentAssemblies = new List<byte[]>(allAssemblies.Count); assemblies.DependentAssemblies.AddRange(allAssemblies); } } exportedLobSystems.Add(lobSystem.Name, assemblies); } } return exportedLobSystems; }