From 8f0b230ae4a0c4c1f294d822a60d382664b1ff88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Tue, 29 Aug 2017 17:11:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ETL=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Areas/Admin/Controllers/FileController.cs | 14 +++--- XCode/Transform/ETL.cs | 11 +++-- XCode/Transform/IETLModule.cs | 43 +++++++++++++++++-- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/NewLife.Cube/Areas/Admin/Controllers/FileController.cs b/NewLife.Cube/Areas/Admin/Controllers/FileController.cs index cf88ef380a..ac20097998 100644 --- a/NewLife.Cube/Areas/Admin/Controllers/FileController.cs +++ b/NewLife.Cube/Areas/Admin/Controllers/FileController.cs @@ -57,12 +57,14 @@ private FileItem GetItme(String r) var inf = GetFile(r) as FileSystemInfo ?? GetDirectory(r); if (inf == null) return null; - var fi = new FileItem(); - fi.Name = inf.Name; - fi.FullName = GetFullName(inf.FullName); - fi.Raw = inf.FullName; - fi.Directory = inf is DirectoryInfo; - fi.LastWrite = inf.LastWriteTime; + var fi = new FileItem + { + Name = inf.Name, + FullName = GetFullName(inf.FullName), + Raw = inf.FullName, + Directory = inf is DirectoryInfo, + LastWrite = inf.LastWriteTime + }; if (inf is FileInfo) { diff --git a/XCode/Transform/ETL.cs b/XCode/Transform/ETL.cs index fd65130fef..303347d3f8 100644 --- a/XCode/Transform/ETL.cs +++ b/XCode/Transform/ETL.cs @@ -81,6 +81,8 @@ public ETL(IEntityOperate source) : this() /// 开始 public virtual void Start() { + Modules.Start(); + var ext = Extracter; if (ext == null) throw new ArgumentNullException(nameof(Extracter), "没有设置数据抽取器"); @@ -88,14 +90,14 @@ public virtual void Start() ext.Init(); if (Stat == null) Stat = new ETLStat(); - - Modules.Init(this); } /// 停止 public virtual void Stop() { _Inited = false; + + Modules.Stop(); } #endregion @@ -108,6 +110,8 @@ protected virtual Boolean Init(IExtractSetting set) { WriteLog("开始处理{0},区间({1} + {3:n0}, {2})", Name, set.Start, set.End, set.Row); + Modules.Init(); + return true; } @@ -115,10 +119,9 @@ protected virtual Boolean Init(IExtractSetting set) /// 返回抽取数据行数,没有数据返回0,初始化或配置失败返回-1 public virtual Int32 Process() { - if (!Modules.Processing()) return -1; + if (!Modules.Processing()) { _Inited = false; return -1; } var set = Extracter.Setting; - if (set == null) { _Inited = false; return -1; } if (!_Inited) { diff --git a/XCode/Transform/IETLModule.cs b/XCode/Transform/IETLModule.cs index 36e5921f78..7357d17cb6 100644 --- a/XCode/Transform/IETLModule.cs +++ b/XCode/Transform/IETLModule.cs @@ -9,23 +9,60 @@ namespace XCode.Transform /// 数据抽取模块,用于自定义抽取过程中各个环节 public interface IETLModule { - void Init(ETL etl); + /// 开始调度 + void Start(); + /// 停止调度 + void Stop(); + + /// 首次初始化任务 + void Init(); + + /// 单批数据处理前 + /// Boolean Processing(); + + /// 单批数据处理后 void Processed(); + /// 实体列表完成后 + /// + /// + /// + /// + /// void OnFinished(IList list, IExtractSetting set, Int32 success, Double fetchCost, Double processCost); + /// 出错 + /// + /// + /// void OnError(Object source, IExtractSetting set, Exception ex); } static class ETLModuleHelper { - public static void Init(this IEnumerable list, ETL etl) + public static void Start(this IEnumerable list) + { + foreach (var item in list) + { + item.Start(); + } + } + + public static void Stop(this IEnumerable list) + { + foreach (var item in list) + { + item.Stop(); + } + } + + public static void Init(this IEnumerable list) { foreach (var item in list) { - item.Init(etl); + item.Init(); } }