ExcelDna.Integration.DnaLibrary.Initialize C# (CSharp) Method

Initialize() private method

private Initialize ( ) : void
return void
        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.
            _exportedAssemblies = GetAssemblies(dnaResolveRoot);
            AssemblyLoader.ProcessAssemblies(_exportedAssemblies, _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();  // TODO: Careful here!?

            // Register COM Server Types immediately
            ComServer.RegisterComClassTypes(comClassTypes);
        }

Usage Example

Example #1
0
        internal static void InitializeRootLibrary(string xllPath)
        {
            // Loads the primary .dna library
            // Load sequence is:
            // 1. Look for a packed .dna file named "__MAIN__" in the .xll.
            // 2. Look for the .dna file in the same directory as the .xll file, with the same name and extension .dna.

            // CAREFUL: Sequence here is fragile - this is the first place where we start logging
            _XllPath         = xllPath;
            _xllPathPathInfo = new FileInfo(xllPath);
            Logging.LogDisplay.CreateInstance();
            Logger.Initialization.Verbose("Enter DnaLibrary.InitializeRootLibrary");
            byte[] dnaBytes = ExcelIntegration.GetDnaFileBytes("__MAIN__");
            if (dnaBytes != null)
            {
                Logger.Initialization.Verbose("Got Dna file from resources.");
                string pathResolveRoot = Path.GetDirectoryName(DnaLibrary.XllPath);
                rootLibrary = LoadFrom(dnaBytes, pathResolveRoot);
                // ... would have displayed error and returned null if there was an error.
            }
            else
            {
                Logger.Initialization.Verbose("No Dna file in resources - looking for file.");
                // No packed .dna file found - load from a .dna file.
                string dnaFileName = Path.ChangeExtension(XllPath, ".dna");
                rootLibrary = LoadFrom(dnaFileName);
                // ... would have displayed error and returned null if there was an error.
            }

            // If there have been problems, ensure that there is at lease some current library.
            if (rootLibrary == null)
            {
                Logger.Initialization.Error("No Dna Library found.");
                rootLibrary = new DnaLibrary();
            }

            rootLibrary.Initialize();
            Logger.Initialization.Verbose("Exit DnaLibrary.Initialize");
        }
All Usage Examples Of ExcelDna.Integration.DnaLibrary::Initialize