private void AdjustPosition() { if (!m_isGlobalModel) { try { m_hostWindow.Left = (int)(QuickSafeReflection.Invoke(m_model.Left, m_comObject).Plus(QuickSafeReflection.Invoke(m_model.Width, m_comObject)) - 60); m_hostWindow.Top = (int)(QuickSafeReflection.Invoke(m_model.Top, m_comObject).Plus(0)); } catch { foreach (var name in m_model.ProgramName.Split(',')) { try { m_comObject = Marshal.GetActiveObject(name); m_hostWindow.Left = (int)(QuickSafeReflection.Invoke(m_model.Left, m_comObject).Plus(QuickSafeReflection.Invoke(m_model.Width, m_comObject)) - 60); m_hostWindow.Top = (int)(QuickSafeReflection.Invoke(m_model.Top, m_comObject).Plus(0)); break; } catch (Exception ex) { QuickVitality.UpdateVitality("error", m_model.ProgramName, "GetActiveObject error. " + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace); } } } } else { var commonObj = m_comObject as QuickCommonObject; if (m_comObject == null) { throw new Exception("公共对象并非CommonObject"); } else { m_hostWindow.Left = commonObj.GetWindowRect().Left + (commonObj.GetWindowRect().Right - commonObj.GetWindowRect().Left - m_hostWindow.Width) / 2; m_hostWindow.Top = commonObj.GetWindowRect().Top + (commonObj.GetWindowRect().Bottom - commonObj.GetWindowRect().Top - m_hostWindow.Height) / 2; } } }
private void InvokeCommand() { int idx = GetSelectedIndex(); var list = m_hostWindow.GetList(); if (idx == -1) { if (!list.HasItems) { return; } idx = 0; } QuickMethod method = m_availableMethods[idx]; String arguments = GetArgumentString(GetQueryText()); String realMethod = "invalid"; try { String[] args = arguments == null?QuickModel.GetArguments(method.MethodDefArgs) : QuickModel.GetArguments(arguments); if (method.GetPluginInterface() != null) { method.GetPluginInterface().Invoke(m_comObject, this); } else if (method.MethodParamRegex == "" || method.MethodParamRegex == "." || args.Length > 0) { //将参数塞进MethodScript中 if (method.MethodScript.Trim()[0] == '!') { //!表示对布尔值进行切换 realMethod = method.MethodScript.Trim().Substring(1); object value = QuickSafeReflection.Invoke(realMethod, m_comObject); if (value is bool) { QuickSafeReflection.Set(realMethod, !(bool)value, m_comObject); } } else if (method.MethodScript.Trim()[0] == '@') { String utilityMethod = null; //如果是@开头,表示调用Utilities中方法来赋值或将返回值传给方法中的{$1} //可能存在!在引号内的风险 if (method.MethodScript.Contains("!")) { utilityMethod = method.MethodScript.Substring(1, method.MethodScript.IndexOf('!') - 1); utilityMethod = ReplaceAruguments(utilityMethod, args); realMethod = method.MethodScript.Substring(method.MethodScript.IndexOf('!') + 1); if (method.MethodScript.Trim()[method.MethodScript.Length - 1] != ')') { QuickSafeReflection.Set(realMethod, QuickSafeReflection.Invoke(utilityMethod, m_utilities), m_comObject); } else { realMethod = ReplaceAruguments(realMethod, (String[])QuickSafeReflection.Invoke(utilityMethod, m_utilities)); QuickSafeReflection.Invoke(realMethod, m_comObject); } } else { utilityMethod = method.MethodScript.Substring(1); realMethod = ReplaceAruguments(utilityMethod, args); QuickSafeReflection.Invoke(realMethod, m_utilities); } } else if (method.MethodScript.Trim()[method.MethodScript.Length - 1] != ')') { //如果不以)结尾,表示是一个赋值方法 realMethod = method.MethodScript; QuickSafeReflection.Set(realMethod, args[0], m_comObject); } else { realMethod = ReplaceAruguments(method.MethodScript, args); QuickSafeReflection.Invoke(realMethod, m_comObject); } } QuickVitality.UpdateVitality("invoke", m_model.ProgramName, realMethod); } catch (Exception ex) { //在此插入异常 QuickVitality.UpdateVitality("error", m_model.ProgramName, "invoking: " + realMethod + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace); } JobDone(); }