Пример #1
0
        public IMacroResult Run(object appDisp, string macroPath, string moduleName,
                                string subName, int opts, IMacroParameter param, bool cacheReg = false)
        {
            var app = CastApplication(appDisp);

            var macro = app.OpenMacro(macroPath);

            GetMacroParametersManager(true, out RotRegister newReg, out IMacroParameterManager macroParamsMgr);

            if (newReg != null)
            {
                if (cacheReg)
                {
                    if (m_Register != null)
                    {
                        try
                        {
                            m_Register.Dispose();
                        }
                        catch (Exception ex)
                        {
                            m_Logger.Log(ex);
                        }
                    }

                    m_Register = newReg;
                }
            }

            try
            {
                var sessionId = CreateMacroSessionId(app, macro);
                macroParamsMgr.PushParameter(sessionId, param);

                try
                {
                    macro.Run(new MacroEntryPoint(moduleName, subName), (MacroRunOptions_e)opts);
                }
                finally
                {
                    macroParamsMgr.TryRemoveParameter(sessionId, param);
                }
            }
            finally
            {
                if (newReg != null && !cacheReg)
                {
                    newReg.Dispose();
                }
            }

            return(param.Result);
        }
Пример #2
0
        private void GetMacroParametersManager(bool createIfNotExist, out RotRegister newRegister, out IMacroParameterManager macroParamsMgr)
        {
            macroParamsMgr = RotHelper.TryGetComObjectByMonikerName <IMacroParameterManager>(MACRO_RUNNER_MONIKER_NAME);

            if (macroParamsMgr == null)
            {
                if (createIfNotExist)
                {
                    macroParamsMgr = new MacroParameterManager();
                    newRegister    = new RotRegister(macroParamsMgr, MACRO_RUNNER_MONIKER_NAME);
                }
                else
                {
                    throw new COMException("Macro parameters manager is not registered");
                }
            }
            else
            {
                newRegister = null;
            }
        }