Skip to content

Commit

Permalink
Update .editorconfig and correct code (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
MareMare authored Jun 6, 2024
1 parent cd12234 commit 42eb936
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 442 deletions.
561 changes: 238 additions & 323 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
3. `A5:SQL Mk-2` で ER 図の編集

![](doc/生成直後のER図.png)

4. `A5:SQL Mk-2` で DDL によるスクリプト生成

![](doc/スクリプト生成.png)
4 changes: 2 additions & 2 deletions src/Disposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class Disposable
/// <summary>
/// 何もしない既定の Dispose 可能なインスタンスを表します。
/// </summary>
private class NopDisposable : IDisposable
private sealed class NopDisposable : IDisposable
{
/// <inheritdoc />
public void Dispose()
Expand All @@ -43,7 +43,7 @@ public void Dispose()
/// <summary>
/// 匿名の <see cref="IDisposable" /> インターフェイスの実装を表します。
/// </summary>
private class AnonymousDisposable : IDisposable
private sealed class AnonymousDisposable : IDisposable
{
/// <summary><see cref="IDisposable.Dispose" /> が呼ばれた時の処理を行うメソッドのデリゲートを表します。</summary>
private volatile Action? _dispose;
Expand Down
19 changes: 10 additions & 9 deletions src/ExcelToA5er.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
<Copyright>© MareMare</Copyright>
<Description>A5:SQL Mk-2 で出力されたテーブル定義書からER図(.a5er)へ変換するツールです。</Description>
<Authors>MareMare</Authors>
<VersionPrefix>2.0.0</VersionPrefix>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<VersionPrefix>2.0.1</VersionPrefix>
<AssemblyVersion>2.0.1.0</AssemblyVersion>
<FileVersion>2.0.1.0</FileVersion>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,29 +27,28 @@

<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.102.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Packaging" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<ItemGroup>
<Compile Update="Templates\A5erRuntimeTextTemplate.cs">
<Compile Update="Templates\A5ErRuntimeTextTemplate.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>A5erRuntimeTextTemplate.tt</DependentUpon>
<DependentUpon>A5ErRuntimeTextTemplate.tt</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="Templates\A5erRuntimeTextTemplate.tt">
<None Update="Templates\A5ErRuntimeTextTemplate.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>A5erRuntimeTextTemplate.cs</LastGenOutput>
<LastGenOutput>A5ErRuntimeTextTemplate.cs</LastGenOutput>
</None>
</ItemGroup>

Expand Down
87 changes: 48 additions & 39 deletions src/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// --------------------------------------------------------------------------------------------------------------------

using ExcelToA5er.Generators;
using ExcelToA5er.Metadatas;
using ExcelToA5er.Metadata;
using ExcelToA5er.Progress;
using ExcelToA5er.Templates;

Expand All @@ -18,7 +18,7 @@ namespace ExcelToA5er;
public partial class MainForm : Form
{
/// <summary>非同期操作の実行時間としての最低時間を表します。</summary>
private static readonly TimeSpan DelayTimeSpan = TimeSpan.FromSeconds(2);
private static readonly TimeSpan _delayTimeSpan = TimeSpan.FromSeconds(2);

/// <summary>現在のテーブル定義書情報を表します。</summary>
private XlsxInformation? _currentXlsxInfo;
Expand All @@ -38,8 +38,8 @@ public MainForm()
/// <returns>リストボックス項目のコレクション。</returns>
private static DisplayItem[] ToDisplayItems(XlsxInformation xlsxInfo)
{
var items = xlsxInfo?.TableDefinitions?.Select(definition => new DisplayItem(definition)).ToArray();
return items ?? Array.Empty<DisplayItem>();
var items = xlsxInfo.TableDefinitions.Select(definition => new DisplayItem(definition)).ToArray();
return items ?? [];
}

/// <summary>
Expand All @@ -49,17 +49,22 @@ private static DisplayItem[] ToDisplayItems(XlsxInformation xlsxInfo)
/// <returns>テーブル定義情報。</returns>
private async Task<XlsxInformation> LoadXlsxAsync(string xlsxFilePath)
{
using var progressForm = new ProgressForm { Title = "読み込み" };
await using var progressScoap = progressForm.UseProgressFormScope(this);
progressScoap.Reporter.ReportStarting("読み込み中です。しばらくお待ちください。");
using var progressForm = new ProgressForm();
progressForm.Title = "読み込み";

var loadTask = XlsxInformation.LoadAsync(xlsxFilePath);
var delayTask = Task.Delay(MainForm.DelayTimeSpan);
await Task.WhenAll(loadTask, delayTask).ConfigureAwait(true);
var progressScope = progressForm.UseProgressFormScope(this);
await using (progressScope.ConfigureAwait(true))
{
progressScope.Reporter.ReportStarting("読み込み中です。しばらくお待ちください。");

var loadTask = XlsxInformation.LoadAsync(xlsxFilePath);
var delayTask = Task.Delay(MainForm._delayTimeSpan);
await Task.WhenAll(loadTask, delayTask).ConfigureAwait(true);

var xlsxInfo = await loadTask.ConfigureAwait(true);
await progressScoap.Reporter.ReportCompletedAsync("読み込みが完了しました。").ConfigureAwait(true);
return xlsxInfo;
var xlsxInfo = await loadTask.ConfigureAwait(true);
await progressScope.Reporter.ReportCompletedAsync("読み込みが完了しました。").ConfigureAwait(true);
return xlsxInfo;
}
}

/// <summary>
Expand All @@ -70,16 +75,21 @@ private async Task<XlsxInformation> LoadXlsxAsync(string xlsxFilePath)
/// <returns>完了を表すタスク。</returns>
private async Task SaveA5erAsync(string outputPath, ICollection<TableDefinition> tableDefinitions)
{
using var progressForm = new ProgressForm { Title = "変換" };
await using var progressScoap = progressForm.UseProgressFormScope(this);
progressScoap.Reporter.ReportStarting("変換中です。しばらくお待ちください。");
using var progressForm = new ProgressForm();
progressForm.Title = "変換";

var progressScope = progressForm.UseProgressFormScope(this);
await using (progressScope.ConfigureAwait(true))
{
progressScope.Reporter.ReportStarting("変換中です。しばらくお待ちください。");

var generateTask = new A5erRuntimeTextTemplate(tableDefinitions).GenerateAsync(outputPath);
var delayTask = Task.Delay(MainForm.DelayTimeSpan);
await Task.WhenAll(generateTask, delayTask).ConfigureAwait(true);
var generateTask = new A5ErRuntimeTextTemplate(tableDefinitions).GenerateAsync(outputPath);
var delayTask = Task.Delay(MainForm._delayTimeSpan);
await Task.WhenAll(generateTask, delayTask).ConfigureAwait(true);

await generateTask.ConfigureAwait(true);
await progressScoap.Reporter.ReportCompletedAsync("変換完了しました。").ConfigureAwait(true);
await generateTask.ConfigureAwait(true);
await progressScope.Reporter.ReportCompletedAsync("変換完了しました。").ConfigureAwait(true);
}
}

/// <summary>
Expand All @@ -99,7 +109,7 @@ private void MainForm_Load(object sender, EventArgs e)
/// <param name="sender">イベントソース。</param>
/// <param name="e">イベントデータ。</param>
private void ListBoxTableInfo_SelectedIndexChanged(object sender, EventArgs e) =>
this.buttonToConvert.Enabled = this.listBoxTableInfo.SelectedItems.Count > 0 && this._currentXlsxInfo?.A5erFilePath != null;
this.buttonToConvert.Enabled = this.listBoxTableInfo.SelectedItems.Count > 0 && this._currentXlsxInfo?.A5ErFilePath != null;

/// <summary>
/// [参照] ボタンがクリックされたときに発生するイベントのイベントハンドラです。
Expand All @@ -108,25 +118,24 @@ private void ListBoxTableInfo_SelectedIndexChanged(object sender, EventArgs e) =
/// <param name="e">イベントデータ。</param>
private async void ButtonToBrowseXlsx_Click(object sender, EventArgs e)
{
var openFileDialog = new OpenFileDialog
{
Title = "テーブル定義書を選択してください。",
Filter = "テーブル定義書(*.xlsx)|*.xlsx",
RestoreDirectory = true,
CheckFileExists = true,
CheckPathExists = true,
ReadOnlyChecked = true,
ShowReadOnly = true,
};
using var openFileDialog = new OpenFileDialog();
openFileDialog.Title = @"テーブル定義書を選択してください。";
openFileDialog.Filter = @"テーブル定義書(*.xlsx)|*.xlsx";
openFileDialog.RestoreDirectory = true;
openFileDialog.CheckFileExists = true;
openFileDialog.CheckPathExists = true;
openFileDialog.ReadOnlyChecked = true;
openFileDialog.ShowReadOnly = true;

if (openFileDialog.ShowDialog() == DialogResult.OK)
{
var xlsxInfo = await this.LoadXlsxAsync(openFileDialog.FileName).ConfigureAwait(true);
var items = MainForm.ToDisplayItems(xlsxInfo);
var items = MainForm.ToDisplayItems(xlsxInfo).Cast<object>().ToArray();
this._currentXlsxInfo = xlsxInfo;
this.listBoxTableInfo.Items.Clear();
this.listBoxTableInfo.Items.AddRange(items);
this.textBoxXlsxFilePath.Text = Path.GetFileName(xlsxInfo.XlsxFilePath);
this.textBoxOutputFilePath.Text = Path.GetFileName(xlsxInfo.A5erFilePath);
this.textBoxOutputFilePath.Text = Path.GetFileName(xlsxInfo.A5ErFilePath);
}
}

Expand All @@ -137,21 +146,21 @@ private async void ButtonToBrowseXlsx_Click(object sender, EventArgs e)
/// <param name="e">イベントデータ。</param>
private async void ButtonToConvert_Click(object sender, EventArgs e)
{
var a5erFilePath = this._currentXlsxInfo?.A5erFilePath;
if (a5erFilePath == null)
var a5ErFilePath = this._currentXlsxInfo?.A5ErFilePath;
if (a5ErFilePath == null)
{
return;
}

var selectedItems = this.listBoxTableInfo.SelectedItems.OfType<DisplayItem>().ToArray();
var tableDefinitions = selectedItems.Select(item => item.TableInfo).ToArray();
await this.SaveA5erAsync(a5erFilePath, tableDefinitions).ConfigureAwait(true);
await this.SaveA5erAsync(a5ErFilePath, tableDefinitions).ConfigureAwait(true);
}

/// <summary>
/// リストボックス項目を表します。
/// </summary>
private class DisplayItem
private sealed class DisplayItem
{
/// <summary>
/// <see cref="DisplayItem"/> クラスの新しいインスタンスを生成します。
Expand All @@ -172,6 +181,6 @@ public DisplayItem(TableDefinition tableDefinition)
public TableDefinition TableInfo { get; }

/// <inheritdoc />
public override string ToString() => this.TableInfo != null ? $"{this.TableInfo.PhysicalName}: {this.TableInfo.LogicalName}" : "<未設定>";
public override string ToString() => $"{this.TableInfo.PhysicalName}: {this.TableInfo.LogicalName}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,51 @@

using ClosedXML.Excel;

namespace ExcelToA5er.Metadatas;
namespace ExcelToA5er.Metadata;

/// <summary>
/// Clossed Xml の拡張メソッドを提供します。
/// Closed Xml の拡張メソッドを提供します。
/// </summary>
internal static class ClosedXmlExtensions
{
/// <summary>対象シートを判断する識別子のキーワードを表します。</summary>
private const string TargetSheetKeyword1 = "テーブル情報";
private const string _targetSheetKeyword1 = "テーブル情報";

/// <summary>対象シートを判断する識別子のキーワードを表します。</summary>
private const string TargetSheetKeyword2 = "エンティティ情報";
private const string _targetSheetKeyword2 = "エンティティ情報";

/// <summary>対象シートの識別子のセルアドレスを表します。</summary>
private const string CellOfTargetSheetKeyword = "A1";
private const string _cellOfTargetSheetKeyword = "A1";

/// <summary>論理テーブル名のセルアドレスを表します。</summary>
private const string CellOfTableLogicalName = "C5";
private const string _cellOfTableLogicalName = "C5";

/// <summary>物理テーブル名のセルアドレスを表します。</summary>
private const string CellOfTablePhysicalName = "C6";
private const string _cellOfTablePhysicalName = "C6";

/// <summary>No.列の先頭セルアドレスを表します。</summary>
private const string CellOfColumnNumberName = "A14";
private const string _cellOfColumnNumberName = "A14";

/// <summary>論理カラム名の先頭セルアドレスを表します。</summary>
private const string CellOfColumnLogicalName = "B14";
private const string _cellOfColumnLogicalName = "B14";

/// <summary>物理カラム名の先頭セルアドレスを表します。</summary>
private const string CellOfColumnPhysicalName = "C14";
private const string _cellOfColumnPhysicalName = "C14";

/// <summary>カラムデータ型名の先頭セルアドレスを表します。</summary>
private const string CellOfColumnDataTypeName = "D14";
private const string _cellOfColumnDataTypeName = "D14";

/// <summary>必須およびPK列の先頭セルアドレスを表します。</summary>
private const string CellOfColumnIsPkOrNotNull = "E14";
private const string _cellOfColumnIsPkOrNotNull = "E14";

/// <summary>カラムコメントの先頭セルアドレスを表します。</summary>
private const string CellOfColumnCommentText = "G14";
private const string _cellOfColumnCommentText = "G14";

/// <summary>PK 列として判定するセル値を表します。</summary>
private const string CellValueOfPK = "PK";
private const string _cellValueOfPk = "PK";

/// <summary>必須列として判定するセル値を表します。</summary>
private const string CellValueOfNotNull = "Yes";
private const string _cellValueOfNotNull = "Yes";

/// <summary>
/// 指定されたワークシートが対象の使徒であるかを取得します。
Expand All @@ -62,8 +62,8 @@ public static bool IsTargetSheet(this IXLWorksheet worksheet)
{
ArgumentNullException.ThrowIfNull(worksheet);

var keyword = worksheet.GetCellStringOrEmpty(CellOfTargetSheetKeyword).Trim().NullIfEmpty();
return keyword == TargetSheetKeyword1 || keyword == TargetSheetKeyword2;
var keyword = worksheet.GetCellStringOrEmpty(ClosedXmlExtensions._cellOfTargetSheetKeyword).Trim().NullIfEmpty();
return keyword is ClosedXmlExtensions._targetSheetKeyword1 or ClosedXmlExtensions._targetSheetKeyword2;
}

/// <summary>
Expand Down Expand Up @@ -92,8 +92,8 @@ public static IEnumerable<TableDefinition> LoadTableDefinitions(this IEnumerable
{
ArgumentNullException.ThrowIfNull(worksheet);

var physicalName = worksheet.GetCellStringOrEmpty(CellOfTablePhysicalName).Trim().NullIfEmpty();
var logicalName = worksheet.GetCellStringOrEmpty(CellOfTableLogicalName).Trim().NullIfEmpty();
var physicalName = worksheet.GetCellStringOrEmpty(ClosedXmlExtensions._cellOfTablePhysicalName).Trim().NullIfEmpty();
var logicalName = worksheet.GetCellStringOrEmpty(ClosedXmlExtensions._cellOfTableLogicalName).Trim().NullIfEmpty();

var definition = physicalName != null
? new TableDefinition
Expand Down Expand Up @@ -140,15 +140,15 @@ private static IEnumerable<ColumnDefinition> LoadColumnDefinitions(this IXLWorks
/// <returns>継続可能な場合は true。それ以外は false。</returns>
private static bool TryLoadColumnDefinition(this IXLWorksheet worksheet, int rowOffset, ref int issuedPkNumber, out ColumnDefinition? definition)
{
var numberName = worksheet.GetCellStringOrEmpty(CellOfColumnNumberName, rowOffset).Trim().NullIfEmpty();
var physicalName = worksheet.GetCellStringOrEmpty(CellOfColumnPhysicalName, rowOffset).Trim().NullIfEmpty();
var logicalName = worksheet.GetCellStringOrEmpty(CellOfColumnLogicalName, rowOffset).Trim().NullIfEmpty();
var dataTypeName = worksheet.GetCellStringOrEmpty(CellOfColumnDataTypeName, rowOffset).Trim().NullIfEmpty();
var commentText = worksheet.GetCellStringOrEmpty(CellOfColumnCommentText, rowOffset).Trim().NullIfEmpty();
var numberName = worksheet.GetCellStringOrEmpty(ClosedXmlExtensions._cellOfColumnNumberName, rowOffset).Trim().NullIfEmpty();
var physicalName = worksheet.GetCellStringOrEmpty(ClosedXmlExtensions._cellOfColumnPhysicalName, rowOffset).Trim().NullIfEmpty();
var logicalName = worksheet.GetCellStringOrEmpty(ClosedXmlExtensions._cellOfColumnLogicalName, rowOffset).Trim().NullIfEmpty();
var dataTypeName = worksheet.GetCellStringOrEmpty(ClosedXmlExtensions._cellOfColumnDataTypeName, rowOffset).Trim().NullIfEmpty();
var commentText = worksheet.GetCellStringOrEmpty(ClosedXmlExtensions._cellOfColumnCommentText, rowOffset).Trim().NullIfEmpty();

var isPkOrNotNullText = worksheet.GetCellStringOrEmpty(CellOfColumnIsPkOrNotNull, rowOffset).Trim();
var isNotNull = isPkOrNotNullText.Contains(CellValueOfNotNull, StringComparison.OrdinalIgnoreCase);
var isPk = isPkOrNotNullText.Contains(CellValueOfPK, StringComparison.OrdinalIgnoreCase);
var isPkOrNotNullText = worksheet.GetCellStringOrEmpty(ClosedXmlExtensions._cellOfColumnIsPkOrNotNull, rowOffset).Trim();
var isNotNull = isPkOrNotNullText.Contains(ClosedXmlExtensions._cellValueOfNotNull, StringComparison.OrdinalIgnoreCase);
var isPk = isPkOrNotNullText.Contains(ClosedXmlExtensions._cellValueOfPk, StringComparison.OrdinalIgnoreCase);

// No.列と物理カラム名ともに有効(空欄以外)な場合に限り、カラム情報として抽出します。
definition = numberName != null && physicalName != null
Expand All @@ -173,7 +173,7 @@ private static bool TryLoadColumnDefinition(this IXLWorksheet worksheet, int row
/// <typeparam name="T">要素の型。</typeparam>
/// <param name="self">要素の列挙子。</param>
/// <returns>null でない要素の列挙子。</returns>
private static IEnumerable<T> EmptyIfNull<T>(this IEnumerable<T> self) => self ?? Enumerable.Empty<T>();
private static IEnumerable<T> EmptyIfNull<T>(this IEnumerable<T>? self) => self ?? [];

/// <summary>
/// 空文字列であれば null にします。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace ExcelToA5er.Metadatas;
namespace ExcelToA5er.Metadata;

/// <summary>
/// カラム情報を表します。
/// </summary>
internal class ColumnDefinition
internal sealed class ColumnDefinition
{
/// <summary>
/// 物理カラム名を取得または設定します。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace ExcelToA5er.Metadatas;
namespace ExcelToA5er.Metadata;

/// <summary>
/// テーブル情報を表します。
/// </summary>
internal partial class TableDefinition
internal sealed partial class TableDefinition
{
/// <summary>
/// 物理テーブル名を取得します。
Expand Down
Loading

0 comments on commit 42eb936

Please sign in to comment.