// The idea is that initialize compiles, loads and sorts out the assemblies, // but does not depend on any calls to Excel. // Then Initialize can be called during RTD registration or loading, // without 'AutoOpening' the add-in internal void Initialize() { // 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. List <ExportedAssembly> assemblies = GetAssemblies(dnaResolveRoot); AssemblyLoader.ProcessAssemblies(assemblies, _methods, _addIns, rtdServerTypes, comClassTypes); // Register RTD Server Types immediately 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(); } // Register COM Server Types immediately ComServer.RegisterComClassTypes(comClassTypes); }
// Only called for the Root DnaLibrary. internal void AutoOpen() { // Register special RegistrationInfo function RegistrationInfo.Register(); SynchronizationManager.Install(); // Register my Methods ExcelIntegration.RegisterMethods(_methods); // Invoke AutoOpen in all assemblies foreach (AssemblyLoader.ExcelAddInInfo addIn in _addIns) { try { if (addIn.AutoOpenMethod != null) { addIn.AutoOpenMethod.Invoke(addIn.Instance, null); } } catch (Exception e) { // TODO: What to do here? Logger.Initialization.Error(e, "DnaLibrary AutoOpen Error"); } } LoadCustomUI(); }
// Only called for the Root DnaLibrary. internal void AutoOpen() { // Register special RegistrationInfo function RegistrationInfo.Register(); SynchronizationManager.Install(); // Register my Methods ExcelIntegration.RegisterMethods(_methods); // Invoke AutoOpen in all assemblies foreach (AssemblyLoader.ExcelAddInInfo addIn in _addIns) { try { if (addIn.AutoOpenMethod != null) { addIn.AutoOpenMethod.Invoke(addIn.Instance, null); } } catch (Exception e) { // TODO: What to do here? Debug.Print(e.Message); } } // Load my UI LoadCustomUI(); }
// Only called for the Root DnaLibrary. internal void AutoOpen() { // Register special RegistrationInfo function RegistrationInfo.Register(); SynchronizationManager.Install(true); // Register my Methods - should this also go into the delayed call? ExcelIntegration.RegisterMethods(_methods); // We defer the rest of the load until we have an Application object... ExcelAsyncUtil.QueueAsMacro(AutoOpenImpl); }
// 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) { try { SynchronizationManager.Install(); } catch (InvalidOperationException) { // This is expected if we are running under HPC or Regsvr32. Logger.Initialization.Warn("SynchonizationManager could not be installed - probably running in HPC host or Regsvr32.exe"); } } // Register COM Server Types immediately ComServer.RegisterComClassTypes(comClassTypes); Logger.Initialization.Verbose("{0} - End Initialize", Name); }
// Only called for the Root DnaLibrary. internal void AutoOpen() { SynchronizationManager.Install(true); if (ExcelDnaUtil.GetApplicationNotProtectedNoThrow() != null) { // Proceed without undue delay AutoOpenImpl(); } else { // Some possibilities that get us here: // * Can't get Application object at all - first time we're trying is here, no workbook open and hence C API is needed but not available // * Excel is shutting down (would have abandoned in the past, now we keep re-trying) // We defer the rest of the load until we have an Application object... ExcelAsyncUtil.QueueAsMacro(AutoOpenImpl); } }
// Initialization - must be called from a macro context (e.g. AutoOpen) // For now only installs the syncmanager. public static void Initialize() { SynchronizationManager.Install(); }