• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

なろうブックマーク分析用ツールのPrism+WinUI3サンプル実装


コミットメタ情報

リビジョン0fe237d994965d47727cf4fdb77d61a5181cbfdd (tree)
日時2022-08-16 22:09:02
作者yoshy <yoshy.org.bitbucket@gz.j...>
コミッターyoshy

ログメッセージ

[MOD] Model と ViewModel の同期を正しく行うように修正

変更サマリ

差分

--- a/TestNarou3.Adaptor/Gateway/ViewModel/BookmarkCategoryViewModel.cs
+++ b/TestNarou3.Adaptor/Gateway/ViewModel/BookmarkCategoryViewModel.cs
@@ -1,4 +1,5 @@
1-using NLog;
1+using CleanAuLait.Core.Log;
2+using NLog;
23 using ObservableCollections;
34 using Prism.Navigation;
45 using Reactive.Bindings;
@@ -64,29 +65,15 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel
6465 .WithINotifyCollectionChangedList()
6566 .AddTo(disposables);
6667
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);
6970
7071 this.Source = source;
7172 }
7273 else
7374 {
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());
9077 }
9178 }
9279
--- a/TestNarou3.Adaptor/Gateway/ViewModel/BookmarkDetailListViewModel.cs
+++ b/TestNarou3.Adaptor/Gateway/ViewModel/BookmarkDetailListViewModel.cs
@@ -1,4 +1,5 @@
1-using NLog;
1+using CleanAuLait.Core.Log;
2+using NLog;
23 using ObservableCollections;
34 using Prism.Navigation;
45 using Reactive.Bindings;
@@ -83,27 +84,15 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel
8384 .WithINotifyCollectionChangedList()
8485 .AddTo(disposables);
8586
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);
8789
8890 this.Source = source;
8991 }
9092 else
9193 {
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());
10796 }
10897 }
10998
--- a/TestNarou3.Domain/Model/Entity/BookmarkCategory.cs
+++ b/TestNarou3.Domain/Model/Entity/BookmarkCategory.cs
@@ -12,28 +12,24 @@ namespace TestNarou3.Domain.Model.Entity
1212 private bool disposedValue;
1313
1414 public BookmarkCategory() : this(
15- Rows: new ObservableList<BookmarkCategoryRow>()
15+ Rows: new()
1616 )
1717 {
1818 }
1919
20- public BookmarkCategory(IEnumerable<BookmarkCategoryRow> lists) : this(
21- Rows: CreateRows(lists)
22- )
20+ public void Refresh(IEnumerable<BookmarkCategoryRow> rows)
2321 {
24- }
22+ this.Rows.Clear();
2523
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.
3026
31- foreach (var row in lists)
27+ //this.Rows.AddRange(rows);
28+
29+ foreach (var row in rows)
3230 {
33- rows.Add(row);
31+ this.Rows.Add(row);
3432 }
35-
36- return rows;
3733 }
3834
3935 protected virtual void Dispose(bool disposing)
--- a/TestNarou3.Domain/Model/Entity/BookmarkDetailList.cs
+++ b/TestNarou3.Domain/Model/Entity/BookmarkDetailList.cs
@@ -12,28 +12,24 @@ namespace TestNarou3.Domain.Model.Entity
1212 private bool disposedValue;
1313
1414 public BookmarkDetailList() : this(
15- Rows: new ObservableList<BookmarkDetailListRow>()
15+ Rows: new()
1616 )
1717 {
1818 }
1919
20- public BookmarkDetailList(IEnumerable<BookmarkDetailListRow> lists) : this(
21- Rows: CreateRows(lists)
22- )
20+ public void Refresh(IEnumerable<BookmarkDetailListRow> rows)
2321 {
24- }
22+ this.Rows.Clear();
2523
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.
3026
31- foreach (var row in lists)
27+ //this.Rows.AddRange(rows);
28+
29+ foreach (var row in rows)
3230 {
33- rows.Add(row);
31+ this.Rows.Add(row);
3432 }
35-
36- return rows;
3733 }
3834
3935 protected virtual void Dispose(bool disposing)
--- a/TestNarou3.Domain/Service/NarouService.cs
+++ b/TestNarou3.Domain/Service/NarouService.cs
@@ -17,8 +17,8 @@ namespace TestNarou3.Domain.Service
1717
1818 private string DataToken { get; set; }
1919
20- private BookmarkCategory Categeory { get; set; }
21- private BookmarkDetailList DetailList { get; set; }
20+ private BookmarkCategory Categeory { get; }
21+ private BookmarkDetailList DetailList { get; }
2222
2323 private readonly INarouRepository repo;
2424
@@ -35,6 +35,9 @@ namespace TestNarou3.Domain.Service
3535
3636 this.vmCategoryRowTranslator = vmCategoryRowTranslator;
3737 this.vmDetailRowTranslator = vmDetailRowTranslator;
38+
39+ this.Categeory = new();
40+ this.DetailList = new();
3841 }
3942
4043 public void Login(string id, string password)
@@ -63,8 +66,7 @@ namespace TestNarou3.Domain.Service
6366 pair => this.vmCategoryRowTranslator.Translate(pair.category, pair.no)
6467 );
6568
66- this.Categeory?.Dispose();
67- this.Categeory = new(rows);
69+ this.Categeory.Refresh(rows);
6870
6971 return this.Categeory;
7072 }
@@ -78,8 +80,7 @@ namespace TestNarou3.Domain.Service
7880 IEnumerable<BookmarkDetailListRow> detailRows =
7981 novelInfos.Skip(1).Select(v => vmDetailRowTranslator.Translate(v));
8082
81- this.DetailList?.Dispose();
82- this.DetailList = new(detailRows);
83+ this.DetailList.Refresh(detailRows);
8384
8485 return this.DetailList;
8586 }