diff --git a/CDP4Composition/Mvvm/BrowserViewModelBase.cs b/CDP4Composition/Mvvm/BrowserViewModelBase.cs index c68345464..33ee70873 100644 --- a/CDP4Composition/Mvvm/BrowserViewModelBase.cs +++ b/CDP4Composition/Mvvm/BrowserViewModelBase.cs @@ -1,8 +1,8 @@ -// ------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smieckowski, Ahmed Abulwafa Ahmed +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed // // This file is part of CDP4-IME Community Edition. // The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration @@ -31,7 +31,6 @@ namespace CDP4Composition.Mvvm using System.Reactive.Linq; using System.Threading.Tasks; using System.Windows; - using System.Windows.Threading; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; @@ -68,26 +67,6 @@ public abstract class BrowserViewModelBase : ViewModelBase, IBrowserViewMo /// private readonly CamelCaseToSpaceConverter camelCaseToSpaceConverter = new CamelCaseToSpaceConverter(); - /// - /// The used to navigate to s of a specific - /// - private readonly IThingDialogNavigationService thingDialogNavigationService; - - /// - /// The used to navigate to a Panel - /// - private readonly IPanelNavigationService panelNavigationService; - - /// - /// The used to navigate to a dialog view-model - /// - private readonly IDialogNavigationService dialogNavigationService; - - /// - /// The used to read and write plugin setting files - /// - private readonly IPluginSettingsService pluginSettingsService; - /// /// Backing field for /// @@ -177,10 +156,10 @@ protected BrowserViewModelBase(T thing, ISession session, IThingDialogNavigation { this.Identifier = Guid.NewGuid(); - this.thingDialogNavigationService = thingDialogNavigationService; - this.panelNavigationService = panelNavigationService; - this.dialogNavigationService = dialogNavigationService; - this.pluginSettingsService = pluginSettingsService; + this.ThingDialogNavigationService = thingDialogNavigationService; + this.PanelNavigationService = panelNavigationService; + this.DialogNavigationService = dialogNavigationService; + this.PluginSettingsService = pluginSettingsService; var defaultThingClassKind = this.GetDefaultThingClassKind(); this.SelectedThingClassKindString = this.camelCaseToSpaceConverter.Convert(defaultThingClassKind, null, null, null).ToString(); @@ -224,8 +203,8 @@ protected BrowserViewModelBase(T thing, ISession session, IThingDialogNavigation /// public string DomainOfExpertise { - get { return this.domainOfExpertise; } - protected set { this.RaiseAndSetIfChanged(ref this.domainOfExpertise, value); } + get => this.domainOfExpertise; + protected set => this.RaiseAndSetIfChanged(ref this.domainOfExpertise, value); } /// @@ -234,60 +213,44 @@ public string DomainOfExpertise /// /// May be overriden to show a confirmation on close /// - public virtual bool IsDirty - { - get { return false; } - set { var x = value; } - } + public virtual bool IsDirty { get; set; } /// /// Gets a value indicating whether the "add" button is enabled /// public bool IsAddButtonEnabled { - get { return this.isAddButtonEnabled; } - private set { this.RaiseAndSetIfChanged(ref this.isAddButtonEnabled, value); } + get => this.isAddButtonEnabled; + private set => this.RaiseAndSetIfChanged(ref this.isAddButtonEnabled, value); } /// /// Gets the used to navigate to a /// - public IDialogNavigationService DialogNavigationService - { - get { return this.dialogNavigationService; } - } + public IDialogNavigationService DialogNavigationService { get; } /// /// Gets the used to navigate to a /// - public IPanelNavigationService PanelNavigationService - { - get { return this.panelNavigationService; } - } + public IPanelNavigationService PanelNavigationService { get; } /// /// Gets the used to navigate to a /// - public IThingDialogNavigationService ThingDialogNavigationService - { - get { return this.thingDialogNavigationService; } - } + public IThingDialogNavigationService ThingDialogNavigationService { get; } /// /// The used to read and write plugin setting files /// - public IPluginSettingsService PluginSettingsService - { - get { return this.pluginSettingsService; } - } + public IPluginSettingsService PluginSettingsService { get; } /// /// Gets or sets a value indicating whether it is possible to write on the /// public bool CanWriteSelectedThing { - get { return this.canWriteSelectedThing; } - set { this.RaiseAndSetIfChanged(ref this.canWriteSelectedThing, value); } + get => this.canWriteSelectedThing; + set => this.RaiseAndSetIfChanged(ref this.canWriteSelectedThing, value); } public Dictionary>)>> CustomFilterOperators { get; } = @@ -361,18 +324,15 @@ public bool CanWriteSelectedThing /// /// Gets the data-source /// - public string DataSource - { - get { return this.Thing.IDalUri.ToString(); } - } + public string DataSource => this.Thing.IDalUri.ToString(); /// /// Gets or sets the name of the active /// public string Person { - get { return this.person; } - set { this.RaiseAndSetIfChanged(ref this.person, value); } + get => this.person; + set => this.RaiseAndSetIfChanged(ref this.person, value); } /// @@ -380,8 +340,8 @@ public string Person /// public bool HasUpdateStarted { - get { return this.hasUpdateStarted; } - protected set { this.RaiseAndSetIfChanged(ref this.hasUpdateStarted, value); } + get => this.hasUpdateStarted; + protected set => this.RaiseAndSetIfChanged(ref this.hasUpdateStarted, value); } /// @@ -389,9 +349,8 @@ public bool HasUpdateStarted /// public IRowViewModelBase SelectedThing { - get { return this.selectedThing; } - set - { this.RaiseAndSetIfChanged(ref this.selectedThing, value); } + get => this.selectedThing; + set => this.RaiseAndSetIfChanged(ref this.selectedThing, value); } /// @@ -404,8 +363,8 @@ public IRowViewModelBase SelectedThing /// public IRowViewModelBase FocusedRow { - get { return this.focusedRow; } - set { this.RaiseAndSetIfChanged(ref this.focusedRow, value); } + get => this.focusedRow; + set => this.RaiseAndSetIfChanged(ref this.focusedRow, value); } /// @@ -413,8 +372,8 @@ public IRowViewModelBase FocusedRow /// public string SelectedThingClassKindString { - get { return this.selectedThingClassKindString; } - set { this.RaiseAndSetIfChanged(ref this.selectedThingClassKindString, value); } + get => this.selectedThingClassKindString; + set => this.RaiseAndSetIfChanged(ref this.selectedThingClassKindString, value); } /// @@ -422,8 +381,8 @@ public string SelectedThingClassKindString /// public string Feedback { - get { return this.feedback; } - set { this.RaiseAndSetIfChanged(ref this.feedback, value); } + get => this.feedback; + set => this.RaiseAndSetIfChanged(ref this.feedback, value); } /// @@ -436,8 +395,8 @@ public string Feedback /// public string Caption { - get { return this.caption; } - protected set { this.RaiseAndSetIfChanged(ref this.caption, value); } + get => this.caption; + protected set => this.RaiseAndSetIfChanged(ref this.caption, value); } /// @@ -445,8 +404,8 @@ public string Caption /// public string ToolTip { - get { return this.tooltip; } - protected set { this.RaiseAndSetIfChanged(ref this.tooltip, value); } + get => this.tooltip; + protected set => this.RaiseAndSetIfChanged(ref this.tooltip, value); } /// @@ -476,9 +435,9 @@ protected void ExecuteCreateCommand(Thing thing, Thing container) var context = container ?? this.Thing; var transactionContext = TransactionContextResolver.ResolveContext(context); - var containerClone = (container != null) ? container.Clone(false) : null; + var containerClone = container?.Clone(false); var transaction = new ThingTransaction(transactionContext, containerClone); - this.thingDialogNavigationService.Navigate(thing, transaction, this.Session, true, ThingDialogKind.Create, this.thingDialogNavigationService, containerClone); + this.ThingDialogNavigationService.Navigate(thing, transaction, this.Session, true, ThingDialogKind.Create, this.ThingDialogNavigationService, containerClone); } catch (Exception ex) { @@ -513,9 +472,9 @@ protected virtual async void ExecuteDeleteCommand(Thing thing) } var confirmation = new ConfirmationDialogViewModel(thing); - var dialogResult = this.dialogNavigationService.NavigateModal(confirmation); + var dialogResult = this.DialogNavigationService.NavigateModal(confirmation); - if (dialogResult == null || !dialogResult.Result.HasValue || !dialogResult.Result.Value) + if (dialogResult?.Result == null || !dialogResult.Result.Value) { return; } @@ -611,7 +570,7 @@ protected void ExecuteUpdateCommand(Thing thing) var transactionContext = TransactionContextResolver.ResolveContext(this.Thing); var transaction = new ThingTransaction(transactionContext, containerClone); - this.thingDialogNavigationService.Navigate(clone, transaction, this.Session, true, ThingDialogKind.Update, this.thingDialogNavigationService, containerClone); + this.ThingDialogNavigationService.Navigate(clone, transaction, this.Session, true, ThingDialogKind.Update, this.ThingDialogNavigationService, containerClone); } /// @@ -638,12 +597,12 @@ protected void ExecuteInspectCommand(Thing thing) return; } - var containerClone = (thing.Container != null) ? thing.Container.Clone(false) : null; + var containerClone = thing.Container?.Clone(false); var context = TransactionContextResolver.ResolveContext(this.Thing); var transaction = new ThingTransaction(context); - this.thingDialogNavigationService.Navigate(thing, transaction, this.Session, true, ThingDialogKind.Inspect, this.thingDialogNavigationService, containerClone); + this.ThingDialogNavigationService.Navigate(thing, transaction, this.Session, true, ThingDialogKind.Inspect, this.ThingDialogNavigationService, containerClone); } /// @@ -657,7 +616,7 @@ protected virtual async void ExecuteRefreshCommand() } catch (Exception e) { - logger.Error("The refresh operation failed: {0}", e); + logger.Error(e,"The refresh operation failed: {0}", e); } } @@ -835,12 +794,14 @@ protected virtual void InitializeCommands() this.CollpaseRowsCommand.Subscribe(_ => this.ExecuteCollapseRows()); var iteration = this.Thing as Iteration ?? this.Thing.GetContainerOfType(); + if (iteration != null) { var domainSwitchSubscription = CDPMessageBus.Current.Listen() .Where(x => x.Iteration.Iid == iteration.Iid) .ObserveOn(RxApp.MainThreadScheduler) - .Subscribe(x => this.UpdateDomain(x)); + .Subscribe(this.UpdateDomain); + this.Disposables.Add(domainSwitchSubscription); } } @@ -861,20 +822,16 @@ public virtual void PopulateContextMenu() this.ContextMenu.Add(new ContextMenuItemViewModel("Edit", "CTRL+E", this.UpdateCommand, MenuItemKind.Edit)); this.ContextMenu.Add(new ContextMenuItemViewModel("Inspect", "CTRL+I", this.InspectCommand, MenuItemKind.Inspect)); - var deprecableThing = this.SelectedThing.Thing as IDeprecatableThing; - - if (deprecableThing == null) + if (!(this.SelectedThing.Thing is IDeprecatableThing deprecableThing)) { - this.ContextMenu.Add(new ContextMenuItemViewModel(string.Format("Delete this {0}", this.camelCaseToSpaceConverter.Convert(this.SelectedThing.Thing.ClassKind, null, null, null)), "", this.DeleteCommand, MenuItemKind.Delete)); + this.ContextMenu.Add(new ContextMenuItemViewModel($"Delete this {this.camelCaseToSpaceConverter.Convert(this.SelectedThing.Thing.ClassKind, null, null, null)}", "", this.DeleteCommand, MenuItemKind.Delete)); } else { this.ContextMenu.Add(new ContextMenuItemViewModel(deprecableThing.IsDeprecated ? "Un-Deprecate" : "Deprecate", "", this.DeprecateCommand, MenuItemKind.Deprecate)); } - var categorizableThing = this.SelectedThing.Thing as ICategorizableThing; - - if (categorizableThing != null && categorizableThing.Category.Any()) + if (this.SelectedThing.Thing is ICategorizableThing categorizableThing && categorizableThing.Category.Any()) { var categoriesMenu = new ContextMenuItemViewModel("Categories", "", null, MenuItemKind.None); @@ -894,7 +851,6 @@ public virtual void PopulateContextMenu() new ContextMenuItemViewModel("Collapse Rows", "", this.CollpaseRowsCommand, MenuItemKind.None, ClassKind.NotThing) : new ContextMenuItemViewModel("Expand Rows", "", this.ExpandRowsCommand, MenuItemKind.None, ClassKind.NotThing)); } - } /// @@ -903,7 +859,7 @@ public virtual void PopulateContextMenu() /// /// The that is to be removed, /// - private async void RemoveCategoryFromSelectedThing(Thing category) + private void RemoveCategoryFromSelectedThing(Thing category) { if (!(category is Category categoryToRemove)) { @@ -927,7 +883,7 @@ private async void RemoveCategoryFromSelectedThing(Thing category) try { this.IsBusy = true; - await this.Session.Write(transaction.FinalizeTransaction()); + this.Session.Write(transaction.FinalizeTransaction()).GetAwaiter().GetResult(); logger.Info("Category {0} removed from from {1}", categoryToRemove.ShortName, this.SelectedThing.Thing.ClassKind); } catch (Exception ex) @@ -976,8 +932,7 @@ public virtual void ComputePermission() /// public virtual void StartDrag(IDragInfo dragInfo) { - var dragSource = dragInfo.Payload as IDragSource; - if (dragSource != null) + if (dragInfo.Payload is IDragSource dragSource) { dragSource.StartDrag(dragInfo); } diff --git a/CDP4Composition/OfficeRibbon/RibbonPart.cs b/CDP4Composition/OfficeRibbon/RibbonPart.cs index 98163787c..44d0e2ebc 100644 --- a/CDP4Composition/OfficeRibbon/RibbonPart.cs +++ b/CDP4Composition/OfficeRibbon/RibbonPart.cs @@ -1,8 +1,27 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. +// +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed +// +// This file is part of CDP4-IME Community Edition. +// The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration +// compliant with ECSS-E-TM-10-25 Annex A and Annex C. +// +// The CDP4-IME Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or any later version. +// +// The CDP4-IME Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------- namespace CDP4Composition { @@ -15,6 +34,7 @@ namespace CDP4Composition using System.Text; using System.Threading.Tasks; using System.Xml.Linq; + using CDP4Composition.Navigation; using CDP4Composition.Navigation.Interfaces; using CDP4Composition.PluginSettingService; @@ -142,7 +162,7 @@ public List ControlIdentifiers public virtual Task OnAction(string ribbonControlId, string ribbonControlTag = "") { logger.Debug("The OnAction method of the {0} is not overriden, therefore the OnAction method only shows this log message", this.GetType()); - return null; + return default; } /// diff --git a/CDP4Composition/Services/RuleVerification/RuleVerificationService.cs b/CDP4Composition/Services/RuleVerification/RuleVerificationService.cs index b5500fabb..71c9adb31 100644 --- a/CDP4Composition/Services/RuleVerification/RuleVerificationService.cs +++ b/CDP4Composition/Services/RuleVerification/RuleVerificationService.cs @@ -1,22 +1,43 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. +// +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed +// +// This file is part of CDP4-IME Community Edition. +// The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration +// compliant with ECSS-E-TM-10-25 Annex A and Annex C. +// +// The CDP4-IME Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or any later version. +// +// The CDP4-IME Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------- namespace CDP4Composition.Services { using System; using System.Collections.Generic; using System.ComponentModel.Composition; - using CDP4Common; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.Exceptions; using CDP4Common.SiteDirectoryData; + using CDP4Dal; using CDP4Dal.Events; using CDP4Dal.Operations; + using NLog; /// @@ -117,26 +138,24 @@ public void Execute(ISession session, RuleVerificationList verificationList) { if (session == null) { - throw new ArgumentNullException("session", "The session may not be null"); + throw new ArgumentNullException(nameof(session), "The session may not be null"); } if (verificationList == null) { - throw new ArgumentNullException("verificationList", "The verificationList may not be null"); + throw new ArgumentNullException(nameof(verificationList), "The verificationList may not be null"); } foreach (var ruleVerification in verificationList.RuleVerification) { - var builtInRuleVerification = ruleVerification as BuiltInRuleVerification; - if (builtInRuleVerification != null && builtInRuleVerification.IsActive) + switch (ruleVerification) { - this.Execute(session, builtInRuleVerification, verificationList); - } - - var userRuleVerification = ruleVerification as UserRuleVerification; - if (userRuleVerification != null && userRuleVerification.IsActive) - { - this.Execute(session, userRuleVerification, verificationList); + case BuiltInRuleVerification builtInRuleVerification when builtInRuleVerification.IsActive: + this.Execute(session, builtInRuleVerification, verificationList); + break; + case UserRuleVerification userRuleVerification when userRuleVerification.IsActive: + this.Execute(session, userRuleVerification, verificationList); + break; } } } @@ -159,7 +178,7 @@ private void Execute(ISession session, BuiltInRuleVerification builtInRuleVerifi if (iteration == null) { - throw new ContainmentException(string.Format("The container Iteration of the RuleVerificationList {0} has not been set", container.Iid)); + throw new ContainmentException($"The container Iteration of the RuleVerificationList {container.Iid} has not been set"); } foreach (var violation in builtInRuleVerification.Violation) @@ -171,13 +190,14 @@ private void Execute(ISession session, BuiltInRuleVerification builtInRuleVerifi CDPMessageBus.Current.SendObjectChangeEvent(builtInRuleVerification, EventKind.Updated); var builtInRule = this.QueryBuiltInRule(builtInRuleVerification); + if (builtInRule == null) { logger.Debug("The BuiltInRule with name {0} is not registered with the Service. The BuiltInRuleVerification cannot be executed", builtInRuleVerification.Name); return; } - IEnumerable violations = builtInRule.Verify(iteration); + var violations = builtInRule.Verify(iteration); this.UpdateExecutedOn(session, builtInRuleVerification); @@ -209,7 +229,7 @@ private void Execute(ISession session, UserRuleVerification userRuleVerification if (iteration == null) { - throw new ContainmentException(string.Format("The container Iteration of the RuleVerificationList {0} has not been set", container.Iid)); + throw new ContainmentException($"The container Iteration of the RuleVerificationList {container.Iid} has not been set"); } foreach (var violation in userRuleVerification.Violation) @@ -270,7 +290,7 @@ private void Execute(ISession session, UserRuleVerification userRuleVerification /// /// The that is to be updated. /// - private async void UpdateExecutedOn(ISession session, RuleVerification ruleVerification) + private void UpdateExecutedOn(ISession session, RuleVerification ruleVerification) { try { @@ -281,7 +301,7 @@ private async void UpdateExecutedOn(ISession session, RuleVerification ruleVerif clone.ExecutedOn = DateTime.UtcNow; var operationContainer = transaction.FinalizeTransaction(); - await session.Write(operationContainer); + session.Write(operationContainer).GetAwaiter().GetResult(); } catch (Exception ex) { @@ -301,8 +321,7 @@ private async void UpdateExecutedOn(ISession session, RuleVerification ruleVerif /// private IBuiltInRule QueryBuiltInRule(BuiltInRuleVerification builtInRuleVerification) { - Lazy lazyBuiltInRule; - this.builtInRules.TryGetValue(builtInRuleVerification.Name, out lazyBuiltInRule); + this.builtInRules.TryGetValue(builtInRuleVerification.Name, out var lazyBuiltInRule); if (lazyBuiltInRule == null) { diff --git a/CDP4Dashboard/ViewModels/Widget/IterationTrackParameterDetailViewModel.cs b/CDP4Dashboard/ViewModels/Widget/IterationTrackParameterDetailViewModel.cs index b6f47b695..38d90d2a4 100644 --- a/CDP4Dashboard/ViewModels/Widget/IterationTrackParameterDetailViewModel.cs +++ b/CDP4Dashboard/ViewModels/Widget/IterationTrackParameterDetailViewModel.cs @@ -1,8 +1,8 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Smiechowski Nathanael +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed // // This file is part of CDP4-IME Community Edition. // The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration diff --git a/CDP4Dashboard/ViewModels/Widget/IterationTrackParameterViewModel.cs b/CDP4Dashboard/ViewModels/Widget/IterationTrackParameterViewModel.cs index 194d5f2f4..f478bfbdc 100644 --- a/CDP4Dashboard/ViewModels/Widget/IterationTrackParameterViewModel.cs +++ b/CDP4Dashboard/ViewModels/Widget/IterationTrackParameterViewModel.cs @@ -1,8 +1,27 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) 2020 RHEA Group. All rights reserved. +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2021 RHEA System S.A. +// +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed +// +// This file is part of CDP4-IME Community Edition. +// The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration +// compliant with ECSS-E-TM-10-25 Annex A and Annex C. +// +// The CDP4-IME Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or any later version. +// +// The CDP4-IME Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . // -// ----------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------- namespace CDP4Dashboard.ViewModels.Widget { @@ -31,8 +50,6 @@ namespace CDP4Dashboard.ViewModels.Widget using CDP4RequirementsVerification; using CDP4RequirementsVerification.Verifiers; - using NLog; - using ReactiveUI; /// @@ -73,11 +90,6 @@ public class IterationTrackParameterViewModel : WidgetBase, I /// private IterationTrackParameter iterationTrackParameter; - /// - /// The Logger. - /// - private static Logger logger = LogManager.GetCurrentClassLogger(); - /// /// The block visibility. /// @@ -131,7 +143,7 @@ public class IterationTrackParameterViewModel : WidgetBase, I /// /// The current /// - private Iteration iteration; + private readonly Iteration iteration; /// /// The cache that stores the listeners that allow this row to react on update on the associated @@ -343,7 +355,8 @@ private void UpdateValueSetListeners() /// /// Verify the 's Requirements' /// - private async void VerifyRequirements() + /// A + private async Task VerifyRequirements() { var binaryRelationshipsToVerify = this.iterationTrackParameter.ParameterOrOverride.QueryRelationships @@ -476,7 +489,7 @@ await this.Session.Read(parameterValueSets, this.RefreshViewValues(); this.UpdateValueSetListeners(); - this.VerifyRequirements(); + await this.VerifyRequirements(); } /// diff --git a/CDP4IME/ViewModels/DataSourceExportViewModel.cs b/CDP4IME/ViewModels/DataSourceExportViewModel.cs index 4f5d45f8c..671cfb00b 100644 --- a/CDP4IME/ViewModels/DataSourceExportViewModel.cs +++ b/CDP4IME/ViewModels/DataSourceExportViewModel.cs @@ -1,21 +1,46 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2018 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. +// +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed +// +// This file is part of CDP4-IME Community Edition. +// The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration +// compliant with ECSS-E-TM-10-25 Annex A and Annex C. +// +// The CDP4-IME Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or any later version. +// +// The CDP4-IME Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------- namespace CDP4IME.ViewModels { using System; using System.Collections.Generic; using System.Linq; - using CDP4Common.CommonData; + using System.Reactive; + using System.Threading.Tasks; + using CDP4Dal.Operations; + using CDP4Composition.Navigation; + using CDP4Dal; using CDP4Dal.Composition; using CDP4Dal.DAL; + using Microsoft.Practices.ServiceLocation; + using ReactiveUI; /// @@ -83,14 +108,13 @@ public class DataSourceExportViewModel : DialogViewModelBase /// /// The file Dialog Service. /// + /// Thrown when is null public DataSourceExportViewModel(IEnumerable sessions, IOpenSaveFileDialogService openSaveFileDialogService) { - if (openSaveFileDialogService == null) - { - throw new ArgumentNullException("The openSaveFileDialogService may not be null", "openSaveFileDialogService"); - } + this.openSaveFileDialogService = openSaveFileDialogService ?? + throw new ArgumentNullException(nameof(openSaveFileDialogService), + $"The {nameof(openSaveFileDialogService)} may not be null"); - this.openSaveFileDialogService = openSaveFileDialogService; this.AvailableDals = new List(); this.OpenSessions = new ReactiveList(sessions); this.DialogNavigationService = ServiceLocator.Current.GetInstance(); @@ -106,9 +130,8 @@ public DataSourceExportViewModel(IEnumerable sessions, IOpenSaveFileDi vm => vm.Path, (passwordRetype, password, selecteddal, selectedsession, path) => selecteddal != null && selectedsession != null && !string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(password) && password == passwordRetype); - - this.OkCommand = ReactiveCommand.Create(canOk); - this.OkCommand.Subscribe(_ => this.ExecuteOk()); + + this.OkCommand = ReactiveCommand.CreateAsyncTask(canOk, async _ => await this.ExecuteOk()); this.BrowseCommand = ReactiveCommand.Create(); this.BrowseCommand.Subscribe(_ => this.ExecuteBrowse()); @@ -124,15 +147,8 @@ public DataSourceExportViewModel(IEnumerable sessions, IOpenSaveFileDi /// public IDalMetaData SelectedDal { - get - { - return this.selectedDal; - } - - set - { - this.RaiseAndSetIfChanged(ref this.selectedDal, value); - } + get => this.selectedDal; + set => this.RaiseAndSetIfChanged(ref this.selectedDal, value); } /// @@ -140,15 +156,8 @@ public IDalMetaData SelectedDal /// public ISession SelectedSession { - get - { - return this.selectedSession; - } - - set - { - this.RaiseAndSetIfChanged(ref this.selectedSession, value); - } + get => this.selectedSession; + set => this.RaiseAndSetIfChanged(ref this.selectedSession, value); } /// @@ -156,15 +165,8 @@ public ISession SelectedSession /// public string PasswordRetype { - get - { - return this.passwordRetype; - } - - set - { - this.RaiseAndSetIfChanged(ref this.passwordRetype, value); - } + get => this.passwordRetype; + set => this.RaiseAndSetIfChanged(ref this.passwordRetype, value); } /// @@ -172,15 +174,8 @@ public string PasswordRetype /// public string Password { - get - { - return this.password; - } - - set - { - this.RaiseAndSetIfChanged(ref this.password, value); - } + get => this.password; + set => this.RaiseAndSetIfChanged(ref this.password, value); } /// @@ -188,15 +183,8 @@ public string Password /// public string Path { - get - { - return this.path; - } - - set - { - this.RaiseAndSetIfChanged(ref this.path, value); - } + get => this.path; + set => this.RaiseAndSetIfChanged(ref this.path, value); } /// @@ -204,15 +192,8 @@ public string Path /// public List AvailableDals { - get - { - return this.availableDals; - } - - private set - { - this.RaiseAndSetIfChanged(ref this.availableDals, value); - } + get => this.availableDals; + private set => this.RaiseAndSetIfChanged(ref this.availableDals, value); } /// @@ -220,21 +201,14 @@ private set /// public ReactiveList OpenSessions { - get - { - return this.openSessions; - } - - private set - { - this.RaiseAndSetIfChanged(ref this.openSessions, value); - } + get => this.openSessions; + private set => this.RaiseAndSetIfChanged(ref this.openSessions, value); } /// /// Gets the Ok Command /// - public ReactiveCommand OkCommand { get; private set; } + public ReactiveCommand OkCommand { get; private set; } /// /// Gets the Cancel Command @@ -249,7 +223,8 @@ private set /// /// Executes the Ok Command /// - private async void ExecuteOk() + /// A + private async Task ExecuteOk() { this.IsBusy = true; this.LoadingMessage = "Exporting..."; @@ -262,13 +237,14 @@ private async void ExecuteOk() var dal = this.dals.Single(x => x.Metadata.DalType == DalType.File); var dalInstance = (IDal)Activator.CreateInstance(dal.Value.GetType()); - var fileExportSession = new Session(dalInstance, creds); + _ = new Session(dalInstance, creds); // create write var operationContainers = new List(); // TODO: allow iteration setup selection by user var openIterations = this.selectedSession.OpenIterations.Select(x => x.Key); + foreach (var iteration in openIterations) { var transactionContext = TransactionContextResolver.ResolveContext(iteration); @@ -279,7 +255,7 @@ private async void ExecuteOk() operationContainers.Add(operationContainer); } - var result = await dalInstance.Write(operationContainers); + await dalInstance.Write(operationContainers); this.DialogResult = new BaseDialogResult(true); } catch (Exception ex) diff --git a/CDP4IME/ViewModels/SessionViewModel.cs b/CDP4IME/ViewModels/SessionViewModel.cs index 2b24e3f60..3e476dcfe 100644 --- a/CDP4IME/ViewModels/SessionViewModel.cs +++ b/CDP4IME/ViewModels/SessionViewModel.cs @@ -1,21 +1,46 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2018 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. +// +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed +// +// This file is part of CDP4-IME Community Edition. +// The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration +// compliant with ECSS-E-TM-10-25 Annex A and Annex C. +// +// The CDP4-IME Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or any later version. +// +// The CDP4-IME Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------- namespace CDP4IME.ViewModels { using System; using System.Globalization; + using System.Reactive; using System.Reactive.Linq; + using System.Threading.Tasks; using System.Windows.Input; using System.Windows.Threading; + using CDP4Composition; using CDP4Composition.Events; using CDP4Composition.Navigation; + using CDP4Dal; + using Microsoft.Practices.ServiceLocation; + using ReactiveUI; /// @@ -23,7 +48,6 @@ namespace CDP4IME.ViewModels /// public class SessionViewModel : ReactiveObject { - #region Fields /// /// Out property for the property /// @@ -32,7 +56,7 @@ public class SessionViewModel : ReactiveObject /// /// The default auto refresh interval /// - private const uint defaultRefreshInterval = 60; + private const uint DefaultRefreshInterval = 60; /// /// Out property for @@ -73,9 +97,7 @@ public class SessionViewModel : ReactiveObject /// Backing field for the property. /// private DateTime lastUpdateDateTime; - #endregion - #region Constructors /// /// Initializes a new instance of the class. /// @@ -85,16 +107,11 @@ public class SessionViewModel : ReactiveObject public SessionViewModel(ISession session) { this.Session = session; - this.AutoRefreshInterval = defaultRefreshInterval; + this.AutoRefreshInterval = DefaultRefreshInterval; - this.Close = ReactiveCommand.Create(); - this.Close.Subscribe(_ => this.ExecuteClose()); - - this.Refresh = ReactiveCommand.Create(); - this.Refresh.Subscribe(_ => this.ExecuteRefresh()); - - this.Reload = ReactiveCommand.Create(); - this.Reload.Subscribe(_ => this.ExecuteReload()); + this.Close = ReactiveCommand.CreateAsyncTask(async _ => await this.ExecuteClose()); + this.Refresh = ReactiveCommand.CreateAsyncTask(async _ => await this.ExecuteRefresh()); + this.Reload = ReactiveCommand.CreateAsyncTask(async _ => await this.ExecuteReload()); this.HideAll = ReactiveCommand.Create(); this.HideAll.Subscribe(_ => this.ExecuteHideAll()); @@ -111,9 +128,7 @@ public SessionViewModel(ISession session) this.WhenAnyValue(x => x.AutoRefreshInterval) .Subscribe(_ => this.SetTimer()); } - #endregion - #region Public properties /// /// Gets the object that is encapsulated by the current . /// @@ -122,7 +137,7 @@ public SessionViewModel(ISession session) /// /// Gets the Close that closes the encapsulated /// - public ReactiveCommand Close { get; private set; } + public ReactiveCommand Close { get; private set; } /// /// Gets the Hide All that closes all the panels associated to this @@ -135,7 +150,7 @@ public SessionViewModel(ISession session) /// /// a refresh loads the latest new data from the data-source /// - public ReactiveCommand Refresh { get; private set; } + public ReactiveCommand Refresh { get; private set; } /// /// Gets the Refresh that reloads the encapsulated @@ -143,29 +158,17 @@ public SessionViewModel(ISession session) /// /// a reload loads all the data from the data-source /// - public ReactiveCommand Reload { get; private set; } + public ReactiveCommand Reload { get; private set; } /// /// Gets the of the current /// - public string DataSourceUri - { - get - { - return this.Session.DataSourceUri; - } - } + public string DataSourceUri => this.Session.DataSourceUri; /// /// Gets the name of the current /// - public string SessionName - { - get - { - return this.Session.Name; - } - } + public string SessionName => this.Session.Name; /// /// Gets or sets a value indicating whether the object has it's @@ -173,15 +176,8 @@ public string SessionName /// public bool IsAutoRefreshEnabled { - get - { - return this.isAutoRefreshEnabled; - } - - set - { - this.RaiseAndSetIfChanged(ref this.isAutoRefreshEnabled, value); - } + get => this.isAutoRefreshEnabled; + set => this.RaiseAndSetIfChanged(ref this.isAutoRefreshEnabled, value); } /// @@ -189,15 +185,8 @@ public bool IsAutoRefreshEnabled /// public uint AutoRefreshInterval { - get - { - return this.autoRefreshInterval; - } - - set - { - this.RaiseAndSetIfChanged(ref this.autoRefreshInterval, value); - } + get => this.autoRefreshInterval; + set => this.RaiseAndSetIfChanged(ref this.autoRefreshInterval, value); } /// @@ -205,15 +194,8 @@ public uint AutoRefreshInterval /// public uint AutoRefreshSecondsLeft { - get - { - return this.autoRefreshSecondsLeft; - } - - set - { - this.RaiseAndSetIfChanged(ref this.autoRefreshSecondsLeft, value); - } + get => this.autoRefreshSecondsLeft; + set => this.RaiseAndSetIfChanged(ref this.autoRefreshSecondsLeft, value); } /// @@ -221,15 +203,9 @@ public uint AutoRefreshSecondsLeft /// public bool IsClosed { - get - { - return this.isClosed; - } + get => this.isClosed; - set - { - this.RaiseAndSetIfChanged(ref this.isClosed, value); - } + set => this.RaiseAndSetIfChanged(ref this.isClosed, value); } /// @@ -237,47 +213,35 @@ public bool IsClosed /// public DateTime LastUpdateDateTime { - get - { - return this.lastUpdateDateTime; - } + get => this.lastUpdateDateTime; - set - { - this.RaiseAndSetIfChanged(ref this.lastUpdateDateTime, value); - } + set => this.RaiseAndSetIfChanged(ref this.lastUpdateDateTime, value); } /// /// Gets the hint displayed on the data-source Refresh button /// - public string LastUpdateDateTimeHint - { - get { return "Last Updated at " + this.lastUpdateDateTimeHint.Value; } - } + public string LastUpdateDateTimeHint => "Last Updated at " + this.lastUpdateDateTimeHint.Value; /// /// Gets a value indicating whether an Error was produced /// - public bool HasError - { - get { return this.hasError.Value; } - } + public bool HasError => this.hasError.Value; /// /// Gets or sets the error message /// public string ErrorMsg { - get { return this.errorMsg; } - set { this.RaiseAndSetIfChanged(ref this.errorMsg, value); } + get => this.errorMsg; + set => this.RaiseAndSetIfChanged(ref this.errorMsg, value); } - #endregion /// /// Executes the Command and closes the /// - private async void ExecuteClose() + /// A + private async Task ExecuteClose() { await this.Session.Close(); this.IsClosed = true; @@ -286,7 +250,8 @@ private async void ExecuteClose() /// /// Executes the Command and refreshes the /// - private async void ExecuteRefresh() + /// A + private async Task ExecuteRefresh() { try { @@ -303,7 +268,8 @@ private async void ExecuteRefresh() /// /// Executes the Command and reloads the /// - private async void ExecuteReload() + /// A + private async Task ExecuteReload() { try { @@ -330,15 +296,11 @@ private void SetTimer() if (this.IsAutoRefreshEnabled) { //dispose of previous timer - if (this.timer != null) - { - this.timer.Stop(); - } + this.timer?.Stop(); this.AutoRefreshSecondsLeft = this.AutoRefreshInterval; - - this.timer = new DispatcherTimer(); - this.timer.Interval = TimeSpan.FromSeconds(1); + + this.timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; this.timer.Tick += this.OntTimerElapsed; this.timer.Start(); } diff --git a/CDP4RelationshipEditor/ViewModels/RelationshipEditorViewModel.cs b/CDP4RelationshipEditor/ViewModels/RelationshipEditorViewModel.cs index 08e9995a3..d6ad916db 100644 --- a/CDP4RelationshipEditor/ViewModels/RelationshipEditorViewModel.cs +++ b/CDP4RelationshipEditor/ViewModels/RelationshipEditorViewModel.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. // // Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed // @@ -29,6 +29,7 @@ namespace CDP4RelationshipEditor.ViewModels using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Reactive; using System.Reactive.Linq; using System.Threading.Tasks; using System.Windows; @@ -99,11 +100,6 @@ public class RelationshipEditorViewModel : BrowserViewModelBase, IPan /// private int currentIteration; - /// - /// Backing field for - /// - private string domainOfExpertise; - /// /// The Panel Caption /// @@ -124,8 +120,8 @@ public class RelationshipEditorViewModel : BrowserViewModelBase, IPan public RelationshipEditorViewModel(Iteration thing, Participant participant, ISession session, IThingDialogNavigationService thingDialogNavigationService, IPanelNavigationService panelNavigationService, IDialogNavigationService dialogNavigationService, IPluginSettingsService pluginSettingsService) : base(thing, session, thingDialogNavigationService, panelNavigationService, dialogNavigationService, pluginSettingsService) { - this.Caption = string.Format("{0}, iteration_{1}", PanelCaption, this.Thing.IterationSetup.IterationNumber); - this.ToolTip = string.Format("{0}\n{1}\n{2}", ((EngineeringModel) this.Thing.Container).EngineeringModelSetup.Name, this.Thing.IDalUri, this.Session.ActivePerson.Name); + this.Caption = $"{PanelCaption}, iteration_{this.Thing.IterationSetup.IterationNumber}"; + this.ToolTip = $"{((EngineeringModel) this.Thing.Container).EngineeringModelSetup.Name}\n{this.Thing.IDalUri}\n{this.Session.ActivePerson.Name}"; this.AddSubscriptions(); this.UpdateProperties(); @@ -145,8 +141,10 @@ protected override void InitializeCommands() this.CreateBinaryRelationshipCommand.Subscribe(_ => this.CreateBinaryRelationshipCommandExecute()); // creation of multi relationship requires selected nodes - this.CreateMultiRelationshipCommand = ReactiveCommand.Create(canCreateMultiRelationship); - this.CreateMultiRelationshipCommand.Subscribe(_ => this.CreateMultiRelationshipCommandExecute()); + // creation of multi relationship requires selected nodes + this.CreateMultiRelationshipCommand = ReactiveCommand.CreateAsyncTask(canCreateMultiRelationship, + async _ => await this.CreateMultiRelationshipCommandExecute()); + } /// @@ -287,7 +285,7 @@ private bool CanCreateMultiRelationship() /// /// Gets or sets the Create Multi Relationship Command /// - public ReactiveCommand CreateMultiRelationshipCommand { get; protected set; } + public ReactiveCommand CreateMultiRelationshipCommand { get; protected set; } /// /// Gets or sets the active of this editor. @@ -299,8 +297,8 @@ private bool CanCreateMultiRelationship() /// public ReactiveList ThingDiagramItems { - get { return this.thingDiagramItems; } - set { this.RaiseAndSetIfChanged(ref this.thingDiagramItems, value); } + get => this.thingDiagramItems; + set => this.RaiseAndSetIfChanged(ref this.thingDiagramItems, value); } /// @@ -308,8 +306,8 @@ public ReactiveList ThingDiagramItems /// public DisposableReactiveList RelationshipRules { - get { return this.relationshipRules; } - set { this.RaiseAndSetIfChanged(ref this.relationshipRules, value); } + get => this.relationshipRules; + set => this.RaiseAndSetIfChanged(ref this.relationshipRules, value); } /// @@ -322,8 +320,8 @@ public DisposableReactiveList RelationshipRules /// public DiagramItem SelectedItem { - get { return this.selectedItem; } - set { this.RaiseAndSetIfChanged(ref this.selectedItem, value); } + get => this.selectedItem; + set => this.RaiseAndSetIfChanged(ref this.selectedItem, value); } /// @@ -331,8 +329,8 @@ public DiagramItem SelectedItem /// public ReactiveList SelectedItems { - get { return this.selectedItems; } - set { this.RaiseAndSetIfChanged(ref this.selectedItems, value); } + get => this.selectedItems; + set => this.RaiseAndSetIfChanged(ref this.selectedItems, value); } /// @@ -340,8 +338,8 @@ public ReactiveList SelectedItems /// public string CurrentModel { - get { return this.currentModel; } - private set { this.RaiseAndSetIfChanged(ref this.currentModel, value); } + get => this.currentModel; + private set => this.RaiseAndSetIfChanged(ref this.currentModel, value); } /// @@ -349,26 +347,14 @@ public string CurrentModel /// public int CurrentIteration { - get { return this.currentIteration; } - private set { this.RaiseAndSetIfChanged(ref this.currentIteration, value); } + get => this.currentIteration; + private set => this.RaiseAndSetIfChanged(ref this.currentIteration, value); } /// /// Gets the view model current /// - public EngineeringModelSetup CurrentEngineeringModelSetup - { - get { return this.Thing.IterationSetup.GetContainerOfType(); } - } - - /// - /// Gets the current name - /// - public string DomainOfExpertise - { - get { return this.domainOfExpertise; } - private set { this.RaiseAndSetIfChanged(ref this.domainOfExpertise, value); } - } + public EngineeringModelSetup CurrentEngineeringModelSetup => this.Thing.IterationSetup.GetContainerOfType(); /// /// The pending rule holds a rule in memory while creating connections, to apply to relationsships in case @@ -390,10 +376,11 @@ public void CreateBinaryRelationshipCommandExecute() /// /// The rule this relationship is based on. /// - public void CreateMultiRelationshipCommandExecute(MultiRelationshipRule rule = null) + /// A + public async Task CreateMultiRelationshipCommandExecute(MultiRelationshipRule rule = null) { var relatableThings = this.SelectedItems.Select(i => ((NamedThingDiagramContentItem) i).Thing); - this.CreateMultiRelationship(relatableThings, rule); + await this.CreateMultiRelationship(relatableThings, rule); } /// @@ -401,11 +388,11 @@ public void CreateMultiRelationshipCommandExecute(MultiRelationshipRule rule = n /// /// The list of that this relationship will apply to. /// The that defines this relationship. - private async void CreateMultiRelationship(IEnumerable relatableThings, MultiRelationshipRule rule) + /// A + private async Task CreateMultiRelationship(IEnumerable relatableThings, MultiRelationshipRule rule) { // send off the relationship - Tuple tuple; - this.Session.OpenIterations.TryGetValue(this.Thing, out tuple); + this.Session.OpenIterations.TryGetValue(this.Thing, out var tuple); var multiRelationship = new MultiRelationship(Guid.NewGuid(), null, null) { Owner = tuple.Item1 }; if (rule != null) @@ -432,18 +419,16 @@ private async void CreateMultiRelationship(IEnumerable relatableThings, M await this.Session.Write(operationContainer); // at this point relationship has gone through. - var returedRelationship = - this.Thing.Relationship.FirstOrDefault(r => r.Iid == multiRelationship.Iid) as MultiRelationship; - if (returedRelationship != null) + if (this.Thing.Relationship.FirstOrDefault(r => r.Iid == multiRelationship.Iid) is MultiRelationship returedRelationship) { this.CreateMultiRelationshipDiagramConnector(returedRelationship); } } catch (Exception ex) { - MessageBox.Show(string.Format("Creation of Binary Relationship failed: {0}", ex.Message), - "Binary Relationship Failed", + MessageBox.Show($"Creation of Multi Relationship failed: {ex.Message}", + "Multi Relationship Failed", MessageBoxButton.OK, MessageBoxImage.Error); } } @@ -452,7 +437,7 @@ private async void CreateMultiRelationship(IEnumerable relatableThings, M /// Creates a /// /// The drawn that is used as a template. - private async void CreateBinaryRelationship(DiagramConnector connector) + private void CreateBinaryRelationship(DiagramConnector connector) { var beginItemContent = ((DiagramContentItem) connector?.BeginItem)?.Content as NamedThingDiagramContentItem; var endItemContent = ((DiagramContentItem)connector?.EndItem)?.Content as NamedThingDiagramContentItem; @@ -467,8 +452,7 @@ private async void CreateBinaryRelationship(DiagramConnector connector) } // send off the relationship - Tuple tuple; - this.Session.OpenIterations.TryGetValue(this.Thing, out tuple); + this.Session.OpenIterations.TryGetValue(this.Thing, out var tuple); var binaryRelationship = new BinaryRelationship(Guid.NewGuid(), null, null) { Owner = tuple.Item1 }; @@ -494,7 +478,7 @@ private async void CreateBinaryRelationship(DiagramConnector connector) try { var operationContainer = containerTransaction.FinalizeTransaction(); - await this.Session.Write(operationContainer); + this.Session.Write(operationContainer).GetAwaiter().GetResult(); // at this point relationship has gone through. @@ -572,9 +556,7 @@ private void CreateBinaryRelationshipDiagramConnector(BinaryRelationship relatio /// public void DragOver(IDropInfo dropInfo) { - var rowPayload = dropInfo.Payload as Thing; - - if (rowPayload != null) + if (dropInfo.Payload is Thing rowPayload) { if (!this.ThingDiagramItems.OfType().Select(x => x.Thing).Contains(rowPayload)) { @@ -654,14 +636,10 @@ protected void OnSelectedThingChanged() return; } - var thingDiagramItem = this.SelectedItem as IThingDiagramItem; - - if (thingDiagramItem == null) + if (!(this.SelectedItem is IThingDiagramItem thingDiagramItem)) { // logic to handle drawing of new connections - var newDiagramConnector = this.SelectedItem as DiagramConnector; - - if (newDiagramConnector != null) + if (this.SelectedItem is DiagramConnector newDiagramConnector) { // a new connection was drawn this.CreateBinaryRelationship(newDiagramConnector); @@ -698,7 +676,7 @@ private void UpdateProperties() { this.DomainOfExpertise = (iterationDomainPair.Value == null || iterationDomainPair.Value.Item1 == null) ? "None" - : string.Format("{0} [{1}]", iterationDomainPair.Value.Item1.Name, iterationDomainPair.Value.Item1.ShortName); + : $"{iterationDomainPair.Value.Item1.Name} [{iterationDomainPair.Value.Item1.ShortName}]"; } } } diff --git a/EngineeringModel/ViewModels/PublicationBrowser/PublicationBrowserViewModel.cs b/EngineeringModel/ViewModels/PublicationBrowser/PublicationBrowserViewModel.cs index 77c90fc0a..37edd19a1 100644 --- a/EngineeringModel/ViewModels/PublicationBrowser/PublicationBrowserViewModel.cs +++ b/EngineeringModel/ViewModels/PublicationBrowser/PublicationBrowserViewModel.cs @@ -1,8 +1,8 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. // -// Author: Sam Gerené, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski +// Author: Sam Gerené, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed // // This file is part of CDP4-IME Community Edition. // The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration @@ -28,7 +28,9 @@ namespace CDP4EngineeringModel.ViewModels using System; using System.Collections.Generic; using System.Linq; + using System.Reactive; using System.Reactive.Linq; + using System.Threading.Tasks; using System.Windows; using CDP4Common.CommonData; @@ -58,7 +60,7 @@ public class PublicationBrowserViewModel : BrowserViewModelBase, IPan /// /// The used to compare the sort-order of rows /// - private static readonly PublicationChildRowComparer rowComparer = new PublicationChildRowComparer(); + private static readonly PublicationChildRowComparer RowComparer = new PublicationChildRowComparer(); /// /// Backing field for @@ -91,8 +93,8 @@ public class PublicationBrowserViewModel : BrowserViewModelBase, IPan public PublicationBrowserViewModel(Iteration iteration, ISession session, IThingDialogNavigationService thingDialogNavigationService, IPanelNavigationService panelNavigationService, IDialogNavigationService dialogNavigationService, IPluginSettingsService pluginSettingsService) : base(iteration, session, thingDialogNavigationService, panelNavigationService, dialogNavigationService, pluginSettingsService) { - this.Caption = string.Format("{0}, iteration_{1}", PanelCaption, this.Thing.IterationSetup.IterationNumber); - this.ToolTip = string.Format("{0}\n{1}\n{2}", ((EngineeringModel)this.Thing.Container).EngineeringModelSetup.Name, this.Thing.IDalUri, this.Session.ActivePerson.Name); + this.Caption = $"{PanelCaption}, iteration_{this.Thing.IterationSetup.IterationNumber}"; + this.ToolTip = $"{((EngineeringModel)this.Thing.Container).EngineeringModelSetup.Name}\n{this.Thing.IDalUri}\n{this.Session.ActivePerson.Name}"; this.AddSubscriptions(); this.UpdatePublications(); @@ -105,7 +107,7 @@ public PublicationBrowserViewModel(Iteration iteration, ISession session, IThing /// /// Gets or sets the Create Command /// - public ReactiveCommand PublishCommand { get; protected set; } + public ReactiveCommand PublishCommand { get; protected set; } /// /// Gets the view model current @@ -180,8 +182,7 @@ protected override void InitializeCommands() { base.InitializeCommands(); - this.PublishCommand = ReactiveCommand.Create(); - this.PublishCommand.Subscribe(_ => this.ExecutePublishCommand()); + this.PublishCommand = ReactiveCommand.CreateAsyncTask(async _ => await this.ExecutePublishCommand()); } /// @@ -319,7 +320,7 @@ private void AddPublishableParameterRowViewModel(ParameterOrOverrideBase paramet // if the domain row has a checkbox, select this one as well. ((PublicationParameterOrOverrideRowViewModel)parameterRow).ToBePublished = domainRow.ToBePublished; - domainRow.ContainedRows.SortedInsert(parameterRow, rowComparer); + domainRow.ContainedRows.SortedInsert(parameterRow, RowComparer); } /// @@ -377,7 +378,7 @@ private void RelocateParameterRowViewModel(ParameterOrOverrideBase parameterOrOv // if the domain row has a checkbox, select this one as well. ((PublicationParameterOrOverrideRowViewModel)parameterRow).ToBePublished = domainRow.ToBePublished; - domainRow.ContainedRows.SortedInsert(parameterRow, rowComparer); + domainRow.ContainedRows.SortedInsert(parameterRow, RowComparer); } } @@ -422,7 +423,7 @@ private IEnumerable GetListOfParametersOrOverridesToPub /// /// Execute the publication. /// - public async void ExecutePublishCommand() + public async Task ExecutePublishCommand() { // get the list of parameters or overrides to publish var parametersOrOverrides = this.GetListOfParametersOrOverridesToPublish().ToList(); @@ -430,8 +431,12 @@ public async void ExecutePublishCommand() // there must be some parameters selected. An empty publication is not possible. if (parametersOrOverrides.Count == 0) { - MessageBox.Show("Please select at least one Parameter or Parameter Override to be published.", - "Publication", MessageBoxButton.OK, MessageBoxImage.Warning); + MessageBox.Show( + "Please select at least one Parameter or Parameter Override to be published.", + "Publication", + MessageBoxButton.OK, + MessageBoxImage.Warning); + return; } @@ -450,6 +455,7 @@ public async void ExecutePublishCommand() var transactionContext = TransactionContextResolver.ResolveContext(this.Thing); var containerTransaction = new ThingTransaction(transactionContext, iteration); containerTransaction.CreateOrUpdate(publication); + try { var operationContainer = containerTransaction.FinalizeTransaction(); @@ -463,8 +469,11 @@ public async void ExecutePublishCommand() } catch (Exception ex) { - MessageBox.Show(string.Format("Publication failed: {0}", ex.Message), "Publication Failed", - MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show( + $"Publication failed: {ex.Message}", + "Publication Failed", + MessageBoxButton.OK, + MessageBoxImage.Error); } finally { @@ -507,6 +516,7 @@ private void UpdatePublications() foreach (var publication in oldPublications) { var row = this.Publications.SingleOrDefault(x => x.Thing == publication); + if (row != null) { this.Publications.RemoveAndDispose(row); @@ -532,6 +542,7 @@ private void UpdateDomains() foreach (var domain in oldDomains) { var row = this.Domains.SingleOrDefault(x => x.Thing == domain); + if (row != null) { this.Domains.RemoveAndDispose(row); @@ -636,9 +647,9 @@ public override void PopulateContextMenu() if (this.SelectedThing != null && this.SelectedThing.ContainedRows.Count > 0) { this.ContextMenu.Add( - this.SelectedThing.IsExpanded ? - new ContextMenuItemViewModel("Collapse Rows", "", this.CollpaseRowsCommand, MenuItemKind.None, ClassKind.NotThing) : - new ContextMenuItemViewModel("Expand Rows", "", this.ExpandRowsCommand, MenuItemKind.None, ClassKind.NotThing)); + this.SelectedThing.IsExpanded + ? new ContextMenuItemViewModel("Collapse Rows", "", this.CollpaseRowsCommand, MenuItemKind.None, ClassKind.NotThing) + : new ContextMenuItemViewModel("Expand Rows", "", this.ExpandRowsCommand, MenuItemKind.None, ClassKind.NotThing)); } } diff --git a/Requirements/ViewModels/ReqIF/ReqIfExportDialogViewModel.cs b/Requirements/ViewModels/ReqIF/ReqIfExportDialogViewModel.cs index 17194bd1f..4a37197d1 100644 --- a/Requirements/ViewModels/ReqIF/ReqIfExportDialogViewModel.cs +++ b/Requirements/ViewModels/ReqIF/ReqIfExportDialogViewModel.cs @@ -1,23 +1,47 @@ -// ------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. +// +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed +// +// This file is part of CDP4-IME Community Edition. +// The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration +// compliant with ECSS-E-TM-10-25 Annex A and Annex C. +// +// The CDP4-IME Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or any later version. +// +// The CDP4-IME Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . // -// ------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------- namespace CDP4Requirements.ViewModels { using System; using System.Collections.Generic; - using System.IO; using System.Linq; + using System.Threading.Tasks; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; + using CDP4Composition.Navigation; + using CDP4Dal; + using CDP4Requirements.ReqIFDal; - using NLog; + using ReactiveUI; + using ReqIFSharp; /// @@ -38,7 +62,7 @@ public class ReqIfExportDialogViewModel : DialogViewModelBase /// /// The /// - private IOpenSaveFileDialogService fileDialogService; + private readonly IOpenSaveFileDialogService fileDialogService; /// /// The @@ -66,28 +90,18 @@ public ReqIfExportDialogViewModel(IEnumerable sessions, IEnumerable(); - this.fileDialogService = fileDialogService; - this.serializer = serializer; + this.fileDialogService = fileDialogService ?? throw new ArgumentNullException(nameof(fileDialogService)); + this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); foreach (var iteration in iterations) { @@ -114,8 +128,8 @@ public ReqIfExportDialogViewModel(IEnumerable sessions, IEnumerable public bool IsDetailExpanded { - get { return this.isDetailExpanded; } - set { this.RaiseAndSetIfChanged(ref this.isDetailExpanded, value); } + get => this.isDetailExpanded; + set => this.RaiseAndSetIfChanged(ref this.isDetailExpanded, value); } /// @@ -123,8 +137,8 @@ public bool IsDetailExpanded /// public string ErrorDetailMessage { - get { return this.errorDetailMessage; } - private set { this.RaiseAndSetIfChanged(ref this.errorDetailMessage, value); } + get => this.errorDetailMessage; + private set => this.RaiseAndSetIfChanged(ref this.errorDetailMessage, value); } /// @@ -142,8 +156,8 @@ public string ErrorDetailMessage /// public ReqIfExportIterationRowViewModel SelectedIteration { - get { return this.selectedIteration; } - set { this.RaiseAndSetIfChanged(ref this.selectedIteration, value); } + get => this.selectedIteration; + set => this.RaiseAndSetIfChanged(ref this.selectedIteration, value); } /// @@ -151,8 +165,8 @@ public ReqIfExportIterationRowViewModel SelectedIteration /// public string Path { - get { return this.path; } - set { this.RaiseAndSetIfChanged(ref this.path, value); } + get => this.path; + set => this.RaiseAndSetIfChanged(ref this.path, value); } /// @@ -173,7 +187,8 @@ public string Path /// /// Executes the Ok Command /// - private async void ExecuteOk() + /// A + private void ExecuteOk() { this.IsBusy = true; this.LoadingMessage = "Exporting..."; @@ -215,8 +230,7 @@ private async void ExecuteOk() /// True if no violations related to the exported data were found private bool CheckModelValidity(Iteration iteration) { - var model = iteration.Container as EngineeringModel; - if (model == null) + if (!(iteration.Container is EngineeringModel model)) { this.ErrorMessage = "The container of the selected Iteration is not set."; return false; diff --git a/Requirements/ViewModels/RequirementBrowser/RequirementsBrowserViewModel.cs b/Requirements/ViewModels/RequirementBrowser/RequirementsBrowserViewModel.cs index 8c8885928..a28b4dd91 100644 --- a/Requirements/ViewModels/RequirementBrowser/RequirementsBrowserViewModel.cs +++ b/Requirements/ViewModels/RequirementBrowser/RequirementsBrowserViewModel.cs @@ -1,8 +1,8 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. +// Copyright (c) 2015-2021 RHEA System S.A. // -// Author: Sam Gerené, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski +// Author: Sam Gerené, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed // // This file is part of CDP4-IME Community Edition. // The CDP4-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration @@ -28,6 +28,7 @@ namespace CDP4Requirements.ViewModels using System; using System.Collections.Generic; using System.Linq; + using System.Reactive; using System.Reactive.Linq; using System.Threading.Tasks; using System.Windows; @@ -70,11 +71,6 @@ namespace CDP4Requirements.ViewModels public class RequirementsBrowserViewModel : ModellingThingBrowserViewModelBase, IPanelViewModel, IDropTarget, IRequirementBrowserDisplaySettings, IDeprecatableBrowserViewModel { - /// - /// The logger for the current class - /// - private static Logger logger = LogManager.GetCurrentClassLogger(); - /// /// The comparer for /// @@ -222,7 +218,7 @@ public int CurrentIteration /// /// Gets the Verify Requirement command /// - public ReactiveCommand VerifyRequirementsCommand { get; private set; } + public ReactiveCommand VerifyRequirementsCommand { get; private set; } /// /// Gets the Navigate To Editor Command @@ -356,8 +352,8 @@ private void UpdateRequirementSpecificationsRows() var currentReqSpec = this.ReqSpecificationRows.Select(x => x.Thing).ToList(); var updatedReqSpec = this.Thing.RequirementsSpecification; - var added = updatedReqSpec.Except(currentReqSpec).Cast().ToList(); - var removed = currentReqSpec.Except(updatedReqSpec).Cast().ToList(); + var added = updatedReqSpec.Except(currentReqSpec).ToList(); + var removed = currentReqSpec.Except(updatedReqSpec).ToList(); foreach (var requirementsSpecification in added) { @@ -499,12 +495,11 @@ private void UpdateProperties() private void ExecuteCreateRequirement() { var req = new Requirement(); - var reqGroup = this.SelectedThing.Thing as RequirementsGroup; var reqSpecification = this.SelectedThing.Thing as RequirementsSpecification ?? this.SelectedThing.Thing.GetContainerOfType(); - if (reqGroup != null) + if (this.SelectedThing.Thing is RequirementsGroup reqGroup) { req.Group = reqGroup; } @@ -526,16 +521,19 @@ protected override void InitializeCommands() this.CreateRelationshipCommand.Subscribe(_ => this.ExecuteCreateCommand(this.Thing)); this.CreateRequirementGroupCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.CanCreateRequirementGroup)); + this.CreateRequirementGroupCommand.Subscribe(_ => this.ExecuteCreateCommand(this.SelectedThing.Thing)); this.CreateRequirementCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.CanCreateRequirement)); this.CreateRequirementCommand.Subscribe(_ => this.ExecuteCreateRequirement()); - this.VerifyRequirementsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.CanVerifyRequirements)); - this.VerifyRequirementsCommand.Subscribe(_ => this.ExecuteVerifyRequirements()); + this.VerifyRequirementsCommand = ReactiveCommand.CreateAsyncTask( + this.WhenAnyValue(x => x.CanVerifyRequirements), + async _ => await this.ExecuteVerifyRequirements()); this.NavigateToRequirementsSpecificationEditorCommand = ReactiveCommand.Create(); + this.NavigateToRequirementsSpecificationEditorCommand.Subscribe(_ => this.ExecuteNavigateToRequirementsSpecificationEditor()); } @@ -714,7 +712,8 @@ private void DeleteBinaryRelationship(Thing obj) /// /// Updates requirement verification for all s contained in this RequirementBrowser /// - private async void ExecuteVerifyRequirements() + /// A + private async Task ExecuteVerifyRequirements() { if (this.CanVerifyRequirements) { @@ -759,6 +758,7 @@ private void ExecuteNavigateToRequirementsSpecificationEditor() var vm = new RequirementsSpecificationEditorViewModel(requirementsSpecification, this.Session, this.ThingDialogNavigationService, this.PanelNavigationService, this.DialogNavigationService, this.PluginSettingsService); + this.openRequirementsSpecificationEditorViewModels.Add(vm); this.PanelNavigationService.Open(vm, true); } @@ -791,6 +791,7 @@ protected void ExecuteCreateEngineeringModelDataNoteCommand(EngineeringModelData var containerClone = model.Clone(false); var transaction = new ThingTransaction(transactionContext, containerClone); + this.ThingDialogNavigationService.Navigate(engineeringModelDataNote, transaction, this.Session, true, ThingDialogKind.Create, this.ThingDialogNavigationService, containerClone); }