Skip to content

Commit

Permalink
完成 API 帳號系統與初步 Restful API 嘗試
Browse files Browse the repository at this point in the history
  • Loading branch information
maxzh1999tw committed Feb 3, 2024
1 parent c5c3278 commit 8eb67b4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
26 changes: 26 additions & 0 deletions Excely.EPPlus.LGPL/Plugins/ErrorRecordPluginExtention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Excely.Plugins;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Excely.EPPlus.LGPL.Plugins
{
public static class ErrorRecordPluginExtention
{
public static ExcelWorksheet ExportToWorksheet(this ErrorRecordPlugin errorRecordPlugin, bool errorRowOnly)
{
if(errorRecordPlugin?.Table == null)
{
throw new ArgumentNullException();
}

for(int rowIndex = 0; rowIndex < errorRecordPlugin.Table.MaxRowCount; rowIndex++)
{
if(!errorRecordPlugin.Errors.Keys.Any(cell => cell.Row == row))
}
}
}
}
6 changes: 6 additions & 0 deletions Excely.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Excely.ClosedXML.UnitTests"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{05E1BF0C-B2F1-41C1-B5AB-52C001A3D557}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Debug", "Debug\Debug.csproj", "{7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,6 +43,10 @@ Global
{075DACAA-3E1D-46E6-B094-0E119B56673B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{075DACAA-3E1D-46E6-B094-0E119B56673B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{075DACAA-3E1D-46E6-B094-0E119B56673B}.Release|Any CPU.Build.0 = Release|Any CPU
{7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
19 changes: 19 additions & 0 deletions Excely/Plugins/ErrorRecordPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Excely.Plugins
{
public class ErrorRecordPlugin
{
public ExcelyTable? Table { get; set; }

public Dictionary<CellLocation, string> Errors { get; set; } = new Dictionary<CellLocation, string>();

public void DoAfterGetTable(ExcelyTable table)
{
Table = table;
}

public void RecordError(CellLocation location, string errorMessage)
{
Errors[location] = errorMessage;
}
}
}
8 changes: 4 additions & 4 deletions Excely/TableConverters/ClassListTableConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ private IEnumerable<TClass> ImportInternal(ExcelyTable table, Func<PropertyInfo,
continue;
}

// 取得欄位解析結果
var value = Options.PropertyValueSettingPolicy(property, table.Data[rowIndex][columnIndex]);

try
{
// 取得欄位解析結果
var value = Options.PropertyValueSettingPolicy(property, table.Data[rowIndex][columnIndex]);

// 嘗試自動轉型
if (value != null && Options.EnableAutoTypeConversion)
{
Expand Down Expand Up @@ -131,7 +131,7 @@ private IEnumerable<TClass> ImportInternal(ExcelyTable table, Func<PropertyInfo,
catch (Exception ex)
{
// 執行錯誤處理
var errorFixed = Options.ErrorHandlingPolicy(new CellLocation(rowIndex, columnIndex), obj, property, value, ex);
var errorFixed = Options.ErrorHandlingPolicy(new CellLocation(rowIndex, columnIndex), obj, property, table.Data[rowIndex][columnIndex], ex);

// 錯誤處理失敗,且要求停止
if (!errorFixed && Options.ThrowWhenError)
Expand Down
4 changes: 4 additions & 0 deletions Excely/Workflows/ExcelyImporterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public abstract class ExcelyImporterBase<TInput>
{
protected abstract ExcelyTable GetTable(TInput input);

public List<Action<ExcelyTable>> DoAfterGetTableCallbackList { get; set; } = new List<Action<ExcelyTable>>();

/// <summary>
/// 將資料匯入為物件列表。
/// </summary>
Expand All @@ -23,6 +25,7 @@ public IEnumerable<TClass> ToClassList<TClass>(
where TClass : class, new()
{
var table = GetTable(dataSource);
DoAfterGetTableCallbackList.ForEach(x => x.Invoke(table));
var converter = options == null ? new ClassListTableConverter<TClass>() : new ClassListTableConverter<TClass>(options);
return converter.ConvertFrom(table);
}
Expand All @@ -38,6 +41,7 @@ public IEnumerable<TClass> ToClassList<TClass>(
DictionaryListTableConverterOptions? options = null)
{
var table = GetTable(dataSource);
DoAfterGetTableCallbackList.ForEach(x => x.Invoke(table));
var converter = options == null ? new DictionaryListTableConverter() : new DictionaryListTableConverter(options);
return converter.ConvertFrom(table);
}
Expand Down

0 comments on commit 8eb67b4

Please sign in to comment.