Beispiel #1
0
        /// <summary>
        /// 直接生成某个命令,并即刻执行。
        /// </summary>
        /// <param name="meta"></param>
        /// <param name="cmdArg"></param>
        /// <returns></returns>
        public static bool TryExecuteCommand(WPFCommand meta, object cmdArg)
        {
            if (meta == null) throw new ArgumentNullException("cmdInfo");

            var cmd = CreateCommand(meta, cmdArg);

            return cmd.TryExecute();
        }
Beispiel #2
0
        internal void Config(WPFCommand cmd)
        {
            if (Label != null)
            {
                cmd.HasLabel(Label);
            }

            if (IsVisible != null) { cmd.IsVisible = IsVisible.Value; }
        }
Beispiel #3
0
        /// <summary>
        /// 使用元数据中指定的分组算法,将命令进行分组。
        /// </summary>
        /// <param name="cmd"></param>
        private void AddCommandIntoGroup(WPFCommand cmd)
        {
            var algorithmType = cmd.GroupAlgorithmType ?? typeof(DefaultAlgorithm);

            var algorithm = Activator.CreateInstance(algorithmType) as GroupAlgorithm;
            algorithm.Context = this.Context;
            algorithm.FinalGroups = this._tmpGroups;
            algorithm.GroupCommand(cmd);
        }
Beispiel #4
0
        protected override void GroupCommandCore(WPFCommand cmd)
        {
            var newGroup = new GeneratableCommandGroup(cmd.Name);
            var generator = new CompoundGenerator
            {
                CommandMetaGroup = newGroup,
                Context = this.Context
            };
            newGroup.Generator = generator;

            //是否生成到菜单中
            if (cmd.HasLocation(CommandLocation.Menu))
            {
                //为每一个命令都声明一个单独的组
                //构造并设置控件生成器
                generator.Add(new MenuItemGenerator
                {
                    CommandMetaGroup = newGroup,
                    Context = this.Context
                });
            }

            if (cmd.HasLocation(CommandLocation.Toolbar))
            {
                if (cmd.Hierarchy.Count != 1)
                {
                    generator.Add(new ButtonItemGenerator
                    {
                        CommandMetaGroup = newGroup,
                        Context = this.Context
                    });
                }
                else
                {
                    string groupName = cmd.Hierarchy[0];
                    newGroup = this.TryFindGroup(groupName);

                    if (newGroup == null)
                    {
                        newGroup = this.AddNewGroup(groupName);
                        newGroup.Generator = new SplitButtonGroupGenerator
                        {
                            CommandMetaGroup = newGroup,
                            Context = this.Context
                        };
                    }
                }
            }

            newGroup.AddCommand(cmd);

            FinalGroups[newGroup.Name] = newGroup;
        }
        protected override void GroupCommandCore(WPFCommand cmd)
        {
            if (cmd.Hierarchy.Count != 1) throw new ArgumentNullException("groupName");

            string groupName = cmd.Hierarchy[0];
            var group = this.TryFindGroup(groupName);

            if (group == null)
            {
                group = this.AddNewGroup(groupName);
                group.Generator = new SplitButtonGroupGenerator
                {
                    CommandMetaGroup = group,
                    Context = this.Context
                };
            }

            group.AddCommand(cmd);
        }
Beispiel #6
0
        //public static ClientCommand NewCommand(Type cmdType)
        //{
        //    var cmdInfo = UIModel.WPFCommands.Find(cmdType);
        //    return NewCommand(cmdInfo);
        //}
        //public static ClientCommand NewCommand(string name)
        //{
        //    var cmdInfo = UIModel.WPFCommands.Find(name);
        //    return NewCommand(cmdInfo);
        //}
        internal static ClientCommand CreateCommand(WPFCommand meta, object cmdArg)
        {
            var command = Activator.CreateInstance(meta.RuntimeType) as ClientCommand;

            command.Meta = meta;
            command.Parameter = cmdArg;
            command.Label = meta.Label.Translate();

            //元数据中所有的扩展属性都会拷贝到 ClientCommand 上。
            command.CopyExtendedProperties(meta);

            var gestures = InputGestureParser.Parse(meta.Gestures);
            command.UICommand = new UICommand(command, typeof(CommandRepository), gestures);

            command.NotifyCreated();

            OnCommandCreated(command);

            return command;
        }
