private void AddNewItem(bool isAlert = true) { var path = SelectXPath; if (!string.IsNullOrEmpty(RootXPath)) { //TODO: 当XPath路径错误时,需要捕获异常 HtmlNode root = null; try { root = HtmlDoc.DocumentNode.SelectSingleNode(RootXPath); } catch (Exception ex) { XLogSys.Print.Error($"{RootXPath} 不能被识别为正确的XPath表达式,请检查"); } if (!(root != null).SafeCheck("使用当前父节点XPath,在文档中找不到任何父节点")) { return; } root = HtmlDoc.DocumentNode.SelectSingleNode(RootXPath)?.ParentNode; HtmlNode node = null; if ( !ControlExtended.SafeInvoke(() => HtmlDoc.DocumentNode.SelectSingleNode(path), ref node, LogType.Info, "检查子节点XPath正确性", true)) { return; } if (!(node != null).SafeCheck("使用当前子节点XPath,在文档中找不到任何子节点")) { return; } if (!node.IsAncestor(root) && isAlert) { if ( MessageBox.Show("当前XPath所在节点不是父节点的后代,请检查对应的XPath,是否依然要添加?", "提示信息", MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } } path = XPath.TakeOff(node.XPath, root.XPath); } if (CrawlItems.FirstOrDefault(d => d.Name == SelectName) == null || MessageBox.Show("已经存在同名的属性,是否依然添加?", "提示信息", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { var item = new CrawlItem { XPath = path, Name = SelectName, SampleData1 = SelectText }; CrawlItems.Add(item); SelectXPath = ""; SelectName = ""; XLogSys.Print.Info("成功添加属性"); } }
public void StartVisit() { if (IsRunning) { return; } if (string.IsNullOrWhiteSpace(SelectText)) { MessageBox.Show("请填写包含在页面中的关键字信息:【2.属性提取】->【搜索字符】"); return; } ControlExtended.SafeInvoke(() => { var url = URL; if (url.StartsWith("http") == false) { url = "http://" + url; } CONFIG.bMITM_HTTPS = true; FiddlerApplication.AfterSessionComplete += FiddlerApplicationAfterSessionComplete; FiddlerApplication.Startup(8888, true, true); System.Diagnostics.Process.Start(url); OnPropertyChanged("IsRunning"); }, LogType.Important, "启动嗅探服务"); }
public void StartVisit() { if (IsRunning) { return; } if (string.IsNullOrWhiteSpace(SelectText)) { MessageBox.Show("请填写包含在页面中的关键字信息:【2.属性提取】->【搜索字符】"); return; } ControlExtended.SafeInvoke(() => { IsJson2xml = true; var url = URL; if (url.StartsWith("http") == false) { url = "http://" + url; } System.Diagnostics.Process.Start(url); FiddlerApplication.BeforeResponse += FiddlerApplicationAfterSessionComplete; FiddlerApplication.Startup(8888, FiddlerCoreStartupFlags.Default); IsRunning = FiddlerApplication.IsStarted(); OnPropertyChanged("IsRunning"); }, LogType.Important, "请在关闭软件前关闭嗅探服务。【否则可能无法正常上网】,尝试启动服务"); }
private async void VisitUrlAsync() { if (!enableRefresh) { return; } URLHTML = await MainFrm.RunBusyWork(() => { HttpStatusCode code; return(GetHtml(URL, out code)); }); if (URLHTML.Contains("尝试自动重定向") && MessageBox.Show("网站提示: " + URLHTML + "\n 通常原因是网站对请求合法性做了检查, 建议填写关键字对网页内容进行自动嗅探", "提示信息", MessageBoxButton.OK) == MessageBoxResult.OK) { return; } ControlExtended.SafeInvoke(() => HtmlDoc.LoadHtml(URLHTML), name: "解析html文档"); if (string.IsNullOrWhiteSpace(selectText) == false) { currentXPaths = HtmlDoc.SearchXPath(SelectText, () => IsAttribute).GetEnumerator(); GetXPathAsync(); } OnPropertyChanged("URLHTML"); }
private void SaveCurrentProject(bool isDefaultPosition = true) { if (currentProject == null) { return; } if (CurrentProject.Tasks.Any() == false && MessageBox.Show("当前工程中没有包含任何任务,请在任务管理页中,将要保存的任务插入到当前工程中", "警告信息", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } if (isDefaultPosition) { ControlExtended.SafeInvoke(() => currentProject.Save(), LogType.Important, "保存当前工程"); var pro = ConfigFile.GetConfig <DataMiningConfig>().Projects.FirstOrDefault(); if (pro != null) { pro.SavePath = currentProject.SavePath; } } else { currentProject.SavePath = null; ControlExtended.SafeInvoke(() => currentProject.Save(), LogType.Important, "另存为当前工程"); } ConfigFile.Config.SaveConfig(); }
private void SaveCurrentProject(bool isDefaultPosition = true) { if (CurrentProject == null) { return; } SaveCurrentTasks(); if (CurrentProject.Tasks.Any() == false && MessageBox.Show(GlobalHelper.Get("key_316"), GlobalHelper.Get("key_151"), MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } if (isDefaultPosition) { ControlExtended.SafeInvoke(() => CurrentProject.Save(dataManager.DataCollections), LogType.Important, GlobalHelper.Get("key_317")); var pro = ConfigFile.GetConfig <DataMiningConfig>().Projects.FirstOrDefault(); if (pro != null) { pro.SavePath = CurrentProject.SavePath; } } else { CurrentProject.SavePath = null; ControlExtended.SafeInvoke(() => CurrentProject.Save(dataManager.DataCollections), LogType.Important, GlobalHelper.Get("key_318")); } ConfigFile.Config.SaveConfig(); }
public void StartVisit() { if (IsRunning) { return; } if (string.IsNullOrWhiteSpace(SelectText) && ConfigFile.Config.Get <bool>("AutoStartStopFiddler") == true) { MessageBox.Show(GlobalHelper.Get("remind_10")); return; } ControlExtended.SafeInvoke(() => { var url = URL; if (url.StartsWith("http") == false) { url = "http://" + url; } CONFIG.IgnoreServerCertErrors = true; CONFIG.bMITM_HTTPS = true; FiddlerApplication.AfterSessionComplete += FiddlerApplicationAfterSessionComplete; var port = ConfigFile.Config.Get <int>("FiddlerPort"); FiddlerApplication.Startup(port, true, true, true); System.Diagnostics.Process.Start(url); XLogSys.Print.Info(GlobalHelper.FormatArgs("fiddler_start", "localhost", port)); OnPropertyChanged("IsRunning"); }, LogType.Important, GlobalHelper.Get("key_661")); }
public void StartVisit() { if (IsRunning) { return; } if (string.IsNullOrEmpty(URLFilter) && string.IsNullOrEmpty(this.ContentFilter)) { MessageBox.Show("请填写至少填写URL前缀或关键字中一项过滤规则"); return; } ControlExtended.SafeInvoke(() => { if (CanSave) { Documents.Clear(); } var url = URL; if (url.StartsWith("http") == false) { url = "http://" + url; } System.Diagnostics.Process.Start(url); FiddlerApplication.BeforeResponse += FiddlerApplicationAfterSessionComplete; FiddlerApplication.Startup(8888, FiddlerCoreStartupFlags.Default); IsRunning = FiddlerApplication.IsStarted(); OnPropertyChanged("IsRunning"); }, LogType.Important, "尝试启动服务"); }
public DataCollection ReadFile(string fileName, string format = null) { IFileConnector exporter = null; if (format != null) { exporter = PluginProvider.GetObjectInstance <IFileConnector>(format); } else { exporter = FileConnector.SmartGetExport(fileName); } if (exporter == null) { return(null); } exporter.FileName = fileName; fileName = exporter.FileName; ControlExtended.SafeInvoke( () => AddDataCollection(exporter.ReadFile(), Path.GetFileNameWithoutExtension(fileName)), LogType.Important); return(GetCollection(fileName)); }
private async void VisitUrlAsync() { if (!enableRefresh) { return; } if (hasInit == false) { return; } URLHTML = await MainFrm.RunBusyWork(() => { HttpStatusCode code; ConfigFile.GetConfig <DataMiningConfig>().RequestCount++; return(GetHtml(URL, out code)); }, title : GlobalHelper.Get("long_visit_web")); if (URLHTML.Contains(GlobalHelper.Get("key_671")) && MessageBox.Show(GlobalHelper.Get("key_672") + URLHTML + GlobalHelper.Get("key_673"), GlobalHelper.Get("key_99"), MessageBoxButton.OK) == MessageBoxResult.OK) { return; } ControlExtended.SafeInvoke(() => { HtmlDoc.LoadHtml(URLHTML); if (MainDescription.IsUIForm) { var dock = MainFrm as IDockableManager ?? ControlExtended.DockableManager; var control = dock?.ViewDictionary.FirstOrDefault(d => d.Model == this); if (control != null) { dynamic invoke = control.View; if (IsSuperMode == false) { invoke.UpdateHtml(URLHTML); OnPropertyChanged("HtmlDoc"); } else { invoke.UpdateHtml(GlobalHelper.Get("key_674")); } } } }, name: GlobalHelper.Get("key_675")); if (string.IsNullOrWhiteSpace(selectText) == false) { currentXPaths = HtmlDoc.SearchXPath(SelectText, () => IsAttribute).GetEnumerator(); GetXPathAsync(); } OnPropertyChanged("URLHTML"); }
private async void VisitUrlAsync() { if (!enableRefresh) { return; } if (hasInit == false) { return; } URLHTML = await MainFrm.RunBusyWork(() => { HttpStatusCode code; RequestManager.Instance.RequestCount++; return(GetHtml(URL, out code)); }); if (URLHTML.Contains("尝试自动重定向") && MessageBox.Show("网站提示: " + URLHTML + "\n 通常原因是网站对请求合法性做了检查, 建议填写关键字对网页内容进行自动嗅探", "提示信息", MessageBoxButton.OK) == MessageBoxResult.OK) { return; } ControlExtended.SafeInvoke(() => { HtmlDoc.LoadHtml(URLHTML); if (MainDescription.IsUIForm) { var dock = MainFrm as IDockableManager ?? ControlExtended.DockableManager; var control = dock?.ViewDictionary.FirstOrDefault(d => d.Model == this); if (control != null) { dynamic invoke = control.View; if (IsSuperMode == false) { invoke.UpdateHtml(URLHTML); OnPropertyChanged("HtmlDoc"); } else { invoke.UpdateHtml("超级模式下内置浏览器不展示内容,请查看左侧的文本内容"); } } } }, name: "解析html文档"); if (string.IsNullOrWhiteSpace(selectText) == false) { currentXPaths = HtmlDoc.SearchXPath(SelectText, () => IsAttribute).GetEnumerator(); GetXPathAsync(); } OnPropertyChanged("URLHTML"); }
private void SafeConnectDB() { ControlExtended.SafeInvoke(() => ConnectDB(), LogType.Important, GlobalHelper.Get("connect_db")); if (IsUseable) { RefreshTableNames(); } }
private void SafeConnectDB() { ControlExtended.SafeInvoke(() => ConnectDB(), LogType.Important, "连接数据库"); if (IsUseable) { RefreshTableNames(); } }
public override IEnumerable <IFreeDocument> ReadFile(Action <int> alreadyGetSize = null) { var xdoc = new XmlDocument(); ControlExtended.SafeInvoke(() => xdoc.Load(FileName), Utils.Logs.LogType.Important); return(ReadText(xdoc, alreadyGetSize)); }
void ICommand.Execute(object parameter) { Analytics.TrackEvent(this.Text, new Dictionary <string, string> { { "Parameter", parameter == null?"null":parameter.ToString() }, { "Description", Description } }); ControlExtended.SafeInvoke(() => Execute?.Invoke(parameter), LogType.Info, GlobalHelper.Get("key_133") + this.Text); //HockeyClient.Current.TrackEvent(this.Text); }
public override IEnumerable <IFreeDocument> Generate(IFreeDocument document = null) { ControlExtended.SafeInvoke(() => { var content = AppHelper.Query(Content, document); argsList = content.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList(); }); return(argsList.Select(doc => new FreeDocument { { this.Column, doc } })); }
public override bool Init(IEnumerable <IFreeDocument> datas) { if (string.IsNullOrEmpty(Content)) { return(base.Init(datas)); } ControlExtended.SafeInvoke(() => { var content = AppHelper.Query(Content); argsList = content.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList(); }); return(base.Init(datas)); }
public virtual IDataProcess Load(bool addui) { IDataProcess process = ProcessManager.GetTask(this.TaskType, this.Name); if (process != null) { return(process); } ControlExtended.SafeInvoke(() => { process = ProcessManager.GetOneInstance(this.TaskType, newOne: true, addUI: addui); ProcessToDo.DictCopyTo(process as IDictionarySerializable); process.Init(); EvalScript(); }, LogType.Important, string.Format(GlobalHelper.Get("key_327"), Name), MainDescription.IsUIForm); return(process); }
private void SaveCurrentProject(bool isDefaultPosition = true) { if (CurrentProject == null) { return; } CurrentProject.Tasks.Clear(); foreach (var process in CurrentProcessCollections) { SaveTask(process, false); } if (CurrentProject.Tasks.Any() == false && MessageBox.Show(GlobalHelper.Get("key_316"), GlobalHelper.Get("key_151"), MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } if (isDefaultPosition) { Task.Factory.StartNew(() => { ControlExtended.SetBusy(ProgressBarState.Indeterminate, message: GlobalHelper.Get("key_308")); ControlExtended.SafeInvoke(() => { CurrentProject.Save(dataManager.DataCollections); }, LogType.Important, GlobalHelper.Get("key_317")); var pro = ConfigFile.GetConfig <DataMiningConfig>().Projects.FirstOrDefault(); if (pro != null) { pro.SavePath = CurrentProject.SavePath; } ControlExtended.SetBusy(ProgressBarState.NoProgress); }); } else { CurrentProject.SavePath = null; ControlExtended.SafeInvoke(() => CurrentProject.Save(dataManager.DataCollections), LogType.Important, GlobalHelper.Get("key_318")); } ConfigFile.Config.SaveConfig(); }
private void SearchChild() { if (string.IsNullOrWhiteSpace(XPath.SelectItem) == false) { List <HtmlNode> nodes = null; ControlExtended.SafeInvoke( () => nodes = HtmlDoc.DocumentNode.SelectNodesPlus(XPath.SelectItem, SelectorFormat.XPath).ToList()); ChildItems.Clear(); if (nodes == null) { XLogSys.Print.Info(GlobalHelper.Get("key_665")); return; } nodes.Execute(d => ChildItems.Add(new CrawlItem { XPath = d.XPath, SampleData1 = d.InnerHtml })); } }
public virtual void Load(bool addui) { if ( (ProcessManager.CurrentProcessCollections.FirstOrDefault(d => d.Name == this.Name) == null).SafeCheck("不能重复加载该任务") == false) { return; } ControlExtended.SafeInvoke(() => { var processname = ProcessToDo["Type"].ToString(); if (string.IsNullOrEmpty(processname)) { return; } var process = ProcessManager.GetOneInstance(processname, newOne: true, addUI: addui); ProcessToDo.DictCopyTo(process as IDictionarySerializable); process.Init(); EvalScript(); }, LogType.Important, $"加载{Name}任务", true); }
public void Build() { ParameterItem param; if (ConfigSelector?.SelectItem == null) { param = Parameters.FirstOrDefault(); } else { param = Parameters.FirstOrDefault(d => d.Name == ConfigSelector.SelectItem); } if (param == null) { Parameter = new Dictionary <string, string>(); return; } ControlExtended.SafeInvoke(() => Parameter = param.GetParameters(), LogType.Info, GlobalHelper.Get("parse_yaml_config")); }
public static async Task <Project> LoadFromUrl(string url) { var resquest = await WebRequest.Create(url).GetResponseAsync(); var response = resquest.GetResponseStream(); var fileConnector = new FileConnectorXML(); var proj = new Project(); ControlExtended.SafeInvoke(() => { var docs = fileConnector.ReadFile(response, url.EndsWith("hproj"), null); if (docs.Any() == false) { throw new Exception("TODO"); } var first = docs.FirstOrDefault(); DocumentToProject(first, proj); }, LogType.Info, GlobalHelper.Get("key_307")); return(proj); }
private void SaveCurrentProject(bool isDefaultPosition = true) { if (currentProject == null) { return; } if (isDefaultPosition) { ControlExtended.SafeInvoke(() => currentProject.Save(), LogType.Important, "保存当前工程"); var pro = ConfigFile.GetConfig <DataMiningConfig>().Projects.FirstOrDefault(); if (pro != null) { pro.SavePath = currentProject.SavePath; } } else { currentProject.SavePath = null; ControlExtended.SafeInvoke(() => currentProject.Save(), LogType.Important, "另存为当前工程"); } ConfigFile.Config.SaveConfig(); }
public IEnumerable <FreeDocument> ReadFile(Stream stream, bool iszip, Action <int> alreadyGetSize = null) { var xdoc = new XmlDocument(); if (iszip) { var zipstream = new ZipInputStream(stream); ZipEntry zipEntry = null; while ((zipEntry = zipstream.GetNextEntry()) != null) { var byteArrayOutputStream = new MemoryStream(); zipstream.CopyTo(byteArrayOutputStream); byte[] b = byteArrayOutputStream.ToArray(); string xml = System.Text.Encoding.UTF8.GetString(b, 0, b.Length); ControlExtended.SafeInvoke(() => xdoc.LoadXml(xml), LogType.Important); break; } } else { ControlExtended.SafeInvoke(() => xdoc.Load(stream), LogType.Important); } return(ReadText(xdoc, alreadyGetSize)); }
void ICommand.Execute(object parameter) { ControlExtended.SafeInvoke(() => Execute?.Invoke(parameter), LogType.Info, GlobalHelper.Get("key_133") + this.Text); }
private void AddNewItem(bool isAlert = true) { var path = SelectXPath; var rootPath = RootXPath; if (!string.IsNullOrEmpty(rootPath)) { //TODO: 当XPath路径错误时,需要捕获异常 HtmlNode root = null; try { root = HtmlDoc.DocumentNode.SelectSingleNodePlus(rootPath, RootFormat); } catch (Exception ex) { XLogSys.Print.Error($"{RootXPath} 不能被识别为正确的{RootFormat}表达式,请检查"); } if (!(root != null).SafeCheck($"使用当前父节点{RootFormat} {RootXPath},在文档中找不到任何父节点")) { return; } root = HtmlDoc.DocumentNode.SelectSingleNodePlus(rootPath, RootFormat)?.ParentNode; HtmlNode node = null; if ( !ControlExtended.SafeInvoke(() => HtmlDoc.DocumentNode.SelectSingleNodePlus(path, SearchFormat), ref node, LogType.Info, "检查子节点XPath正确性", true)) { return; } if (!(node != null).SafeCheck("使用当前子节点XPath,在文档中找不到任何子节点")) { return; } if (!node.IsAncestor(root) && isAlert) { if ( MessageBox.Show("当前XPath所在节点不是父节点的后代,请检查对应的XPath,是否依然要添加?", "提示信息", MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } } string attr = ""; string attrValue = ""; XPathAnalyzer.GetAttribute(path, out attr, out attrValue); if (SearchFormat == SelectorFormat.XPath) { path = XPath.TakeOffPlus(node.XPath, root.XPath); if (attr != "") { path += "/@" + attr + "[1]"; } } } if (CrawlItems.FirstOrDefault(d => d.Name == SelectName) == null || MessageBox.Show("已经存在同名的属性,是否依然添加?", "提示信息", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { var item = new CrawlItem { XPath = path, Name = SelectName, SampleData1 = SelectText }; item.Format = SearchFormat; CrawlItems.Add(item); SelectXPath = ""; SelectName = ""; XLogSys.Print.Info("成功添加属性"); } }
private void AddNewItem(bool isAlert = true) { var path = SelectXPath; var rootPath = RootXPath; if (!string.IsNullOrEmpty(rootPath)) { //TODO: 当XPath路径错误时,需要捕获异常 HtmlNode root = null; try { root = HtmlDoc.DocumentNode.SelectSingleNodePlus(rootPath, RootFormat); } catch (Exception) { XLogSys.Print.Error(string.Format(GlobalHelper.Get("key_662"), RootXPath, RootFormat)); } if (!(root != null).SafeCheck(string.Format(GlobalHelper.Get("key_663"), RootFormat, RootXPath))) { return; } root = HtmlDoc.DocumentNode.SelectSingleNodePlus(rootPath, RootFormat)?.ParentNode; HtmlNode node = null; if ( !ControlExtended.SafeInvoke(() => HtmlDoc.DocumentNode.SelectSingleNodePlus(path, SearchFormat), ref node, LogType.Info, GlobalHelper.Get("key_664"), true)) { return; } if (!(node != null).SafeCheck(GlobalHelper.Get("key_665"))) { return; } if (!node.IsAncestor(root) && isAlert) { if ( MessageBox.Show(GlobalHelper.Get("key_666"), GlobalHelper.Get("key_99"), MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } } string attr = ""; string attrValue = ""; XPathAnalyzer.GetAttribute(path, out attr, out attrValue); if (SearchFormat == SelectorFormat.XPath) { path = XPath.TakeOffPlus(node.XPath, root.XPath); if (attr != "") { path += "/@" + attr + "[1]"; } } } if (CrawlItems.FirstOrDefault(d => d.Name == SelectName) == null || MessageBox.Show(GlobalHelper.Get("add_column_sure"), GlobalHelper.Get("key_99"), MessageBoxButton.OKCancel) == MessageBoxResult.OK) { var item = new CrawlItem { XPath = path, Name = SelectName, SampleData1 = SelectText }; item.Format = SearchFormat; CrawlItems.Add(item); SelectXPath = ""; SelectName = ""; XLogSys.Print.Info(GlobalHelper.Get("key_668")); } }
void ICommand.Execute(object parameter) { ControlExtended.SafeInvoke(() => Execute?.Invoke(parameter), LogType.Info, "点击按钮: " + this.Text); }
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); }