private bool DropAction(string sender, object attr) { if (sender == "Drop") { var objs = attr as object[]; if (objs.Count() == 2) { var p = objs[0] as SmartGroup; var t = objs[1] as XFrmWorkAttribute; var item = PluginProvider.GetObjectInstance(t.MyType) as IColumnProcess; if (string.IsNullOrEmpty(p.Name) == false) { item.Column = p.Name; } InsertModule(item); ETLMount++; RefreshSamples(); } } if (sender == "Click") { var smart = attr as SmartGroup; if (smart != null) { attr = smart.ColumnInfo; } var window = PropertyGridFactory.GetPropertyWindow(attr); window.Closed += (s, e) => RefreshSamples(); window.ShowDialog(); } if (sender != "Delete") { return(true); } var a = attr as IColumnProcess; if (MessageBox.Show("确实要删除" + a.TypeName + "吗?", "提示信息", MessageBoxButton.OKCancel) != MessageBoxResult.OK) { return(true); } CurrentETLTools.Remove(a); RefreshSamples(); return(true); }
private void ConfigParam() { PropertyGridFactory.GetPropertyWindow(this.Http).ShowDialog(); }
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 void RefreshSamples(bool canGetDatas = true) { if (shouldUpdate == false) { return; } if (SysProcessManager == null) { return; } if (!mudoleHasInit) { return; } OnPropertyChanged("AllETLMount"); var tasks = SysProcessManager.CurrentProcessTasks.Where(d => d.Publisher == this).ToList(); if (tasks.Any()) { var str = $"{Name}已经有任务在执行,由于调整参数,是否要取消当前任务重新执行?\n 【取消】:【不再提醒】"; if (isErrorRemind == false) { XLogSys.Print.Warn($"{Name}已经有任务在执行,请在任务管理器中取消该任务后再刷新"); return; } if (!MainDescription.IsUIForm) { return; } var result = MessageBox.Show(str, "提示信息", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { foreach (var item in tasks) { item.Remove(); } XLogSys.Print.Warn(str + " 已经取消"); } else if (result == MessageBoxResult.Cancel) { isErrorRemind = false; } else { return; } } if (dataView == null && MainDescription.IsUIForm && IsUISupport) { var dock = MainFrm as IDockableManager ?? ControlExtended.DockableManager; var control = dock?.ViewDictionary.FirstOrDefault(d => d.Model == this); if (control != null) { if (control.View is IRemoteInvoke) { var invoke = control.View as IRemoteInvoke; invoke.RemoteFunc = DropAction; } dynamic dy = control.View; dataView = dy.DataList; scrollViewer = dy.ScrollViewer; alltoolList = dy.ETLToolList; currentToolList = dy.CurrentETLToolList; currentToolList.MouseDoubleClick += (s, e) => { if (e.ChangedButton != MouseButton.Left) { return; } var process = currentToolList.SelectedItem as IColumnProcess; if (process == null) { return; } var oldProp = process.UnsafeDictSerializePlus(); var window = PropertyGridFactory.GetPropertyWindow(process); window.Closed += (s2, e2) => { if ( (oldProp.IsEqual(process.UnsafeDictSerializePlus()) == false && IsAutoRefresh).SafeCheck ("检查模块参数是否修改", LogType.Debug)) { RefreshSamples(); } }; window.ShowDialog(); }; dragMgr = new ListViewDragDropManager <IColumnProcess>(currentToolList); dragMgr.ShowDragAdorner = true; alltoolList.MouseMove += (s, e) => { if (e.LeftButton == MouseButtonState.Pressed) { var attr = alltoolList.SelectedItem as XFrmWorkAttribute; if (attr == null) { return; } var data = new DataObject(typeof(XFrmWorkAttribute), attr); try { DragDrop.DoDragDrop(control.View as UserControl, data, DragDropEffects.Move); } catch (Exception ex) { } } }; } } if (dataView == null) { return; } Analyzer.Items.Clear(); var alltools = CurrentETLTools.Take(ETLMount).ToList(); var func = alltools.Aggregate(isexecute: false, analyzer: Analyzer); if (!canGetDatas) { return; } SmartGroupCollection.Clear(); Documents.Clear(); shouldUpdate = false; var i = 0; foreach (var currentEtlTool in CurrentETLTools) { (currentEtlTool).ETLIndex = i++; } shouldUpdate = true; if (!MainDescription.IsUIForm) { return; } all_columns.Clear(); dataView.Columns.Clear(); AddColumn("", alltools); var temptask = TemporaryTask.AddTempTask(Name + "_转换", func(new List <IFreeDocument>()).Take(SampleMount), data => { ControlExtended.UIInvoke(() => { foreach (var key in data.GetKeys().Where(d => all_columns.Contains(d) == false).OrderBy(d => d)) { AddColumn(key, alltools); DeleteColumn(""); all_columns.Add(key); } Documents.Add((data)); InitUI(); }); }, r => { var tool = CurrentTool; var outputCol = new List <string>(); var inputCol = new List <string>(); if (tool != null) { inputCol.Add(tool.Column); var transformer = tool as IColumnDataTransformer; if (transformer != null) { if (transformer is CrawlerTF) { var crawler = transformer as CrawlerTF; outputCol = crawler?.Crawler?.CrawlItems.Select(d => d.Name).ToList(); } else if (transformer is ETLBase) { var etl = transformer as ETLBase; var target = etl.GetModule <SmartETLTool>(etl.ETLSelector.SelectItem); outputCol = target?.Documents.GetKeys().ToList(); inputCol.AddRange(etl.MappingSet.Split(' ').Select(d => d.Split(':')[0])); } else { outputCol = transformer.NewColumn.Split(' ').ToList(); } SmartGroupCollection.Where(d => outputCol != null && outputCol.Contains(d.Name)) .Execute(d => d.GroupType = GroupType.Output); SmartGroupCollection.Where(d => inputCol.Contains(d.Name)) .Execute(d => d.GroupType = GroupType.Input); } } var firstOutCol = outputCol?.FirstOrDefault(); if (firstOutCol != null) { var index = all_columns.IndexOf(firstOutCol); if (index != -1 && ETLMount < AllETLMount) { scrollViewer.ScrollToHorizontalOffset(index * CellWidth); } } var nullgroup = SmartGroupCollection.FirstOrDefault(d => string.IsNullOrEmpty(d.Name)); nullgroup?.Value.AddRange( alltools.Where( d => Documents.GetKeys().Contains(d.Column) == false && string.IsNullOrEmpty(d.Column) == false)); nullgroup?.OnPropertyChanged("Value"); } , SampleMount); temptask.Publisher = this; temptask.IsSelected = true; SysProcessManager.CurrentProcessTasks.Add(temptask); }
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); }
private bool DropAction(string sender, object attr) { if (sender == "Drop") { var objs = attr as object[]; if (objs.Count() == 2) { var p = objs[0] as SmartGroup; var t = objs[1] as XFrmWorkAttribute; var item = PluginProvider.GetObjectInstance(t.MyType) as IColumnProcess; if (string.IsNullOrEmpty(p.Name) == false) { item.Column = p.Name; } item.Father = this; shouldUpdate = false; InsertModule(item); shouldUpdate = true; if (NeedConfig(item)) { var window = PropertyGridFactory.GetPropertyWindow(item); window.ShowDialog(); } ETLMount++; } } if (sender == "Click") { var smart = attr as SmartGroup; if (smart != null) { attr = smart.ColumnInfo; } var window = PropertyGridFactory.GetPropertyWindow(attr); var oldProp = attr.UnsafeDictSerializePlus(); window.Closed += (s, e) => { if (oldProp.IsEqual(attr.UnsafeDictSerializePlus()) == false && IsAutoRefresh) { RefreshSamples(); } }; window.ShowDialog(); } if (sender != "Delete") { return(true); } var a = attr as IColumnProcess; if (MessageBox.Show("确实要删除" + a.TypeName + "吗?", "提示信息", MessageBoxButton.OKCancel) != MessageBoxResult.OK) { return(true); } CurrentETLTools.Remove(a); if (IsAutoRefresh) { RefreshSamples(); } return(true); }
public virtual IEnumerable <IFreeDocument> TransformManyData(IEnumerable <IFreeDocument> datas) { var olddatas = datas; var errorCounter = 0; foreach (var data in datas) { var newdatas = InternalTransformManyData(data); if (MainDescription.IsUIForm) { if (((olddatas is IList) == false || !olddatas.Any()) && newdatas is IList && (!newdatas.Any())) { errorCounter++; if (errorCounter == 5 && isErrorRemind) { //连续三次无值输出,表示为异常现象 if (ControlExtended.UIInvoke(() => { var result = MessageBox.Show( $"作用在列名`{Column}`的 模块`{TypeName}` 已经连续 {5} 次没有成功获取数据,可能需要重新修改参数 \n【是】:【进入调试模式】 \n【否】:【取消当前任务】 \n【取消】:【不再提示】", "参数设置可能有误", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { var window = PropertyGridFactory.GetPropertyWindow(this); var list = processManager.CurrentProcessTasks.Where( task => task.Publisher == Father && task.IsPause == false).ToList(); list.Execute(task => task.Remove()); // window.Closed += (s, e) => Father.ETLMount++; Father.ETLMount = Math.Max(0, Father.CurrentETLTools.IndexOf(this)); window.ShowDialog(); window.Topmost = true; return(true); } else if (result == MessageBoxResult.Cancel) { isErrorRemind = false; return(true); } return(false); }) == false) { yield break; } } } else { errorCounter = 0; } } if (newdatas == null) { yield break; } foreach (var newdata in newdatas) { yield return(newdata); } } }
public virtual IEnumerable <IFreeDocument> TransformManyData(IEnumerable <IFreeDocument> datas, AnalyzeItem analyzer = null) { var olddatas = datas; var errorCounter = 0; foreach (var data in datas) { IEnumerable <IFreeDocument> newdatas = null; try { DateTime now = DateTime.Now; newdatas = InternalTransformManyData(data); if (analyzer != null) { analyzer.RunningTime += DateTime.Now - now; } } catch (Exception ex) { if (analyzer != null) { analyzer.Analyzer.AddErrorLog(data, ex, this); } else { XLogSys.Print.Error(string.Format(GlobalHelper.Get("key_208"), this.Column, this.TypeName, ex)); } } if (MainDescription.IsUIForm) { if (((olddatas is IList) == false || !olddatas.Any()) && newdatas is IList && (!newdatas.Any())) { errorCounter++; if (errorCounter == 5 && isErrorRemind) { //连续三次无值输出,表示为异常现象 if (ControlExtended.UIInvoke(() => { var result = MessageBox.Show( string.Format(GlobalHelper.Get("fail_remind"), Column, TypeName), GlobalHelper.Get("key_570"), MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { var window = PropertyGridFactory.GetPropertyWindow(this); var list = processManager.CurrentProcessTasks.Where( task => task.Publisher == Father && task.IsPause == false).ToList(); list.Execute(task => task.Remove()); // window.Closed += (s, e) => Father.ETLMount++; Father.ETLMount = Math.Max(0, Father.CurrentETLTools.IndexOf(this)); window.ShowDialog(); window.Topmost = true; return(true); } if (result == MessageBoxResult.Cancel) { isErrorRemind = false; return(true); } return(false); }) == false) { yield break; } } } else { errorCounter = 0; } } if (newdatas == null) { continue; } foreach (var newdata in newdatas) { yield return(newdata); } } }
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); }