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

InitializeRootLibrary() static private method

static private InitializeRootLibrary ( string xllPath ) : void
xllPath string
return void
        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.

            Debug.WriteLine("Enter DnaLibrary.InitializeRootLibrary");
            _XllPath = xllPath;
            Logging.LogDisplay.CreateInstance();
            byte[] dnaBytes = ExcelIntegration.GetDnaFileBytes("__MAIN__");
            if (dnaBytes != null)
            {
                Debug.WriteLine("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
            {
                Debug.WriteLine("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)
            {
                Debug.WriteLine("No Dna Library found.");
                rootLibrary = new DnaLibrary();
            }

            rootLibrary.Initialize();
            Debug.WriteLine("Exit DnaLibrary.Initialize");
        }

Usage Example

Example #1
0
 // Called via Reflection from Loader
 internal static void Initialize(string xllPath)
 {
     ExcelDnaUtil.Initialize();              // Set up window handle
     Logging.TraceLogger.Initialize();
     DnaLibrary.InitializeRootLibrary(xllPath);
 }