Skip to content

Commit

Permalink
merger: minor refactoring of folder to content type auto detection to…
Browse files Browse the repository at this point in the history
… improve performance a little
  • Loading branch information
stojy committed Sep 20, 2023
1 parent 7b2ef9a commit 269b6b8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ClrVpin/Merger/MergerViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
Expand Down Expand Up @@ -42,7 +43,7 @@ public MergerViewModel()
SourceFolderModel = new GenericFolderTypeModel("Source", Settings.Merger.SourceFolder, true, folder =>
{
Settings.Merger.SourceFolder = folder;
TryUpdateDestinationFolder(folder);
TryUpdateDestinationContentType(folder);
});

var destinationContentTypes = Model.Settings.GetFixableContentTypes().Select((contentType, i) =>
Expand All @@ -53,7 +54,7 @@ public MergerViewModel()
Tip = contentType.Tip + (contentType.IsFolderValid == false ? Model.OptionsDisabledMessage : null)
});
DestinationContentTypesView = new ListCollectionView<FeatureType>(destinationContentTypes);
TryUpdateDestinationFolder(Settings.Merger.DestinationContentType);
TryUpdateDestinationContentType(Settings.Merger.DestinationContentType);

IgnoreWordsString = string.Join(", ", Settings.Merger.IgnoreIWords);
IgnoreWordsChangedCommand = new ActionCommand(IgnoreWordsChanged);
Expand Down Expand Up @@ -126,13 +127,15 @@ private void UpdateDestinationContentTypeSettings()
IsValid = !string.IsNullOrEmpty(Settings.Merger.DestinationContentType);
}

private void TryUpdateDestinationFolder(string folder)
private void TryUpdateDestinationContentType(string folder)
{
// attempt to assign destination folder automatically based on the specified folder
var directory = Path.GetFileName(folder)?.ToLower();

// attempt to assign destination content type automatically based on the specified folder
// - if a folder for a disabled content type is specified (e.g. folder in settings hasn't been configured), then remove the selected item (if any)
var matchedContentType = DestinationContentTypesView
.Where(contentType => contentType.IsActive)
.FirstOrDefault(c => folder?.ToLower().EndsWith(c.Description.ToLower()) ?? false);
.FirstOrDefault(c => directory == c.Description.ToLower());

DestinationContentType = matchedContentType;
DestinationContentTypesView.MoveCurrentTo(DestinationContentType);
Expand Down

0 comments on commit 269b6b8

Please sign in to comment.