예제 #1
0
        public static void ActiveModelContent(this IDockableManager manager, object model)
        {
            var view = manager.ViewDictionary.FirstOrDefault(d => d.Model == model);

            if (view == null)
            {
                return;
            }

            manager.ActiveThisContent(view.View);
        }
예제 #2
0
        public override bool Init()
        {
            base.Init();
            dockableManager    = MainFrmUI as IDockableManager;
            dataManager        = MainFrmUI.PluginDictionary["数据管理"] as IDataManager;
            propertyGridWindow = MainFrmUI.PluginDictionary["属性配置器"] as XFrmWorkPropertyGrid;

            var aboutAuthor = new BindingAction("联系和打赏作者", d =>
            {
                var view       = PluginProvider.GetObjectInstance <ICustomView>("关于作者");
                var window     = new Window();
                window.Title   = "关于作者";
                window.Content = view;
                window.ShowDialog();
            });
            var helplink = new BindingAction("使用文档", d =>
            {
                var url = "https://github.com/ferventdesert/Hawk/wiki";
                System.Diagnostics.Process.Start(url);
            });

            var feedback = new BindingAction("反馈问题", d =>
            {
                var url = "https://github.com/ferventdesert/Hawk/issues";
                System.Diagnostics.Process.Start(url);
            });


            var giveme = new BindingAction("捐赠", d =>
            {
                var url = "https://github.com/ferventdesert/Hawk/wiki/8.%E5%85%B3%E4%BA%8E%E4%BD%9C%E8%80%85";
                System.Diagnostics.Process.Start(url);
            });
            var blog = new BindingAction("博客", d =>
            {
                var url = "http://www.cnblogs.com/buptzym/";
                System.Diagnostics.Process.Start(url);
            });
            var pluginCommands = new BindingAction("帮助");

            pluginCommands.ChildActions.Add(helplink);
            pluginCommands.ChildActions.Add(aboutAuthor);
            pluginCommands.ChildActions.Add(feedback);
            pluginCommands.ChildActions.Add(giveme);
            pluginCommands.ChildActions.Add(blog);
            MainFrmUI.CommandCollection.Add(pluginCommands);
            ProcessCollection = new ObservableCollection <IDataProcess>();


            CurrentProcessTasks = new ObservableCollection <TaskBase>();
            BindingCommands     = new BindingAction("运行");
            var sysCommand = new BindingAction();

            sysCommand.ChildActions.Add(
                new Command(
                    "清空任务列表",
                    obj =>
            {
                if (MessageBox.Show("确定清空所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    ProcessCollection.RemoveElementsNoReturn(d => true, RemoveOperation);
                }
            }, obj => true,
                    "clear"));

            sysCommand.ChildActions.Add(
                new Command(
                    "保存全部任务",
                    obj =>
            {
                if (MessageBox.Show("确定保存所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    SaveCurrentTasks();
                }
            }, obj => true,
                    "clear"));

            BindingCommands.ChildActions.Add(sysCommand);

            var taskAction1 = new BindingAction();


            taskAction1.ChildActions.Add(new Command("加载本任务",
                                                     obj => (obj as ProcessTask).Load(true),
                                                     obj => obj is ProcessTask, "download"));


            taskAction1.ChildActions.Add(new Command("删除任务",
                                                     obj => CurrentProject.Tasks.Remove(obj as ProcessTask),
                                                     obj => obj is ProcessTask));
            taskAction1.ChildActions.Add(new Command("执行任务脚本",
                                                     (obj => (obj as ProcessTask).EvalScript()),
                                                     obj => (obj is ProcessTask) && CurrentProcessCollections.FirstOrDefault(d => d.Name == (obj as ProcessTask).Name) != null));

            BindingCommands.ChildActions.Add(taskAction1);
            var taskAction2 = new BindingAction("任务列表2");

            taskAction2.ChildActions.Add(new Command("开始任务",
                                                     obj =>
            {
                var task = obj as TaskBase;
                task.Start();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null && task.IsStart == false);
            }, "download"));

            taskAction2.ChildActions.Add(new Command("取消任务",
                                                     obj =>
            {
                var task = obj as TaskBase;
                if (task.IsStart)
                {
                    task.Cancel();
                }

                task.Remove();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null);
            }, "download"));


            var taskListAction = new BindingAction("任务列表命令");

            taskListAction.ChildActions.Add(new Command("全选",
                                                        d => CurrentProcessTasks.Execute(d2 => d2.IsSelected = true), null, "check"));

            taskListAction.ChildActions.Add(new Command("反选",
                                                        d => CurrentProcessTasks.Execute(d2 => d2.IsSelected = !d2.IsSelected), null, "redo"));

            taskListAction.ChildActions.Add(new Command("暂停",
                                                        d => CurrentProcessTasks.Where(d2 => d2.IsSelected).Execute(d2 => d2.IsPause = true), null, "pause"));
            taskListAction.ChildActions.Add(new Command("恢复",
                                                        d => CurrentProcessTasks.Where(d2 => d2.IsSelected).Execute(d2 => d2.IsPause = false), null, "play"));

            taskListAction.ChildActions.Add(new Command("取消",
                                                        d => CurrentProcessTasks.RemoveElementsNoReturn(d2 => d2.IsSelected, d2 => d2.Cancel()), null, "delete"));

            BindingCommands.ChildActions.Add(taskListAction);

            BindingCommands.ChildActions.Add(taskListAction);

            var processAction = new BindingAction();


            processAction.ChildActions.Add(new Command("配置", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                ShowConfigUI(process);
            }, obj => true, "settings"));
            processAction.ChildActions.Add(new Command("查看视图", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                (MainFrmUI as IDockableManager).ActiveModelContent(process);
            }, obj => true, "tv"));
            processAction.ChildActions.Add(new Command("拷贝", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                ProcessCollection.Remove(obj as IDataProcess);
                var item = GetOneInstance(process.TypeName, true, false);
                (process as IDictionarySerializable).DictCopyTo(item as IDictionarySerializable);
                item.Init();
                ProcessCollection.Add(item);
            }, obj => true, "new"));

            processAction.ChildActions.Add(new Command("移除", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }

                RemoveOperation(process);
                ProcessCollection.Remove(process);
                ShowConfigUI(null);
            }, obj => true, "delete"));

            processAction.ChildActions.Add(new Command("保存任务", obj =>
            {
                var process = obj as IDataProcess;
                if (process == null)
                {
                    return;
                }
                SaveTask(process, true);
            }, obj => obj is IDictionarySerializable));
            processAction.ChildActions.Add(new Command("显示并配置", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                var view = (MainFrmUI as IDockableManager).ViewDictionary.FirstOrDefault(d => d.Model == process);
                if (view == null)
                {
                    LoadProcessView(process);
                }
                (MainFrmUI as IDockableManager).ActiveModelContent(process);
                ShowConfigUI(process);
            }, obj => true, "delete"));


            BindingCommands.ChildActions.Add(processAction);
            BindingCommands.ChildActions.Add(taskAction2);
            var attributeactions = new BindingAction("模块");

            attributeactions.ChildActions.Add(new Command("添加", obj =>
            {
                var attr = obj as XFrmWorkAttribute;
                if (attr == null)
                {
                    return;
                }

                var process = GetOneInstance(attr.MyType.Name, newOne: true, isAddUI: true);
                process.Init();
            }));
            BindingCommands.ChildActions.Add(attributeactions);

            var config = ConfigFile.GetConfig <DataMiningConfig>();

            if (config.Projects.Any())
            {
                var project = config.Projects.FirstOrDefault();
                if (project != null)
                {
                    ControlExtended.SafeInvoke(() =>
                    {
                        currentProject = ProjectItem.LoadProject(project.SavePath);
                        NotifyCurrentProjectChanged();
                    }, LogType.Info, "加载默认工程");
                }
            }

            if (MainDescription.IsUIForm)
            {
                ProgramNameFilterView =
                    new ListCollectionView(PluginProvider.GetPluginCollection(typeof(IDataProcess)).ToList());

                ProgramNameFilterView.GroupDescriptions.Clear();
                ProgramNameFilterView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
                var taskView    = PluginProvider.GetObjectInstance <ICustomView>("任务管理视图");
                var userControl = taskView as UserControl;
                if (userControl != null)
                {
                    userControl.DataContext = this;
                    ((INotifyCollectionChanged)CurrentProcessTasks).CollectionChanged += (s, e) =>
                    {
                        ControlExtended.UIInvoke(() => {
                            if (e.Action == NotifyCollectionChangedAction.Add)
                            {
                                dockableManager.ActiveThisContent("任务管理视图");
                            }
                        });
                    }
                    ;
                    dockableManager.AddDockAbleContent(taskView.FrmState, this, taskView, "任务管理视图");
                }
                ProcessCollectionView = new ListCollectionView(ProcessCollection);
                ProcessCollectionView.GroupDescriptions.Clear();
                ProcessCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));


                ProjectTaskList = new ListCollectionView(CurrentProject.Tasks);
                ProjectTaskList.GroupDescriptions.Clear();

                ProjectTaskList.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));


                OnPropertyChanged("ProjectTaskList");
                ProjectTaskList = new ListCollectionView(CurrentProject.Tasks);
                ProjectTaskList.GroupDescriptions.Clear();

                ProjectTaskList.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));
                OnPropertyChanged("ProjectTaskList");
            }

            var file = MainFrmUI.CommandCollection.FirstOrDefault(d => d.Text == "文件");

            file.ChildActions.Add(new BindingAction("新建项目", obj => CreateNewProject()));
            file.ChildActions.Add(new BindingAction("加载项目", obj => LoadProject()));
            file.ChildActions.Add(new BindingAction("保存项目", obj => SaveCurrentProject()));
            file.ChildActions.Add(new BindingAction("项目另存为", obj => SaveCurrentProject(false)));
            return(true);
        }
