ファイル整理用ツールのPrism+WPFサンプル実装
Revisão | 3efb8167194b572d6c1931e2dedd2a4e2a2bddf2 (tree) |
---|---|
Hora | 2023-09-24 14:20:43 |
Autor | yoshy <yoshy.org.bitbucket@gz.j...> |
Commiter | yoshy |
[MOD] ファイルシステム操作系インタラクタ・ロジック処理上で行っていたフォルダツリーの更新処理をプレゼンタに移譲
@@ -0,0 +1,11 @@ | ||
1 | +using CleanAuLait.UseCase.Boundary.Presenter; | |
2 | +using FolderCategorizer2.UseCase.FileSystemOperation.Request; | |
3 | +using FolderCategorizer2.UseCase.FileSystemOperation.Response; | |
4 | + | |
5 | +namespace FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter | |
6 | +{ | |
7 | + public interface IFileSystemCopyOperationPresenter | |
8 | + : IPresenter<FileSystemCopyOperationRequest, FileSystemCopyOperationResponse> | |
9 | + { | |
10 | + } | |
11 | +} | |
\ No newline at end of file |
@@ -0,0 +1,11 @@ | ||
1 | +using CleanAuLait.UseCase.Boundary.Presenter; | |
2 | +using FolderCategorizer2.UseCase.FileSystemOperation.Request; | |
3 | +using FolderCategorizer2.UseCase.FileSystemOperation.Response; | |
4 | + | |
5 | +namespace FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter | |
6 | +{ | |
7 | + public interface IFileSystemMoveOperationPresenter | |
8 | + : IPresenter<FileSystemMoveOperationRequest, FileSystemMoveOperationResponse> | |
9 | + { | |
10 | + } | |
11 | +} | |
\ No newline at end of file |
@@ -1,13 +1,12 @@ | ||
1 | 1 | using CleanAuLait.UseCase.Interactor; |
2 | 2 | using CleanAuLait.UseCase.Response; |
3 | -using FolderCategorizer2.Domain.Boundary.Service; | |
4 | 3 | using FolderCategorizer2.Domain.Service.Dto; |
4 | +using FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter; | |
5 | 5 | using FolderCategorizer2.UseCase.Boundary.FileSystemOperation.Interactor; |
6 | 6 | using FolderCategorizer2.UseCase.FileSystemOperation.Request; |
7 | 7 | using FolderCategorizer2.UseCase.FileSystemOperation.Response; |
8 | 8 | using FolderCategorizer2.UseCase.Internal; |
9 | 9 | using System.Collections.Generic; |
10 | -using System.Linq; | |
11 | 10 | |
12 | 11 | namespace FolderCategorizer2.UseCase.FileSystemOperation.Interactor |
13 | 12 | { |
@@ -20,18 +19,18 @@ namespace FolderCategorizer2.UseCase.FileSystemOperation.Interactor | ||
20 | 19 | private readonly IFileSystemOperationLogic operation; |
21 | 20 | private readonly IFileSystemVerifyLogic verifier; |
22 | 21 | private readonly IFileSystemDialogLogic dialog; |
23 | - private readonly IFolderTreeService folderTree; | |
22 | + private readonly IFileSystemCopyOperationPresenter presenter; | |
24 | 23 | |
25 | 24 | public FileSystemCopyOperationInteractor( |
26 | 25 | IFileSystemOperationLogic operation, |
27 | 26 | IFileSystemVerifyLogic verifier, |
28 | 27 | IFileSystemDialogLogic dialog, |
29 | - IFolderTreeService folderTree) | |
28 | + IFileSystemCopyOperationPresenter presenter) | |
30 | 29 | { |
31 | 30 | this.operation = operation; |
32 | 31 | this.verifier = verifier; |
33 | 32 | this.dialog = dialog; |
34 | - this.folderTree = folderTree; | |
33 | + this.presenter = presenter; | |
35 | 34 | } |
36 | 35 | |
37 | 36 | public override FileSystemCopyOperationResponse Interact(FileSystemCopyOperationRequest req) |
@@ -65,18 +64,10 @@ namespace FolderCategorizer2.UseCase.FileSystemOperation.Interactor | ||
65 | 64 | return UseCaseResponse.Abort<FileSystemCopyOperationResponse>("エラーのため処理が中止されました"); |
66 | 65 | } |
67 | 66 | |
68 | - SelectNode(sourceTargetEntries); | |
67 | + FileSystemCopyOperationResponse res = new(sourceTargetEntries); | |
69 | 68 | |
70 | - return new(); | |
69 | + return this.presenter.Present(req, res); | |
71 | 70 | } |
72 | 71 | |
73 | - private void SelectNode(IEnumerable<FileSystemSourceFilesTargetFolder> sourceTargetEntries) | |
74 | - { | |
75 | - FileSystemSourceFilesTargetFolder sourceTargetEntry = sourceTargetEntries.First(); | |
76 | - | |
77 | - string treeId = sourceTargetEntry.TreeID; | |
78 | - | |
79 | - this.folderTree.SelectNode(treeId, sourceTargetEntry.TargetFolder.RelativePath); | |
80 | - } | |
81 | 72 | } |
82 | 73 | } |
@@ -1,13 +1,12 @@ | ||
1 | 1 | using CleanAuLait.UseCase.Interactor; |
2 | 2 | using CleanAuLait.UseCase.Response; |
3 | -using FolderCategorizer2.Domain.Boundary.Service; | |
4 | 3 | using FolderCategorizer2.Domain.Service.Dto; |
4 | +using FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter; | |
5 | 5 | using FolderCategorizer2.UseCase.Boundary.FileSystemOperation.Interactor; |
6 | 6 | using FolderCategorizer2.UseCase.FileSystemOperation.Request; |
7 | 7 | using FolderCategorizer2.UseCase.FileSystemOperation.Response; |
8 | 8 | using FolderCategorizer2.UseCase.Internal; |
9 | 9 | using System.Collections.Generic; |
10 | -using System.Linq; | |
11 | 10 | |
12 | 11 | namespace FolderCategorizer2.UseCase.FileSystemOperation.Interactor |
13 | 12 | { |
@@ -20,18 +19,18 @@ namespace FolderCategorizer2.UseCase.FileSystemOperation.Interactor | ||
20 | 19 | private readonly IFileSystemOperationLogic operation; |
21 | 20 | private readonly IFileSystemVerifyLogic verifier; |
22 | 21 | private readonly IFileSystemDialogLogic dialog; |
23 | - private readonly IFolderTreeService folderTree; | |
22 | + private readonly IFileSystemMoveOperationPresenter presenter; | |
24 | 23 | |
25 | 24 | public FileSystemMoveOperationInteractor( |
26 | 25 | IFileSystemOperationLogic operation, |
27 | 26 | IFileSystemVerifyLogic verifier, |
28 | 27 | IFileSystemDialogLogic dialog, |
29 | - IFolderTreeService folderTree) | |
28 | + IFileSystemMoveOperationPresenter presenter) | |
30 | 29 | { |
31 | 30 | this.operation = operation; |
32 | 31 | this.verifier = verifier; |
33 | 32 | this.dialog = dialog; |
34 | - this.folderTree = folderTree; | |
33 | + this.presenter = presenter; | |
35 | 34 | } |
36 | 35 | |
37 | 36 | public override FileSystemMoveOperationResponse Interact(FileSystemMoveOperationRequest req) |
@@ -65,21 +64,9 @@ namespace FolderCategorizer2.UseCase.FileSystemOperation.Interactor | ||
65 | 64 | return UseCaseResponse.Abort<FileSystemMoveOperationResponse>("エラーのため処理が中止されました"); |
66 | 65 | } |
67 | 66 | |
68 | - SelectNode(sourceTargetEntries); | |
67 | + FileSystemMoveOperationResponse res = new(sourceTargetEntries); | |
69 | 68 | |
70 | - return new(); | |
69 | + return this.presenter.Present(req, res); | |
71 | 70 | } |
72 | - | |
73 | - private void SelectNode(IEnumerable<FileSystemSourceFilesTargetFolder> sourceTargetEntries) | |
74 | - { | |
75 | - // FIX ME | |
76 | - | |
77 | - FileSystemSourceFilesTargetFolder sourceTargetEntry = sourceTargetEntries.First(); | |
78 | - | |
79 | - string treeId = sourceTargetEntry.TreeID; | |
80 | - | |
81 | - this.folderTree.SelectNode(treeId, sourceTargetEntry.TargetFolder.RelativePath); | |
82 | - } | |
83 | - | |
84 | 71 | } |
85 | 72 | } |
@@ -1,8 +1,16 @@ | ||
1 | 1 | using CleanAuLait.UseCase.Response; |
2 | +using FolderCategorizer2.Domain.Service.Dto; | |
3 | +using System.Collections.Generic; | |
4 | +using System.Linq; | |
2 | 5 | |
3 | 6 | namespace FolderCategorizer2.UseCase.FileSystemOperation.Response |
4 | 7 | { |
5 | - public record class FileSystemCopyOperationResponse : UseCaseResponse | |
8 | + public record class FileSystemCopyOperationResponse( | |
9 | + IEnumerable<FileSystemSourceFilesTargetFolder> SourceTargetEntries) : UseCaseResponse | |
6 | 10 | { |
11 | + public FileSystemCopyOperationResponse() : this( | |
12 | + Enumerable.Empty<FileSystemSourceFilesTargetFolder>()) | |
13 | + { | |
14 | + } | |
7 | 15 | } |
8 | 16 | } |
@@ -1,8 +1,16 @@ | ||
1 | 1 | using CleanAuLait.UseCase.Response; |
2 | +using FolderCategorizer2.Domain.Service.Dto; | |
3 | +using System.Collections.Generic; | |
4 | +using System.Linq; | |
2 | 5 | |
3 | 6 | namespace FolderCategorizer2.UseCase.FileSystemOperation.Response |
4 | 7 | { |
5 | - public record class FileSystemMoveOperationResponse : UseCaseResponse | |
8 | + public record class FileSystemMoveOperationResponse( | |
9 | + IEnumerable<FileSystemSourceFilesTargetFolder> SourceTargetEntries) : UseCaseResponse | |
6 | 10 | { |
11 | + public FileSystemMoveOperationResponse() : this( | |
12 | + Enumerable.Empty<FileSystemSourceFilesTargetFolder>()) | |
13 | + { | |
14 | + } | |
7 | 15 | } |
8 | 16 | } |
@@ -16,16 +16,13 @@ namespace FolderCategorizer2.UseCase.Internal | ||
16 | 16 | private static readonly ILogger logger = LogManager.GetCurrentClassLogger(); |
17 | 17 | |
18 | 18 | private readonly IFileSystemService fileSystem; |
19 | - private readonly IFolderTreeService folderTree; | |
20 | 19 | private readonly IUniversalDialogProxy dialog; |
21 | 20 | |
22 | 21 | public FileSystemOperationLogic( |
23 | 22 | IFileSystemService fileSystem, |
24 | - IFolderTreeService folderTree, | |
25 | 23 | IUniversalDialogProxy dialog) |
26 | 24 | { |
27 | 25 | this.fileSystem = fileSystem; |
28 | - this.folderTree = folderTree; | |
29 | 26 | this.dialog = dialog; |
30 | 27 | } |
31 | 28 |
@@ -41,6 +38,9 @@ namespace FolderCategorizer2.UseCase.Internal | ||
41 | 38 | string sourceFullPath = PathHelper.CreateCanonicalPath(sourceFolderPath, name); |
42 | 39 | string targetFullPath = PathHelper.CreateCanonicalPath(targetFolderPath, name); |
43 | 40 | |
41 | + logger.Trace("copy: from {0}", sourceFullPath); | |
42 | + logger.Trace("copy: to {0}", targetFullPath); | |
43 | + | |
44 | 44 | Retry: |
45 | 45 | try |
46 | 46 | { |
@@ -65,12 +65,9 @@ namespace FolderCategorizer2.UseCase.Internal | ||
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | } |
68 | - } | |
69 | 68 | |
70 | - string treeId = sourceTargetEntry.TreeID; | |
71 | - | |
72 | - this.folderTree.RefreshFolderTree(treeId, sourceTargetEntry.SourceFiles.RelativePath); | |
73 | - this.folderTree.RefreshFolderTree(treeId, sourceTargetEntry.TargetFolder.RelativePath); | |
69 | + logger.Trace("copied."); | |
70 | + } | |
74 | 71 | } |
75 | 72 | |
76 | 73 | return true; |
@@ -88,6 +85,9 @@ namespace FolderCategorizer2.UseCase.Internal | ||
88 | 85 | string sourceFullPath = PathHelper.CreateCanonicalPath(sourceFolderPath, name); |
89 | 86 | string targetFullPath = PathHelper.CreateCanonicalPath(targetFolderPath, name); |
90 | 87 | |
88 | + logger.Trace("move: from {0}", sourceFullPath); | |
89 | + logger.Trace("move: to {0}", targetFullPath); | |
90 | + | |
91 | 91 | Retry: |
92 | 92 | try |
93 | 93 | { |
@@ -112,12 +112,9 @@ namespace FolderCategorizer2.UseCase.Internal | ||
112 | 112 | return false; |
113 | 113 | } |
114 | 114 | } |
115 | - } | |
116 | 115 | |
117 | - string treeId = sourceTargetEntry.TreeID; | |
118 | - | |
119 | - this.folderTree.RefreshFolderTree(treeId, sourceTargetEntry.SourceFiles.RelativePath); | |
120 | - this.folderTree.RefreshFolderTree(treeId, sourceTargetEntry.TargetFolder.RelativePath); | |
116 | + logger.Trace("moved."); | |
117 | + } | |
121 | 118 | } |
122 | 119 | |
123 | 120 | return true; |
@@ -141,7 +138,7 @@ namespace FolderCategorizer2.UseCase.Internal | ||
141 | 138 | catch (Exception e) when (e is IOException || e is InvalidOperationException) |
142 | 139 | { |
143 | 140 | string msg = string.Format( |
144 | - "ファイルのコピー中に次のエラーが発生しました。\n{0}\n\n削除対象:{1}", | |
141 | + "ファイルの削除中に次のエラーが発生しました。\n{0}\n\n削除対象:{1}", | |
145 | 142 | e.Message, sourceFullPath); |
146 | 143 | |
147 | 144 | IDialogResult result = this.dialog.ShowAbortRetryIgnoreDialog("ファイルの削除 - エラー", msg, MessageBoxImage.Hand); |
@@ -158,10 +155,6 @@ namespace FolderCategorizer2.UseCase.Internal | ||
158 | 155 | } |
159 | 156 | } |
160 | 157 | } |
161 | - | |
162 | - string treeId = sourceFiles.TreeID; | |
163 | - | |
164 | - this.folderTree.RefreshFolderTree(treeId, sourceFiles.RelativePath); | |
165 | 158 | } |
166 | 159 | |
167 | 160 | return true; |
@@ -197,10 +190,6 @@ namespace FolderCategorizer2.UseCase.Internal | ||
197 | 190 | return false; |
198 | 191 | } |
199 | 192 | } |
200 | - | |
201 | - string treeId = targetEntry.TreeID; | |
202 | - | |
203 | - this.folderTree.RefreshFolderTree(treeId, targetEntry.RelativePath); | |
204 | 193 | } |
205 | 194 | |
206 | 195 | return true; |
@@ -236,10 +225,6 @@ namespace FolderCategorizer2.UseCase.Internal | ||
236 | 225 | return false; |
237 | 226 | } |
238 | 227 | } |
239 | - | |
240 | - string treeId = targetEntry.TreeID; | |
241 | - | |
242 | - this.folderTree.RefreshFolderTree(treeId, targetEntry.RelativePath); | |
243 | 228 | } |
244 | 229 | |
245 | 230 | return true; |
@@ -276,10 +261,6 @@ namespace FolderCategorizer2.UseCase.Internal | ||
276 | 261 | return false; |
277 | 262 | } |
278 | 263 | } |
279 | - | |
280 | - string treeId = sourceFile.TreeID; | |
281 | - | |
282 | - this.folderTree.RefreshFolderTree(treeId, sourceFile.RelativePath); | |
283 | 264 | } |
284 | 265 | |
285 | 266 | return true; |
@@ -102,6 +102,8 @@ namespace FolderCategorizer2.Adaptor | ||
102 | 102 | containerRegistry.RegisterSingleton<IFolderTreeReplaceTreePresenter, FolderTreeReplaceTreePresenter>(); |
103 | 103 | containerRegistry.RegisterSingleton<IFileListReplaceListPresenter, FileListReplaceListPresenter>(); |
104 | 104 | |
105 | + containerRegistry.RegisterSingleton<IFileSystemCopyOperationPresenter, FileSystemCopyOperationPresenter>(); | |
106 | + containerRegistry.RegisterSingleton<IFileSystemMoveOperationPresenter, FileSystemMoveOperationPresenter>(); | |
105 | 107 | containerRegistry.RegisterSingleton<IFileSystemDeleteOperationPresenter, FileSystemDeleteOperationPresenter>(); |
106 | 108 | containerRegistry.RegisterSingleton<IFileSystemRenameOperationPresenter, FileSystemRenameOperationPresenter>(); |
107 | 109 | containerRegistry.RegisterSingleton<IFileSystemNewFolderOperationPresenter, FileSystemNewFolderOperationPresenter>(); |
@@ -0,0 +1,51 @@ | ||
1 | +using FolderCategorizer2.Domain.Boundary.Service; | |
2 | +using FolderCategorizer2.Domain.Service.Dto; | |
3 | +using FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter; | |
4 | +using FolderCategorizer2.UseCase.FileSystemOperation.Request; | |
5 | +using FolderCategorizer2.UseCase.FileSystemOperation.Response; | |
6 | +using System.Collections.Generic; | |
7 | +using System.Linq; | |
8 | + | |
9 | +namespace FolderCategorizer2.Adaptor.Presenter | |
10 | +{ | |
11 | + public class FileSystemCopyOperationPresenter : IFileSystemCopyOperationPresenter | |
12 | + { | |
13 | + private readonly IFolderTreeService folderTree; | |
14 | + | |
15 | + public FileSystemCopyOperationPresenter(IFolderTreeService folderTree) | |
16 | + { | |
17 | + this.folderTree = folderTree; | |
18 | + } | |
19 | + | |
20 | + public FileSystemCopyOperationResponse Present( | |
21 | + FileSystemCopyOperationRequest req, FileSystemCopyOperationResponse res) | |
22 | + { | |
23 | + IEnumerable<FileSystemSourceFilesTargetFolder> sourceTargetEntries = res.SourceTargetEntries; | |
24 | + | |
25 | + RefreshNodes(sourceTargetEntries); | |
26 | + SelectNode(sourceTargetEntries); | |
27 | + | |
28 | + return res; | |
29 | + } | |
30 | + | |
31 | + private void RefreshNodes(IEnumerable<FileSystemSourceFilesTargetFolder> sourceTargetEntries) | |
32 | + { | |
33 | + foreach (FileSystemSourceFilesTargetFolder sourceTargetEntry in sourceTargetEntries) | |
34 | + { | |
35 | + string treeId = sourceTargetEntry.TreeID; | |
36 | + | |
37 | + this.folderTree.RefreshFolderTree(treeId, sourceTargetEntry.SourceFiles.RelativePath); | |
38 | + this.folderTree.RefreshFolderTree(treeId, sourceTargetEntry.TargetFolder.RelativePath); | |
39 | + } | |
40 | + } | |
41 | + | |
42 | + private void SelectNode(IEnumerable<FileSystemSourceFilesTargetFolder> sourceTargetEntries) | |
43 | + { | |
44 | + FileSystemSourceFilesTargetFolder sourceTargetEntry = sourceTargetEntries.First(); | |
45 | + | |
46 | + string treeId = sourceTargetEntry.TreeID; | |
47 | + | |
48 | + this.folderTree.SelectNode(treeId, sourceTargetEntry.TargetFolder.RelativePath); | |
49 | + } | |
50 | + } | |
51 | +} |
@@ -1,25 +1,44 @@ | ||
1 | 1 | using FolderCategorizer2.Adaptor.Boundary.ViewModel; |
2 | +using FolderCategorizer2.Domain.Boundary.Service; | |
3 | +using FolderCategorizer2.Domain.Service.Dto; | |
2 | 4 | using FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter; |
3 | 5 | using FolderCategorizer2.UseCase.FileSystemOperation.Request; |
4 | 6 | using FolderCategorizer2.UseCase.FileSystemOperation.Response; |
7 | +using System.Collections.Generic; | |
5 | 8 | |
6 | 9 | namespace FolderCategorizer2.Adaptor.Presenter |
7 | 10 | { |
8 | 11 | public class FileSystemDeleteOperationPresenter : IFileSystemDeleteOperationPresenter |
9 | 12 | { |
13 | + private readonly IFolderTreeService folderTree; | |
10 | 14 | private readonly IFileListViewModel targetVm; |
11 | 15 | |
12 | - public FileSystemDeleteOperationPresenter(IFileListViewModel targetVm) | |
16 | + public FileSystemDeleteOperationPresenter( | |
17 | + IFolderTreeService folderTree, | |
18 | + IFileListViewModel targetVm) | |
13 | 19 | { |
20 | + this.folderTree = folderTree; | |
14 | 21 | this.targetVm = targetVm; |
15 | 22 | } |
16 | 23 | |
17 | 24 | public FileSystemDeleteOperationResponse Present( |
18 | 25 | FileSystemDeleteOperationRequest req, FileSystemDeleteOperationResponse res) |
19 | 26 | { |
27 | + RefreshNodes(req.SourceFilesList); | |
28 | + | |
20 | 29 | this.targetVm.ReplaceSource(res.Diff); |
21 | 30 | |
22 | 31 | return res; |
23 | 32 | } |
33 | + | |
34 | + private void RefreshNodes(IEnumerable<FileSystemSourceFiles> sourceFileList) | |
35 | + { | |
36 | + foreach (FileSystemSourceFiles sourceFiles in sourceFileList) | |
37 | + { | |
38 | + string treeId = sourceFiles.TreeID; | |
39 | + | |
40 | + this.folderTree.RefreshFolderTree(treeId, sourceFiles.RelativePath); | |
41 | + } | |
42 | + } | |
24 | 43 | } |
25 | 44 | } |
@@ -0,0 +1,53 @@ | ||
1 | +using FolderCategorizer2.Domain.Boundary.Service; | |
2 | +using FolderCategorizer2.Domain.Service.Dto; | |
3 | +using FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter; | |
4 | +using FolderCategorizer2.UseCase.FileSystemOperation.Request; | |
5 | +using FolderCategorizer2.UseCase.FileSystemOperation.Response; | |
6 | +using System.Collections.Generic; | |
7 | +using System.Linq; | |
8 | + | |
9 | +namespace FolderCategorizer2.Adaptor.Presenter | |
10 | +{ | |
11 | + public class FileSystemMoveOperationPresenter : IFileSystemMoveOperationPresenter | |
12 | + { | |
13 | + private readonly IFolderTreeService folderTree; | |
14 | + | |
15 | + public FileSystemMoveOperationPresenter(IFolderTreeService folderTree) | |
16 | + { | |
17 | + this.folderTree = folderTree; | |
18 | + } | |
19 | + | |
20 | + public FileSystemMoveOperationResponse Present( | |
21 | + FileSystemMoveOperationRequest req, FileSystemMoveOperationResponse res) | |
22 | + { | |
23 | + IEnumerable<FileSystemSourceFilesTargetFolder> sourceTargetEntries = res.SourceTargetEntries; | |
24 | + | |
25 | + RefreshNodes(sourceTargetEntries); | |
26 | + | |
27 | + // FIX ME: freeze screen | |
28 | + //SelectNode(sourceTargetEntries); | |
29 | + | |
30 | + return res; | |
31 | + } | |
32 | + | |
33 | + private void RefreshNodes(IEnumerable<FileSystemSourceFilesTargetFolder> sourceTargetEntries) | |
34 | + { | |
35 | + foreach (FileSystemSourceFilesTargetFolder sourceTargetEntry in sourceTargetEntries) | |
36 | + { | |
37 | + string treeId = sourceTargetEntry.TreeID; | |
38 | + | |
39 | + this.folderTree.RefreshFolderTree(treeId, sourceTargetEntry.SourceFiles.RelativePath); | |
40 | + this.folderTree.RefreshFolderTree(treeId, sourceTargetEntry.TargetFolder.RelativePath); | |
41 | + } | |
42 | + } | |
43 | + | |
44 | + private void SelectNode(IEnumerable<FileSystemSourceFilesTargetFolder> sourceTargetEntries) | |
45 | + { | |
46 | + FileSystemSourceFilesTargetFolder sourceTargetEntry = sourceTargetEntries.First(); | |
47 | + | |
48 | + string treeId = sourceTargetEntry.TreeID; | |
49 | + | |
50 | + this.folderTree.SelectNode(treeId, sourceTargetEntry.TargetFolder.RelativePath); | |
51 | + } | |
52 | + } | |
53 | +} |
@@ -1,25 +1,44 @@ | ||
1 | 1 | using FolderCategorizer2.Adaptor.Boundary.ViewModel; |
2 | +using FolderCategorizer2.Domain.Boundary.Service; | |
3 | +using FolderCategorizer2.Domain.Service.Dto; | |
2 | 4 | using FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter; |
3 | 5 | using FolderCategorizer2.UseCase.FileSystemOperation.Request; |
4 | 6 | using FolderCategorizer2.UseCase.FileSystemOperation.Response; |
7 | +using System.Collections.Generic; | |
5 | 8 | |
6 | 9 | namespace FolderCategorizer2.Adaptor.Presenter |
7 | 10 | { |
8 | 11 | public class FileSystemNewFileOperationPresenter : IFileSystemNewFileOperationPresenter |
9 | 12 | { |
13 | + private readonly IFolderTreeService folderTree; | |
10 | 14 | private readonly IFileListViewModel targetVm; |
11 | 15 | |
12 | - public FileSystemNewFileOperationPresenter(IFileListViewModel targetVm) | |
16 | + public FileSystemNewFileOperationPresenter( | |
17 | + IFolderTreeService folderTree, | |
18 | + IFileListViewModel targetVm) | |
13 | 19 | { |
20 | + this.folderTree = folderTree; | |
14 | 21 | this.targetVm = targetVm; |
15 | 22 | } |
16 | 23 | |
17 | 24 | public FileSystemNewFileOperationResponse Present( |
18 | 25 | FileSystemNewFileOperationRequest req, FileSystemNewFileOperationResponse res) |
19 | 26 | { |
27 | + RefreshNodes(req.Targets); | |
28 | + | |
20 | 29 | this.targetVm.ReplaceSource(res.Diff); |
21 | 30 | |
22 | 31 | return res; |
23 | 32 | } |
33 | + | |
34 | + private void RefreshNodes(IEnumerable<FileSystemPathEntry> targetEntries) | |
35 | + { | |
36 | + foreach (FileSystemPathEntry targetEntry in targetEntries) | |
37 | + { | |
38 | + string treeId = targetEntry.TreeID; | |
39 | + | |
40 | + this.folderTree.RefreshFolderTree(treeId, targetEntry.RelativePath); | |
41 | + } | |
42 | + } | |
24 | 43 | } |
25 | 44 | } |
@@ -1,25 +1,44 @@ | ||
1 | 1 | using FolderCategorizer2.Adaptor.Boundary.ViewModel; |
2 | +using FolderCategorizer2.Domain.Boundary.Service; | |
3 | +using FolderCategorizer2.Domain.Service.Dto; | |
2 | 4 | using FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter; |
3 | 5 | using FolderCategorizer2.UseCase.FileSystemOperation.Request; |
4 | 6 | using FolderCategorizer2.UseCase.FileSystemOperation.Response; |
7 | +using System.Collections.Generic; | |
5 | 8 | |
6 | 9 | namespace FolderCategorizer2.Adaptor.Presenter |
7 | 10 | { |
8 | 11 | public class FileSystemNewFolderOperationPresenter : IFileSystemNewFolderOperationPresenter |
9 | 12 | { |
13 | + private readonly IFolderTreeService folderTree; | |
10 | 14 | private readonly IFileListViewModel targetVm; |
11 | 15 | |
12 | - public FileSystemNewFolderOperationPresenter(IFileListViewModel targetVm) | |
16 | + public FileSystemNewFolderOperationPresenter( | |
17 | + IFolderTreeService folderTree, | |
18 | + IFileListViewModel targetVm) | |
13 | 19 | { |
20 | + this.folderTree = folderTree; | |
14 | 21 | this.targetVm = targetVm; |
15 | 22 | } |
16 | 23 | |
17 | 24 | public FileSystemNewFolderOperationResponse Present( |
18 | 25 | FileSystemNewFolderOperationRequest req, FileSystemNewFolderOperationResponse res) |
19 | 26 | { |
27 | + RefreshNodes(req.Targets); | |
28 | + | |
20 | 29 | this.targetVm.ReplaceSource(res.Diff); |
21 | 30 | |
22 | 31 | return res; |
23 | 32 | } |
33 | + | |
34 | + private void RefreshNodes(IEnumerable<FileSystemPathEntry> targetEntries) | |
35 | + { | |
36 | + foreach (FileSystemPathEntry targetEntry in targetEntries) | |
37 | + { | |
38 | + string treeId = targetEntry.TreeID; | |
39 | + | |
40 | + this.folderTree.RefreshFolderTree(treeId, targetEntry.RelativePath); | |
41 | + } | |
42 | + } | |
24 | 43 | } |
25 | 44 | } |
@@ -1,25 +1,44 @@ | ||
1 | 1 | using FolderCategorizer2.Adaptor.Boundary.ViewModel; |
2 | +using FolderCategorizer2.Domain.Boundary.Service; | |
3 | +using FolderCategorizer2.Domain.Service.Dto; | |
2 | 4 | using FolderCategorizer2.UseCase.Boundary.FileListOperation.Presenter; |
3 | 5 | using FolderCategorizer2.UseCase.FileSystemOperation.Request; |
4 | 6 | using FolderCategorizer2.UseCase.FileSystemOperation.Response; |
7 | +using System.Collections.Generic; | |
5 | 8 | |
6 | 9 | namespace FolderCategorizer2.Adaptor.Presenter |
7 | 10 | { |
8 | 11 | public class FileSystemRenameOperationPresenter : IFileSystemRenameOperationPresenter |
9 | 12 | { |
13 | + private readonly IFolderTreeService folderTree; | |
10 | 14 | private readonly IFileListViewModel targetVm; |
11 | 15 | |
12 | - public FileSystemRenameOperationPresenter(IFileListViewModel targetVm) | |
16 | + public FileSystemRenameOperationPresenter( | |
17 | + IFolderTreeService folderTree, | |
18 | + IFileListViewModel targetVm) | |
13 | 19 | { |
20 | + this.folderTree = folderTree; | |
14 | 21 | this.targetVm = targetVm; |
15 | 22 | } |
16 | 23 | |
17 | 24 | public FileSystemRenameOperationResponse Present( |
18 | 25 | FileSystemRenameOperationRequest req, FileSystemRenameOperationResponse res) |
19 | 26 | { |
27 | + RefreshNodes(req.SourceFileList); | |
28 | + | |
20 | 29 | this.targetVm.ReplaceSource(res.Diff); |
21 | 30 | |
22 | 31 | return res; |
23 | 32 | } |
33 | + | |
34 | + private void RefreshNodes(IEnumerable<FileSystemSourceFile> sourceFileList) | |
35 | + { | |
36 | + foreach (FileSystemSourceFile sourceFile in sourceFileList) | |
37 | + { | |
38 | + string treeId = sourceFile.TreeID; | |
39 | + | |
40 | + this.folderTree.RefreshFolderTree(treeId, sourceFile.RelativePath); | |
41 | + } | |
42 | + } | |
24 | 43 | } |
25 | 44 | } |
@@ -1,4 +1,5 @@ | ||
1 | -using FolderCategorizer2.Domain.Boundary.Repository; | |
1 | +using CleanAuLait.Core.IO; | |
2 | +using FolderCategorizer2.Domain.Boundary.Repository; | |
2 | 3 | using FolderCategorizer2.Domain.Model.Const; |
3 | 4 | using FolderCategorizer2.Domain.Service.Dto; |
4 | 5 | using FolderCategorizer2.OuterEdge.Translator; |
@@ -108,69 +109,160 @@ namespace FolderCategorizer2.OuterEdge.Repository.OS | ||
108 | 109 | |
109 | 110 | public void MoveFile(string targetPath, string sourceFullPath) |
110 | 111 | { |
112 | +#if false | |
111 | 113 | if (Directory.Exists(sourceFullPath)) |
112 | 114 | { |
113 | 115 | logger.Debug("FileSystem.MoveDirectory({0}, {1})", sourceFullPath, targetPath); |
114 | - VBFileSystem.MoveDirectory(sourceFullPath, targetPath); | |
116 | + VBFileSystem.MoveDirectory(sourceFullPath, targetPath, UIOption.AllDialogs); | |
115 | 117 | } |
116 | 118 | else if (File.Exists(sourceFullPath)) |
117 | 119 | { |
118 | 120 | logger.Debug("FileSystem.MoveFile({0}, {1})", sourceFullPath, targetPath); |
119 | - VBFileSystem.MoveFile(sourceFullPath, targetPath); | |
121 | + VBFileSystem.MoveFile(sourceFullPath, targetPath, UIOption.AllDialogs); | |
120 | 122 | } |
121 | 123 | else |
122 | 124 | { |
123 | 125 | throw new FileNotFoundException($"{sourceFullPath}が存在しないか無効です"); |
124 | 126 | } |
127 | +#else | |
128 | + if (Directory.Exists(sourceFullPath)) | |
129 | + { | |
130 | + logger.Debug("Directory.Move({0}, {1})", sourceFullPath, targetPath); | |
131 | + Directory.Move(sourceFullPath, targetPath); | |
132 | + } | |
133 | + else if (File.Exists(sourceFullPath)) | |
134 | + { | |
135 | + logger.Debug("File.Move({0}, {1})", sourceFullPath, targetPath); | |
136 | + File.Move(sourceFullPath, targetPath); | |
137 | + } | |
138 | + else | |
139 | + { | |
140 | + throw new FileNotFoundException($"{sourceFullPath}が存在しないか無効です"); | |
141 | + } | |
142 | +#endif | |
125 | 143 | } |
126 | 144 | |
127 | 145 | public void CopyFile(string targetPath, string sourceFullPath) |
128 | 146 | { |
147 | +#if false | |
129 | 148 | if (Directory.Exists(sourceFullPath)) |
130 | 149 | { |
131 | 150 | logger.Debug("FileSystem.CopyDirectory({0}, {1})", sourceFullPath, targetPath); |
132 | - VBFileSystem.CopyDirectory(sourceFullPath, targetPath); | |
151 | + VBFileSystem.CopyDirectory(sourceFullPath, targetPath, UIOption.AllDialogs); | |
133 | 152 | } |
134 | 153 | else if (File.Exists(sourceFullPath)) |
135 | 154 | { |
136 | 155 | logger.Debug("FileSystem.CopyFile({0}, {1})", sourceFullPath, targetPath); |
137 | - VBFileSystem.CopyFile(sourceFullPath, targetPath); | |
156 | + VBFileSystem.CopyFile(sourceFullPath, targetPath, UIOption.AllDialogs); | |
138 | 157 | } |
139 | 158 | else |
140 | 159 | { |
141 | 160 | throw new FileNotFoundException($"{sourceFullPath}が存在しないか無効です"); |
142 | 161 | } |
162 | +#else | |
163 | + if (Directory.Exists(sourceFullPath)) | |
164 | + { | |
165 | + //logger.Debug("Directory.Copy({0}, {1})", sourceFullPath, targetPath); | |
166 | + CopyDirectory(targetPath, sourceFullPath); | |
167 | + } | |
168 | + else if (File.Exists(sourceFullPath)) | |
169 | + { | |
170 | + logger.Debug("File.Copy({0}, {1})", sourceFullPath, targetPath); | |
171 | + File.Copy(sourceFullPath, targetPath); | |
172 | + } | |
173 | + else | |
174 | + { | |
175 | + throw new FileNotFoundException($"{sourceFullPath}が存在しないか無効です"); | |
176 | + } | |
177 | +#endif | |
178 | + } | |
179 | + | |
180 | + /// <see cref="https://learn.microsoft.com/ja-jp/dotnet/standard/io/how-to-copy-directories"/> | |
181 | + private void CopyDirectory(string targetPath, string sourceFullPath) | |
182 | + { | |
183 | + // Get information about the source directory | |
184 | + DirectoryInfo dir = new(sourceFullPath); | |
185 | + | |
186 | + // Check if the source directory exists | |
187 | + if (!dir.Exists) | |
188 | + throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}"); | |
189 | + | |
190 | + // Cache directories before we start copying | |
191 | + DirectoryInfo[] dirs = dir.GetDirectories(); | |
192 | + | |
193 | + // Create the destination directory | |
194 | + logger.Debug("Directory.CreateDirectory({0})", targetPath); | |
195 | + Directory.CreateDirectory(targetPath); | |
196 | + | |
197 | + // Get the files in the source directory and copy to the destination directory | |
198 | + foreach (FileInfo file in dir.GetFiles()) | |
199 | + { | |
200 | + string targetFilePath = Path.Combine(targetPath, file.Name); | |
201 | + logger.Debug("FileInfo({0}).CopyTo({1})", file.FullName, targetFilePath); | |
202 | + file.CopyTo(targetFilePath); | |
203 | + } | |
204 | + | |
205 | + // Recursively call this method | |
206 | + foreach (DirectoryInfo subDir in dirs) | |
207 | + { | |
208 | + string newDestinationDir = Path.Combine(targetPath, subDir.Name); | |
209 | + CopyDirectory(newDestinationDir, subDir.FullName); | |
210 | + } | |
143 | 211 | } |
144 | 212 | |
145 | 213 | public void DeleteFile(string sourceFullPath) |
146 | 214 | { |
215 | +#if false | |
147 | 216 | if (Directory.Exists(sourceFullPath)) |
148 | 217 | { |
149 | 218 | logger.Debug("FileSystem.DeleteDirectory({0})", sourceFullPath); |
150 | - VBFileSystem.DeleteDirectory(sourceFullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); | |
219 | + VBFileSystem.DeleteDirectory(sourceFullPath, UIOption.AllDialogs, RecycleOption.SendToRecycleBin); | |
151 | 220 | } |
152 | 221 | else if (File.Exists(sourceFullPath)) |
153 | 222 | { |
154 | 223 | logger.Debug("FileSystem.DeleteFile({0})", sourceFullPath); |
155 | - VBFileSystem.DeleteFile(sourceFullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); | |
224 | + VBFileSystem.DeleteFile(sourceFullPath, UIOption.AllDialogs, RecycleOption.SendToRecycleBin); | |
225 | + } | |
226 | + else | |
227 | + { | |
228 | + throw new FileNotFoundException($"{sourceFullPath}が存在しないか無効です"); | |
229 | + } | |
230 | +#else | |
231 | + if (Directory.Exists(sourceFullPath)) | |
232 | + { | |
233 | + logger.Debug("Directory.Delete({0})", sourceFullPath); | |
234 | + Directory.Delete(sourceFullPath, true); | |
235 | + } | |
236 | + else if (File.Exists(sourceFullPath)) | |
237 | + { | |
238 | + logger.Debug("File.Delete({0})", sourceFullPath); | |
239 | + File.Delete(sourceFullPath); | |
156 | 240 | } |
157 | 241 | else |
158 | 242 | { |
159 | 243 | throw new FileNotFoundException($"{sourceFullPath}が存在しないか無効です"); |
160 | 244 | } |
245 | +#endif | |
161 | 246 | } |
162 | 247 | |
163 | 248 | public void RenameFile(string sourceFullPath, string targetName) |
164 | 249 | { |
250 | + | |
165 | 251 | if (Directory.Exists(sourceFullPath)) |
166 | 252 | { |
167 | - logger.Debug("FileSystem.RenameDirectory({0}, {1})", sourceFullPath, targetName); | |
168 | - VBFileSystem.RenameDirectory(sourceFullPath, targetName); | |
253 | + DirectoryInfo di = new(sourceFullPath); | |
254 | + string targetFullPath = PathHelper.CreateCanonicalRelativePath(di.Parent.FullName, targetName); | |
255 | + | |
256 | + logger.Debug("Directory.Move({0}, {1})", sourceFullPath, targetFullPath); | |
257 | + Directory.Move(sourceFullPath, targetFullPath); | |
169 | 258 | } |
170 | 259 | else if (File.Exists(sourceFullPath)) |
171 | 260 | { |
172 | - logger.Debug("FileSystem.RenameFile({0}, {1})", sourceFullPath, targetName); | |
173 | - VBFileSystem.RenameFile(sourceFullPath, targetName); | |
261 | + DirectoryInfo di = new(sourceFullPath); | |
262 | + string targetFullPath = PathHelper.CreateCanonicalRelativePath(di.Parent.FullName, targetName); | |
263 | + | |
264 | + logger.Debug("File.Move({0}, {1})", sourceFullPath, targetFullPath); | |
265 | + File.Move(sourceFullPath, targetFullPath); | |
174 | 266 | } |
175 | 267 | else |
176 | 268 | { |
@@ -14,13 +14,12 @@ | ||
14 | 14 | <None Remove="Resources\message.properties" /> |
15 | 15 | </ItemGroup> |
16 | 16 | <ItemGroup> |
17 | - <PackageReference Include="AutoMapper" Version="12.0.0" /> | |
18 | - <PackageReference Include="gong-wpf-dragdrop" Version="3.2.0" /> | |
19 | - <PackageReference Include="NLog" Version="5.0.4" /> | |
17 | + <PackageReference Include="AutoMapper" Version="12.0.1" /> | |
18 | + <PackageReference Include="gong-wpf-dragdrop" Version="3.2.1" /> | |
20 | 19 | <PackageReference Include="Prism.Unity" Version="8.1.97" /> |
21 | 20 | <PackageReference Include="Prism.Wpf" Version="8.1.97" /> |
22 | - <PackageReference Include="ReactiveProperty" Version="8.1.2" /> | |
23 | - <PackageReference Include="ReactiveProperty.WPF" Version="8.1.2" /> | |
21 | + <PackageReference Include="ReactiveProperty" Version="9.3.1" /> | |
22 | + <PackageReference Include="ReactiveProperty.WPF" Version="9.3.1" /> | |
24 | 23 | </ItemGroup> |
25 | 24 | <ItemGroup> |
26 | 25 | <ProjectReference Include="..\..\CleanAuLait.ObservableCollectionsMod\CleanAuLait.ObservableCollectionsMod.csproj" /> |