public QuickMainWindowHandler(object comObject, QuickModel model, QuickContext context, IntPtr hostPtr)
 {
     m_comObject         = comObject;
     m_model             = model;
     m_hostPtr           = hostPtr;
     m_context           = context;
     m_utilities         = new Utilities(comObject);
     m_defaultIcon       = null;
     m_bitmapSourceCache = null;
     m_isGlobalModel     = true;
     m_locked            = false;
 }
Beispiel #2
0
        public void OnTemplateSelected(int index)
        {
            if (index < 0)
            {
                return;
            }

            var    item        = m_host.GetTemplateListInTemplate().Items[index];
            string filename    = ((FrameworkElement)item).Tag.ToString();
            var    methodsList = m_host.GetMethodsListInTemplate();

            m_currentModel = QuickModel.GetModel(filename);
            methodsList.Items.Clear();
            foreach (var i in m_currentModel.MethodList)
            {
                methodsList.Items.Add(i);
            }
        }
 public QuickMainWindowHandler(object comObject, QuickModel model, QuickContext context, IntPtr hostPtr, bool isGlobalModel, Process currentProcess)
     : this(comObject, model, context, hostPtr)
 {
     m_isGlobalModel = isGlobalModel;
     if (!isGlobalModel)
     {
         try
         {
             var icon = Icon.ExtractAssociatedIcon(currentProcess.MainModule.FileName);     //获得主线程图标
             if (icon != null)
             {
                 SetDefaultIcon(icon);
             }
         }
         catch
         {
         }
     }
 }
        public void ReplaceMethods(IQuickPluginMethod[] methods)
        {
            QuickModel model = new QuickModel(m_model);

            foreach (var m in methods)
            {
                QuickMethod qm = new QuickMethod();
                qm.Application       = m.AvailableApplicationName();
                qm.MethodDefArgs     = " ";
                qm.MethodParamRegex  = ".";    //一定可以接受参数
                qm.MethodDescription = m.GetDescription(this);
                qm.MethodName        = m.GetName();
                qm.SetAdditionMethod(m);
                model.MethodList.Add(qm);
            }
            m_context.ReplaceSubModel(model);
            FilterList(GetQueryText());
            ResetPage();
            RefreshList();
        }
        private void FilterList(String queryText)
        {
            // 将符合条件的选项筛选进available list
            m_availableMethods = new List <QuickMethod>();
            var        subModel     = m_context.GetSubModel();
            bool       isSubModel   = (subModel != null);
            QuickModel currentModel = subModel ?? m_model;

            foreach (QuickMethod methodItem in currentModel.MethodList)
            {
                string query      = queryText;
                bool   hasParams  = false;
                Regex  reg_params = GetArgumentRegex(methodItem.MethodParamRegex);
                Match  m          = reg_params.Match(query);

                if (m.Success)
                {
                    query     = reg_params.Replace(query, "").Trim(); //表示取出参数后的字符串
                    hasParams = true;
                }
                else
                {
                    hasParams = false;
                }

                if (query.Trim() == "" || methodItem.MethodName.Replace(" ", "").HasString(query) || isSubModel)
                {
                    if (hasParams)
                    {
                        //滤过不含参数的指令。含有参数的方法,其正则表达式不为空
                        if (methodItem.MethodParamRegex == "")
                        {
                            continue;
                        }
                    }
                    m_availableMethods.Add(methodItem);
                }
            }
        }
        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();
        }