예제 #3
0
        public override bool Init()
        {
            base.Init();
            dockableManager    = MainFrmUI as IDockableManager;
            dataManager        = MainFrmUI.PluginDictionary["数据管理"] as IDataManager;
            propertyGridWindow = MainFrmUI.PluginDictionary["属性配置器"] as XFrmWorkPropertyGrid;


            ProcessCollection = new ObservableCollection <IDataProcess>();


            CurrentProcessTasks = new ObservableCollection <TaskBase>();
            BindingCommands     = new BindingAction("运行");
            var sysCommand = new BindingAction();

            sysCommand.ChildActions.Add(
                new Command(
                    "清空模块列表",
                    obj =>
            {
                if (MessageBox.Show("确定清空所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    ProcessCollection.RemoveElementsNoReturn(d => true, RemoveOperation);
                }
            }, obj => true,
                    "clear"));

            sysCommand.ChildActions.Add(
                new Command(
                    "保存全部模块",
                    obj =>
            {
                if (MessageBox.Show("确定保存所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    foreach (var process in CurrentProcessCollections)
                    {
                        SaveTask(process, false);
                    }
                    CurrentProject.Save();
                }
            }, obj => true,
                    "clear"));

            BindingCommands.ChildActions.Add(sysCommand);

            var taskAction1 = new BindingAction();


            taskAction1.ChildActions.Add(new Command("加载本任务",
                                                     obj => (obj as ProcessTask).Load(true),
                                                     obj => obj is ProcessTask, "download"));


            taskAction1.ChildActions.Add(new Command("删除任务",
                                                     obj => CurrentProject.Tasks.Remove(obj as ProcessTask),
                                                     obj => obj is ProcessTask));
            taskAction1.ChildActions.Add(new Command("执行任务脚本",
                                                     (obj => (obj as ProcessTask).EvalScript()),
                                                     obj => (obj is ProcessTask) && CurrentProcessCollections.FirstOrDefault(d => d.Name == (obj as ProcessTask).Name) != null));

            BindingCommands.ChildActions.Add(taskAction1);
            var taskAction2 = new BindingAction("任务列表2");

            taskAction2.ChildActions.Add(new Command("开始任务",
                                                     obj =>
            {
                var task = obj as TaskBase;
                task.Start();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null && task.IsStart == false);
            }, "download"));

            taskAction2.ChildActions.Add(new Command("取消任务",
                                                     obj =>
            {
                var task = obj as TaskBase;
                if (task.IsStart)
                {
                    task.Cancel();
                }

                task.Remove();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null);
            }, "download"));


            var taskListAction = new BindingAction("任务列表命令");


            BindingCommands.ChildActions.Add(taskListAction);

            BindingCommands.ChildActions.Add(taskListAction);

            var processAction = new BindingAction();


            processAction.ChildActions.Add(new Command("配置", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                ShowConfigUI(process);
            }, obj => true, "settings"));
            processAction.ChildActions.Add(new Command("查看视图", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                (MainFrmUI as IDockableManager).ActiveModelContent(process);
            }, obj => true, "tv"));
            processAction.ChildActions.Add(new Command("拷贝", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                ProcessCollection.Remove(obj as IDataProcess);
                var item = GetOneInstance(process.TypeName, true, false);
                (process as IDictionarySerializable).DictCopyTo(item as IDictionarySerializable);
                item.Init();
                ProcessCollection.Add(item);
            }, obj => true, "new"));

            processAction.ChildActions.Add(new Command("移除", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }

                RemoveOperation(process);
                ProcessCollection.Remove(process);
                ShowConfigUI(null);
            }, obj => true, "delete"));

            processAction.ChildActions.Add(new Command("保存任务", obj =>
            {
                var process = obj as IDataProcess;
                if (process == null)
                {
                    return;
                }
                SaveTask(process, true);
            }, obj => obj is IDictionarySerializable));
            processAction.ChildActions.Add(new Command("显示并配置", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                var view = (MainFrmUI as IDockableManager).ViewDictionary.FirstOrDefault(d => d.Model == process);
                if (view == null)
                {
                    LoadProcessView(process);
                }
                (MainFrmUI as IDockableManager).ActiveModelContent(process);
                ShowConfigUI(process);
            }, obj => true, "delete"));


            BindingCommands.ChildActions.Add(processAction);
            BindingCommands.ChildActions.Add(taskAction2);
            var attributeactions = new BindingAction("模块");

            attributeactions.ChildActions.Add(new Command("添加", obj =>
            {
                var attr = obj as XFrmWorkAttribute;
                if (attr == null)
                {
                    return;
                }

                var process = GetOneInstance(attr.MyType.Name, newOne: true, isAddUI: true);
                process.Init();
            }));
            BindingCommands.ChildActions.Add(attributeactions);

            var config = ConfigFile.GetConfig <DataMiningConfig>();

            if (config.Projects.Any())
            {
                var project = config.Projects.FirstOrDefault();
                if (project != null)
                {
                    ControlExtended.SafeInvoke(() =>
                    {
                        currentProject = ProjectItem.LoadProject(project.SavePath);
                        NotifyCurrentProjectChanged();
                    }, LogType.Info, "加载默认工程");
                }
            }

            if (MainDescription.IsUIForm)
            {
                ProgramNameFilterView =
                    new ListCollectionView(PluginProvider.GetPluginCollection(typeof(IDataProcess)).ToList());

                ProgramNameFilterView.GroupDescriptions.Clear();
                ProgramNameFilterView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
                var taskView    = PluginProvider.GetObjectInstance <ICustomView>("任务管理视图");
                var userControl = taskView as UserControl;
                if (userControl != null)
                {
                    userControl.DataContext = this;
                    ((INotifyCollectionChanged)CurrentProcessTasks).CollectionChanged += (s, e) =>
                    {
                        ControlExtended.UIInvoke(() => {
                            if (e.Action == NotifyCollectionChangedAction.Add)
                            {
                                dockableManager.ActiveThisContent("任务管理视图");
                            }
                        });
                    }
                    ;
                    dockableManager.AddDockAbleContent(taskView.FrmState, this, taskView, "任务管理视图");
                }
                ProcessCollectionView = new ListCollectionView(ProcessCollection);
                ProcessCollectionView.GroupDescriptions.Clear();
                ProcessCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));


                ProjectTaskList = new ListCollectionView(CurrentProject.Tasks);
                ProjectTaskList.GroupDescriptions.Clear();

                ProjectTaskList.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));


                OnPropertyChanged("ProjectTaskList");
                ProjectTaskList = new ListCollectionView(CurrentProject.Tasks);
                ProjectTaskList.GroupDescriptions.Clear();

                ProjectTaskList.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));
                OnPropertyChanged("ProjectTaskList");
            }

            var file = MainFrmUI.CommandCollection.FirstOrDefault(d => d.Text == "文件");

            file.ChildActions.Add(new BindingAction("新建项目", obj => CreateNewProject()));
            file.ChildActions.Add(new BindingAction("加载项目", obj => LoadProject()));
            file.ChildActions.Add(new BindingAction("保存项目", obj => SaveCurrentProject()));
            file.ChildActions.Add(new BindingAction("项目另存为", obj => SaveCurrentProject(false)));

            return(true);
        }
