Beispiel #1
0
        public void OnDeleteMethod()
        {
            var list = m_host.GetMethodsListInTemplate();
            var item = list.SelectedItem;

            if (item != null)
            {
                var method = new QuickMethod();
                m_currentModel.MethodList.Remove((QuickMethod)item);
                list.Items.Remove(item);
                SaveModel();
            }
        }
Beispiel #2
0
        public void OnCreateNewMethod()
        {
            var list   = m_host.GetMethodsListInTemplate();
            var item   = list.SelectedItem;
            var method = new QuickMethod();

            if (item != null)
            {
                m_currentModel.MethodList.Insert(list.SelectedIndex, method);
                list.Items.Insert(list.SelectedIndex, method);
            }
            else
            {
                m_currentModel.MethodList.Add(method);
                list.Items.Insert(list.Items.Count, new QuickMethod());
            }
            SaveModel();
        }
        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 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();
        }