/// <summary> /// 在集合中获取一个实例,若无该实例,将搜索插件,并自动添加之 /// </summary> /// <param name="name"></param> /// <param name="isAddToList">是否要加入列表,被托管 </param> /// <returns></returns> public static T Get <T>(this ICollection <T> collection, string name, bool?isAddToList = true) where T : class, IProcess { var process = collection.FirstOrDefault(d => name == d.GetType().Name); if (process != null) { return(process); } var newProcess = PluginProvider.GetPluginCollection(typeof(T)).FirstOrDefault(d => d.Name == name); if (newProcess == null) { // throw new Exception(string.Format("要获取的插件{0}无法在插件集合中找到")); return(null); } if (isAddToList == true) { collection.Add(newProcess.MyType); var newone = collection.FirstOrDefault(d => name == d.GetType().Name); return(newone); } var plugin = PluginProvider.GetObjectInstance(newProcess.MyType) as T; return(plugin); }
static FileConnector() { ConnectorDictionary = new Dictionary <XFrmWorkAttribute, string>(); foreach (XFrmWorkAttribute item in PluginProvider.GetPluginCollection(typeof(IFileConnector))) { var ins = PluginProvider.GetObjectInstance(item.MyType) as IFileConnector; ConnectorDictionary.Add(item, ins.ExtentFileName); } }
public FileDataTransformer() { ConnectorSelector = new ExtendSelector <XFrmWorkAttribute>(PluginProvider.GetPluginCollection(typeof(IFileConnector))); ConnectorSelector.SelectChanged += (s, e) => { Connector = PluginProvider.GetObjectInstance <IFileConnector>(ConnectorSelector.SelectItem.Name); OnPropertyChanged("Connector"); }; Enabled = false; }
public ReadFileTF() { ConnectorSelector = new ExtendSelector <XFrmWorkAttribute>(PluginProvider.GetPluginCollection(typeof(IFileConnector))); ConnectorSelector.SelectChanged += (s, e) => { if (ConnectorSelector.SelectItem == null) { return; } Connector = PluginProvider.GetObjectInstance <IFileConnector>(ConnectorSelector.SelectItem.Name); OnPropertyChanged("Connector"); }; Enabled = false; }
public ProxyProvider() { ProxyStrategy = ProxyStrategy.NoAgent; MaxVisitCount = 100000; Proxies = new ObservableCollection <Proxy>(); ParaGeneratorSelector = new ExtendSelector <XFrmWorkAttribute>(PluginProvider.GetPluginCollection(typeof(IColumnGenerator))); ParaGeneratorSelector.SelectChanged += (s, e) => { ParaGenerator = PluginProvider.GetObjectInstance <IColumnGenerator>(ParaGeneratorSelector.SelectItem.Name); ParaGenerator.Column = "ProxyIp"; OnPropertyChanged("ParaGenerator"); }; ParaGeneratorSelector.SelectItem = ParaGeneratorSelector.Collection.FirstOrDefault(d => d.Name == "从文本生成"); }
public static string GetAllToolMarkdownDoc() { var sb = new StringBuilder(); var tools = PluginProvider.GetPluginCollection(typeof(IColumnProcess)); var groupConverter = new GroupConverter(); foreach (var toolgroup in tools.GroupBy(d => groupConverter.Convert(d, null, null, null))) { sb.Append(string.Format("# {0}\n", toolgroup.Key)); foreach (var tool in toolgroup) { sb.Append(GetMarkdownScript(tool.MyType, true)); } } return(sb.ToString()); }
public void DictDeserialize(IDictionary <string, object> docu, Scenario scenario = Scenario.Database) { this.UnsafeDictDeserialize(docu); if (docu.ContainsKey("ParaGenerator")) { List <XFrmWorkAttribute> coll = PluginProvider.GetPluginCollection(typeof(IColumnGenerator)); object doc2 = docu["ParaGenerator"]; var p = doc2 as IDictionary <string, object>; object name = p["Type"]; if (name != null) { ParaGeneratorSelector.SelectItem = coll.FirstOrDefault(d => d.Name == name.ToString()); ParaGenerator?.DictDeserialize(p); } } }
public SmartETLTool() { AllETLTools = new List <XFrmWorkAttribute>(); CurrentETLTools = new ObservableCollection <IColumnProcess>(); Dict = new ObservableCollection <SmartGroup>(); Documents = new ObservableCollection <IFreeDocument>(); SampleMount = 20; MaxThreadCount = 20; IsUISupport = true; AllETLTools.AddRange( PluginProvider.GetPluginCollection(typeof(IColumnProcess))); if (MainDescription.IsUIForm) { ETLToolsView = new ListCollectionView(AllETLTools); ETLToolsView.GroupDescriptions.Clear(); ETLToolsView.GroupDescriptions.Add(new PropertyGroupDescription("Self", new GroupConverter())); } }
public override void DictDeserialize(IDictionary <string, object> docu, Scenario scenario = Scenario.Database) { this.UnsafeDictDeserialize(docu); if (docu.ContainsKey("Connector")) { var coll = PluginProvider.GetPluginCollection(typeof(IFileConnector)); var doc2 = docu["Connector"]; var p = doc2 as IDictionary <string, object>; var name = p["Type"]; if (name != null) { var result = coll.FirstOrDefault(d => d.MyType.Name == name.ToString()); ConnectorSelector.SelectItem = result; Connector?.DictDeserialize(p); } } }
public SmartETLTool() { AllETLTools = new List <XFrmWorkAttribute>(); CurrentETLTools = new ObservableCollection <IColumnProcess>(); SmartGroupCollection = new ObservableCollection <SmartGroup>(); Documents = new ObservableCollection <IFreeDocument>(); SampleMount = 20; MaxThreadCount = 20; IsUISupport = true; Analyzer = new Analyzer(); IsAutoRefresh = true; AllETLTools.AddRange( PluginProvider.GetPluginCollection(typeof(IColumnProcess))); if (MainDescription.IsUIForm) { ETLToolsView = new ListCollectionView(AllETLTools); ETLToolsView.GroupDescriptions.Clear(); ETLToolsView.GroupDescriptions.Add(new PropertyGroupDescription("Self", new GroupConverter())); ETLToolsView.SortDescriptions.Add(new SortDescription("GroupName", ListSortDirection.Ascending)); ETLToolsView.CustomSort = new NameComparer(); } }
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 = null; try { dataAll = await GetDataFromDB(items.Connector, items.Name, true, items.Connector is FileManager ? -1 : 200); } catch (Exception ex) { MessageBox.Show("文件打开失败" + ex.Message); return; } 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); }
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); }
public override bool Init() { if (MainDescription.IsUIForm) { DataCollections = new SafeObservable <DataCollection>(); dockableManager = MainFrmUI as IDockableManager; var views = "223:Mini 794:Middle"; foreach (var item in views.Split(' ')) { var item2 = item.Split(':'); var name = item2[0]; var control = FrmState.Mini; Enum.TryParse(item2[1], out control); var itemName = "key_" + name; itemName = GlobalHelper.Get(itemName); var view = PluginProvider.GetObjectInstance <ICustomView>(GlobalHelper.Get(itemName)); var userControl = view as UserControl; if (userControl != null) { if (name == "223") { dynamic dcontrol = userControl; dataListBox = dcontrol.dataListBox as ListBox; } userControl.DataContext = MainFrmUI; dockableManager.AddDockAbleContent(control, view, itemName); } } } else { DataCollections = new ObservableCollection <DataCollection>(); } processManager = MainFrmUI.PluginDictionary["DataProcessManager"] as IProcessManager; commands = new List <ICommand>(); var dbaction = new BindingAction(); dbaction.ChildActions.Add(new Command(GlobalHelper.Get("key_224"), obj => { var w = PropertyGridFactory.GetPropertyWindow(obj); w.ShowDialog(); }, obj => obj != null, "edit")); dbaction.ChildActions.Add( new Command(GlobalHelper.Get("key_142"), obj => RefreshConnect(obj as IDataBaseConnector), obj => obj != null, "refresh")); dbaction.ChildActions.Add( new Command(GlobalHelper.Get("key_213"), 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()); }; PropertyGridFactory.GetPropertyWindow(query).ShowDialog(); }, obj => obj != null, "magnify")); dbaction.ChildActions.Add( new Command(GlobalHelper.Get("key_225"), obj => { if ( MessageBox.Show(GlobalHelper.Get("key_226"), GlobalHelper.Get("key_99"), MessageBoxButton.YesNoCancel) == MessageBoxResult.Yes) { var con = obj as DBConnectorBase; _dbConnections.Remove(con); } }, obj => obj != null, "delete")); var dataaction = new BindingAction(); var tableAction = new BindingAction(); tableAction.ChildActions.Add(new Command( GlobalHelper.Get("view"), async obj => { var items = obj as TableInfo; List <IFreeDocument> dataAll = null; try { dataAll = await GetDataFromDB(items.Connector, items.Name, true, items.Connector is FileManager ? -1 : 200); } catch (Exception ex) { MessageBox.Show(GlobalHelper.Get("key_228") + ex.Message); return; } if (dataAll == null || dataAll.Count == 0) { XLogSys.Print.Warn(GlobalHelper.Get("key_229")); return; } if (items.Connector is FileManager) { var file = (items.Connector as FileManager).LastFileName; var name = Path.GetFileNameWithoutExtension(file); AddDataCollection(dataAll, name, isCover: true); return; } var excel = PluginProvider.GetObjectInstance <IDataViewer>(GlobalHelper.Get("key_230")); if (excel == null) { return; } var view = excel.SetCurrentView(dataAll.Select(d => d).ToList()); if (ControlExtended.DockableManager != null) { ControlExtended.DockableManager.AddDockAbleContent( FrmState.Custom, view, items.Name); } }, obj => obj != null)); tableAction.ChildActions.Add(new Command( GlobalHelper.Get("key_231"), async obj => { var items = obj as TableInfo; var datas = await GetDataFromDB(items.Connector, items.Name, true); if (datas == null) { return; } AddDataCollection(datas, items.Name); }, obj => obj != null, "add")); tableAction.ChildActions.Add(new Command( GlobalHelper.Get("key_232"), obj => { var con = obj as TableInfo; ReadCollection(con.Connector, con.Name, true); }, obj => obj != null, "layer_add")); tableAction.ChildActions.Add(new Command( GlobalHelper.Get("key_233"), obj => { var items = obj as TableInfo; DropTable(items.Connector, items.Name); }, obj => obj != null, "delete")); tableAction.ChildActions.Add(new Command( GlobalHelper.Get("key_234"), obj => { var w = PropertyGridFactory.GetPropertyWindow(obj); w.ShowDialog(); }, obj => obj != null, "edit")); tableAction.ChildActions.Add(new Command( GlobalHelper.Get("key_213"), 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()); }; PropertyGridFactory.GetPropertyWindow(query).ShowDialog(); }, obj => obj != null, "magnify")); var visitData = new BindingAction(GlobalHelper.Get("key_235")); var 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(GlobalHelper.Get("key_236"), GlobalHelper.Get("key_99")); return; } ControlExtended.UIInvoke(() => { var view = PluginProvider.GetObjectInstance <IDataViewer>(d.Name); var r = view.SetCurrentView(data.ComputeData); if (ControlExtended.DockableManager != null) { var window = new Window { Title = data.Name + " " + d.Name }; window.WindowState = WindowState.Maximized; window.Content = r; window.Activate(); window.ShowDialog(); } }); }; return(comm); }); visitData.Execute = obj => visitCommands.FirstOrDefault(d => d.Text == GlobalHelper.Get("key_230")).Execute(obj); foreach (var visitCommand in visitCommands) { visitData.ChildActions.Add(visitCommand); } dataaction.ChildActions.Add(new Command( GlobalHelper.Get("smartetl_name"), obj => { var collection = GetSelectedCollection(obj).FirstOrDefault(); if (collection == null) { return; } var plugin = processManager.GetOneInstance("SmartETLTool", true, true, true) as SmartETLTool; dynamic generator = PluginProvider.GetObjectByType <IColumnProcess>("TableGE"); generator.Father = plugin; generator.TableSelector.SelectItem = collection.Name; plugin.CurrentETLTools.Add(generator); plugin.ETLMount++; plugin.Init(); //plugin.RefreshSamples(true); ControlExtended.DockableManager.ActiveModelContent(plugin); }, obj => true, "new")); var saveData = new Command(GlobalHelper.Get("key_237"), d => { var collection = GetSelectedCollection(d).FirstOrDefault(); if (collection == null) { return; } var ofd = new SaveFileDialog { Filter = FileConnector.GetDataFilter(), DefaultExt = "*" }; ofd.FileName = collection.Name + ".xlsx"; if (ofd.ShowDialog() == true) { var filename = ofd.FileName; SaveFile(collection.Name, filename); } }, obj => true, "save"); dataaction.ChildActions.Add(saveData); dataaction.ChildActions.Add(visitData); dataaction.ChildActions.Add(new Command( GlobalHelper.Get("key_238"), obj => { if (obj != null) { foreach (var collection in GetSelectedCollection(obj)) { if (collection == null) { return; } var n = collection.Clone(true); n.Name = GetNewName(collection.Name); DataCollections.Add(n); } } else { DataCollections.Add(new DataCollection(new List <IFreeDocument>()) { Name = GetNewName(GlobalHelper.Get("key_239")) }); } ; }, obj => true, "add")); dataaction.ChildActions.Add(new Command( GlobalHelper.Get("key_240"), obj => { var collection = GetSelectedCollection(obj).ToList(); if (!collection.Any()) { return; } PropertyGridFactory.GetPropertyWindow(collection.FirstOrDefault()).ShowDialog(); }, obj => true, "settings")); dataaction.ChildActions.Add(new Command( GlobalHelper.Get("key_169"), obj => { foreach (var collection in GetSelectedCollection(obj)) { if (collection != null) { DataCollections.Remove(collection); } } }, obj => true, "delete")); var convert = new BindingAction(GlobalHelper.Get("key_241")); dataaction.ChildActions.Add(convert); convert.ChildActions.Add(new Command(GlobalHelper.Get("key_242"), obj => { var coll = GetSelectedCollection(obj).FirstOrDefault(); if (coll == null) { return; } if (coll.Count > 500000) { if ( MessageBox.Show(GlobalHelper.Get("key_243"), GlobalHelper.Get("key_99"), MessageBoxButton.YesNoCancel) != MessageBoxResult.Yes) { return; } } var docuts = new List <IFreeDocument>(); var task = TemporaryTask <FreeDocument> .AddTempTaskSimple(GlobalHelper.Get("key_242"), coll.ComputeData, d => { if (d != null) { docuts.Add(d); } }, result => { var collection = new DataCollection(docuts) { Name = coll.Name + '1' }; AddDataCollection(collection); DataCollections.Remove(coll); }); processManager.CurrentProcessTasks.Add(task); })); var insertdb = new BindingAction(GlobalHelper.Get("key_244")); insertdb.SetChildActionSource(() => { return(_dbConnections.Select(dataBaseConnector => new Command(dataBaseConnector.Name, obj => { var data = obj as DataCollection; processManager.CurrentProcessTasks.Add( TemporaryTask <FreeDocument> .AddTempTaskSimple(data.Name + GlobalHelper.Get("key_245"), dataBaseConnector.InserDataCollection(data), null, continueAction: (a) => dataBaseConnector.RefreshTableNames(), count: data.Count / 1000)); }, obj => dataBaseConnector.IsUseable, icon: "database")).Cast <ICommand>().ToList()); }); dataaction.ChildActions.Add(insertdb); var otherDataAction = new BindingAction(); otherDataAction.ChildActions.Add(new Command(GlobalHelper.Get("key_132"), obj => CleanData(), obj => DataCollections.Count > 0, "clear")); commands.Add(dbaction); commands.Add(tableAction); commands.Add(dataaction); commands.Add(otherDataAction); var dblistAction = new BindingAction(GlobalHelper.Get("key_246")); var addnew = new BindingAction(GlobalHelper.Get("key_247")) { Icon = "add" }; dblistAction.ChildActions.Add(addnew); foreach (var 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); }, Icon = "connect" }); } commands.Add(dblistAction); dockableManager = MainFrmUI as IDockableManager; if (processManager?.CurrentProject != null) { LoadDataConnections(processManager.CurrentProject.DBConnections); } if (MainDescription.IsUIForm) { ConfigUI = PropertyGridFactory.GetInstance(_dbConnections.FirstOrDefault()); } var changed = DataCollections as INotifyCollectionChanged; changed.CollectionChanged += (s, e) => OnDataSourceChanged(new EventArgs()); return(true); }
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); }
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); }
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); }