Beispiel #7
0
        /// <summary>
        /// 记录执行错误的日志
        /// </summary>
        /// <param name="view"></param>
        /// <param name="ex"></param>
        private static void LogCommandFailed(WPFCommand cmd, LogicalView view, Exception ex)
        {
            if (DisableLog(cmd, view)) return;

            string title = "执行命令失败:" + cmd.Label;
            string coderContent = string.Format(
            @"类型名:{0}
            命令类型:{1}
            发生异常:{2}
            堆栈:{3}", view.EntityType.Name, cmd.Name, ex.Message, ex.StackTrace);

            LogAsync(title, coderContent, view);
        }
Beispiel #8
0
 private static bool DisableLog(WPFCommand cmd, LogicalView view)
 {
     return view is QueryLogicalView;
 }
Beispiel #9
0
        /// <summary>
        /// 记录日志
        /// </summary>
        /// <param name="view"></param>
        private static void LogCommandSuccess(WPFCommand cmd, LogicalView view)
        {
            if (DisableLog(cmd, view)) return;

            string title = "执行命令完成:" + cmd.Label;
            string coderContent = string.Format(
            @"类型名:{0}
            命令名称:{1}", view.EntityType.Name, cmd.Name);

            LogAsync(title, coderContent, view);
        }
Beispiel #10
0
        /// <summary>
        /// 为当前的命令元数据生成一个客户端运行时命令对象。
        /// </summary>
        /// <param name="groupGenerator"></param>
        /// <returns></returns>
        private static ClientCommand CreateItemCommand(WPFCommand commandMeta, object commandArg)
        {
            var command = CommandRepository.CreateCommand(commandMeta, commandArg);

            var view = commandArg as LogicalView;
            if (view != null)
            {
                view.Commands.Add(command);
            }

            return command;
        }
Beispiel #11
0
 /// <summary>
 /// 获取元数据对应的客户端运行时命令。
 /// 
 /// 一个元数据只会生成一个运行时命令。而一个运行时命令,则可以同时生成工具栏、菜单等多个位置的控件。
 /// </summary>
 /// <param name="meta"></param>
 /// <returns></returns>
 public ClientCommand GetClientCommand(WPFCommand meta)
 {
     return _clientCommands[meta];
 }
Beispiel #12
0
 /// <summary>
 /// 添加一个Command
 /// </summary>
 /// <param name="item"></param>
 public void AddCommand(WPFCommand item)
 {
     this.Commands.Add(item);
 }
Beispiel #13
0
 /// <summary>
 /// 此方法为Command生成一个可生成控件的组,并加入到 FinalGroups 中。
 /// </summary>
 /// <param name="cmd"></param>
 /// <returns></returns>
 protected abstract void GroupCommandCore(WPFCommand cmd);
Beispiel #14
0
 /// <summary>
 /// 调用此方法为Command生成一个可生成控件的组,并加入到ExistingGroups中
 /// </summary>
 /// <param name="cmd"></param>
 public void GroupCommand(WPFCommand cmd)
 {
     this.GroupCommandCore(cmd);
 }
Beispiel #15
0
        public void AddCommand(WPFCommand cmd, object commandArg = null)
        {
            if (commandArg == null)
            {
                var window = WorkspaceWindow.GetOuterWorkspaceWindow(this.InnerContent) as ModuleWorkspaceWindow;
                if (window == null) throw new ArgumentNullException("内部控件没有 WindowTemplate 时,必须提供 commandArg 参数。");
                commandArg = window.MainView;
            }

            var items = commandPanel.Items;
            items.Remove(btnConfirm);
            items.Remove(btnCancel);

            AutoUI.BlockUIFactory.AppendCommands(commandPanel, commandArg, cmd);

            //始终把 btnConfirm、btnCancel 放到最后。
            items.Add(btnConfirm);
            items.Add(btnCancel);

            //commandPanel.Style = RafyResources.Rafy_CommandsContainer_Style;

            //Button btn = new Button()
            //{
            //    Margin = new Thickness(10, 2, 20, 2),
            //};
            //commandPanel.Children.Insert(0, btn);
            //if (window != null)
            //{
            //    btn.CommandParameter = window.View;
            //}
            //else
            //    btn.CommandParameter = View;
            //ButtonCommand.SetCommand(btn, CommandRepository.NewCommand(commandName));
        }