예제 #4
0
        public override bool Init()
        {
            base.Init();
            GitHubApi           = new GitHubAPI();
            MarketProjects      = new ObservableCollection <ProjectItem>();
            dockableManager     = MainFrmUI as IDockableManager;
            dataManager         = MainFrmUI.PluginDictionary["DataManager"] as IDataManager;
            ProcessCollection   = new ObservableCollection <IDataProcess>();
            CurrentProcessTasks = new ObservableCollection <TaskBase>();
            if (!MainDescription.IsUIForm)
            {
                return(true);
            }
            this.datatTimer = new DispatcherTimer();
            var aboutAuthor = new BindingAction(GlobalHelper.Get("key_262"), d =>
            {
                var view       = PluginProvider.GetObjectInstance <ICustomView>(GlobalHelper.Get("key_263"));
                var window     = new Window();
                window.Title   = GlobalHelper.Get("key_263");
                window.Content = view;
                window.ShowDialog();
            })
            {
                Description = GlobalHelper.Get("key_264"), Icon = "information"
            };
            var mainlink = new BindingAction(GlobalHelper.Get("key_265"), d =>
            {
                var url = "https://github.com/ferventdesert/Hawk";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = GlobalHelper.Get("key_266"), Icon = "home"
            };
            var helplink = new BindingAction(GlobalHelper.Get("key_267"), d =>
            {
                var url = "https://ferventdesert.github.io/Hawk/";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = GlobalHelper.Get("key_268"), Icon = "question"
            };

            var feedback = new BindingAction(GlobalHelper.Get("key_269"), d =>
            {
                var url = "https://github.com/ferventdesert/Hawk/issues";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = GlobalHelper.Get("key_270"), Icon = "reply_people"
            };


            var giveme = new BindingAction(GlobalHelper.Get("key_271"), d =>
            {
                var url =
                    "https://github.com/ferventdesert/Hawk/wiki/8-%E5%85%B3%E4%BA%8E%E4%BD%9C%E8%80%85%E5%92%8C%E6%8D%90%E8%B5%A0";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = GlobalHelper.Get("key_272"), Icon = "smiley_happy"
            };
            var blog = new BindingAction(GlobalHelper.Get("key_273"), d =>
            {
                var url = "http://www.cnblogs.com/buptzym/";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = GlobalHelper.Get("key_274"), Icon = "tower"
            };

            var update = new BindingAction(GlobalHelper.Get("checkupgrade"),
                                           d =>
            {
                AutoUpdater.Start("https://raw.githubusercontent.com/ferventdesert/Hawk/global/Hawk/autoupdate.xml");
            })
            {
                Description = GlobalHelper.Get("checkupgrade"), Icon = "arrow_up"
            };
            var helpCommands = new BindingAction(GlobalHelper.Get("key_275"))
            {
                Icon = "magnify"
            };

            helpCommands.ChildActions.Add(mainlink);
            helpCommands.ChildActions.Add(helplink);

            helpCommands.ChildActions.Add(feedback);
            helpCommands.ChildActions.Add(giveme);
            helpCommands.ChildActions.Add(blog);
            helpCommands.ChildActions.Add(aboutAuthor);
            helpCommands.ChildActions.Add(update);
            MainFrmUI.CommandCollection.Add(helpCommands);

            var hierarchy    = (Hierarchy)LogManager.GetRepository();
            var debugCommand = new BindingAction(GlobalHelper.Get("debug"))
            {
                ChildActions = new ObservableCollection <ICommand>
                {
                    new BindingAction(GlobalHelper.Get("key_277"))
                    {
                        ChildActions =
                            new ObservableCollection <ICommand>
                        {
                            new BindingAction("Debug", obj => hierarchy.Root.Level = Level.Debug),
                            new BindingAction("Info", obj => hierarchy.Root.Level  = Level.Info),
                            new BindingAction("Warn", obj => hierarchy.Root.Level  = Level.Warn),
                            new BindingAction("Error", obj => hierarchy.Root.Level = Level.Error),
                            new BindingAction("Fatal", obj => hierarchy.Root.Level = Level.Fatal)
                        }
                    }
                },
                Icon = ""
            };

            MainFrmUI.CommandCollection.Add(debugCommand);

            BindingCommands = new BindingAction(GlobalHelper.Get("key_279"));
            var sysCommand = new BindingAction();

            sysCommand.ChildActions.Add(
                new Command(
                    GlobalHelper.Get("key_280"),
                    obj =>
            {
                if (
                    MessageBox.Show(GlobalHelper.Get("key_281"), GlobalHelper.Get("key_99"),
                                    MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    ProcessCollection.RemoveElementsNoReturn(d => true, RemoveOperation);
                }
            }, obj => true,
                    "clear"));

            sysCommand.ChildActions.Add(
                new Command(
                    GlobalHelper.Get("key_282"),
                    obj =>
            {
                if (
                    MessageBox.Show(GlobalHelper.Get("key_283"), GlobalHelper.Get("key_99"),
                                    MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    SaveCurrentProject();
                }
            }, obj => true,
                    "save"));

            BindingCommands.ChildActions.Add(sysCommand);

            var taskAction1 = new BindingAction();


            taskAction1.ChildActions.Add(new Command(GlobalHelper.Get("key_284"),
                                                     async obj =>
            {
                var project = await GetRemoteProjectContent();
                if (project != null)
                {
                    foreach (var param in project.Parameters)
                    {
                        //TODO: how check if it is same? name?
                        if (CurrentProject.Parameters.FirstOrDefault(d => d.Name == param.Name) == null)
                        {
                            CurrentProject.Parameters.Add(param);
                        }
                    }
                    CurrentProject.ConfigSelector.SelectItem = project.ConfigSelector.SelectItem;
                }

                (obj as ProcessTask).Load(true);
            },
                                                     obj => obj is ProcessTask, "inbox_out"));



            BindingCommands.ChildActions.Add(taskAction1);
            var taskAction2 = new BindingAction(GlobalHelper.Get("key_287"));

            taskAction2.ChildActions.Add(new Command(GlobalHelper.Get("key_288"),
                                                     obj =>
            {
                var task = obj as TaskBase;
                task.Start();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null && task.IsStart == false);
            }, "play"));

            taskAction2.ChildActions.Add(new Command(GlobalHelper.Get("cancel_task"),
                                                     obj =>
            {
                var task = obj as TaskBase;
                if (task.IsStart)
                {
                    task.Remove();
                }

                task.Remove();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null);
            }, "cancel"));


            var runningTaskActions = new BindingAction(GlobalHelper.Get("key_290"));


            runningTaskActions.ChildActions.Add(new Command(GlobalHelper.Get("key_291"),
                                                            d => GetSelectedTask(d).Execute(d2 => { d2.IsPause = true; d2.ShouldPause = true; }), d => true, "pause"));
            runningTaskActions.ChildActions.Add(new Command(GlobalHelper.Get("key_292"),
                                                            d => GetSelectedTask(d).Execute(d2 => { d2.IsPause = false; d2.ShouldPause = false; }), d => ProcessTaskCanExecute(d, false), "play"));

            runningTaskActions.ChildActions.Add(new Command(GlobalHelper.Get("key_293"),
                                                            d =>
            {
                var selectedTasks = GetSelectedTask(d).ToList();
                CurrentProcessTasks.Where(d2 => selectedTasks.Contains(d2)).ToList().Execute(d2 => d2.Remove());
            }, d => ProcessTaskCanExecute(d, null), "delete"));


            runningTaskActions.ChildActions.Add(new Command(GlobalHelper.Get("property"),
                                                            d =>
            {
                var selectedTasks = GetSelectedTask(d).FirstOrDefault();
                PropertyGridFactory.GetPropertyWindow(selectedTasks).ShowDialog();
            }, d => ProcessTaskCanExecute(d, null), "settings"));



            BindingCommands.ChildActions.Add(runningTaskActions);
            BindingCommands.ChildActions.Add(runningTaskActions);


            var processAction = new BindingAction();


            dynamic processview =
                (MainFrmUI as IDockableManager).ViewDictionary.FirstOrDefault(d => d.Name == GlobalHelper.Get("key_794"))
                .View;

            processView = processview.processListBox as ListBox;

            var tickInterval = ConfigFile.GetConfig().Get <int>("AutoSaveTime");

            if (tickInterval > 0)
            {
                this.datatTimer.Tick    += timeCycle;
                this.datatTimer.Interval = new TimeSpan(0, 0, 0, tickInterval);
                this.datatTimer.Start();
            }
            ConfigFile.GetConfig().PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "AutoSaveTime")
                {
                    var tick = ConfigFile.GetConfig().Get <int>("AutoSaveTime");
                    if (tick <= 0)
                    {
                        tick = 1000000;
                    }
                    this.datatTimer.Interval = new TimeSpan(0, 0, 0, tick);
                }
            };

            processAction.ChildActions.Add(new Command(GlobalHelper.Get("key_294"), obj =>
            {
                if (obj != null)
                {
                    foreach (var process in GetSelectedProcess(obj))
                    {
                        if (process == null)
                        {
                            return;
                        }
                        var old = obj as IDataProcess;
                        if (old == null)
                        {
                            return;
                        }

                        var name = process.GetType().ToString().Split('.').Last();
                        var item = GetOneInstance(name, true, true);
                        (process as IDictionarySerializable).DictCopyTo(item as IDictionarySerializable);
                        item.Init();
                        item.Name = process.Name + "_copy";
                    }
                }
                else
                {
                    var plugin = GetOneInstance("SmartETLTool", true, true, true) as SmartETLTool;
                    plugin.Init();
                    ControlExtended.DockableManager.ActiveModelContent(plugin);
                }
            }, obj => true, "add"));

            processAction.ChildActions.Add(new Command(GlobalHelper.Get("key_295"), obj =>
            {
                if (obj == null)
                {
                    var plugin = GetOneInstance("SmartCrawler", true, true, true) as SmartCrawler;
                    plugin.Init();
                    ControlExtended.DockableManager.ActiveModelContent(plugin);
                }
                else
                {
                    foreach (var process in GetSelectedProcess(obj))
                    {
                        if (process == null)
                        {
                            return;
                        }
                        var name = process.GetType().ToString().Split('.').Last();
                        var item = GetOneInstance(name, true, true);

                        (process as IDictionarySerializable).DictCopyTo(item as IDictionarySerializable);
                        item.Init();
                        item.Name = process.Name + "_copy";
                    }
                }
            }, obj => true, "cloud_add"));


            processAction.ChildActions.Add(new Command(GlobalHelper.Get("key_296"), obj =>
            {
                if (obj == null)
                {
                    SaveCurrentProject();
                }
                else
                {
                    foreach (var process in GetSelectedProcess(obj))
                    {
                        SaveTask(process, false);
                    }
                }
            }, obj => true, "save"));
            processAction.ChildActions.Add(new Command(GlobalHelper.Get("key_297"), obj =>
            {
                var process = GetSelectedProcess(obj).FirstOrDefault();
                if (process == null)
                {
                    return;
                }
                var view = (MainFrmUI as IDockableManager).ViewDictionary.FirstOrDefault(d => d.Model == process);
                if (view == null)
                {
                    LoadProcessView(process);
                }
                (MainFrmUI as IDockableManager).ActiveModelContent(process);

                process.Init();
            }, obj => true, "tv"));
            processAction.ChildActions.Add(new Command(GlobalHelper.Get("key_298"), obj =>
            {
                if (MessageBox.Show(GlobalHelper.Get("delete_confirm"), GlobalHelper.Get("key_99"), MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    return;
                }
                foreach (var process in GetSelectedProcess(obj))
                {
                    if (process == null)
                    {
                        return;
                    }

                    RemoveOperation(process);
                    ProcessCollection.Remove(process);
                    var tasks = CurrentProcessTasks.Where(d => d.Publisher == process).ToList();
                    if (tasks.Any())
                    {
                        foreach (var item in tasks)
                        {
                            item.Remove();
                            XLogSys.Print.Warn(string.Format(GlobalHelper.Get("key_299"), process.Name, item.Name));
                        }
                    }
                }
            }, obj => true, "delete"));
            processAction.ChildActions.Add(new Command(GlobalHelper.Get("key_300"),
                                                       obj => { ControlExtended.DockableManager.ActiveThisContent(GlobalHelper.Get("ModuleMgmt")); },
                                                       obj => true, "home"));
            processAction.ChildActions.Add(new Command(GlobalHelper.Get("find_ref"),
                                                       obj =>
            {
                PrintReferenced(obj as IDataProcess);
            }, obj => true, "diagram"));
            processAction.ChildActions.Add(new Command(GlobalHelper.Get("property"),
                                                       obj =>
            {
                PropertyGridFactory.GetPropertyWindow(obj).ShowDialog();
            }, obj => true, "settings"));
            processAction.ChildActions.Add(new Command(GlobalHelper.Get("param_group"),
                                                       obj =>
            {
                this.dockableManager.ActiveThisContent(GlobalHelper.Get("ModuleMgmt"));
                MainTabIndex = 2;
            }, obj => true, "equalizer"));
            BindingCommands.ChildActions.Add(processAction);
            BindingCommands.ChildActions.Add(taskAction2);


            var attributeactions = new BindingAction(GlobalHelper.Get("key_301"));

            attributeactions.ChildActions.Add(new Command(GlobalHelper.Get("key_302"), obj =>
            {
                var attr = obj as XFrmWorkAttribute;
                if (attr == null)
                {
                    return;
                }

                var process = GetOneInstance(attr.MyType.Name, newOne: true, isAddUI: true);
                process.Init();
            }, icon: "add"));
            BindingCommands.ChildActions.Add(attributeactions);


            var marketAction = new BindingAction();

            marketAction.ChildActions.Add(new Command(GlobalHelper.Get("connect_market"), async obj =>
            {
                GitHubApi.Connect(ConfigFile.GetConfig().Get <string>("Login"), ConfigFile.GetConfig().Get <string>("Password"));
                MarketProjects.Clear();
                ControlExtended.SetBusy(ProgressBarState.Indeterminate, message: GlobalHelper.Get("get_remote_projects"));
                MarketProjects.AddRange(await GitHubApi.GetProjects(ConfigFile.GetConfig().Get <string>("MarketUrl")));
                ControlExtended.SetBusy(ProgressBarState.NoProgress);
            }, icon: "refresh"));

            BindingCommands.ChildActions.Add(marketAction);


            var marketProjectAction = new BindingAction();

            marketProjectAction.ChildActions.Add(new Command(GlobalHelper.Get("key_307"), async obj =>
            {
                var projectItem = obj as ProjectItem;
                var keep        = MessageBoxResult.Yes;
                if (projectItem == null)
                {
                    return;
                }
                if (MessageBox.Show(GlobalHelper.Get("is_load_remote_project"), GlobalHelper.Get("key_99"), MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    return;
                }
                if (NeedSave())
                {
                    keep = MessageBox.Show(GlobalHelper.Get("keep_old_datas"), GlobalHelper.Get("key_99"),
                                           MessageBoxButton.YesNoCancel);
                    if (keep == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }
                var proj = await this.GetRemoteProjectContent(projectItem);
                LoadProject(proj, keep == MessageBoxResult.Yes);
            }, icon: "download"));


            var config = ConfigFile.GetConfig <DataMiningConfig>();

            if (config.Projects.Any())
            {
                var project = config.Projects.FirstOrDefault();
                if (project != null)
                {
                    ControlExtended.SafeInvoke(() => { CurrentProject = LoadProject(project.SavePath); }, LogType.Info,
                                               GlobalHelper.Get("key_303"));
                }
            }
            BindingCommands.ChildActions.Add(marketProjectAction);
            if (MainDescription.IsUIForm)
            {
                ProgramNameFilterView =
                    new ListCollectionView(PluginProvider.GetPluginCollection(typeof(IDataProcess)).ToList());

                ProgramNameFilterView.GroupDescriptions.Clear();
                ProgramNameFilterView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
                var taskView    = PluginProvider.GetObjectInstance <ICustomView>(GlobalHelper.Get("key_304"));
                var userControl = taskView as UserControl;
                if (userControl != null)
                {
                    userControl.DataContext = this;
                    dynamic control = userControl;
                    currentProcessTasksView = control.currentProcessTasksView;
                    ((INotifyCollectionChanged)CurrentProcessTasks).CollectionChanged += (s, e) =>
                    {
                        ControlExtended.UIInvoke(() =>
                        {
                            if (e.Action == NotifyCollectionChangedAction.Add)
                            {
                                dockableManager.ActiveThisContent(GlobalHelper.Get("key_304"));
                            }
                        });
                    }
                    ;
                    dockableManager.AddDockAbleContent(taskView.FrmState, this, taskView, GlobalHelper.Get("key_304"));
                }
                ProcessCollectionView = new ListCollectionView(ProcessCollection);
                ProcessCollectionView.GroupDescriptions.Clear();
                ProcessCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));
            }

            var fileCommand = MainFrmUI.CommandCollection.FirstOrDefault(d => d.Text == GlobalHelper.Get("key_305"));

            fileCommand.ChildActions.Add(new BindingAction(GlobalHelper.Get("key_306"), obj => CreateNewProject())
            {
                Icon = "add"
            });
            fileCommand.ChildActions.Add(new BindingAction(GlobalHelper.Get("key_307"), obj =>
            {
                var keep = MessageBoxResult.No;
                if (NeedSave())
                {
                    keep = MessageBox.Show(GlobalHelper.Get("keep_old_datas"), GlobalHelper.Get("key_99"),
                                           MessageBoxButton.YesNoCancel);
                    if (keep == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }
                LoadProject(keepLast: keep == MessageBoxResult.Yes);
            })
            {
                Icon = "inbox_out"
            });
            fileCommand.ChildActions.Add(new BindingAction(GlobalHelper.Get("key_308"), obj => SaveCurrentProject())
            {
                Icon = "save"
            });
            fileCommand.ChildActions.Add(new BindingAction(GlobalHelper.Get("key_309"), obj => SaveCurrentProject(false))
            {
                Icon = "save"
            });
            fileCommand.ChildActions.Add(new BindingAction(GlobalHelper.Get("generate_project_doc"), obj =>
            {
                if (CurrentProject == null)
                {
                    return;
                }
                var doc     = this.GenerateRemark(this.ProcessCollection);
                var docItem = new DocumentItem()
                {
                    Title = this.CurrentProject.Name, Document = doc
                };
                PropertyGridFactory.GetPropertyWindow(docItem).ShowDialog();
            }, obj => CurrentProject != null)
            {
                Icon = "help"
            });
            fileCommand.ChildActions.Add(new BindingAction(GlobalHelper.Get("recent_file"))
            {
                Icon         = "save",
                ChildActions =
                    new ObservableCollection <ICommand>(config.Projects.Select(d => new BindingAction(d.SavePath, obj =>
                {
                    var keep = MessageBoxResult.No;
                    if (NeedSave())
                    {
                        keep = MessageBox.Show(GlobalHelper.Get("keep_old_datas"), GlobalHelper.Get("key_99"),
                                               MessageBoxButton.YesNoCancel);
                        if (keep == MessageBoxResult.Cancel)
                        {
                            return;
                        }
                    }
                    LoadProject(d.SavePath, keep == MessageBoxResult.Yes);
                })
                {
                    Icon = "folder"
                }))
            });
            var languageMenu = new BindingAction(GlobalHelper.Get("key_lang"))
            {
                Icon = "layout"
            };

            var files = Directory.GetFiles("Lang");

            foreach (var f in files)
            {
                var ba = new BindingAction(f, obj => { AppHelper.LoadLanguage(f); })
                {
                    Icon = "layout"
                };

                languageMenu.ChildActions.Add(ba);
            }
            //  helpCommands.ChildActions.Add(languageMenu);

            return(true);
        }
예제 #5
0
        public override bool Init()
        {
            base.Init();
            dockableManager = MainFrmUI as IDockableManager;
            dataManager = MainFrmUI.PluginDictionary["数据管理"] as IDataManager;
            propertyGridWindow = MainFrmUI.PluginDictionary["属性配置器"] as XFrmWorkPropertyGrid;

            ProcessCollection = new ObservableCollection<IDataProcess>();

            CurrentProcessTasks = new ObservableCollection<TaskBase>();
            BindingCommands = new BindingAction("运行");
            var sysCommand = new BindingAction();

            sysCommand.ChildActions.Add(
                new Command(
                    "清空模块列表",
                    obj =>
                    {
                        if (MessageBox.Show("确定清空所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                            MessageBoxResult.OK)
                        {
                            ProcessCollection.RemoveElementsNoReturn(d => true, RemoveOperation);
                        }
                    }, obj => true,
                    "clear"));

            sysCommand.ChildActions.Add(
                new Command(
                    "保存全部模块",
                    obj =>
                    {
                        if (MessageBox.Show("确定保存所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                            MessageBoxResult.OK)
                        {
                            SaveCurrentTasks();
                        }
                    }, obj => true,
                    "clear"));

            BindingCommands.ChildActions.Add(sysCommand);

            var taskAction1 = new BindingAction();

            taskAction1.ChildActions.Add(new Command("加载本任务",
                obj => (obj as ProcessTask).Load(true),
                obj => obj is ProcessTask, "download"));

            taskAction1.ChildActions.Add(new Command("删除任务",
                obj => CurrentProject.Tasks.Remove(obj as ProcessTask),
                obj => obj is ProcessTask));
            taskAction1.ChildActions.Add(new Command("执行任务脚本",
             (obj=>(obj as ProcessTask).EvalScript()),
             obj =>(obj is ProcessTask)&& CurrentProcessCollections.FirstOrDefault(d => d.Name == (obj as ProcessTask).Name) != null));

            BindingCommands.ChildActions.Add(taskAction1);
            var taskAction2 = new BindingAction("任务列表2");
            taskAction2.ChildActions.Add(new Command("开始任务",
                obj =>
                {
                    var task = obj as TaskBase;
                    task.Start();
                },
                obj =>
                {
                    var task = obj as TaskBase;
                    return task != null && task.IsStart == false;
                }, "download"));

            taskAction2.ChildActions.Add(new Command("取消任务",
                obj =>
                {
                    var task = obj as TaskBase;
                    if (task.IsStart)
                    {
                        task.Cancel();
                    }

                    task.Remove();
                },
                obj =>
                {
                    var task = obj as TaskBase;
                    return task != null;
                }, "download"));

            var taskListAction = new BindingAction("任务列表命令");

            taskListAction.ChildActions.Add(new Command("全选",
                d => CurrentProcessTasks.Execute(d2 => d2.IsSelected = true), null, "check"));

            taskListAction.ChildActions.Add(new Command("反选",
                d => CurrentProcessTasks.Execute(d2 => d2.IsSelected =!d2.IsSelected), null, "redo"));

            taskListAction.ChildActions.Add(new Command("暂停",
                d => CurrentProcessTasks.Where(d2 => d2.IsSelected).Execute(d2 => d2.IsPause = true), null, "pause"));
            taskListAction.ChildActions.Add(new Command("恢复",
                d => CurrentProcessTasks.Where(d2 => d2.IsSelected).Execute(d2 => d2.IsPause = false), null, "play"));

            taskListAction.ChildActions.Add(new Command("取消",
               d => CurrentProcessTasks.RemoveElementsNoReturn(d2=>d2.IsSelected,d2=>d2.Cancel()), null,"delete"));

            BindingCommands.ChildActions.Add(taskListAction);

            BindingCommands.ChildActions.Add(taskListAction);

            var processAction = new BindingAction();

            processAction.ChildActions.Add(new Command("配置", obj =>
            {
                var process = GetProcess(obj);
                if (process == null) return;
                ShowConfigUI(process);
            }, obj => true, "settings"));
            processAction.ChildActions.Add(new Command("查看视图", obj =>
            {
                var process = GetProcess(obj);
                if (process == null) return;
                (MainFrmUI as IDockableManager).ActiveModelContent(process);
            }, obj => true, "tv"));
            processAction.ChildActions.Add(new Command("拷贝", obj =>
            {
                var process = GetProcess(obj);
                if (process == null) return;
                ProcessCollection.Remove(obj as IDataProcess);
                var item = GetOneInstance(process.TypeName, true, false);
                (process as IDictionarySerializable).DictCopyTo(item as IDictionarySerializable);
                item.Init();
                ProcessCollection.Add(item);
            }, obj => true, "new"));

            processAction.ChildActions.Add(new Command("移除", obj =>
            {
                var process = GetProcess(obj);
                if (process == null) return;

                RemoveOperation(process);
                ProcessCollection.Remove(process);
                ShowConfigUI(null);
            }, obj => true, "delete"));

            processAction.ChildActions.Add(new Command("保存任务", obj =>
            {
                var process = obj as IDataProcess;
                if (process == null)
                    return;
                SaveTask(process, true);
            }, obj => obj is IDictionarySerializable));
            processAction.ChildActions.Add(new Command("显示并配置", obj =>
            {
                var process = GetProcess(obj);
                if (process == null) return;
                var view = (MainFrmUI as IDockableManager).ViewDictionary.FirstOrDefault(d => d.Model == process);
                if (view == null)
                {
                    LoadProcessView(process);
                }
                (MainFrmUI as IDockableManager).ActiveModelContent(process);
                ShowConfigUI(process);
            }, obj => true, "delete"));

            BindingCommands.ChildActions.Add(processAction);
            BindingCommands.ChildActions.Add(taskAction2);
            var attributeactions = new BindingAction("模块");
            attributeactions.ChildActions.Add(new Command("添加", obj =>
            {
                var attr = obj as XFrmWorkAttribute;
                if (attr == null)
                    return;

                var process = GetOneInstance(attr.MyType.Name, newOne: true, isAddUI: true);
                process.Init();
            }));
            BindingCommands.ChildActions.Add(attributeactions);

            var config = ConfigFile.GetConfig<DataMiningConfig>();
            if (config.Projects.Any())
            {
                var project = config.Projects.FirstOrDefault();
                if (project != null)
                {
                    ControlExtended.SafeInvoke(() =>
                    {
                        currentProject = ProjectItem.LoadProject(project.SavePath);
                        NotifyCurrentProjectChanged();
                    }, LogType.Info, "加载默认工程");
                }
            }

            if (MainDescription.IsUIForm)
            {
                ProgramNameFilterView =
                    new ListCollectionView(PluginProvider.GetPluginCollection(typeof (IDataProcess)).ToList());

                ProgramNameFilterView.GroupDescriptions.Clear();
                ProgramNameFilterView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
                var taskView = PluginProvider.GetObjectInstance<ICustomView>("任务管理视图");
                var userControl = taskView as UserControl;
                if (userControl != null)
                {
                    userControl.DataContext = this;
                    ((INotifyCollectionChanged) CurrentProcessTasks).CollectionChanged += (s, e) =>
                    {
                        ControlExtended.UIInvoke(() => {
                            if (e.Action == NotifyCollectionChangedAction.Add)
                            {
                                dockableManager.ActiveThisContent("任务管理视图");
                            }
                        });

                    }
                        ;
                    dockableManager.AddDockAbleContent(taskView.FrmState, this, taskView, "任务管理视图");
                }
                ProcessCollectionView = new ListCollectionView(ProcessCollection);
                ProcessCollectionView.GroupDescriptions.Clear();
                ProcessCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));

                ProjectTaskList = new ListCollectionView(CurrentProject.Tasks);
                ProjectTaskList.GroupDescriptions.Clear();

                ProjectTaskList.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));

                OnPropertyChanged("ProjectTaskList");
                ProjectTaskList = new ListCollectionView(CurrentProject.Tasks);
                ProjectTaskList.GroupDescriptions.Clear();

                ProjectTaskList.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));
                OnPropertyChanged("ProjectTaskList");
            }

            var file = MainFrmUI.CommandCollection.FirstOrDefault(d => d.Text == "文件");
            file.ChildActions.Add(new BindingAction("新建项目", obj => CreateNewProject()));
            file.ChildActions.Add(new BindingAction("加载项目", obj => LoadProject()));
            file.ChildActions.Add(new BindingAction("保存项目", obj => SaveCurrentProject()));
            file.ChildActions.Add(new BindingAction("项目另存为", obj => SaveCurrentProject(false)));

            return true;
        }
예제 #6
0
        public override bool Init()
        {
            base.Init();
            dockableManager    = MainFrmUI as IDockableManager;
            dataManager        = MainFrmUI.PluginDictionary["数据管理"] as IDataManager;
            propertyGridWindow = MainFrmUI.PluginDictionary["属性配置器"] as XFrmWorkPropertyGrid;

            var aboutAuthor = new BindingAction("关于", d =>
            {
                var view       = PluginProvider.GetObjectInstance <ICustomView>("关于作者");
                var window     = new Window();
                window.Title   = "关于作者";
                window.Content = view;
                window.ShowDialog();
            })
            {
                Description = "Hawk版本与检查更新", Icon = "information"
            };
            var mainlink = new BindingAction("项目主页", d =>
            {
                var url = "https://github.com/ferventdesert/Hawk";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = "访问Hawk的开源项目地址", Icon = "home"
            };
            var helplink = new BindingAction("使用文档", d =>
            {
                var url = "https://github.com/ferventdesert/Hawk/wiki";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = "这里有使用Hawk的案例与完整教程", Icon = "question"
            };

            var feedback = new BindingAction("反馈问题", d =>
            {
                var url = "https://github.com/ferventdesert/Hawk/issues";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = "出现bug或者问题了?欢迎反馈", Icon = "reply_people"
            };


            var giveme = new BindingAction("捐赠", d =>
            {
                var url = "https://github.com/ferventdesert/Hawk/wiki/8-%E5%85%B3%E4%BA%8E%E4%BD%9C%E8%80%85%E5%92%8C%E6%8D%90%E8%B5%A0";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = "你的支持是作者更新Hawk的动力", Icon = "smiley_happy"
            };
            var blog = new BindingAction("博客", d =>
            {
                var url = "http://www.cnblogs.com/buptzym/";
                System.Diagnostics.Process.Start(url);
            })
            {
                Description = "作者沙漠君的博客", Icon = "tower"
            };

            var helpCommands = new BindingAction("帮助")
            {
                Icon = "magnify"
            };

            helpCommands.ChildActions.Add(mainlink);
            helpCommands.ChildActions.Add(helplink);

            helpCommands.ChildActions.Add(feedback);
            helpCommands.ChildActions.Add(giveme);
            helpCommands.ChildActions.Add(blog);
            helpCommands.ChildActions.Add(aboutAuthor);
            MainFrmUI.CommandCollection.Add(helpCommands);

            Hierarchy hierarchy    = (Hierarchy)LogManager.GetRepository();
            var       debugCommand = new BindingAction("调试")
            {
                ChildActions = new ObservableCollection <ICommand>()
                {
                    new BindingAction("级别设置")
                    {
                        ChildActions =
                            new ObservableCollection <ICommand>()
                        {
                            new BindingAction("Debug", obj => hierarchy.Root.Level = Level.Debug),
                            new BindingAction("Info", obj => hierarchy.Root.Level  = Level.Info),
                            new BindingAction("Warn", obj => hierarchy.Root.Level  = Level.Warn),
                            new BindingAction("Error", obj => hierarchy.Root.Level = Level.Error),
                            new BindingAction("Fatal", obj => hierarchy.Root.Level = Level.Fatal),
                        }
                    }
                },

                Icon = ""
            };

            MainFrmUI.CommandCollection.Add(debugCommand);
            debugCommand?.ChildActions.Add(new BindingAction("Web请求统计", obj =>
            {
                if (debugGrid == null)
                {
                    debugGrid = PropertyGridFactory.GetInstance(RequestManager.Instance);
                }
                else
                {
                    debugGrid.SetObjectView(RequestManager.Instance);
                }

                dynamic control =
                    (this.MainFrmUI as IDockableManager).ViewDictionary.FirstOrDefault(d => d.View == debugGrid)
                    ?.Container;
                if (control != null)
                {
                    control.Show();
                }

                else
                {
                    (this.MainFrmUI as IDockableManager).AddDockAbleContent(FrmState.Mini, debugGrid, "Web请求统计");
                }
            })
            {
                Icon = "graph_line"
            });
            ProcessCollection = new ObservableCollection <IDataProcess>();


            CurrentProcessTasks = new ObservableCollection <TaskBase>();
            BindingCommands     = new BindingAction("运行");
            var sysCommand = new BindingAction();

            sysCommand.ChildActions.Add(
                new Command(
                    "清空任务列表",
                    obj =>
            {
                if (MessageBox.Show("确定清空所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    ProcessCollection.RemoveElementsNoReturn(d => true, RemoveOperation);
                }
            }, obj => true,
                    "clear"));

            sysCommand.ChildActions.Add(
                new Command(
                    "保存全部任务",
                    obj =>
            {
                if (MessageBox.Show("确定保存所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    SaveCurrentTasks();
                }
            }, obj => true,
                    "save"));

            BindingCommands.ChildActions.Add(sysCommand);

            var taskAction1 = new BindingAction();


            taskAction1.ChildActions.Add(new Command("加载本任务",
                                                     obj => (obj as ProcessTask).Load(true),
                                                     obj => obj is ProcessTask, "inbox_out"));


            taskAction1.ChildActions.Add(new Command("删除任务",
                                                     obj => CurrentProject.Tasks.Remove(obj as ProcessTask),
                                                     obj => obj is ProcessTask, "delete"));
            taskAction1.ChildActions.Add(new Command("执行任务脚本",
                                                     (obj => (obj as ProcessTask).EvalScript()),
                                                     obj => (obj is ProcessTask) && CurrentProcessCollections.FirstOrDefault(d => d.Name == (obj as ProcessTask).Name) != null));
            taskAction1.ChildActions.Add(new Command("配置", obj => PropertyGridFactory.GetPropertyWindow(obj).ShowDialog()
                                                     ));



            BindingCommands.ChildActions.Add(taskAction1);
            var taskAction2 = new BindingAction("任务列表2");

            taskAction2.ChildActions.Add(new Command("开始任务",
                                                     obj =>
            {
                var task = obj as TaskBase;
                task.Start();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null && task.IsStart == false);
            }, "play"));

            taskAction2.ChildActions.Add(new Command("取消任务",
                                                     obj =>
            {
                var task = obj as TaskBase;
                if (task.IsStart)
                {
                    task.Remove();
                }

                task.Remove();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null);
            }, "cancel"));


            var taskListAction = new BindingAction("任务列表命令");

            taskListAction.ChildActions.Add(new Command("全选",
                                                        d => CurrentProcessTasks.Execute(d2 => d2.IsSelected = true), null, "check"));

            taskListAction.ChildActions.Add(new Command("反选",
                                                        d => CurrentProcessTasks.Execute(d2 => d2.IsSelected = !d2.IsSelected), null, "redo"));

            taskListAction.ChildActions.Add(new Command("暂停",
                                                        d => CurrentProcessTasks.Where(d2 => d2.IsSelected).Execute(d2 => d2.IsPause = true), null, "pause"));
            taskListAction.ChildActions.Add(new Command("恢复",
                                                        d => CurrentProcessTasks.Where(d2 => d2.IsSelected).Execute(d2 => d2.IsPause = false), null, "play"));

            taskListAction.ChildActions.Add(new Command("取消",
                                                        d => CurrentProcessTasks.RemoveElementsNoReturn(d2 => d2.IsSelected, d2 => d2.Remove()), null, "delete"));

            BindingCommands.ChildActions.Add(taskListAction);

            BindingCommands.ChildActions.Add(taskListAction);

            var processAction = new BindingAction();



            processAction.ChildActions.Add(new Command("新建或复制数据清洗", obj =>
            {
                if (obj != null)
                {
                    var process = GetProcess(obj);
                    if (process == null)
                    {
                        return;
                    }
                    var old = obj as IDataProcess;
                    if (old == null)
                    {
                        return;
                    }

                    //ProcessCollection.Remove(old);
                    var name = process.GetType().ToString().Split('.').Last();

                    var item = GetOneInstance(name, true, true);
                    (process as IDictionarySerializable).DictCopyTo(item as IDictionarySerializable);
                    item.Init();
                    item.Name = old.Name + "_copy";
                    ProcessCollection.Add(item);
                }
                else
                {
                    var plugin = this.GetOneInstance("SmartETLTool", true, true, true) as SmartETLTool;
                    plugin.Init();
                    ControlExtended.DockableManager.ActiveModelContent(plugin);
                }
            }, obj => true, "add"));

            processAction.ChildActions.Add(new Command("新建或复制采集器", obj =>
            {
                if (obj == null)
                {
                    var plugin = this.GetOneInstance("SmartCrawler", true, true, true) as SmartCrawler;
                    plugin.Init();
                    ControlExtended.DockableManager.ActiveModelContent(plugin);
                }
                else
                {
                    var process = GetProcess(obj);
                    if (process == null)
                    {
                        return;
                    }
                    var old = obj as IDataProcess;
                    if (old == null)
                    {
                        return;
                    }

                    //ProcessCollection.Remove(old);
                    var name = process.GetType().ToString().Split('.').Last();

                    var item = GetOneInstance(name, true, true);
                    (process as IDictionarySerializable).DictCopyTo(item as IDictionarySerializable);
                    item.Init();
                    item.Name = old.Name + "_copy";
                    ProcessCollection.Add(item);
                }
            }, obj => true, "cloud_add"));



            processAction.ChildActions.Add(new Command("保存任务", obj =>
            {
                var process = obj as IDataProcess;
                if (process == null)
                {
                    foreach (var target in CurrentProcessCollections)
                    {
                        SaveTask(target, false);
                    }
                }
                else
                {
                    SaveTask(process, true);
                }
            }, obj => true, "save"));
            processAction.ChildActions.Add(new Command("显示并配置", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                var view = (MainFrmUI as IDockableManager).ViewDictionary.FirstOrDefault(d => d.Model == process);
                if (view == null)
                {
                    LoadProcessView(process);
                }
                (MainFrmUI as IDockableManager).ActiveModelContent(process);
                ShowConfigUI(process);
            }, obj => true, "delete"));
            processAction.ChildActions.Add(new Command("移除", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }

                RemoveOperation(process);
                ProcessCollection.Remove(process);
                var tasks = this.CurrentProcessTasks.Where(d => d.Publisher == process).ToList();
                if (tasks.Any())
                {
                    foreach (var item in tasks)
                    {
                        item.Remove();
                        XLogSys.Print.Warn($"由于任务{process.Name} 已经被删除, 相关任务${item.Name} 也已经被强行取消");
                    }
                }
                ShowConfigUI(null);
            }, obj => true, "delete"));
            processAction.ChildActions.Add(new Command("打开欢迎页面", obj =>
            {
                ControlExtended.DockableManager.ActiveThisContent("模块管理");
            }, obj => true, "home"));


            BindingCommands.ChildActions.Add(processAction);
            BindingCommands.ChildActions.Add(taskAction2);
            var attributeactions = new BindingAction("模块");

            attributeactions.ChildActions.Add(new Command("添加", obj =>
            {
                var attr = obj as XFrmWorkAttribute;
                if (attr == null)
                {
                    return;
                }

                var process = GetOneInstance(attr.MyType.Name, newOne: true, isAddUI: true);
                process.Init();
            }, icon: "add"));
            BindingCommands.ChildActions.Add(attributeactions);

            var config = ConfigFile.GetConfig <DataMiningConfig>();

            if (config.Projects.Any())
            {
                var project = config.Projects.FirstOrDefault();
                if (project != null)
                {
                    ControlExtended.SafeInvoke(() =>
                    {
                        currentProject = ProjectItem.LoadProject(project.SavePath);
                        NotifyCurrentProjectChanged();
                    }, LogType.Info, "加载默认工程");
                }
            }

            if (MainDescription.IsUIForm)
            {
                ProgramNameFilterView =
                    new ListCollectionView(PluginProvider.GetPluginCollection(typeof(IDataProcess)).ToList());

                ProgramNameFilterView.GroupDescriptions.Clear();
                ProgramNameFilterView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
                var taskView    = PluginProvider.GetObjectInstance <ICustomView>("工作线程视图");
                var userControl = taskView as UserControl;
                if (userControl != null)
                {
                    userControl.DataContext = this;
                    ((INotifyCollectionChanged)CurrentProcessTasks).CollectionChanged += (s, e) =>
                    {
                        ControlExtended.UIInvoke(() => {
                            if (e.Action == NotifyCollectionChangedAction.Add)
                            {
                                dockableManager.ActiveThisContent("工作线程视图");
                            }
                        });
                    }
                    ;
                    dockableManager.AddDockAbleContent(taskView.FrmState, this, taskView, "工作线程视图");
                }
                ProcessCollectionView = new ListCollectionView(ProcessCollection);
                ProcessCollectionView.GroupDescriptions.Clear();
                ProcessCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));



                OnPropertyChanged("ProjectTaskList");
                ProjectTaskList = new ListCollectionView(CurrentProject.Tasks);
                ProjectTaskList.GroupDescriptions.Clear();

                ProjectTaskList.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));
                OnPropertyChanged("ProjectTaskList");
            }

            var file = MainFrmUI.CommandCollection.FirstOrDefault(d => d.Text == "文件");

            file.ChildActions.Add(new BindingAction("新建项目", obj => CreateNewProject())
            {
                Icon = "add"
            });
            file.ChildActions.Add(new BindingAction("加载项目", obj => LoadProject())
            {
                Icon = "inbox_out"
            });
            file.ChildActions.Add(new BindingAction("保存项目", obj => SaveCurrentProject())
            {
                Icon = "save"
            });
            file.ChildActions.Add(new BindingAction("项目另存为", obj => SaveCurrentProject(false))
            {
                Icon = "save"
            });
            file.ChildActions.Add(new BindingAction("最近打开的文件")
            {
                Icon         = "save",
                ChildActions = new ObservableCollection <ICommand>(config.Projects.Select(d => new BindingAction(d.SavePath, obj => LoadProject(d.SavePath))
                {
                    Icon = "folder"
                }))
            });
            return(true);
        }