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; }
public override bool Init() { if (MainDescription.IsUIForm) { DataCollections = new SafeObservable<DataCollection>(); dockableManager = MainFrmUI as IDockableManager; var view = PluginProvider.GetObjectInstance<ICustomView>("系统状态视图"); var userControl = view as UserControl; if (userControl != null) { userControl.DataContext = MainFrmUI; dockableManager.AddDockAbleContent(FrmState.Mini, view, "系统状态视图"); } } else { DataCollections = new ObservableCollection<DataCollection>(); } processManager = MainFrmUI.PluginDictionary["模块管理"] as IProcessManager; commands = new List<ICommand>(); var dbaction = new BindingAction(); dbaction.ChildActions.Add(new Command("配置连接", obj => { Window w = PropertyGridFactory.GetPropertyWindow(obj); w.ShowDialog(); }, obj => obj != null)); dbaction.ChildActions.Add( new Command("刷新", obj => RefreshConnect(obj as IDataBaseConnector), obj => obj != null)); dbaction.ChildActions.Add( new Command("执行查询", obj => { var query = new QueryEntity(); query.Connector = obj as IDataBaseConnector; query.GetQueryFunc = d => { if (d == null) return; if (d.Any() == false) return; AddDataCollection(d, GetNewName()); }; propertyGridWindow.SetObjectView(query); }, obj => obj != null)); dbaction.ChildActions.Add( new Command("删除连接", obj => { if (MessageBox.Show("确定要删除该连接吗?", "提示信息", MessageBoxButton.YesNoCancel) == MessageBoxResult.Yes) { var con = obj as DBConnectorBase; _dbConnections.Remove(con); } }, obj => obj != null)); var dataaction = new BindingAction(); var tableAction = new BindingAction(); tableAction.ChildActions.Add(new Command( "查看", async obj => { var items = obj as TableInfo; List<IFreeDocument> dataAll = await GetDataFromDB(items.Connector, items.Name, true, items.Connector is FileManager ? -1 : 200); if (dataAll == null || dataAll.Count == 0) { XLogSys.Print.Warn("没有在表中的发现可用的数据"); return; } if (items.Connector is FileManager) { string file = (items.Connector as FileManager).LastFileName; var name = Path.GetFileNameWithoutExtension(file); AddDataCollection(dataAll, name); return; } var excel = PluginProvider.GetObjectInstance<IDataViewer>("可编辑列表"); if (excel == null) return; object view = excel.SetCurrentView(dataAll.Select(d=>d as IFreeDocument).ToList()); if (ControlExtended.DockableManager != null) { ControlExtended.DockableManager.AddDockAbleContent( FrmState.Custom, view, items.Name); } }, obj => obj != null)); tableAction.ChildActions.Add(new Command( "添加到数据集", async obj => { var items = obj as TableInfo; List<IFreeDocument> datas = await GetDataFromDB(items.Connector, items.Name, true); if (datas == null) return; AddDataCollection(datas, items.Name); }, obj => obj != null)); tableAction.ChildActions.Add(new Command( "添加虚拟数据集", obj => { var con = obj as TableInfo; ReadCollection(con.Connector, con.Name, true); }, obj => obj != null)); tableAction.ChildActions.Add(new Command( "删除表", obj => { var items = obj as TableInfo; DropTable(items.Connector, items.Name); }, obj => obj != null)); tableAction.ChildActions.Add(new Command( "查看属性", obj => { Window w = PropertyGridFactory.GetPropertyWindow(obj); w.ShowDialog(); }, obj => obj != null)); tableAction.ChildActions.Add(new Command( "执行查询", obj => { var query = new QueryEntity(); query.TableInfo = obj as TableInfo; query.Connector = query.TableInfo.Connector; query.GetQueryFunc = d => { if (d == null) return; if (d.Any() == false) return; AddDataCollection(d, GetNewName()); }; propertyGridWindow.SetObjectView(query); }, obj => obj != null)); var visitData = new BindingAction("浏览方式"); IEnumerable<Command> visitCommands = PluginProvider.GetPluginCollection(typeof (IDataViewer)).Select( d => { var comm = new Command(d.Name); comm.Execute = d2 => { var data = d2 as DataCollection; if (data.Count == 0) { MessageBox.Show("不存在任何数据", "提示信息"); return; } ControlExtended.UIInvoke(() => { var view = PluginProvider.GetObjectInstance<IDataViewer>(d.Name); object r = view.SetCurrentView(data.ComputeData); if (ControlExtended.DockableManager != null) { ControlExtended.DockableManager.AddDockAbleContent( FrmState.Float, r, data.Name + " " + d.Name); } }); }; return comm; }); visitData.Execute = obj => visitCommands.FirstOrDefault(d => d.Text == "可编辑列表").Execute(obj); foreach (Command visitCommand in visitCommands) { visitData.ChildActions.Add(visitCommand); } dataaction.ChildActions.Add(new Command( "数据清洗", obj => { DataCollection collection = GetCollection(obj); if (collection == null) return; var plugin = processManager.GetOneInstance("SmartETLTool", true, true) as SmartETLTool; dynamic generator = PluginProvider.GetObjectByType<IColumnProcess>("TableGE"); generator.TableSelector.SelectItem = collection; plugin.CurrentETLTools.Add(generator); plugin.RefreshSamples(true); ControlExtended.DockableManager.ActiveModelContent(plugin); }, obj => true, "new")); dataaction.ChildActions.Add(new Command( "拷贝", obj => { DataCollection collection = GetCollection(obj); if (collection == null) return; DataCollection n = collection.Clone(true); n.Name = GetNewName(collection.Name); DataCollections.Add(n); }, obj => true, "page_new")); var saveData = new Command("另存为", d => { DataCollection collection = GetCollection(d); if (collection == null) return; var ofd = new SaveFileDialog {Filter = FileConnector.GetDataFilter(), DefaultExt = "*"}; ofd.FileName = collection.Name + ".xlsx"; if (ofd.ShowDialog() == true) { string filename = ofd.FileName; SaveFile(collection.Name, filename); } }, obj => true, "save"); dataaction.ChildActions.Add(saveData); dataaction.ChildActions.Add(visitData); dataaction.ChildActions.Add(new Command( "新建", obj => DataCollections.Add(new DataCollection(new List<IFreeDocument>()) { Name = GetNewName("新建数据集") }), obj => true, "box")); dataaction.ChildActions.Add(new Command( "配置", obj => { DataCollection collection = GetCollection(obj); if (collection != null) propertyGridWindow.SetObjectView(collection); }, obj => true, "settings")); dataaction.ChildActions.Add(new Command( "删除", obj => { DataCollection collection = GetCollection(obj); if (collection != null) DataCollections.Remove(collection); }, obj => true, "delete")); var convert = new BindingAction("转换表类型"); dataaction.ChildActions.Add(convert); convert.ChildActions.Add(new Command("转为非虚拟数据集", obj => { DataCollection coll = GetCollection(obj); if (coll.Count > 500000) { if ( MessageBox.Show("本集合数据量较大,转换可能会占用较高的内存和导致程序崩溃,确定继续吗?", "提示信息", MessageBoxButton.YesNoCancel) != MessageBoxResult.Yes) { return; } } var docuts = new List<IFreeDocument>(); var task=TemporaryTask.AddTempTask("转为非虚拟数据集", coll.ComputeData, d => { if (d != null) docuts.Add(d as IFreeDocument); }, result => { var collection = new DataCollection(docuts) {Name = coll.Name + '1'}; AddDataCollection(collection); this.DataCollections.Remove(coll); }); processManager.CurrentProcessTasks.Add(task); })); var insertdb = new BindingAction("保存到数据库"); insertdb.SetChildActionSource(() => { return _dbConnections.Select(dataBaseConnector => new Command(dataBaseConnector.Name, obj => { var data = obj as DataCollection; processManager.CurrentProcessTasks.Add(TemporaryTask.AddTempTask(data.Name + "插入到数据库", dataBaseConnector.InserDataCollection(data), result => dataBaseConnector.RefreshTableNames(), count: data.Count/1000)); })).Cast<ICommand>().ToList(); }); dataaction.ChildActions.Add(insertdb); var otherDataAction = new BindingAction(); otherDataAction.ChildActions.Add(new Command("清空数据", obj => CleanData(), obj => DataCollections.Count > 0)); commands.Add(dbaction); commands.Add(tableAction); commands.Add(dataaction); commands.Add(otherDataAction); var dblistAction = new BindingAction("数据库管理"); var addnew = new BindingAction("增加新连接"); dblistAction.ChildActions.Add(addnew); foreach (XFrmWorkAttribute item in PluginProvider.GetPluginCollection(typeof (IDataBaseConnector))) { addnew.ChildActions.Add(new Command(item.Name) { Execute = obj => { var con = PluginProvider.GetObjectInstance(item.MyType) as DBConnectorBase; con.Name = item.Name; _dbConnections.Add(con); } }); } commands.Add(dblistAction); dockableManager = MainFrmUI as IDockableManager; if (processManager?.CurrentProject != null) { LoadDataConnections(); } processManager.OnCurrentProjectChanged += (s, e) => LoadDataConnections(); ConfigUI = PropertyGridFactory.GetInstance(_dbConnections.FirstOrDefault()); propertyGridWindow = MainFrmUI.PluginDictionary["属性配置器"] as XFrmWorkPropertyGrid; var changed = DataCollections as INotifyCollectionChanged; changed.CollectionChanged += (s, e) => OnDataSourceChanged(new EventArgs()); return true; }