using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using BridgeConnector.Lib.Assembly; namespace Component.All { /// /// Responsible for working with setup components which don't require any special treatment /// public class Component_Setup_Manager : IDisposable, IManageComponents { #region Private Members private bool _disposed = false; private Dictionary _componentsLoaded = new Dictionary(); #endregion #region Construction /// /// Constructor /// public Component_Setup_Manager() { } /// /// Finalizer /// ~Component_Setup_Manager() { Dispose(true); } #endregion #region IManageComponents Members /// /// Checks if there are Newer Components embedded then that were installed on the system /// /// true, if newer components were found, false otherwise public bool AreNewerComponentsAvailable() { //# If nothing is installed, no need to continue if (GetAllInstalledComponents() == null) return true; // if the lengths don't match, something must get installed if (GetAllInstalledComponents().Length != GetAllEmbeddedComponents().Length) return true; // # Otherwise, let's determine 1 by 1 foreach (ComponentConfig.Component component in GetAllEmbeddedComponents()) { int nIndex = Common.GetIndexForComponentUniqueLabel(component.UniqueLabel, GetAllInstalledComponents()); if (nIndex == -1) return true; else if (GetAllInstalledComponents()[nIndex].CompareTo(component) != 0) return true; } return false; } /// /// Returns the Component Definitions for all Newer components found on the system /// /// a list of newer setup components, or empty list for none public IInstallComponent[] GetNewerComponents(ref SetupEvents setupEventObj) { // # Extract all, or let's determine 1 by 1 and extract bool bInstalledCompsFound = (GetAllInstalledComponents() != null); foreach (ComponentConfig.Component component in GetAllEmbeddedComponents()) { bool bInstall = true; if (bInstalledCompsFound) { int nIndex = Common.GetIndexForComponentUniqueLabel(component.UniqueLabel, GetAllInstalledComponents()); if (nIndex != -1) bInstall = (GetAllInstalledComponents()[nIndex].CompareTo(component) != 0); } // mark component for Installation if (bInstall) { string asmName = "Component.Setup." + component.UniqueLabel; _componentsLoaded[component.UniqueLabel] = Assembly.Load(asmName); } } List ComponentsToInstall = new List(); if (_componentsLoaded.Count > 0) { foreach (Assembly asm in _componentsLoaded.Values) { IInstallComponent installComp = null; Type[] types = asm.GetTypes(); foreach (Type t in types) { if (t.GetInterface(typeof(IInstallComponent).Name) != null) { installComp = (IInstallComponent)asm.CreateInstance(t.FullName); break; } } // Check IInstallComponent was found if (installComp == null) { Common.Log.Error(String.Format("Component {0} contains no IInstallComponent Definition.", AssemblyW.GetAssemblyName(asm))); continue; } // Check if class also implements ISetup if (installComp is ISetup) ((ISetup)installComp).ComponentLoaded(ref setupEventObj); // Add to Install Components ComponentsToInstall.Add(installComp); } } return ComponentsToInstall.ToArray(); } /// /// Retrieves the list of all installed components, in order to uninstall /// /// a list of all installed components, null otherwise public IInstallComponent[] GetAllInstalledComponents(string ComponentsSeperatedbySemiColonOrBlankForAll, ref SetupEvents setupEventObj) { // TO DO: //string[] ComponentsUniqueLabels = null; //if (!String.IsNullOrEmpty(ComponentsSeperatedbySemiColonOrBlankForAll)) // ComponentsUniqueLabels = ComponentsSeperatedbySemiColonOrBlankForAll.Split(';'); return null; } /// /// Retrieves the list of all installed components /// /// a list of all installed components, null otherwise public ComponentConfig.Component[] GetAllInstalledComponents() { if (Common.InstalledConfig != null && Common.InstalledConfig.SetupComponents.Components.Length > 0) return Common.InstalledConfig.SetupComponents.Components; return null; } /// /// Retrieves the list of all installed componentsW /// /// a list of all installed componentsW, null otherwise public ComponentConfig.ComponentW GetAllInstalledComponentsW() { return Common.InstalledConfig.SetupComponents; } /// /// Retrieves the list of all Embedded components /// /// a list of all embedded components, null otherwise public ComponentConfig.Component[] GetAllEmbeddedComponents() { if (Common.EmbeddedConfig != null && Common.EmbeddedConfig.SetupComponents.Components.Length > 0) return Common.EmbeddedConfig.SetupComponents.Components; return null; } #endregion #region IDisposable Members /// /// Dispose of all extracted files /// public void Dispose() { Dispose(true); // Use SupressFinalize in case a subclass // of this type implements a finalizer GC.SuppressFinalize(this); } /// /// Make sure to conserve disk space, to delete all files that were extracted /// by this program /// /// if true, delete all files extracted by this dll protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { _componentsLoaded.Clear(); _componentsLoaded = null; } // Indicate that the instance has been disposed. _disposed = true; } } #endregion } }