Initialize() public method

public Initialize ( ) : void
return void
        // Must be called on the main Excel thread
        public void Initialize()
        {
            Debug.Assert(Thread.CurrentThread.ManagedThreadId == 1);
            Logger.Provider.Info("ExcelDnaIntelliSenseProvider.Initialize");

            _xmlProvider.Initialize();

            lock (_xllRegistrationInfos)
            {
                Logger.Provider.Info("ExcelDnaIntelliSenseProvider.Initialize - inside lock");
                foreach (var xllPath in GetLoadedXllPaths())
                {
                    if (!_xllRegistrationInfos.ContainsKey(xllPath))
                    {
                        Logger.Provider.Verbose(string.Format("ExcelDnaIntelliSenseProvider.Initialize: Adding XllRegistrationInfo for {0}", xllPath));
                        XllRegistrationInfo regInfo = new XllRegistrationInfo(xllPath);
                        _xllRegistrationInfos[xllPath] = regInfo;

                        _xmlProvider.RegisterXmlFunctionInfo(GetXmlPath(xllPath));

                        regInfo.Refresh();
                    }
                }
            }
            Logger.Provider.Info("ExcelDnaIntelliSenseProvider.Initialize - after lock");
        }
        public void Initialize()
        {
            Logger.Provider.Info("WorkbookIntelliSenseProvider.Initialize");
            _xmlProvider.Initialize();

            // The events are just to keep track of the set of open workbooks,
            var xlApp = (Application)ExcelDnaUtil.Application;

            xlApp.WorkbookOpen           += Excel_WorkbookOpen;
            xlApp.WorkbookBeforeClose    += Excel_WorkbookBeforeClose;
            xlApp.WorkbookAddinInstall   += Excel_WorkbookAddinInstall;
            xlApp.WorkbookAddinUninstall += Excel_WorkbookAddinUninstall;

            lock (_workbookRegistrationInfos)
            {
                foreach (Workbook wb in xlApp.Workbooks)
                {
                    var name = wb.Name;
                    if (!_workbookRegistrationInfos.ContainsKey(name))
                    {
                        WorkbookRegistrationInfo regInfo = new WorkbookRegistrationInfo(name);
                        _workbookRegistrationInfos[name] = regInfo;

                        regInfo.Refresh();

                        RegisterWithXmlProvider(wb);
                    }
                }
                if (ExcelDnaUtil.ExcelVersion >= 14.0)
                {
                    foreach (AddIn addIn in xlApp.AddIns2)
                    {
                        if (addIn.IsOpen && Path.GetExtension(addIn.FullName) != ".xll")
                        {
                            // Can it be "Open" and not be loaded?
                            var      name = addIn.Name;
                            Workbook wbAddIn;
                            try
                            {
                                // TODO: Log
                                wbAddIn = xlApp.Workbooks[name];
                            }
                            catch
                            {
                                // TODO: Log
                                continue;
                            }

                            WorkbookRegistrationInfo regInfo = new WorkbookRegistrationInfo(name);
                            _workbookRegistrationInfos[name] = regInfo;

                            regInfo.Refresh();

                            RegisterWithXmlProvider(wbAddIn);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public void Initialize()
        {
            Logger.Provider.Info("WorkbookIntelliSenseProvider.Initialize");
            _xmlProvider.Initialize();

            // The events are just to keep track of the set of open workbooks,
            var xlApp = (Application)ExcelDnaUtil.Application;

            xlApp.WorkbookOpen           += Excel_WorkbookOpen;
            xlApp.WorkbookBeforeClose    += Excel_WorkbookBeforeClose;
            xlApp.WorkbookAddinInstall   += Excel_WorkbookAddinInstall;
            xlApp.WorkbookAddinUninstall += Excel_WorkbookAddinUninstall;
            Logger.Provider.Verbose("WorkbookIntelliSenseProvider.Initialize - Installed event listeners");

            lock (_workbookRegistrationInfos)
            {
                Logger.Provider.Verbose("WorkbookIntelliSenseProvider.Initialize - Starting Workbooks loop");
                foreach (Workbook wb in xlApp.Workbooks)
                {
                    var name = wb.Name;
                    Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.Initialize - Adding registration for {name}");
                    if (!_workbookRegistrationInfos.ContainsKey(name))
                    {
                        WorkbookRegistrationInfo regInfo = new WorkbookRegistrationInfo(name);
                        _workbookRegistrationInfos[name] = regInfo;

                        regInfo.Refresh();

                        RegisterWithXmlProvider(wb);
                    }
                }

                // NOTE: This access to AddIns2 might have caused long load delays
                //if (ExcelDnaUtil.ExcelVersion >= 14.0)
                //{
                //    foreach (AddIn addIn in xlApp.AddIns2)
                //    {
                //        if (addIn.IsOpen && Path.GetExtension(addIn.FullName) != ".xll")
                //        {
                //            // Can it be "Open" and not be loaded?
                //            var name = addIn.Name;
                //            Workbook wbAddIn;
                //            try
                //            {
                //                // TODO: Log
                //                wbAddIn = xlApp.Workbooks[name];
                //            }
                //            catch
                //            {
                //                // TODO: Log
                //                continue;
                //            }

                //            WorkbookRegistrationInfo regInfo = new WorkbookRegistrationInfo(name);
                //            _workbookRegistrationInfos[name] = regInfo;

                //            regInfo.Refresh();

                //            RegisterWithXmlProvider(wbAddIn);
                //        }
                //    }
                //}

                Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.Initialize - Checking Add-Ins");

                var loadedAddIns = Integration.XlCall.Excel(Integration.XlCall.xlfDocuments, 2) as object[, ];
                if (loadedAddIns == null)
                {
                    // This is normal if there are none
                    Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.Initialize - DOCUMENTS(2) returned null");
                    return;
                }
                for (int i = 0; i < loadedAddIns.GetLength(1); i++)
                {
                    var addInName = loadedAddIns[0, i] as string;
                    Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.Initialize - Checking Add-In {addInName}");
                    if (addInName != null && Path.GetExtension(addInName) != ".xll")    // We don't actually expect the .xll add-ins here - and they're taken care of elsewhere
                    {
                        // Can it be "Open" and not be loaded?
                        var      name = addInName;
                        Workbook wbAddIn;
                        try
                        {
                            // TODO: Log
                            wbAddIn = xlApp.Workbooks[name];
                        }
                        catch
                        {
                            // TODO: Log
                            continue;
                        }

                        Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.Initialize - Adding registration for add-in {name}");

                        WorkbookRegistrationInfo regInfo = new WorkbookRegistrationInfo(name);
                        _workbookRegistrationInfos[name] = regInfo;

                        regInfo.Refresh();

                        RegisterWithXmlProvider(wbAddIn);
                    }
                }
            }
        }
 public void Initialize()
 {
     Logger.Provider.Info("WorkbookIntelliSenseProvider.Initialize");
     _xmlProvider.Initialize();
     ExcelAsyncUtil.QueueAsMacro(OnInitialize);
 }