Skip to content

Commit

Permalink
优化ETL过滤模块
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Aug 29, 2017
1 parent 6f7a137 commit 8f0b230
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
14 changes: 8 additions & 6 deletions NewLife.Cube/Areas/Admin/Controllers/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 7 additions & 4 deletions XCode/Transform/ETL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,23 @@ public ETL(IEntityOperate source) : this()
/// <summary>开始</summary>
public virtual void Start()
{
Modules.Start();

var ext = Extracter;
if (ext == null) throw new ArgumentNullException(nameof(Extracter), "没有设置数据抽取器");

//if (ext.Setting == null) ext.Setting = new ExtractSetting();
ext.Init();

if (Stat == null) Stat = new ETLStat();

Modules.Init(this);
}

/// <summary>停止</summary>
public virtual void Stop()
{
_Inited = false;

Modules.Stop();
}
#endregion

Expand All @@ -108,17 +110,18 @@ protected virtual Boolean Init(IExtractSetting set)
{
WriteLog("开始处理{0},区间({1} + {3:n0}, {2})", Name, set.Start, set.End, set.Row);

Modules.Init();

return true;
}

/// <summary>抽取并处理一批数据</summary>
/// <returns>返回抽取数据行数,没有数据返回0,初始化或配置失败返回-1</returns>
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)
{
Expand Down
43 changes: 40 additions & 3 deletions XCode/Transform/IETLModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,60 @@ namespace XCode.Transform
/// <summary>数据抽取模块,用于自定义抽取过程中各个环节</summary>
public interface IETLModule
{
void Init(ETL etl);
/// <summary>开始调度</summary>
void Start();

/// <summary>停止调度</summary>
void Stop();

/// <summary>首次初始化任务</summary>
void Init();

/// <summary>单批数据处理前</summary>
/// <returns></returns>
Boolean Processing();

/// <summary>单批数据处理后</summary>
void Processed();

/// <summary>实体列表完成后</summary>
/// <param name="list"></param>
/// <param name="set"></param>
/// <param name="success"></param>
/// <param name="fetchCost"></param>
/// <param name="processCost"></param>
void OnFinished(IList<IEntity> list, IExtractSetting set, Int32 success, Double fetchCost, Double processCost);

/// <summary>出错</summary>
/// <param name="source"></param>
/// <param name="set"></param>
/// <param name="ex"></param>
void OnError(Object source, IExtractSetting set, Exception ex);
}

static class ETLModuleHelper
{
public static void Init(this IEnumerable<IETLModule> list, ETL etl)
public static void Start(this IEnumerable<IETLModule> list)
{
foreach (var item in list)
{
item.Start();
}
}

public static void Stop(this IEnumerable<IETLModule> list)
{
foreach (var item in list)
{
item.Stop();
}
}

public static void Init(this IEnumerable<IETLModule> list)
{
foreach (var item in list)
{
item.Init(etl);
item.Init();
}
}

Expand Down

0 comments on commit 8f0b230

Please sign in to comment.