なろうブックマーク分析用ツールのPrism+WinUI3サンプル実装
Revision | 0fe237d994965d47727cf4fdb77d61a5181cbfdd (tree) |
---|---|
Zeit | 2022-08-16 22:09:02 |
Autor | yoshy <yoshy.org.bitbucket@gz.j...> |
Commiter | yoshy |
[MOD] Model と ViewModel の同期を正しく行うように修正
@@ -1,4 +1,5 @@ | ||
1 | -using NLog; | |
1 | +using CleanAuLait.Core.Log; | |
2 | +using NLog; | |
2 | 3 | using ObservableCollections; |
3 | 4 | using Prism.Navigation; |
4 | 5 | using Reactive.Bindings; |
@@ -64,29 +65,15 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel | ||
64 | 65 | .WithINotifyCollectionChangedList() |
65 | 66 | .AddTo(disposables); |
66 | 67 | |
67 | - logger.Trace("BookmarkCategoryViewModel.SynchronizeWith: source rows [{0}], collection view [{1}]", | |
68 | - source.Rows.Count, this.Rows.GetType().FullName); | |
68 | + logger.Trace("BookmarkCategoryViewModel.SynchronizeWith: source [{0}], collection view [{1}]", | |
69 | + source.ToHashString(), this.Rows.GetType().FullName); | |
69 | 70 | |
70 | 71 | this.Source = source; |
71 | 72 | } |
72 | 73 | else |
73 | 74 | { |
74 | - int oldCount = this.Source.Rows.Count; | |
75 | - | |
76 | - this.Source.Rows.Clear(); | |
77 | - | |
78 | - // due to the communication toolkit datagrid does not support range operations, | |
79 | - // we have to add the data row by row. | |
80 | - | |
81 | - //this.Source.Rows.AddRange(source.Rows); | |
82 | - | |
83 | - foreach (var row in source.Rows) | |
84 | - { | |
85 | - this.Source.Rows.Add(row); | |
86 | - } | |
87 | - | |
88 | - logger.Trace("BookmarkCategoryViewModel.SynchronizeWith: source rows [{0}] -> [{1}]", | |
89 | - oldCount, source.Rows.Count); | |
75 | + logger.Trace("BookmarkCategoryViewModel.SynchronizeWith: viewmodel already synchronized to model [{0}]", | |
76 | + this.Source.ToHashString()); | |
90 | 77 | } |
91 | 78 | } |
92 | 79 |
@@ -1,4 +1,5 @@ | ||
1 | -using NLog; | |
1 | +using CleanAuLait.Core.Log; | |
2 | +using NLog; | |
2 | 3 | using ObservableCollections; |
3 | 4 | using Prism.Navigation; |
4 | 5 | using Reactive.Bindings; |
@@ -83,27 +84,15 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel | ||
83 | 84 | .WithINotifyCollectionChangedList() |
84 | 85 | .AddTo(disposables); |
85 | 86 | |
86 | - logger.Trace("BookmarkDetailListViewModel.SynchronizeWith: source rows [{0}], collection view [{1}]", source.Rows.Count, this.Rows.GetType().FullName); | |
87 | + logger.Trace("BookmarkDetailListViewModel.SynchronizeWith: source [{0}], collection view [{1}]", | |
88 | + source.ToHashString(), this.Rows.GetType().FullName); | |
87 | 89 | |
88 | 90 | this.Source = source; |
89 | 91 | } |
90 | 92 | else |
91 | 93 | { |
92 | - int oldCount = this.Source.Rows.Count; | |
93 | - | |
94 | - this.Source.Rows.Clear(); | |
95 | - | |
96 | - // due to the communication toolkit datagrid does not support range operations, | |
97 | - // we have to add the data row by row. | |
98 | - | |
99 | - //this.Source.Rows.AddRange(source.Rows); | |
100 | - | |
101 | - foreach (var row in source.Rows) | |
102 | - { | |
103 | - this.Source.Rows.Add(row); | |
104 | - } | |
105 | - | |
106 | - logger.Trace("BookmarkDetailListViewModel.SynchronizeWith: source rows [{0}] -> [{1}]", oldCount, source.Rows.Count); | |
94 | + logger.Trace("BookmarkDetailListViewModel.SynchronizeWith: viewmodel already synchronized to model [{0}]", | |
95 | + this.Source.ToHashString()); | |
107 | 96 | } |
108 | 97 | } |
109 | 98 |
@@ -12,28 +12,24 @@ namespace TestNarou3.Domain.Model.Entity | ||
12 | 12 | private bool disposedValue; |
13 | 13 | |
14 | 14 | public BookmarkCategory() : this( |
15 | - Rows: new ObservableList<BookmarkCategoryRow>() | |
15 | + Rows: new() | |
16 | 16 | ) |
17 | 17 | { |
18 | 18 | } |
19 | 19 | |
20 | - public BookmarkCategory(IEnumerable<BookmarkCategoryRow> lists) : this( | |
21 | - Rows: CreateRows(lists) | |
22 | - ) | |
20 | + public void Refresh(IEnumerable<BookmarkCategoryRow> rows) | |
23 | 21 | { |
24 | - } | |
22 | + this.Rows.Clear(); | |
25 | 23 | |
26 | - private static ObservableList<BookmarkCategoryRow> | |
27 | - CreateRows(IEnumerable<BookmarkCategoryRow> lists) | |
28 | - { | |
29 | - ObservableList<BookmarkCategoryRow> rows = new(); | |
24 | + // due to the communication toolkit datagrid does not support range operations, | |
25 | + // we have to add the data row by row. | |
30 | 26 | |
31 | - foreach (var row in lists) | |
27 | + //this.Rows.AddRange(rows); | |
28 | + | |
29 | + foreach (var row in rows) | |
32 | 30 | { |
33 | - rows.Add(row); | |
31 | + this.Rows.Add(row); | |
34 | 32 | } |
35 | - | |
36 | - return rows; | |
37 | 33 | } |
38 | 34 | |
39 | 35 | protected virtual void Dispose(bool disposing) |
@@ -12,28 +12,24 @@ namespace TestNarou3.Domain.Model.Entity | ||
12 | 12 | private bool disposedValue; |
13 | 13 | |
14 | 14 | public BookmarkDetailList() : this( |
15 | - Rows: new ObservableList<BookmarkDetailListRow>() | |
15 | + Rows: new() | |
16 | 16 | ) |
17 | 17 | { |
18 | 18 | } |
19 | 19 | |
20 | - public BookmarkDetailList(IEnumerable<BookmarkDetailListRow> lists) : this( | |
21 | - Rows: CreateRows(lists) | |
22 | - ) | |
20 | + public void Refresh(IEnumerable<BookmarkDetailListRow> rows) | |
23 | 21 | { |
24 | - } | |
22 | + this.Rows.Clear(); | |
25 | 23 | |
26 | - private static ObservableList<BookmarkDetailListRow> | |
27 | - CreateRows(IEnumerable<BookmarkDetailListRow> lists) | |
28 | - { | |
29 | - ObservableList<BookmarkDetailListRow> rows = new(); | |
24 | + // due to the communication toolkit datagrid does not support range operations, | |
25 | + // we have to add the data row by row. | |
30 | 26 | |
31 | - foreach (var row in lists) | |
27 | + //this.Rows.AddRange(rows); | |
28 | + | |
29 | + foreach (var row in rows) | |
32 | 30 | { |
33 | - rows.Add(row); | |
31 | + this.Rows.Add(row); | |
34 | 32 | } |
35 | - | |
36 | - return rows; | |
37 | 33 | } |
38 | 34 | |
39 | 35 | protected virtual void Dispose(bool disposing) |
@@ -17,8 +17,8 @@ namespace TestNarou3.Domain.Service | ||
17 | 17 | |
18 | 18 | private string DataToken { get; set; } |
19 | 19 | |
20 | - private BookmarkCategory Categeory { get; set; } | |
21 | - private BookmarkDetailList DetailList { get; set; } | |
20 | + private BookmarkCategory Categeory { get; } | |
21 | + private BookmarkDetailList DetailList { get; } | |
22 | 22 | |
23 | 23 | private readonly INarouRepository repo; |
24 | 24 |
@@ -35,6 +35,9 @@ namespace TestNarou3.Domain.Service | ||
35 | 35 | |
36 | 36 | this.vmCategoryRowTranslator = vmCategoryRowTranslator; |
37 | 37 | this.vmDetailRowTranslator = vmDetailRowTranslator; |
38 | + | |
39 | + this.Categeory = new(); | |
40 | + this.DetailList = new(); | |
38 | 41 | } |
39 | 42 | |
40 | 43 | public void Login(string id, string password) |
@@ -63,8 +66,7 @@ namespace TestNarou3.Domain.Service | ||
63 | 66 | pair => this.vmCategoryRowTranslator.Translate(pair.category, pair.no) |
64 | 67 | ); |
65 | 68 | |
66 | - this.Categeory?.Dispose(); | |
67 | - this.Categeory = new(rows); | |
69 | + this.Categeory.Refresh(rows); | |
68 | 70 | |
69 | 71 | return this.Categeory; |
70 | 72 | } |
@@ -78,8 +80,7 @@ namespace TestNarou3.Domain.Service | ||
78 | 80 | IEnumerable<BookmarkDetailListRow> detailRows = |
79 | 81 | novelInfos.Skip(1).Select(v => vmDetailRowTranslator.Translate(v)); |
80 | 82 | |
81 | - this.DetailList?.Dispose(); | |
82 | - this.DetailList = new(detailRows); | |
83 | + this.DetailList.Refresh(detailRows); | |
83 | 84 | |
84 | 85 | return this.DetailList; |
85 | 86 | } |