FreeTrainの進化系を目指す
Repository のパッケージ移動、 _ICommandTriggerFactory.cs削除
@@ -1,6 +1,6 @@ | ||
1 | 1 | using System; |
2 | 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
3 | -using nft.core.data; | |
3 | +using nft.framework.repository; | |
4 | 4 | using nft.framework; |
5 | 5 | using static System.Diagnostics.Trace; |
6 | 6 | using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert; |
@@ -76,7 +76,7 @@ | ||
76 | 76 | } |
77 | 77 | |
78 | 78 | [TestMethod] |
79 | - public void IModelRepositoryExtension() | |
79 | + public void IRepositoryExtension() | |
80 | 80 | { |
81 | 81 | this.repository = new TestRepository(); |
82 | 82 | WriteLine("IModelRepository拡張メソッドのテスト"); |
@@ -1,82 +0,0 @@ | ||
1 | -using nft.framework; | |
2 | -using System; | |
3 | -using System.Collections.Generic; | |
4 | -using System.Linq; | |
5 | -using System.Text; | |
6 | -using System.Threading.Tasks; | |
7 | - | |
8 | -namespace nft.core.data | |
9 | -{ | |
10 | - /// <summary> | |
11 | - /// データリポジトリのコアインターフェース | |
12 | - /// 標準実装はRepositoryBase | |
13 | - /// </summary> | |
14 | - /// <typeparam name="T"></typeparam> | |
15 | - public interface IRepository<T> where T: IHasNameAndID | |
16 | - { | |
17 | - /// <summary> | |
18 | - /// モデルを追加する。既にモデル | |
19 | - /// </summary> | |
20 | - /// <param name="model"></param> | |
21 | - void Add(T model); | |
22 | - | |
23 | - /// <summary> | |
24 | - /// IDで指定したモデルを削除し、削除したモデルを返す。該当モデルが存在しない場合エラーにはならず、nullを返す。 | |
25 | - /// </summary> | |
26 | - /// <param name="id"></param> | |
27 | - /// <returns>removed model or null if not exist</returns> | |
28 | - T RemoveByID(string id); | |
29 | - | |
30 | - /// <summary> | |
31 | - /// IDを指定してモデルを取得する。 | |
32 | - /// setがないのは、間違ったIDでmodel登録されるのを防ぐため。Addを使用してください。 | |
33 | - /// </summary> | |
34 | - /// <param name="id"></param> | |
35 | - /// <returns></returns> | |
36 | - T this[string id] { get; } | |
37 | - | |
38 | - /// <summary> | |
39 | - /// リポジトリに含まれるすべてのモデルのリストを取得します | |
40 | - /// </summary> | |
41 | - IEnumerable<T> List { get; } | |
42 | - | |
43 | - /// <summary> | |
44 | - /// リポジトリに含まれるモデルの数を取得します | |
45 | - /// </summary> | |
46 | - int Count { get; } | |
47 | - } | |
48 | - | |
49 | - /// <summary> | |
50 | - /// IRepositoryの拡張メソッド | |
51 | - /// </summary> | |
52 | - public static class RepositoryExtesion | |
53 | - { | |
54 | - /// <summary> | |
55 | - /// 指定したモデルを削除する。 | |
56 | - /// </summary> | |
57 | - /// <typeparam name="T"></typeparam> | |
58 | - /// <param name="repository"></param> | |
59 | - /// <param name="model">The model to be removed</param> | |
60 | - public static void Remove<T>(this IRepository<T> repository, T model) where T: IHasNameAndID | |
61 | - { | |
62 | - repository.RemoveByID(model.ID); | |
63 | - } | |
64 | - | |
65 | - /// <summary> | |
66 | - /// リポジトリに指定したIDのモデルが存在するかどうか調べる。存在すればtrue | |
67 | - /// </summary> | |
68 | - /// <typeparam name="T"></typeparam> | |
69 | - /// <param name="repository"></param> | |
70 | - /// <param name="model"></param> | |
71 | - /// <returns>true if the model correspond to the id is exist.</returns> | |
72 | - public static bool HasID<T>(this IRepository<T> repository, T model) where T : class, IHasNameAndID | |
73 | - { | |
74 | - return repository[model.ID] != null; | |
75 | - } | |
76 | - | |
77 | - public static T findByID<T>(this IRepository<T> repository, string id, T _default = null) where T : class, IHasNameAndID | |
78 | - { | |
79 | - return repository[id] ?? _default; | |
80 | - } | |
81 | - } | |
82 | -} |
@@ -1,52 +0,0 @@ | ||
1 | -using nft.framework; | |
2 | -using System; | |
3 | -using System.Collections.Generic; | |
4 | -using System.Linq; | |
5 | -using System.Text; | |
6 | -using System.Threading.Tasks; | |
7 | - | |
8 | -namespace nft.core.data | |
9 | -{ | |
10 | - public class RepositoryBase<T> : IRepository<T> where T: class, IHasNameAndID | |
11 | - { | |
12 | - protected Dictionary<string, T> dictionary = new Dictionary<string, T>(); | |
13 | - | |
14 | - public T this[string id] | |
15 | - { | |
16 | - get | |
17 | - { | |
18 | - T ret; | |
19 | - if( dictionary.TryGetValue(id, out ret) ) return ret; | |
20 | - return null; | |
21 | - } | |
22 | - } | |
23 | - | |
24 | - public int Count | |
25 | - { | |
26 | - get | |
27 | - { | |
28 | - return dictionary.Count; | |
29 | - } | |
30 | - } | |
31 | - | |
32 | - public IEnumerable<T> List | |
33 | - { | |
34 | - get | |
35 | - { | |
36 | - return dictionary.Values; | |
37 | - } | |
38 | - } | |
39 | - | |
40 | - public void Add(T model) | |
41 | - { | |
42 | - dictionary.Add(model.ID, model); | |
43 | - } | |
44 | - | |
45 | - public T RemoveByID(string id) | |
46 | - { | |
47 | - T ret = this[id]; | |
48 | - dictionary.Remove(id); | |
49 | - return ret; | |
50 | - } | |
51 | - } | |
52 | -} |
@@ -0,0 +1,39 @@ | ||
1 | +using nft.framework; | |
2 | +using System; | |
3 | +using System.Collections.Generic; | |
4 | +using System.Linq; | |
5 | +using System.Reflection; | |
6 | +using System.Text; | |
7 | +using System.Threading.Tasks; | |
8 | + | |
9 | +namespace nft.framework.repository | |
10 | +{ | |
11 | + public class DefaultRepositoryBuilder<T,U> : IRepositoryBuilder<T> where T: class, IHasNameAndID where U: IRepository<T> | |
12 | + { | |
13 | + protected Dictionary<string, T> dictionary = new Dictionary<string, T>(); | |
14 | + | |
15 | + public void Add(T model) | |
16 | + { | |
17 | + dictionary.Add(model.ID, model); | |
18 | + } | |
19 | + | |
20 | + public T RemoveByID(string id) | |
21 | + { | |
22 | + T ret; | |
23 | + if (!dictionary.TryGetValue(id, out ret)) { | |
24 | + ret = null; | |
25 | + } | |
26 | + dictionary.Remove(id); | |
27 | + return ret; | |
28 | + } | |
29 | + | |
30 | + public IRepository<T> Finalize() | |
31 | + { | |
32 | + Type[] types = { typeof(IDictionary<string, T>) }; | |
33 | + ConstructorInfo ci = typeof(U).GetConstructor(types); | |
34 | + object[] args = { this.dictionary }; | |
35 | + U repository = (U) ci.Invoke( args ); | |
36 | + return repository; | |
37 | + } | |
38 | + } | |
39 | +} |
@@ -0,0 +1,82 @@ | ||
1 | +using nft.framework; | |
2 | +using System; | |
3 | +using System.Collections.Generic; | |
4 | +using System.Linq; | |
5 | +using System.Text; | |
6 | +using System.Threading.Tasks; | |
7 | + | |
8 | +namespace nft.framework.repository | |
9 | +{ | |
10 | + /// <summary> | |
11 | + /// データリポジトリのコアインターフェース | |
12 | + /// 標準実装はRepositoryBase | |
13 | + /// </summary> | |
14 | + /// <typeparam name="T"></typeparam> | |
15 | + public interface IRepository<T> where T: IHasNameAndID | |
16 | + { | |
17 | + /// <summary> | |
18 | + /// モデルを追加する。既にモデル | |
19 | + /// </summary> | |
20 | + /// <param name="model"></param> | |
21 | + void Add(T model); | |
22 | + | |
23 | + /// <summary> | |
24 | + /// IDで指定したモデルを削除し、削除したモデルを返す。該当モデルが存在しない場合エラーにはならず、nullを返す。 | |
25 | + /// </summary> | |
26 | + /// <param name="id"></param> | |
27 | + /// <returns>removed model or null if not exist</returns> | |
28 | + T RemoveByID(string id); | |
29 | + | |
30 | + /// <summary> | |
31 | + /// IDを指定してモデルを取得する。 | |
32 | + /// setがないのは、間違ったIDでmodel登録されるのを防ぐため。Addを使用してください。 | |
33 | + /// </summary> | |
34 | + /// <param name="id"></param> | |
35 | + /// <returns></returns> | |
36 | + T this[string id] { get; } | |
37 | + | |
38 | + /// <summary> | |
39 | + /// リポジトリに含まれるすべてのモデルのリストを取得します | |
40 | + /// </summary> | |
41 | + IEnumerable<T> List { get; } | |
42 | + | |
43 | + /// <summary> | |
44 | + /// リポジトリに含まれるモデルの数を取得します | |
45 | + /// </summary> | |
46 | + int Count { get; } | |
47 | + } | |
48 | + | |
49 | + /// <summary> | |
50 | + /// IRepositoryの拡張メソッド | |
51 | + /// </summary> | |
52 | + public static class RepositoryExtesion | |
53 | + { | |
54 | + /// <summary> | |
55 | + /// 指定したモデルを削除する。 | |
56 | + /// </summary> | |
57 | + /// <typeparam name="T"></typeparam> | |
58 | + /// <param name="repository"></param> | |
59 | + /// <param name="model">The model to be removed</param> | |
60 | + public static void Remove<T>(this IRepository<T> repository, T model) where T: IHasNameAndID | |
61 | + { | |
62 | + repository.RemoveByID(model.ID); | |
63 | + } | |
64 | + | |
65 | + /// <summary> | |
66 | + /// リポジトリに指定したIDのモデルが存在するかどうか調べる。存在すればtrue | |
67 | + /// </summary> | |
68 | + /// <typeparam name="T"></typeparam> | |
69 | + /// <param name="repository"></param> | |
70 | + /// <param name="model"></param> | |
71 | + /// <returns>true if the model correspond to the id is exist.</returns> | |
72 | + public static bool HasID<T>(this IRepository<T> repository, T model) where T : class, IHasNameAndID | |
73 | + { | |
74 | + return repository[model.ID] != null; | |
75 | + } | |
76 | + | |
77 | + public static T findByID<T>(this IRepository<T> repository, string id, T _default = null) where T : class, IHasNameAndID | |
78 | + { | |
79 | + return repository[id] ?? _default; | |
80 | + } | |
81 | + } | |
82 | +} |
@@ -0,0 +1,36 @@ | ||
1 | +using nft.framework; | |
2 | +using System; | |
3 | +using System.Collections.Generic; | |
4 | +using System.Linq; | |
5 | +using System.Text; | |
6 | +using System.Threading.Tasks; | |
7 | + | |
8 | +namespace nft.framework.repository | |
9 | +{ | |
10 | + /// <summary> | |
11 | + /// データリポジトリビルダーのインターフェース | |
12 | + /// 標準実装はRepositoryBuilderBase | |
13 | + /// </summary> | |
14 | + /// <typeparam name="T"></typeparam> | |
15 | + public interface IRepositoryBuilder<T> where T: IHasNameAndID | |
16 | + { | |
17 | + /// <summary> | |
18 | + /// モデルを追加する。既にモデル | |
19 | + /// </summary> | |
20 | + /// <param name="model"></param> | |
21 | + void Add(T model); | |
22 | + | |
23 | + /// <summary> | |
24 | + /// IDで指定したモデルを削除し、削除したモデルを返す。該当モデルが存在しない場合エラーにはならず、nullを返す。 | |
25 | + /// </summary> | |
26 | + /// <param name="id"></param> | |
27 | + /// <returns>removed model or null if not exist</returns> | |
28 | + T RemoveByID(string id); | |
29 | + | |
30 | + | |
31 | + IRepository<T> Finalize(); | |
32 | + } | |
33 | + | |
34 | + | |
35 | + | |
36 | +} |
@@ -0,0 +1,52 @@ | ||
1 | +using nft.framework; | |
2 | +using System; | |
3 | +using System.Collections.Generic; | |
4 | +using System.Linq; | |
5 | +using System.Text; | |
6 | +using System.Threading.Tasks; | |
7 | + | |
8 | +namespace nft.framework.repository | |
9 | +{ | |
10 | + public class RepositoryBase<T> : IRepository<T> where T: class, IHasNameAndID | |
11 | + { | |
12 | + protected Dictionary<string, T> dictionary = new Dictionary<string, T>(); | |
13 | + | |
14 | + public T this[string id] | |
15 | + { | |
16 | + get | |
17 | + { | |
18 | + T ret; | |
19 | + if( dictionary.TryGetValue(id, out ret) ) return ret; | |
20 | + return null; | |
21 | + } | |
22 | + } | |
23 | + | |
24 | + public int Count | |
25 | + { | |
26 | + get | |
27 | + { | |
28 | + return dictionary.Count; | |
29 | + } | |
30 | + } | |
31 | + | |
32 | + public IEnumerable<T> List | |
33 | + { | |
34 | + get | |
35 | + { | |
36 | + return dictionary.Values; | |
37 | + } | |
38 | + } | |
39 | + | |
40 | + public void Add(T model) | |
41 | + { | |
42 | + dictionary.Add(model.ID, model); | |
43 | + } | |
44 | + | |
45 | + public T RemoveByID(string id) | |
46 | + { | |
47 | + T ret = this[id]; | |
48 | + dictionary.Remove(id); | |
49 | + return ret; | |
50 | + } | |
51 | + } | |
52 | +} |
@@ -1,24 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Windows.Forms; | |
3 | - | |
4 | -namespace nft.ui.command | |
5 | -{ | |
6 | - /// <summary> | |
7 | - /// CommandTriggerFactory の概要の説明です。 | |
8 | - /// </summary> | |
9 | - public class CommandTriggerFactory | |
10 | - { | |
11 | - public static ICommandTrigger Create(ToolStripMenuItem item) | |
12 | - { return new MenuItemTrigger(item); } | |
13 | - public static ICommandTrigger Create( Button item ) | |
14 | - { return new ButtonTrigger(item); } | |
15 | - public static ICommandTrigger Create( CheckBox item ) | |
16 | - { return new CheckBoxTrigger(item); } | |
17 | - public static ICommandTrigger Create( ToolStripButton item ) | |
18 | - { return new ToolBarItemTrigger(item); } | |
19 | - public static ICommandTrigger Create( ToolBarButton item ) | |
20 | - { return new ToolBarButtonTrigger(item); } | |
21 | - public static ICommandTrigger Create( Control item ) | |
22 | - { return new ControlTrigger(item); } | |
23 | - } | |
24 | -} |
@@ -24,10 +24,10 @@ | ||
24 | 24 | /// </summary> |
25 | 25 | private void InitializeComponent() { |
26 | 26 | this.panel1 = new System.Windows.Forms.Panel(); |
27 | + this.cbList = new System.Windows.Forms.ComboBox(); | |
27 | 28 | this.panel2 = new System.Windows.Forms.Panel(); |
29 | + this.tbInfo = new System.Windows.Forms.TextBox(); | |
28 | 30 | this.renderView = new nft.framework.drawing.RenderViewPanel(); |
29 | - this.lbCaption = new System.Windows.Forms.Label(); | |
30 | - this.tbInfo = new System.Windows.Forms.TextBox(); | |
31 | 31 | this.panel1.SuspendLayout(); |
32 | 32 | this.panel2.SuspendLayout(); |
33 | 33 | this.SuspendLayout(); |
@@ -35,13 +35,23 @@ | ||
35 | 35 | // panel1 |
36 | 36 | // |
37 | 37 | this.panel1.AutoSize = true; |
38 | - this.panel1.Controls.Add(this.lbCaption); | |
38 | + this.panel1.Controls.Add(this.cbList); | |
39 | 39 | this.panel1.Dock = System.Windows.Forms.DockStyle.Top; |
40 | 40 | this.panel1.Location = new System.Drawing.Point(0, 0); |
41 | 41 | this.panel1.Name = "panel1"; |
42 | - this.panel1.Size = new System.Drawing.Size(200, 20); | |
42 | + this.panel1.Size = new System.Drawing.Size(200, 23); | |
43 | 43 | this.panel1.TabIndex = 3; |
44 | 44 | // |
45 | + // cbList | |
46 | + // | |
47 | + this.cbList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | |
48 | + | System.Windows.Forms.AnchorStyles.Right))); | |
49 | + this.cbList.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; | |
50 | + this.cbList.Location = new System.Drawing.Point(0, 0); | |
51 | + this.cbList.Name = "cbList"; | |
52 | + this.cbList.Size = new System.Drawing.Size(200, 20); | |
53 | + this.cbList.TabIndex = 0; | |
54 | + // | |
45 | 55 | // panel2 |
46 | 56 | // |
47 | 57 | this.panel2.AutoSize = true; |
@@ -52,28 +62,6 @@ | ||
52 | 62 | this.panel2.Size = new System.Drawing.Size(200, 60); |
53 | 63 | this.panel2.TabIndex = 4; |
54 | 64 | // |
55 | - // renderView | |
56 | - // | |
57 | - this.renderView.Dock = System.Windows.Forms.DockStyle.Fill; | |
58 | - this.renderView.Location = new System.Drawing.Point(0, 20); | |
59 | - this.renderView.Name = "renderView"; | |
60 | - this.renderView.Size = new System.Drawing.Size(200, 157); | |
61 | - this.renderView.SurfaceUsage = nft.framework.drawing.SurfaceUsage.Normal; | |
62 | - this.renderView.TabIndex = 5; | |
63 | - // | |
64 | - // lbCaption | |
65 | - // | |
66 | - this.lbCaption.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | |
67 | - | System.Windows.Forms.AnchorStyles.Right))); | |
68 | - this.lbCaption.AutoEllipsis = true; | |
69 | - this.lbCaption.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; | |
70 | - this.lbCaption.Location = new System.Drawing.Point(0, 0); | |
71 | - this.lbCaption.Name = "lbCaption"; | |
72 | - this.lbCaption.Size = new System.Drawing.Size(200, 20); | |
73 | - this.lbCaption.TabIndex = 0; | |
74 | - this.lbCaption.Text = "label1"; | |
75 | - this.lbCaption.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; | |
76 | - // | |
77 | 65 | // tbInfo |
78 | 66 | // |
79 | 67 | this.tbInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
@@ -87,6 +75,15 @@ | ||
87 | 75 | this.tbInfo.Size = new System.Drawing.Size(200, 57); |
88 | 76 | this.tbInfo.TabIndex = 0; |
89 | 77 | // |
78 | + // renderView | |
79 | + // | |
80 | + this.renderView.Dock = System.Windows.Forms.DockStyle.Fill; | |
81 | + this.renderView.Location = new System.Drawing.Point(0, 23); | |
82 | + this.renderView.Name = "renderView"; | |
83 | + this.renderView.Size = new System.Drawing.Size(200, 154); | |
84 | + this.renderView.SurfaceUsage = nft.framework.drawing.SurfaceUsage.Normal; | |
85 | + this.renderView.TabIndex = 5; | |
86 | + // | |
90 | 87 | // BuildTool |
91 | 88 | // |
92 | 89 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); |
@@ -107,10 +104,9 @@ | ||
107 | 104 | #endregion |
108 | 105 | |
109 | 106 | private System.Windows.Forms.Panel panel1; |
110 | - private System.Windows.Forms.Label lbCaption; | |
111 | 107 | private System.Windows.Forms.Panel panel2; |
112 | 108 | private System.Windows.Forms.TextBox tbInfo; |
113 | 109 | private framework.drawing.RenderViewPanel renderView; |
114 | - | |
110 | + private System.Windows.Forms.ComboBox cbList; | |
115 | 111 | } |
116 | 112 | } |