From 932c55dbc5488b08dbaaa86e5b184f5f3d2637d1 Mon Sep 17 00:00:00 2001 From: jbe2277 Date: Sat, 25 Nov 2023 21:35:25 +0100 Subject: [PATCH] InfoMan: simplify code by using new C# features --- .../ViewModels/ContactListViewModelTest.cs | 6 +--- .../Controllers/ContactController.cs | 6 ++-- .../Controllers/ModuleController.cs | 6 ++-- .../Controllers/SelectContactController.cs | 4 +-- .../DtoFactory.cs | 4 +-- .../SampleData/SampleDataProvider.cs | 19 +++++------- .../AddressBookRootTest.cs | 6 ++-- .../AddressBookRoot.cs | 7 +---- .../Views/ContactListView.xaml.cs | 6 ++-- .../Views/SelectContactWindow.xaml.cs | 2 +- .../InformationManager/Assembler/App.xaml.cs | 4 +-- .../ApplicationsTest.cs | 2 +- .../ViewModels/EmailListViewModelTest.cs | 6 +--- .../ViewModels/NewEmailViewModelTest.cs | 16 ++++------ .../Controllers/EditEmailAccountController.cs | 4 +-- .../Controllers/EmailAccountsController.cs | 4 +-- .../Controllers/EmailFolderController.cs | 4 +-- .../Controllers/ModuleController.cs | 23 +++++++-------- .../Controllers/NewEmailController.cs | 4 +-- .../SampleData/SampleDataProvider.cs | 29 ++++++++----------- .../ViewModels/BasicEmailAccountViewModel.cs | 3 +- .../Emails/EmailFolderTest.cs | 2 +- .../Emails/EmailClientRoot.cs | 13 ++++----- .../Emails/EmailFolder.cs | 7 +---- .../DesignData/SampleNewEmailViewModel.cs | 2 +- .../Views/EmailAccountsWindow.xaml.cs | 2 +- .../Views/EmailListView.xaml.cs | 10 +++---- .../Views/Pop3SettingsView.xaml.cs | 2 +- .../Services/MockNavigationService.cs | 7 +---- .../Services/MockShellService.cs | 7 +---- .../Services/MockShellViewModel.cs | 7 +---- .../Services/ShellServiceTest.cs | 6 ++-- .../ViewModels/ShellViewModelTest.cs | 6 ++-- .../Views/MockShellView.cs | 7 +---- .../Services/NavigationService.cs | 7 +---- .../Views/ShellWindow.xaml.cs | 7 ++--- 36 files changed, 98 insertions(+), 159 deletions(-) diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications.Test/ViewModels/ContactListViewModelTest.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications.Test/ViewModels/ContactListViewModelTest.cs index 2d404078..2ba11149 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications.Test/ViewModels/ContactListViewModelTest.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications.Test/ViewModels/ContactListViewModelTest.cs @@ -13,11 +13,7 @@ public class ContactListViewModelTest : AddressBookTest public void PropertiesTest() { var viewModel = Get(); - var contacts = new List() - { - new(), - new() - }; + var contacts = new List() { new(), new() }; Assert.IsNull(viewModel.Contacts); viewModel.Contacts = contacts; diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/ContactController.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/ContactController.cs index 98471881..e40d044c 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/ContactController.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/ContactController.cs @@ -25,7 +25,7 @@ public ContactController(IShellService shellService, ContactLayoutViewModel cont ContactListViewModel = contactListViewModel; ContactViewModel = contactViewModel; NewContactCommand = new DelegateCommand(NewContact); - deleteContactCommand = new DelegateCommand(DeleteContact, CanDeleteContact); + deleteContactCommand = new(DeleteContact, CanDeleteContact); } public AddressBookRoot Root { get; set; } = null!; @@ -40,7 +40,7 @@ public ContactController(IShellService shellService, ContactLayoutViewModel cont public void Initialize() { - contactsView = new ObservableListView(Root!.Contacts, null, ContactListViewModel.Filter, null); + contactsView = new(Root!.Contacts, null, ContactListViewModel.Filter, null); ContactListViewModel.Contacts = contactsView; ContactListViewModel.DeleteContactCommand = DeleteContactCommand; WeakEvent.PropertyChanged.Add(ContactListViewModel, ContactListViewModelPropertyChanged); @@ -60,7 +60,7 @@ public void Shutdown() private void NewContact() { - Contact newContact = Root.AddNewContact(); + var newContact = Root.AddNewContact(); ContactListViewModel.SelectedContact = newContact; ContactListViewModel.FocusItem(); } diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/ModuleController.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/ModuleController.cs index 0afa30d8..10215cde 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/ModuleController.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/ModuleController.cs @@ -33,7 +33,7 @@ public ModuleController(IShellService shellService, IDocumentService documentSer this.navigationService = navigationService; this.contactControllerFactory = contactControllerFactory; this.selectContactControllerFactory = selectContactControllerFactory; - serializer = new Lazy(CreateDataContractSerializer); + serializer = new(CreateDataContractSerializer); } internal AddressBookRoot Root { get; private set; } = null!; @@ -44,7 +44,7 @@ public void Initialize() { if (stream.Length == 0) { - Root = new AddressBookRoot(); + Root = new(); foreach (var x in SampleDataProvider.CreateContacts()) Root.AddContact(x); } else Root = (AddressBookRoot)serializer.Value.ReadObject(stream)!; @@ -80,7 +80,7 @@ private void ShowAddressBook() var uiNewContactCommand = new ToolBarCommand(activeContactController.NewContactCommand, "_New contact", "Creates a new contact."); var uiDeleteCommand = new ToolBarCommand(activeContactController.DeleteContactCommand, "_Delete", "Deletes the selected contact."); - shellService.AddToolBarCommands(new[] { uiNewContactCommand, uiDeleteCommand }); + shellService.AddToolBarCommands([ uiNewContactCommand, uiDeleteCommand ]); } private void CloseAddressBook() diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/SelectContactController.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/SelectContactController.cs index 87929386..a39243cb 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/SelectContactController.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/Controllers/SelectContactController.cs @@ -19,7 +19,7 @@ public SelectContactController(SelectContactViewModel selectContactViewModel, Co { this.selectContactViewModel = selectContactViewModel; ContactListViewModel = contactListViewModel; - selectContactCommand = new DelegateCommand(SelectContact, CanSelectContact); + selectContactCommand = new(SelectContact, CanSelectContact); } public object OwnerView { get; set; } = null!; @@ -32,7 +32,7 @@ public SelectContactController(SelectContactViewModel selectContactViewModel, Co public void Initialize() { - contactsView = new ObservableListView(Root.Contacts, null, ContactListViewModel.Filter, null); + contactsView = new(Root.Contacts, null, ContactListViewModel.Filter, null); ContactListViewModel.Contacts = contactsView; ContactListViewModel.SelectedContact = Root.Contacts.FirstOrDefault(); selectContactViewModel.ContactListView = ContactListViewModel.View; diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/DtoFactory.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/DtoFactory.cs index 57b68991..1db15fe6 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/DtoFactory.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/DtoFactory.cs @@ -5,6 +5,6 @@ namespace Waf.InformationManager.AddressBook.Modules.Applications; internal static class DtoFactory { - [return: NotNullIfNotNull("contact")] - public static ContactDto? ToDto(this Contact? contact) => contact != null ? new ContactDto(contact.Firstname, contact.Lastname, contact.Email) : null; + [return: NotNullIfNotNull(nameof(contact))] + public static ContactDto? ToDto(this Contact? contact) => contact != null ? new(contact.Firstname, contact.Lastname, contact.Email) : null; } diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/SampleData/SampleDataProvider.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/SampleData/SampleDataProvider.cs index ff9ad5b3..b3eb8096 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/SampleData/SampleDataProvider.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Applications/SampleData/SampleDataProvider.cs @@ -6,18 +6,13 @@ namespace Waf.InformationManager.AddressBook.Modules.Applications.SampleData; [GeneratedCode("ToSuppressCodeAnalysis", "1.0.0.0")] public static class SampleDataProvider { - public static IReadOnlyList CreateContacts() - { - var contacts = new List() - { - CreateContact("Jesper", "Aaberg", "jesper.aaberg@example.com", "(111) 555-0100", "A. Datum Corporation", "Main St. 4567", "Buffalo", "New York", "98052", "United States"), - CreateContact("Lori", "Penor", "lori.penor@fabrikam.com", "(111) 555-0104", "Baldwin Museum of Science", "Front St. 3598", "Seattle", "Washington", "12345", "United States"), - CreateContact("Michael", "Pfeiffer", "michael.pfeiffer@fabrikam.com", "(222) 555-0105", "Blue Yonder Airlines", "Front St. 1234", "Seattle", "Washington", "12345", "United States"), - CreateContact("Terry", "Adams", "terry.adams@adventure-works.com", "(333) 555-0102", "Adventure Works", "Main St. 789", "Buffalo", "New York", "98052", "United States"), - CreateContact("Miles", "Reid", "miles.reid@adventure-works.com", "(444) 555-0123", "Adventure Works", "22nd St NE 349", "Miami", "Florida", "98052", "United States") - }; - return contacts; - } + public static IReadOnlyList CreateContacts() => [ + CreateContact("Jesper", "Aaberg", "jesper.aaberg@example.com", "(111) 555-0100", "A. Datum Corporation", "Main St. 4567", "Buffalo", "New York", "98052", "United States"), + CreateContact("Lori", "Penor", "lori.penor@fabrikam.com", "(111) 555-0104", "Baldwin Museum of Science", "Front St. 3598", "Seattle", "Washington", "12345", "United States"), + CreateContact("Michael", "Pfeiffer", "michael.pfeiffer@fabrikam.com", "(222) 555-0105", "Blue Yonder Airlines", "Front St. 1234", "Seattle", "Washington", "12345", "United States"), + CreateContact("Terry", "Adams", "terry.adams@adventure-works.com", "(333) 555-0102", "Adventure Works", "Main St. 789", "Buffalo", "New York", "98052", "United States"), + CreateContact("Miles", "Reid", "miles.reid@adventure-works.com", "(444) 555-0123", "Adventure Works", "22nd St NE 349", "Miami", "Florida", "98052", "United States") + ]; private static Contact CreateContact(string firstname, string lastname, string email, string phone, string company, string street, string city, string state, string postalCode, string country) { diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Domain.Test/AddressBookRootTest.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Domain.Test/AddressBookRootTest.cs index 2861664b..5c1a0471 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Domain.Test/AddressBookRootTest.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Domain.Test/AddressBookRootTest.cs @@ -16,13 +16,13 @@ public void AddAndRemoveContacts() Assert.IsFalse(root.Contacts.Any()); var contact1 = root.AddNewContact(); - AssertHelper.SequenceEqual(new[] { contact1 }, root.Contacts); + AssertHelper.SequenceEqual([ contact1 ], root.Contacts); var contact2 = new Contact(); root.AddContact(contact2); - AssertHelper.SequenceEqual(new[] { contact1, contact2 }, root.Contacts); + AssertHelper.SequenceEqual([ contact1, contact2 ], root.Contacts); root.RemoveContact(contact1); - AssertHelper.SequenceEqual(new[] { contact2 }, root.Contacts); + AssertHelper.SequenceEqual([ contact2 ], root.Contacts); } } diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Domain/AddressBookRoot.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Domain/AddressBookRoot.cs index efdd1366..11dafb5c 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Domain/AddressBookRoot.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Domain/AddressBookRoot.cs @@ -7,12 +7,7 @@ namespace Waf.InformationManager.AddressBook.Modules.Domain; public class AddressBookRoot : ValidatableModel { [DataMember] - private readonly ObservableList contacts; - - public AddressBookRoot() - { - contacts = new(); - } + private readonly ObservableList contacts = []; public IReadOnlyList Contacts => contacts; diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Presentation/Views/ContactListView.xaml.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Presentation/Views/ContactListView.xaml.cs index 9d78a6ff..7b3e4d4f 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Presentation/Views/ContactListView.xaml.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Presentation/Views/ContactListView.xaml.cs @@ -16,7 +16,7 @@ public partial class ContactListView : IContactListView public ContactListView() { InitializeComponent(); - viewModel = new Lazy(() => ViewHelper.GetViewModel(this)!); + viewModel = new(() => ViewHelper.GetViewModel(this)!); Loaded += LoadedHandler; } @@ -30,13 +30,13 @@ public void FocusItem() return; } - Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)(() => + Dispatcher.BeginInvoke(DispatcherPriority.Background, () => { // It is necessary to delay this code because data binding updates the values asynchronously. contactsBox.ScrollIntoView(ViewModel.SelectedContact); var selectedListBoxItem = (ListBoxItem)contactsBox.ItemContainerGenerator.ContainerFromItem(ViewModel.SelectedContact); selectedListBoxItem?.Focus(); - })); + }); } private void LoadedHandler(object sender, RoutedEventArgs e) diff --git a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Presentation/Views/SelectContactWindow.xaml.cs b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Presentation/Views/SelectContactWindow.xaml.cs index 14e59573..7faba7f3 100644 --- a/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Presentation/Views/SelectContactWindow.xaml.cs +++ b/src/System.Waf/Samples/InformationManager/AddressBook.Modules.Presentation/Views/SelectContactWindow.xaml.cs @@ -16,7 +16,7 @@ public partial class SelectContactWindow : ISelectContactView public SelectContactWindow() { InitializeComponent(); - viewModel = new Lazy(() => ViewHelper.GetViewModel(this)!); + viewModel = new(() => ViewHelper.GetViewModel(this)!); } public SelectContactViewModel ViewModel => viewModel.Value; diff --git a/src/System.Waf/Samples/InformationManager/Assembler/App.xaml.cs b/src/System.Waf/Samples/InformationManager/Assembler/App.xaml.cs index 1eb154d3..dce4b713 100644 --- a/src/System.Waf/Samples/InformationManager/Assembler/App.xaml.cs +++ b/src/System.Waf/Samples/InformationManager/Assembler/App.xaml.cs @@ -34,7 +34,7 @@ private static readonly (string loggerNamePattern, LogLevel minLevel)[] logSetti private AggregateCatalog? catalog; private CompositionContainer? container; - private IEnumerable moduleControllers = Array.Empty(); + private IEnumerable moduleControllers = []; public App() { @@ -81,7 +81,7 @@ protected override void OnStartup(StartupEventArgs e) // Load module assemblies as well. See App.config file. foreach (var x in Settings.Default.ModuleAssemblies) catalog.Catalogs.Add(new AssemblyCatalog(x)); - container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); + container = new(catalog, CompositionOptions.DisableSilentRejection); var batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); diff --git a/src/System.Waf/Samples/InformationManager/Common.Applications.Test/ApplicationsTest.cs b/src/System.Waf/Samples/InformationManager/Common.Applications.Test/ApplicationsTest.cs index ee3ce4a9..5b76c053 100644 --- a/src/System.Waf/Samples/InformationManager/Common.Applications.Test/ApplicationsTest.cs +++ b/src/System.Waf/Samples/InformationManager/Common.Applications.Test/ApplicationsTest.cs @@ -21,7 +21,7 @@ protected override void OnInitialize() OnCatalogInitialize(catalog); - Container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); + Container = new(catalog, CompositionOptions.DisableSilentRejection); var batch = new CompositionBatch(); batch.AddExportedValue(Container); Container.Compose(batch); diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications.Test/ViewModels/EmailListViewModelTest.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications.Test/ViewModels/EmailListViewModelTest.cs index c23792e6..1a904177 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications.Test/ViewModels/EmailListViewModelTest.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications.Test/ViewModels/EmailListViewModelTest.cs @@ -13,11 +13,7 @@ public class EmailListViewModelTest : EmailClientTest public void PropertiesTest() { var viewModel = Get(); - var emails = new List() - { - new(), - new(), - }; + var emails = new List() { new(), new() }; Assert.IsNull(viewModel.SelectedEmail); AssertHelper.PropertyChangedEvent(viewModel, x => x.SelectedEmail, () => viewModel.SelectedEmail = emails[0]); diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications.Test/ViewModels/NewEmailViewModelTest.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications.Test/ViewModels/NewEmailViewModelTest.cs index 061acc3a..a3cd0979 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications.Test/ViewModels/NewEmailViewModelTest.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications.Test/ViewModels/NewEmailViewModelTest.cs @@ -16,11 +16,7 @@ public void PropertiesTest() // Email accounts tests - var emailAccounts = new List() - { - new(), - new() - }; + var emailAccounts = new List() { new(), new() }; AssertHelper.PropertyChangedEvent(viewModel, x => x.SelectedEmailAccount, () => viewModel.SelectedEmailAccount = emailAccounts[0]); Assert.AreEqual(emailAccounts[0], viewModel.SelectedEmailAccount); @@ -41,7 +37,7 @@ public void PropertiesTest() string cc = cc1 + ", " + cc2; AssertHelper.PropertyChangedEvent(viewModel, x => x.CC, () => viewModel.CC = cc); Assert.AreEqual(cc1 + "; " + cc2, viewModel.CC); - AssertHelper.SequenceEqual(new[] { cc1, cc2 }, email.CC); + AssertHelper.SequenceEqual([ cc1, cc2 ], email.CC); string bcc1 = "user@adventure-works.com"; string bcc2 = "harry@example.com"; @@ -49,16 +45,16 @@ public void PropertiesTest() string bcc = bcc1 + "; " + bcc2 + " " + bcc3; AssertHelper.PropertyChangedEvent(viewModel, x => x.Bcc, () => viewModel.Bcc = bcc); Assert.AreEqual(bcc1 + "; " + bcc2 + "; " + bcc3, viewModel.Bcc); - AssertHelper.SequenceEqual(new[] { bcc1, bcc2, bcc3 }, email.Bcc); + AssertHelper.SequenceEqual([ bcc1, bcc2, bcc3 ], email.Bcc); string newEmail = "mike@adventure-works.com"; - AssertHelper.PropertyChangedEvent(viewModel, x => x.To, () => email.To = new[] { newEmail }); + AssertHelper.PropertyChangedEvent(viewModel, x => x.To, () => email.To = [ newEmail ]); Assert.AreEqual(newEmail, viewModel.To); - AssertHelper.PropertyChangedEvent(viewModel, x => x.CC, () => email.CC = new[] { newEmail }); + AssertHelper.PropertyChangedEvent(viewModel, x => x.CC, () => email.CC = [ newEmail ]); Assert.AreEqual(newEmail, viewModel.CC); - AssertHelper.PropertyChangedEvent(viewModel, x => x.Bcc, () => email.Bcc = new[] { newEmail }); + AssertHelper.PropertyChangedEvent(viewModel, x => x.Bcc, () => email.Bcc = [ newEmail ]); Assert.AreEqual(newEmail, viewModel.Bcc); viewModel.Email = new Email(); diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/EditEmailAccountController.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/EditEmailAccountController.cs index 411cdeae..2a32f6e7 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/EditEmailAccountController.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/EditEmailAccountController.cs @@ -29,8 +29,8 @@ public EditEmailAccountController(EditEmailAccountViewModel editEmailAccountView this.basicEmailAccountViewModel = basicEmailAccountViewModel; this.pop3SettingsViewModelFactory = pop3SettingsViewModelFactory; this.exchangeSettingsViewModelFactory = exchangeSettingsViewModelFactory; - backCommand = new DelegateCommand(Back, CanBack); - nextCommand = new DelegateCommand(Next, CanNext); + backCommand = new(Back, CanBack); + nextCommand = new(Next, CanNext); } public object OwnerWindow { get; set; } = null!; diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/EmailAccountsController.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/EmailAccountsController.cs index ce851ada..bdff0e31 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/EmailAccountsController.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/EmailAccountsController.cs @@ -33,8 +33,8 @@ public EmailAccountsController(IShellService shellService, ExportFactory(EmailFolder.Emails, null, EmailListViewModel.Filter, x => x.OrderByDescending(y => y.Sent)); + emailsView = new(EmailFolder.Emails, null, EmailListViewModel.Filter, x => x.OrderByDescending(y => y.Sent)); EmailListViewModel.Emails = emailsView; EmailListViewModel.DeleteEmailCommand = DeleteEmailCommand; emailListViewModelPropertyChangedProxy = WeakEvent.PropertyChanged.Add(EmailListViewModel, EmailListViewModelPropertyChanged); diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/ModuleController.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/ModuleController.cs index 1bd0d7de..d0ea5014 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/ModuleController.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/ModuleController.cs @@ -24,7 +24,7 @@ internal class ModuleController : IModuleController private readonly ExportFactory newEmailControllerFactory; private readonly DelegateCommand newEmailCommand; private readonly Lazy serializer; - private readonly List itemCountSynchronizers; + private readonly List itemCountSynchronizers = []; private EmailFolderController? activeEmailFolderController; [ImportingConstructor] @@ -37,9 +37,8 @@ public ModuleController(IShellService shellService, IDocumentService documentSer this.emailAccountsController = emailAccountsController; this.emailFolderControllerFactory = emailFolderControllerFactory; this.newEmailControllerFactory = newEmailControllerFactory; - newEmailCommand = new DelegateCommand(NewEmail); - itemCountSynchronizers = new List(); - serializer = new Lazy(CreateDataContractSerializer); + newEmailCommand = new(NewEmail); + serializer = new(CreateDataContractSerializer); } internal EmailClientRoot Root { get; private set; } = null!; @@ -50,7 +49,7 @@ public void Initialize() { if (stream.Length == 0) { - Root = new EmailClientRoot(); + Root = new(); Root.AddEmailAccount(SampleDataProvider.CreateEmailAccount()); foreach (var email in SampleDataProvider.CreateInboxEmails()) { Root.Inbox.AddEmail(email); } foreach (var email in SampleDataProvider.CreateSentEmails()) { Root.Sent.AddEmail(email); } @@ -64,15 +63,15 @@ public void Initialize() emailAccountsController.Root = Root; var node = navigationService.AddNavigationNode("Inbox", ShowInbox, CloseCurrentView, 1, 1); - itemCountSynchronizers.Add(new ItemCountSynchronizer(node, Root.Inbox)); + itemCountSynchronizers.Add(new(node, Root.Inbox)); node = navigationService.AddNavigationNode("Outbox", ShowOutbox, CloseCurrentView, 1, 2); - itemCountSynchronizers.Add(new ItemCountSynchronizer(node, Root.Outbox)); + itemCountSynchronizers.Add(new(node, Root.Outbox)); node = navigationService.AddNavigationNode("Sent", ShowSentEmails, CloseCurrentView, 1, 3); - itemCountSynchronizers.Add(new ItemCountSynchronizer(node, Root.Sent)); + itemCountSynchronizers.Add(new(node, Root.Sent)); node = navigationService.AddNavigationNode("Drafts", ShowDrafts, CloseCurrentView, 1, 4); - itemCountSynchronizers.Add(new ItemCountSynchronizer(node, Root.Drafts)); + itemCountSynchronizers.Add(new(node, Root.Drafts)); node = navigationService.AddNavigationNode("Deleted", ShowDeletedEmails, CloseCurrentView, 1, 5); - itemCountSynchronizers.Add(new ItemCountSynchronizer(node, Root.Deleted)); + itemCountSynchronizers.Add(new(node, Root.Deleted)); } public void Run() { } @@ -92,7 +91,7 @@ private void ShowEmails(EmailFolder emailFolder) var uiNewEmailCommand = new ToolBarCommand(newEmailCommand, "_New email", "Creates a new email."); var uiDeleteEmailCommand = new ToolBarCommand(activeEmailFolderController.DeleteEmailCommand, "_Delete", "Deletes the selected email."); var uiEmailAccountsCommand = new ToolBarCommand(emailAccountsController.EmailAccountsCommand, "_Email accounts", "Opens a window that shows the email accounts."); - shellService.AddToolBarCommands(new[] { uiNewEmailCommand, uiDeleteEmailCommand, uiEmailAccountsCommand }); + shellService.AddToolBarCommands([ uiNewEmailCommand, uiDeleteEmailCommand, uiEmailAccountsCommand ]); } private void ShowInbox() => ShowEmails(Root.Inbox); @@ -120,7 +119,7 @@ private void NewEmail() newEmailController.Run(); } - private DataContractSerializer CreateDataContractSerializer() => new(typeof(EmailClientRoot), new[] { typeof(ExchangeSettings), typeof(Pop3Settings) }); + private DataContractSerializer CreateDataContractSerializer() => new(typeof(EmailClientRoot), [ typeof(ExchangeSettings), typeof(Pop3Settings) ]); private class ItemCountSynchronizer : Model diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/NewEmailController.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/NewEmailController.cs index eff10982..af629133 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/NewEmailController.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/Controllers/NewEmailController.cs @@ -25,8 +25,8 @@ public NewEmailController(IMessageService messageService, IShellService shellSer this.shellService = shellService; this.addressBookService = addressBookService; NewEmailViewModel = newEmailViewModel; - selectContactCommand = new DelegateCommand(SelectContact); - sendCommand = new DelegateCommand(SendEmail); + selectContactCommand = new(SelectContact); + sendCommand = new(SendEmail); } public EmailClientRoot Root { get; set; } = null!; diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/SampleData/SampleDataProvider.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/SampleData/SampleDataProvider.cs index 5da916ea..1d1a68c0 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/SampleData/SampleDataProvider.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/SampleData/SampleDataProvider.cs @@ -14,23 +14,18 @@ public static EmailAccount CreateEmailAccount() return emailAccount; } - public static IReadOnlyList CreateInboxEmails() - { - var emails = new List() - { - CreateEmail("Aliquam cras class maecenas", new DateTime(2003, 11, 5, 8, 20, 14), "someone@example.com", new[] { "harry@example.com", "user-2@fabrikam.com", "someone@adventure-works.com" }, new[] { "someone-4@adventure-works.com" }, "Vestibulum aenean mauris maecenas pellentesque nullam aliquam cras adipiscing class nam suspendisse praesent parturient integer condimentum consectetuer vestibulum curabitur curae pellentesque vestibulum scelerisque phasellus duis sed nunc donec amet accumsan ante sollicitudin quisque dis arcu consequat etiam fusce convallis dignissim adipiscing elementum pellentesque facilisis fermentum fringilla diam aptent consectetuer vivamus lorem aliquam morbi eget habitasse pellentesque aliquet hendrerit blandit sollicitudin elit nulla pellentesque proin est enim commodo conubia bibendum ullamcorper himenaeos parturient hac leo dictumst augue suspendisse erat mus cubilia condimentum scelerisque auctor imperdiet congue vestibulum vestibulum cursus dapibus eros nibh eleifend ullamcorper adipiscing egestas facilisi parturient vestibulum malesuada"), - CreateEmail("Duis nunc", new DateTime(2006, 12, 29, 7, 6, 5), "user@adventure-works.com", new[] { "harry@example.com", "admin@adventure-works.com" }, null, "Euismod dolor penatibus vestibulum nec suspendisse feugiat dictum fames porttitor gravida nisi felis faucibus consectetuer non lectus condimentum ipsum pellentesque justo libero nisl per iaculis tincidunt sed sollicitudin ligula habitant pellentesque lacinia nunc inceptos interdum lacus lorem sem litora scelerisque ullamcorper luctus lobortis tristique consectetuer sit suspendisse pellentesque condimentum adipiscing odio parturient nascetur scelerisque magnis orci pede ultricies mattis mauris vestibulum pharetra vel venenatis vulputate nam sed"), - CreateEmail("Proin nam", new DateTime(2004, 9, 19, 19, 13, 20), "user-1@fabrikam.com", new[] { "user-6@fabrikam.com" }, new[] { "harry@example.com" }, "Sapien sollicitudin amet ante pellentesque semper dapibus consectetuer scelerisque adipiscing pellentesque lobortis nascetur sociis arcu egestas pharetra himenaeos sit proin ullamcorper diam taciti parturient vel sollicitudin eget suspendisse nam placerat elit pulvinar euismod sed condimentum enim imperdiet scelerisque pellentesque malesuada sagittis vestibulum ullamcorper erat suspendisse penatibus consectetuer augue senectus dolor condimentum pellentesque vestibulum porttitor sollicitudin"), - CreateEmail("Auctor congue diam accumsan", new DateTime(2003, 8, 10, 23, 5, 39), "user-7@fabrikam.com", new[] { "harry@example.com" }, null, "Fames sociosqu feugiat dis pellentesque eros tincidunt consectetuer felis suscipit gravida est torquent ultrices pellentesque scelerisque tristique adipiscing iaculis ultricies nibh tellus ipsum sollicitudin tempor pellentesque consectetuer justo ullamcorper parturient nisi vestibulum suspendisse hac venenatis vehicula lacus vestibulum pellentesque lacinia sollicitudin condimentum volutpat maecenas tempus vulputate tortor adipiscing curabitur laoreet nisl"), - CreateEmail("Aliquet eleifend blandit", new DateTime(2006, 12, 29, 16, 26, 00), "someone@adventure-works.com", new[] { "harry@example.com" }, new[] { "mike@adventure-works.com" }, "Proin facilisi imperdiet augue ante faucibus commodo hac vestibulum habitant pellentesque leo malesuada arcu inceptos interdum diam lobortis nascetur penatibus pharetra conubia condimentum dictum lectus cubilia adipiscing libero eget parturient dolor fames consectetuer elit mus pellentesque enim felis dapibus vestibulum ligula nec placerat porttitor vestibulum scelerisque erat ipsum tincidunt ullamcorper pulvinar sagittis justo lacus lorem suspendisse adipiscing litora sollicitudin parturient vestibulum non condimentum pellentesque luctus tristique eros senectus nibh sociosqu magnis consectetuer per"), - CreateEmail("Egestas nisi mattis", new DateTime(2010, 1, 19, 7, 13, 4), "user-2@fabrikam.com", new[] { "harry@example.com" }, null, "Scelerisque nisl ultricies suscipit magna torquent venenatis massa metus vulputate sed curabitur pellentesque nunc morbi ullamcorper mauris vestibulum sollicitudin neque odio phasellus mollis sem consequat convallis sit orci ultrices dignissim euismod feugiat pellentesque elementum vel vehicula adipiscing montes gravida netus iaculis volutpat parturient facilisis maecenas lacinia praesent consectetuer nulla accumsan fermentum nostra suspendisse nam ornare porta vestibulum bibendum condimentum fringilla laoreet dictumst vestibulum habitasse purus hendrerit adipiscing risus pede himenaeos sed pellentesque"), - CreateEmail("Lorem tempor", new DateTime(2006, 2, 2, 17, 44, 29), "user-6@fabrikam.com", new[] { "user-7@fabrikam.com", "harry@example.com" }, null, "Venenatis amet vulputate sed morbi ante curabitur phasellus aliquet nulla pellentesque arcu tempus tortor turpis diam nascetur sollicitudin blandit pellentesque eget consequat convallis proin parturient dignissim vestibulum elit sem elementum commodo augue condimentum facilisis scelerisque sit varius conubia pharetra aenean vestibulum vel ullamcorper fermentum dolor fames consectetuer placerat enim nam"), - CreateEmail("Felis sed pulvinar ipsum", new DateTime(2003, 8, 23, 23, 38, 50), "user-8@fabrikam.com", new[] { "harry@example.com" }, null, "Cubilia dis sagittis mauris nullam senectus aptent sociosqu suscipit adipiscing parturient fringilla justo habitasse torquent lacus suspendisse est auctor erat lorem eros condimentum hac pellentesque ultrices vestibulum nibh sollicitudin leo magna massa congue cursus nisi vestibulum vehicula pellentesque mus nec consectetuer nisl dapibus non scelerisque hendrerit pellentesque metus per ullamcorper morbi dictum adipiscing suspendisse neque lectus nunc egestas libero condimentum parturient odio volutpat maecenas praesent euismod ligula scelerisque feugiat vestibulum vestibulum ullamcorper sollicitudin netus orci sed adipiscing suspendisse nulla litora accumsan gravida pede quam condimentum scelerisque bibendum dictumst quis ullamcorper himenaeos urna eleifend porta luctus parturient imperdiet suspendisse iaculis magnis"), - CreateEmail("Nunc sed dis suscipit", new DateTime(2012, 8, 9, 5, 58, 21), "user-2@fabrikam.com", new[] { "harry@example.com" }, new[] { "user-3@fabrikam.com" }, "Scelerisque est odio orci montes pellentesque vulputate nostra euismod parturient ornare hac vestibulum vestibulum proin platea augue adipiscing dolor pede leo torquent quam primis curabitur rutrum ultrices vehicula sollicitudin parturient pellentesque consectetuer pellentesque fames sollicitudin volutpat sapien pellentesque vestibulum phasellus semper maecenas feugiat sociis consequat felis vestibulum ipsum justo mus praesent gravida ullamcorper consectetuer pellentesque taciti suspendisse adipiscing iaculis nec tellus quis tempor convallis parturient tempus non lacinia condimentum dignissim sollicitudin tortor per elementum scelerisque accumsan urna ullamcorper facilisis laoreet bibendum turpis varius suspendisse lacus dictumst cras sed aenean eleifend"), - CreateEmail("Taciti enim", new DateTime(2005, 9, 5, 16, 34, 45), "someone-2@adventure-works.com", new[] { "harry@example.com" }, null, "Sed condimentum proin sodales vestibulum scelerisque erat vehicula sem augue adipiscing sit parturient vel volutpat maecenas viverra ullamcorper suspendisse nam praesent dolor vestibulum condimentum vestibulum sed pellentesque fames adipiscing eros nibh venenatis felis parturient aliquam dis est hac integer nisi scelerisque accumsan quisque bibendum ullamcorper dictumst ipsum vulputate curabitur vestibulum justo lacus sollicitudin"), - }; - return emails; - } + public static IReadOnlyList CreateInboxEmails() => [ + CreateEmail("Aliquam cras class maecenas", new DateTime(2003, 11, 5, 8, 20, 14), "someone@example.com", new[] { "harry@example.com", "user-2@fabrikam.com", "someone@adventure-works.com" }, new[] { "someone-4@adventure-works.com" }, "Vestibulum aenean mauris maecenas pellentesque nullam aliquam cras adipiscing class nam suspendisse praesent parturient integer condimentum consectetuer vestibulum curabitur curae pellentesque vestibulum scelerisque phasellus duis sed nunc donec amet accumsan ante sollicitudin quisque dis arcu consequat etiam fusce convallis dignissim adipiscing elementum pellentesque facilisis fermentum fringilla diam aptent consectetuer vivamus lorem aliquam morbi eget habitasse pellentesque aliquet hendrerit blandit sollicitudin elit nulla pellentesque proin est enim commodo conubia bibendum ullamcorper himenaeos parturient hac leo dictumst augue suspendisse erat mus cubilia condimentum scelerisque auctor imperdiet congue vestibulum vestibulum cursus dapibus eros nibh eleifend ullamcorper adipiscing egestas facilisi parturient vestibulum malesuada"), + CreateEmail("Duis nunc", new DateTime(2006, 12, 29, 7, 6, 5), "user@adventure-works.com", new[] { "harry@example.com", "admin@adventure-works.com" }, null, "Euismod dolor penatibus vestibulum nec suspendisse feugiat dictum fames porttitor gravida nisi felis faucibus consectetuer non lectus condimentum ipsum pellentesque justo libero nisl per iaculis tincidunt sed sollicitudin ligula habitant pellentesque lacinia nunc inceptos interdum lacus lorem sem litora scelerisque ullamcorper luctus lobortis tristique consectetuer sit suspendisse pellentesque condimentum adipiscing odio parturient nascetur scelerisque magnis orci pede ultricies mattis mauris vestibulum pharetra vel venenatis vulputate nam sed"), + CreateEmail("Proin nam", new DateTime(2004, 9, 19, 19, 13, 20), "user-1@fabrikam.com", new[] { "user-6@fabrikam.com" }, new[] { "harry@example.com" }, "Sapien sollicitudin amet ante pellentesque semper dapibus consectetuer scelerisque adipiscing pellentesque lobortis nascetur sociis arcu egestas pharetra himenaeos sit proin ullamcorper diam taciti parturient vel sollicitudin eget suspendisse nam placerat elit pulvinar euismod sed condimentum enim imperdiet scelerisque pellentesque malesuada sagittis vestibulum ullamcorper erat suspendisse penatibus consectetuer augue senectus dolor condimentum pellentesque vestibulum porttitor sollicitudin"), + CreateEmail("Auctor congue diam accumsan", new DateTime(2003, 8, 10, 23, 5, 39), "user-7@fabrikam.com", new[] { "harry@example.com" }, null, "Fames sociosqu feugiat dis pellentesque eros tincidunt consectetuer felis suscipit gravida est torquent ultrices pellentesque scelerisque tristique adipiscing iaculis ultricies nibh tellus ipsum sollicitudin tempor pellentesque consectetuer justo ullamcorper parturient nisi vestibulum suspendisse hac venenatis vehicula lacus vestibulum pellentesque lacinia sollicitudin condimentum volutpat maecenas tempus vulputate tortor adipiscing curabitur laoreet nisl"), + CreateEmail("Aliquet eleifend blandit", new DateTime(2006, 12, 29, 16, 26, 00), "someone@adventure-works.com", new[] { "harry@example.com" }, new[] { "mike@adventure-works.com" }, "Proin facilisi imperdiet augue ante faucibus commodo hac vestibulum habitant pellentesque leo malesuada arcu inceptos interdum diam lobortis nascetur penatibus pharetra conubia condimentum dictum lectus cubilia adipiscing libero eget parturient dolor fames consectetuer elit mus pellentesque enim felis dapibus vestibulum ligula nec placerat porttitor vestibulum scelerisque erat ipsum tincidunt ullamcorper pulvinar sagittis justo lacus lorem suspendisse adipiscing litora sollicitudin parturient vestibulum non condimentum pellentesque luctus tristique eros senectus nibh sociosqu magnis consectetuer per"), + CreateEmail("Egestas nisi mattis", new DateTime(2010, 1, 19, 7, 13, 4), "user-2@fabrikam.com", new[] { "harry@example.com" }, null, "Scelerisque nisl ultricies suscipit magna torquent venenatis massa metus vulputate sed curabitur pellentesque nunc morbi ullamcorper mauris vestibulum sollicitudin neque odio phasellus mollis sem consequat convallis sit orci ultrices dignissim euismod feugiat pellentesque elementum vel vehicula adipiscing montes gravida netus iaculis volutpat parturient facilisis maecenas lacinia praesent consectetuer nulla accumsan fermentum nostra suspendisse nam ornare porta vestibulum bibendum condimentum fringilla laoreet dictumst vestibulum habitasse purus hendrerit adipiscing risus pede himenaeos sed pellentesque"), + CreateEmail("Lorem tempor", new DateTime(2006, 2, 2, 17, 44, 29), "user-6@fabrikam.com", new[] { "user-7@fabrikam.com", "harry@example.com" }, null, "Venenatis amet vulputate sed morbi ante curabitur phasellus aliquet nulla pellentesque arcu tempus tortor turpis diam nascetur sollicitudin blandit pellentesque eget consequat convallis proin parturient dignissim vestibulum elit sem elementum commodo augue condimentum facilisis scelerisque sit varius conubia pharetra aenean vestibulum vel ullamcorper fermentum dolor fames consectetuer placerat enim nam"), + CreateEmail("Felis sed pulvinar ipsum", new DateTime(2003, 8, 23, 23, 38, 50), "user-8@fabrikam.com", new[] { "harry@example.com" }, null, "Cubilia dis sagittis mauris nullam senectus aptent sociosqu suscipit adipiscing parturient fringilla justo habitasse torquent lacus suspendisse est auctor erat lorem eros condimentum hac pellentesque ultrices vestibulum nibh sollicitudin leo magna massa congue cursus nisi vestibulum vehicula pellentesque mus nec consectetuer nisl dapibus non scelerisque hendrerit pellentesque metus per ullamcorper morbi dictum adipiscing suspendisse neque lectus nunc egestas libero condimentum parturient odio volutpat maecenas praesent euismod ligula scelerisque feugiat vestibulum vestibulum ullamcorper sollicitudin netus orci sed adipiscing suspendisse nulla litora accumsan gravida pede quam condimentum scelerisque bibendum dictumst quis ullamcorper himenaeos urna eleifend porta luctus parturient imperdiet suspendisse iaculis magnis"), + CreateEmail("Nunc sed dis suscipit", new DateTime(2012, 8, 9, 5, 58, 21), "user-2@fabrikam.com", new[] { "harry@example.com" }, new[] { "user-3@fabrikam.com" }, "Scelerisque est odio orci montes pellentesque vulputate nostra euismod parturient ornare hac vestibulum vestibulum proin platea augue adipiscing dolor pede leo torquent quam primis curabitur rutrum ultrices vehicula sollicitudin parturient pellentesque consectetuer pellentesque fames sollicitudin volutpat sapien pellentesque vestibulum phasellus semper maecenas feugiat sociis consequat felis vestibulum ipsum justo mus praesent gravida ullamcorper consectetuer pellentesque taciti suspendisse adipiscing iaculis nec tellus quis tempor convallis parturient tempus non lacinia condimentum dignissim sollicitudin tortor per elementum scelerisque accumsan urna ullamcorper facilisis laoreet bibendum turpis varius suspendisse lacus dictumst cras sed aenean eleifend"), + CreateEmail("Taciti enim", new DateTime(2005, 9, 5, 16, 34, 45), "someone-2@adventure-works.com", new[] { "harry@example.com" }, null, "Sed condimentum proin sodales vestibulum scelerisque erat vehicula sem augue adipiscing sit parturient vel volutpat maecenas viverra ullamcorper suspendisse nam praesent dolor vestibulum condimentum vestibulum sed pellentesque fames adipiscing eros nibh venenatis felis parturient aliquam dis est hac integer nisi scelerisque accumsan quisque bibendum ullamcorper dictumst ipsum vulputate curabitur vestibulum justo lacus sollicitudin"), + ]; public static IReadOnlyList CreateSentEmails() { diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/ViewModels/BasicEmailAccountViewModel.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/ViewModels/BasicEmailAccountViewModel.cs index 96813cf6..bb7fa22f 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/ViewModels/BasicEmailAccountViewModel.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Applications/ViewModels/BasicEmailAccountViewModel.cs @@ -10,13 +10,12 @@ namespace Waf.InformationManager.EmailClient.Modules.Applications.ViewModels; public class BasicEmailAccountViewModel : ViewModel { private EmailAccount emailAccount = null!; - private bool isPop3Checked; + private bool isPop3Checked = true; private bool isExchangeChecked; [ImportingConstructor] public BasicEmailAccountViewModel(IBasicEmailAccountView view) : base(view) { - isPop3Checked = true; } public EmailAccount EmailAccount diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain.Test/Emails/EmailFolderTest.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain.Test/Emails/EmailFolderTest.cs index 94d1c753..c980ff19 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain.Test/Emails/EmailFolderTest.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain.Test/Emails/EmailFolderTest.cs @@ -22,7 +22,7 @@ public void AddAndRemoveEmails() var email2 = new Email(); emailFolder.AddEmail(email2); - AssertHelper.SequenceEqual(new[] { email1, email2 }, emailFolder.Emails); + AssertHelper.SequenceEqual([ email1, email2 ], emailFolder.Emails); bool deleteEmailCalled = false; emailDeletionService.DeleteEmailAction = (folder, email) => diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/EmailClientRoot.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/EmailClientRoot.cs index 42ea0ac2..ce4e2e5f 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/EmailClientRoot.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/EmailClientRoot.cs @@ -6,7 +6,7 @@ namespace Waf.InformationManager.EmailClient.Modules.Domain.Emails; [DataContract] public class EmailClientRoot : ValidatableModel, IEmailDeletionService { - [DataMember] private readonly ObservableList emailAccounts; + [DataMember] private readonly ObservableList emailAccounts = []; [DataMember] private readonly EmailFolder inbox; [DataMember] private readonly EmailFolder outbox; [DataMember] private readonly EmailFolder sent; @@ -15,12 +15,11 @@ public class EmailClientRoot : ValidatableModel, IEmailDeletionService public EmailClientRoot() { - emailAccounts = new(); - inbox = new EmailFolder(); - outbox = new EmailFolder(); - sent = new EmailFolder(); - drafts = new EmailFolder(); - deleted = new EmailFolder(); + inbox = new(); + outbox = new(); + sent = new(); + drafts = new(); + deleted = new(); Initialize(); } diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/EmailFolder.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/EmailFolder.cs index d5801ab5..9ecbed3b 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/EmailFolder.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/EmailFolder.cs @@ -6,14 +6,9 @@ namespace Waf.InformationManager.EmailClient.Modules.Domain.Emails; [DataContract] public class EmailFolder : ValidatableModel { - [DataMember] private readonly ObservableList emails; + [DataMember] private readonly ObservableList emails = []; private ReadOnlyObservableList? readOnlyEmails; - public EmailFolder() - { - emails = new(); - } - public IReadOnlyObservableList Emails => readOnlyEmails ??= new ReadOnlyObservableList(emails); internal IEmailDeletionService EmailDeletionService { get; set; } = null!; diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/DesignData/SampleNewEmailViewModel.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/DesignData/SampleNewEmailViewModel.cs index 2f6b3076..c3561d4b 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/DesignData/SampleNewEmailViewModel.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/DesignData/SampleNewEmailViewModel.cs @@ -8,7 +8,7 @@ public class SampleNewEmailViewModel : NewEmailViewModel { public SampleNewEmailViewModel() : base(new MockNewEmailView()) { - EmailAccounts = new[] { SampleDataProvider.CreateEmailAccount() }; + EmailAccounts = [ SampleDataProvider.CreateEmailAccount() ]; SelectedEmailAccount = EmailAccounts[0]; Email = SampleDataProvider.CreateSentEmails()[1]; } diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailAccountsWindow.xaml.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailAccountsWindow.xaml.cs index 423388f8..34c20fd8 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailAccountsWindow.xaml.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailAccountsWindow.xaml.cs @@ -16,7 +16,7 @@ public partial class EmailAccountsWindow : IEmailAccountsView public EmailAccountsWindow() { InitializeComponent(); - viewModel = new Lazy(() => ViewHelper.GetViewModel(this)!); + viewModel = new(() => ViewHelper.GetViewModel(this)!); } public void ShowDialog(object owner) diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailListView.xaml.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailListView.xaml.cs index d5ffc9cd..898ec546 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailListView.xaml.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailListView.xaml.cs @@ -16,7 +16,7 @@ public partial class EmailListView : IEmailListView public EmailListView() { InitializeComponent(); - viewModel = new Lazy(() => this.GetViewModel()!); + viewModel = new(() => this.GetViewModel()!); Loaded += LoadedHandler; } @@ -29,13 +29,13 @@ public void FocusItem() emailsBox.Focus(); return; } - Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)(() => + Dispatcher.BeginInvoke(DispatcherPriority.Background, () => { - // It is necessary to delay this code because data binding updates the values asynchronously. - emailsBox.ScrollIntoView(ViewModel.SelectedEmail); + // It is necessary to delay this code because data binding updates the values asynchronously. + emailsBox.ScrollIntoView(ViewModel.SelectedEmail); var selectedListBoxItem = (ListBoxItem)emailsBox.ItemContainerGenerator.ContainerFromItem(ViewModel.SelectedEmail); selectedListBoxItem?.Focus(); - })); + }); } private void LoadedHandler(object sender, RoutedEventArgs e) diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/Pop3SettingsView.xaml.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/Pop3SettingsView.xaml.cs index ec7b5f62..c1298556 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/Pop3SettingsView.xaml.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/Pop3SettingsView.xaml.cs @@ -16,7 +16,7 @@ public partial class Pop3SettingsView : IPop3SettingsView public Pop3SettingsView() { InitializeComponent(); - viewModel = new Lazy(() => this.GetViewModel()!); + viewModel = new(() => this.GetViewModel()!); Loaded += LoadedHandler; Unloaded += UnloadedHandler; } diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockNavigationService.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockNavigationService.cs index 50c743eb..5089139a 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockNavigationService.cs +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockNavigationService.cs @@ -6,12 +6,7 @@ namespace Test.InformationManager.Infrastructure.Modules.Applications.Services; [Export(typeof(INavigationService)), Export] public class MockNavigationService : INavigationService { - private readonly List navigationNodes; - - public MockNavigationService() - { - navigationNodes = new List(); - } + private readonly List navigationNodes = []; public IReadOnlyList NavigationNodes => navigationNodes; diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockShellService.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockShellService.cs index 28736f47..94815ffe 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockShellService.cs +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockShellService.cs @@ -7,12 +7,7 @@ namespace Test.InformationManager.Infrastructure.Modules.Applications.Services; [Export(typeof(IShellService)), Export] public class MockShellService : Model, IShellService { - private readonly List toolBarCommands; - - public MockShellService() - { - toolBarCommands = new List(); - } + private readonly List toolBarCommands = []; public IReadOnlyList ToolBarCommands => toolBarCommands; diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockShellViewModel.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockShellViewModel.cs index 044ee448..2baac134 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockShellViewModel.cs +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/MockShellViewModel.cs @@ -5,12 +5,7 @@ namespace Test.InformationManager.Infrastructure.Modules.Applications.Services; public class MockShellViewModel : IShellViewModel { - private readonly List toolBarCommands; - - public MockShellViewModel() - { - toolBarCommands = new List(); - } + private readonly List toolBarCommands = []; public IReadOnlyList ToolBarCommands => toolBarCommands; diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/ShellServiceTest.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/ShellServiceTest.cs index 564cf7e9..dc7ffa98 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/ShellServiceTest.cs +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/ShellServiceTest.cs @@ -36,9 +36,9 @@ public void ToolBarCommandsDelegation() var emptyCommand = new DelegateCommand(() => { }); var newToolBarCommands = new[] { - new ToolBarCommand(emptyCommand, "Command 1"), - new ToolBarCommand(emptyCommand, "Command 2") - }; + new ToolBarCommand(emptyCommand, "Command 1"), + new ToolBarCommand(emptyCommand, "Command 2") + }; Assert.IsFalse(mockShellViewModel.ToolBarCommands.Any()); shellService.AddToolBarCommands(newToolBarCommands); diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/ViewModels/ShellViewModelTest.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/ViewModels/ShellViewModelTest.cs index 6850426b..93a03457 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/ViewModels/ShellViewModelTest.cs +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/ViewModels/ShellViewModelTest.cs @@ -50,9 +50,9 @@ public void ToolBarCommandsDelegation() var emptyCommand = new DelegateCommand(() => { }); var newToolBarCommands = new[] { - new ToolBarCommand(emptyCommand, "Command 1"), - new ToolBarCommand(emptyCommand, "Command 2") - }; + new ToolBarCommand(emptyCommand, "Command 1"), + new ToolBarCommand(emptyCommand, "Command 2") + }; Assert.IsFalse(shellView.ToolBarCommands.Any()); shellViewModel.AddToolBarCommands(newToolBarCommands); diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Views/MockShellView.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Views/MockShellView.cs index dc9ff71e..ae4a5af1 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Views/MockShellView.cs +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Views/MockShellView.cs @@ -8,12 +8,7 @@ namespace Test.InformationManager.Infrastructure.Modules.Applications.Views; [Export(typeof(IShellView)), Export] public class MockShellView : MockView, IShellView { - private readonly List toolBarCommands; - - public MockShellView() - { - toolBarCommands = new List(); - } + private readonly List toolBarCommands = []; public IReadOnlyList ToolBarCommands => toolBarCommands; diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications/Services/NavigationService.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications/Services/NavigationService.cs index 503ba8f7..be17149f 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications/Services/NavigationService.cs +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications/Services/NavigationService.cs @@ -7,12 +7,7 @@ namespace Waf.InformationManager.Infrastructure.Modules.Applications.Services; [Export(typeof(INavigationService)), Export] public class NavigationService : Model, INavigationService { - private readonly ObservableList navigationNodes; - - public NavigationService() - { - navigationNodes = new(); - } + private readonly ObservableList navigationNodes = []; public IReadOnlyObservableList NavigationNodes => navigationNodes; diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Presentation/Views/ShellWindow.xaml.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Presentation/Views/ShellWindow.xaml.cs index 1c29207a..226a4bd4 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Presentation/Views/ShellWindow.xaml.cs +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Presentation/Views/ShellWindow.xaml.cs @@ -12,13 +12,12 @@ namespace Waf.InformationManager.Infrastructure.Modules.Presentation.Views; public partial class ShellWindow : IShellView { private readonly Lazy viewModel; - private readonly List dynamicToolBarItems; + private readonly List dynamicToolBarItems = []; public ShellWindow() { InitializeComponent(); - viewModel = new Lazy(() => this.GetViewModel()!); - dynamicToolBarItems = new List(); + viewModel = new(() => this.GetViewModel()!); Loaded += LoadedHandler; } @@ -65,7 +64,7 @@ public void AddToolBarCommands(IReadOnlyList commands) public void ClearToolBarCommands() { - dynamicToolBarItems.ForEach(x => toolBar.Items.Remove(x)); + dynamicToolBarItems.ForEach(toolBar.Items.Remove); dynamicToolBarItems.Clear(); }