Exemple #1
0
        // The idea is that Initialize compiles, loads and sorts out the assemblies,
        //    but does not depend on any calls to Excel (except if we need to install the sync manager).
        // Then Initialize can be called during RTD registration or loading,
        //    without 'AutoOpening' the add-in.
        // TODO: Check that the registration calls we make in SyncContext.Install are safe in the COM Server context!?
        internal void Initialize()
        {
            Logger.Initialization.Verbose("{0} - Begin Initialize", Name);
            // Get MethodsInfos and AddIn classes from assemblies
            List <Type> rtdServerTypes             = new List <Type>();
            List <ExcelComClassType> comClassTypes = new List <ExcelComClassType>();

            // Recursively get assemblies down .dna tree.
            _exportedAssemblies = GetAssemblies(dnaResolveRoot);
            AssemblyLoader.ProcessAssemblies(_exportedAssemblies, _methods, _addIns, rtdServerTypes, comClassTypes);

            // Register RTD Server Types (i.e. remember that these types are available as RTD servers, with relevant ProgId etc.)
            RtdRegistration.RegisterRtdServerTypes(rtdServerTypes);

            // CAREFUL: This interacts with the implementation of ExcelRtdServer to implement the thread-safe synchronization.
            // Check whether we have an ExcelRtdServer type, and need to install the Sync Window
            // Uninstalled in the AutoClose
            bool registerSyncManager = false;

            foreach (Type rtdType in rtdServerTypes)
            {
                if (rtdType.IsSubclassOf(typeof(ExcelRtdServer)))
                {
                    registerSyncManager = true;
                    break;
                }
            }
            if (registerSyncManager)
            {
                SynchronizationManager.Install();  // TODO: Careful here!?
            }

            // Register COM Server Types immediately
            ComServer.RegisterComClassTypes(comClassTypes);
            Logger.Initialization.Verbose("{0} - End Initialize", Name);
        }