From 8decce4d5be95004e6abf42bed3c75bd0d02f9c6 Mon Sep 17 00:00:00 2001 From: "VKMTHD\\haraldmartini" <harald.martini@student.tugraz.at> Date: Mon, 27 Mar 2023 11:26:38 +0200 Subject: [PATCH] cleaned up viewmodel factories --- VECTO3GUI2020/Helper/XmlHelper.cs | 2 +- VECTO3GUI2020/Ninject/DocumentModule.cs | 16 ++-- .../Ninject/DocumentViewModelFactoryModule.cs | 25 +----- VECTO3GUI2020/Ninject/FactoryModule.cs | 14 ++- .../Ninject/MultiStageViewModelFactory.cs | 76 ++++++++++------- VECTO3GUI2020/Ninject/MultistageModule.cs | 12 +-- .../Ninject/MultistageViewModelModule.cs | 60 +++++++++++++ VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs | 6 +- VECTO3GUI2020/VECTO3GUI2020.csproj | 8 +- .../Implementation/JobListViewModel.cs | 77 +++++++++-------- .../ViewModel/MultiStage/ClassDiagram1.cd | 85 +++++++++++++++++++ .../Implementation/StageInputViewModel.cs | 13 +-- .../Interfaces/IMultiStageViewModelFactory.cs | 31 +------ 13 files changed, 281 insertions(+), 144 deletions(-) create mode 100644 VECTO3GUI2020/Ninject/MultistageViewModelModule.cs create mode 100644 VECTO3GUI2020/ViewModel/MultiStage/ClassDiagram1.cd diff --git a/VECTO3GUI2020/Helper/XmlHelper.cs b/VECTO3GUI2020/Helper/XmlHelper.cs index 9401e88606..bc1fe3e1dc 100644 --- a/VECTO3GUI2020/Helper/XmlHelper.cs +++ b/VECTO3GUI2020/Helper/XmlHelper.cs @@ -42,7 +42,7 @@ namespace VECTO3GUI2020.Helper if (xmlDocument == null) return false; - var documentType = XMLHelper.GetDocumentType(xmlDocument.DocumentElement.LocalName); + var documentType = XMLHelper.GetDocumentTypeFromRootElement(xmlDocument.DocumentElement.LocalName); if (documentType == null) { throw new VectoException("unknown xml file! {0}", xmlDocument.DocumentElement.LocalName); diff --git a/VECTO3GUI2020/Ninject/DocumentModule.cs b/VECTO3GUI2020/Ninject/DocumentModule.cs index 31fd37e953..856d5d1793 100644 --- a/VECTO3GUI2020/Ninject/DocumentModule.cs +++ b/VECTO3GUI2020/Ninject/DocumentModule.cs @@ -12,15 +12,17 @@ namespace VECTO3GUI2020.Ninject public override void Load() { - Bind<IDocumentViewModel>().To<DeclarationJobViewModel>().Named(XmlDocumentType.DeclarationJobData.ToString()); - Bind<IDocumentViewModel>().To<MultiStageJobViewModel_v0_1>() - .Named(XmlDocumentType.MultistepOutputData.ToString()); + //Bind<IDocumentViewModel>().To<DeclarationJobViewModel>().Named(XmlDocumentType.DeclarationJobData.ToString()); - Bind<IDocumentViewModel>().To<CreateVifViewModel>() - .Named(typeof(JSONInputDataV10_PrimaryAndStageInputBus).ToString()); - Bind<IDocumentViewModel>().To<CompletedBusV7ViewModel>() - .Named(typeof(JSONInputDataCompletedBusFactorMethodV7).ToString()); + //Bind<IDocumentViewModel>().To<MultiStageJobViewModel_v0_1>() + // .Named(XmlDocumentType.MultistepOutputData.ToString()); + + //Bind<IDocumentViewModel>().To<CreateVifViewModel>() + // .Named(typeof(JSONInputDataV10_PrimaryAndStageInputBus).ToString()); + + //Bind<IDocumentViewModel>().To<CompletedBusV7ViewModel>() + // .Named(typeof(JSONInputDataCompletedBusFactorMethodV7).ToString()); //Bind<IDocumentViewModel>().To<MultistageJobViewModel>().Named(XmlDocumentType.MultistageOutputData.ToString()); //Bind<IDocumentViewModel>().To<DeclarationTrailerJobDocumentViewModel>().Named(XmlDocumentType.DeclarationTrailerJobData.ToString()); diff --git a/VECTO3GUI2020/Ninject/DocumentViewModelFactoryModule.cs b/VECTO3GUI2020/Ninject/DocumentViewModelFactoryModule.cs index 83c81b3a54..60bf8594f3 100644 --- a/VECTO3GUI2020/Ninject/DocumentViewModelFactoryModule.cs +++ b/VECTO3GUI2020/Ninject/DocumentViewModelFactoryModule.cs @@ -1,37 +1,20 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; using Ninject.Extensions.Factory; -using Ninject.Extensions.NamedScope; using Ninject.Modules; using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Resources; using TUGraz.VectoCore.InputData.FileIO.XML; -using TUGraz.VectoCore.InputData.FileIO.XML.Declaration; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider.v24; -using TUGraz.VectoCore.InputData.Reader; using TUGraz.VectoCore.Utils; using TUGraz.VectoCore.Utils.Ninject; using VECTO3GUI2020.Helper; -using VECTO3GUI2020.Ninject.Util; using VECTO3GUI2020.ViewModel.Implementation.Common; using VECTO3GUI2020.ViewModel.Implementation.Document; -using VECTO3GUI2020.ViewModel.Implementation.JobEdit; using VECTO3GUI2020.ViewModel.Interfaces.Document; -using VECTO3GUI2020.ViewModel.Interfaces.JobEdit; using VECTO3GUI2020.ViewModel.MultiStage.Implementation; using VECTO3GUI2020.ViewModel.MultiStage.Interfaces; namespace VECTO3GUI2020.Ninject { - - - public class DocumentViewModelFactoryModule : NinjectModule { #region Overrides of NinjectModule @@ -47,7 +30,7 @@ namespace VECTO3GUI2020.Ninject public override void Load() { - Bind<IDocumentViewModelFactory>().To<DocumentViewModelFactory>().DefinesNamedScope(DocumentViewModelFactoryScope); + Bind<IDocumentViewModelFactory>().To<DocumentViewModelFactory>().Named(DocumentViewModelFactoryScope); #region MultistepViewModel @@ -57,7 +40,7 @@ namespace VECTO3GUI2020.Ninject #region DeclarationInputData - Bind<IDeclarationInputViewModelFactory>().ToFactory(() => new CombineArgumentsToNameInstanceProvider( + Bind<IDeclarationInputViewModelFactory>().ToFactory( () => new CombineArgumentsToNameInstanceProvider(true, new [] { new CombineArgumentsToNameInstanceProvider.MethodSettings() { methods = new []{typeof(IDeclarationInputViewModelFactory).GetMethod(nameof(IDeclarationInputViewModelFactory.CreateDeclarationViewModel))}, @@ -120,11 +103,7 @@ namespace VECTO3GUI2020.Ninject Bind<IPrimaryAndStageInputViewModelFactory>().ToFactory().Named(PrimaryAndStageInputScope); Bind<IDocumentViewModel>().To<CreateVifViewModel>().WhenParentNamed(PrimaryAndStageInputScope); - - } - - #endregion } } diff --git a/VECTO3GUI2020/Ninject/FactoryModule.cs b/VECTO3GUI2020/Ninject/FactoryModule.cs index fa07b41e55..9b8b9455de 100644 --- a/VECTO3GUI2020/Ninject/FactoryModule.cs +++ b/VECTO3GUI2020/Ninject/FactoryModule.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Ninject.Extensions.Factory; using Ninject.Modules; +using TUGraz.VectoCore; using VECTO3GUI2020.Ninject.Util; using VECTO3GUI2020.Util.XML.Interfaces; using VECTO3GUI2020.ViewModel.Interfaces.Document; @@ -14,15 +15,20 @@ using VECTO3GUI2020.ViewModel.MultiStage.Interfaces; namespace VECTO3GUI2020.Ninject { - public class FactoryModule : NinjectModule + public class FactoryModule : AbstractNinjectModule { public override void Load() { + LoadModule<DocumentViewModelFactoryModule>(); + + Bind<IXMLWriterFactory>().ToFactory(() => new UseFirstArgumentTypeAsNameInstanceProvider(fallback:true)); //Bind<IMultiStageViewModelFactory>().ToFactory(() => new UseFirstArgumentAsNameInstanceProvider(skipFirstArgument: true, fallback: true)); Bind<IJobEditViewModelFactory>().ToFactory(() => new UseFirstArgumentTypeAsNameInstanceProvider()); - Bind<IDocumentViewModelFactory>().ToFactory(() => new UseFirstArgumentAsNameInstanceProvider(false)); + + + Bind<IComponentViewModelFactory>().ToFactory( () => new UseFirstArgumentTypeAsNameInstanceProvider(true)); @@ -31,8 +37,8 @@ namespace VECTO3GUI2020.Ninject InSingletonScope(); Bind<IMultiStageViewModelFactoryDefaultInstanceProvider>(). ToFactory(); - Bind<IMultiStageViewModelFactoryTypeAsNameInstanceProvider>(). - ToFactory(() => new UseFirstArgumentTypeAsNameInstanceProvider()); + //Bind<IMultiStageViewModelFactoryTypeAsNameInstanceProvider>(). + // ToFactory(() => new UseFirstArgumentTypeAsNameInstanceProvider()); Bind<IMultistageViewModelFactoryFirstParameterAsNameInstanceProvider>().ToFactory(() => new UseFirstArgumentAsNameInstanceProvider(skipFirstArgument: false)); diff --git a/VECTO3GUI2020/Ninject/MultiStageViewModelFactory.cs b/VECTO3GUI2020/Ninject/MultiStageViewModelFactory.cs index 5f2bc79206..d5d55853bb 100644 --- a/VECTO3GUI2020/Ninject/MultiStageViewModelFactory.cs +++ b/VECTO3GUI2020/Ninject/MultiStageViewModelFactory.cs @@ -1,5 +1,14 @@ -using TUGraz.VectoCommon.InputData; +using Ninject; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCore.InputData.FileIO.XML; +using TUGraz.VectoCore.InputData.FileIO.XML.Declaration; +using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider.v24; +using TUGraz.VectoCore.Models.Simulation; +using TUGraz.VectoCore.Utils; using VECTO3GUI2020.ViewModel.Implementation; +using VECTO3GUI2020.ViewModel.Implementation.Common; +using VECTO3GUI2020.ViewModel.Implementation.Document; +using VECTO3GUI2020.ViewModel.Interfaces; using VECTO3GUI2020.ViewModel.Interfaces.Common; using VECTO3GUI2020.ViewModel.Interfaces.Document; using VECTO3GUI2020.ViewModel.Interfaces.JobEdit.Vehicle; @@ -11,27 +20,26 @@ namespace VECTO3GUI2020.Ninject public class MultiStageViewModelFactory : IMultiStageViewModelFactory { private IMultiStageViewModelFactoryDefaultInstanceProvider _multiStageVmFactoryDefaultInstanceProvider; - private IMultiStageViewModelFactoryTypeAsNameInstanceProvider _multiStageViewModelFactoryTypeAsNameInstanceProvider; private IMultistageViewModelFactoryFirstParameterAsNameInstanceProvider _multistageViewModelFactoryFirstParameterAsNameInstanceProvider; + private readonly IDocumentViewModelFactory _documentViewModelFactory; - public MultiStageViewModelFactory(IMultiStageViewModelFactoryDefaultInstanceProvider multiStageVmFactoryDefaultInstanceProvider, - IMultiStageViewModelFactoryTypeAsNameInstanceProvider multiStageViewModelFactoryTypeAsNameInstanceProvider, IMultistageViewModelFactoryFirstParameterAsNameInstanceProvider multistageViewModelFactoryFirstParameterAsNameInstanceProvider) + + public MultiStageViewModelFactory( + IMultiStageViewModelFactoryDefaultInstanceProvider multiStageVmFactoryDefaultInstanceProvider, + IMultistageViewModelFactoryFirstParameterAsNameInstanceProvider multistageViewModelFactoryFirstParameterAsNameInstanceProvider, + IDocumentViewModelFactory documentViewModelFactory) { _multiStageVmFactoryDefaultInstanceProvider = multiStageVmFactoryDefaultInstanceProvider; - _multiStageViewModelFactoryTypeAsNameInstanceProvider = multiStageViewModelFactoryTypeAsNameInstanceProvider; _multistageViewModelFactoryFirstParameterAsNameInstanceProvider = multistageViewModelFactoryFirstParameterAsNameInstanceProvider; + + _documentViewModelFactory = documentViewModelFactory; } #region Implementation of IMultiStageViewModelFactoryDefaultInstanceProvider - public IDocumentViewModel GetStageInputViewModel(bool exemptedVehicle) - { - return _multiStageVmFactoryDefaultInstanceProvider.GetStageInputViewModel(exemptedVehicle); - } - public IViewModelBase GetNewMultistageJobViewModel() { return _multiStageVmFactoryDefaultInstanceProvider.GetNewMultistageJobViewModel(); @@ -79,45 +87,49 @@ namespace VECTO3GUI2020.Ninject return _multiStageVmFactoryDefaultInstanceProvider.GetAuxiliariesViewModel(consolidatedAuxiliariesInputData); } - public ICreateVifViewModel GetCreateNewVifViewModel(bool completed) - { - return _multiStageVmFactoryDefaultInstanceProvider.GetCreateNewVifViewModel(completed); - } + //public ICreateVifViewModel GetCreateNewVifViewModel(bool completed) + //{ + // return _multiStageVmFactoryDefaultInstanceProvider.GetCreateNewVifViewModel(completed); + //} - public ICreateVifViewModel GetCreateNewVifViewModel() - { - return _multiStageVmFactoryDefaultInstanceProvider.GetCreateNewVifViewModel(); - } + //public ICreateVifViewModel GetCreateNewVifViewModel() + //{ + // return _multiStageVmFactoryDefaultInstanceProvider.GetCreateNewVifViewModel(); + //} #endregion - #region Implementation of IMultiStageViewModelFactoryTypeAsNameInstanceProvider + - public IDocumentViewModel CreateDocumentViewModel(IDeclarationInputDataProvider inputData) - { - return _multiStageViewModelFactoryTypeAsNameInstanceProvider.CreateDocumentViewModel(inputData); - } - public IDocumentViewModel CreateDocumentViewModel(IInputDataProvider inputData) - { - return _multiStageViewModelFactoryTypeAsNameInstanceProvider.CreateDocumentViewModel(inputData); - } - public IVehicleViewModel CreateStageInputVehicleViewModel(IVehicleDeclarationInputData inputData) + #region Implementation of IMultistageViewModelFactoryFirstParameterAsNameInstanceProvider + + public IVehicleViewModel CreateStageInputVehicleViewModel(string inputProviderType) { - return _multiStageViewModelFactoryTypeAsNameInstanceProvider.CreateStageInputVehicleViewModel(inputData); + return _multistageViewModelFactoryFirstParameterAsNameInstanceProvider.CreateStageInputVehicleViewModel(inputProviderType); } #endregion + #region Implementation of IDocumentViewModelFactory - #region Implementation of IMultistageViewModelFactoryFirstParameterAsNameInstanceProvider + public IDocumentViewModel CreateDocumentViewModel(IInputDataProvider declarationInput) + { + return _documentViewModelFactory.CreateDocumentViewModel(declarationInput); + } - public IVehicleViewModel CreateStageInputVehicleViewModel(string inputProviderType) + public IDocumentViewModel GetCreateNewStepInputViewModel(bool exemptedVehicle) { - return _multistageViewModelFactoryFirstParameterAsNameInstanceProvider.CreateStageInputVehicleViewModel(inputProviderType); + return _documentViewModelFactory.GetCreateNewStepInputViewModel(exemptedVehicle); + } + + public IDocumentViewModel GetCreateNewVifViewModel(bool completed) + { + return _documentViewModelFactory.GetCreateNewVifViewModel(completed); } #endregion + } } \ No newline at end of file diff --git a/VECTO3GUI2020/Ninject/MultistageModule.cs b/VECTO3GUI2020/Ninject/MultistageModule.cs index 0d0ddb97ea..275135c596 100644 --- a/VECTO3GUI2020/Ninject/MultistageModule.cs +++ b/VECTO3GUI2020/Ninject/MultistageModule.cs @@ -36,14 +36,14 @@ namespace VECTO3GUI2020.Ninject Bind<IMultistageDependencies>().To<MultistageLazyDependencies>(); - Bind<ICreateVifViewModel>().To<CreateVifViewModel>(). - NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetCreateNewVifViewModel()); + //Bind<ICreateVifViewModel>().To<CreateVifViewModel>(). + // NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetCreateNewVifViewModel()); - Bind<IDocumentViewModel>().To<StageInputViewModel>() - .Named(typeof(XMLDeclarationInputDataProviderV20).ToString()); + //Bind<IDocumentViewModel>().To<StageInputViewModel>() + // .Named(typeof(XMLDeclarationInputDataProviderV20).ToString()); - Bind<IDocumentViewModel>().To<StageInputViewModel>() - .NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetStageInputViewModel(default(bool))); + //Bind<IDocumentViewModel>().To<StageInputViewModel>() + // .NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetStageInputViewModel(default(bool))); Bind<IAdditionalJobInfoViewModel>().To<AdditionalJobInfoViewModelMultiStage>() .WhenInjectedInto(typeof(IMultiStageJobViewModel)); diff --git a/VECTO3GUI2020/Ninject/MultistageViewModelModule.cs b/VECTO3GUI2020/Ninject/MultistageViewModelModule.cs new file mode 100644 index 0000000000..99b1c6d2f6 --- /dev/null +++ b/VECTO3GUI2020/Ninject/MultistageViewModelModule.cs @@ -0,0 +1,60 @@ +using Ninject.Extensions.Factory; +using Ninject.Modules; +using TUGraz.VectoCore.InputData.FileIO.XML.Declaration; +using VECTO3GUI2020.Model.Multistage; +using VECTO3GUI2020.ViewModel.Implementation.Common; +using VECTO3GUI2020.ViewModel.Interfaces.Common; +using VECTO3GUI2020.ViewModel.Interfaces.Document; +using VECTO3GUI2020.ViewModel.Interfaces.JobEdit.Vehicle; +using VECTO3GUI2020.ViewModel.MultiStage.Implementation; +using VECTO3GUI2020.ViewModel.MultiStage.Interfaces; + +namespace VECTO3GUI2020.Ninject +{ + // public class MultistageViewModelModule : NinjectModule + // { + // public override void Load() + // { + + // Bind<IViewModelBase>().To<NewMultiStageJobViewModel>(). + // NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetNewMultistageJobViewModel()); + + // Bind<IMultiStageJobViewModel>().To<MultiStageJobViewModel_v0_1>(). + // NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetMultiStageJobViewModel(null)); + + // Bind<IVehicleViewModel>().To<InterimStageBusVehicleViewModel_v2_8>(). + // NamedLikeFactoryMethod((IMultiStageViewModelFactory f)=>f.GetInterimStageVehicleViewModel()); + + // Bind<IManufacturingStageViewModel>().To<ManufacturingStageViewModel_v0_1>(). + // NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetManufacturingStageViewModel(null, false)); + + // Bind<IMultistageAirdragViewModel>().To<MultistageAirdragViewModel>(). + // NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetMultistageAirdragViewModel()); + + // Bind<IMultistageAuxiliariesViewModel>().To<MultistageAuxiliariesViewModel>(). + // NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetAuxiliariesViewModel(null)); + + // Bind<IMultistageDependencies>().To<MultistageLazyDependencies>(); + + // Bind<ICreateVifViewModel>().To<CreateVifViewModel>(). + // NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetCreateNewVifViewModel()); + + // Bind<IDocumentViewModel>().To<StageInputViewModel>() + // .Named(typeof(XMLDeclarationInputDataProviderV20).ToString()); + + // Bind<IDocumentViewModel>().To<StageInputViewModel>() + // .NamedLikeFactoryMethod((IMultiStageViewModelFactory f) => f.GetStageInputViewModel(default(bool))); + + // Bind<IAdditionalJobInfoViewModel>().To<AdditionalJobInfoViewModelMultiStage>() + // .WhenInjectedInto(typeof(IMultiStageJobViewModel)); + + // Bind<IAdditionalJobInfoViewModel>().To<AdditionalJobInfoViewModelNewVif>() + // .WhenInjectedInto(typeof(ICreateVifViewModel)); + + // Bind<IAdditionalJobInfoViewModel>().To<AdditionalJobInfoViewModelStageInput>() + // .WhenInjectedInto(typeof(IStageViewModelBase)); + + // Bind<JSONJob>().ToSelf(); + // } + //} +} diff --git a/VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs b/VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs index cfbe3a2fc2..54081f7830 100644 --- a/VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs +++ b/VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs @@ -1,5 +1,6 @@ using System.Windows; using Ninject.Modules; +using TUGraz.VectoCore; using VECTO3GUI2020.Helper; using VECTO3GUI2020.Model.Implementation; using VECTO3GUI2020.Model.Interfaces; @@ -9,12 +10,15 @@ using VECTO3GUI2020.ViewModel.Interfaces; namespace VECTO3GUI2020.Ninject { - public class Vecto3GUI2020Module : NinjectModule + public class Vecto3GUI2020Module : AbstractNinjectModule { #region Overrides of NinjectModule public override void Load() { + LoadModule<MultistageModule>(); + + Bind<IJobListViewModel>().To<JobListViewModel>().InSingletonScope(); Bind<IMainWindowViewModel>().To<MainWindowViewModel>(); diff --git a/VECTO3GUI2020/VECTO3GUI2020.csproj b/VECTO3GUI2020/VECTO3GUI2020.csproj index 1c31f8ef61..7391cfdddf 100644 --- a/VECTO3GUI2020/VECTO3GUI2020.csproj +++ b/VECTO3GUI2020/VECTO3GUI2020.csproj @@ -9,7 +9,7 @@ <ApplicationIcon>Resources\Icons\Icon2.ico</ApplicationIcon> <UseWPF>true</UseWPF> <UseWindowsForms>true</UseWindowsForms> - <PublishTrimmed >false</PublishTrimmed > + <PublishTrimmed>false</PublishTrimmed> <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets> <TargetFrameworks>net48;net6.0-windows</TargetFrameworks> <DefineConstants /> @@ -107,6 +107,12 @@ <Resource Include="Resources\Images\VECTO-About.png" /> </ItemGroup> + <ItemGroup> + <Page Update="MainWindow.xaml"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Page> + </ItemGroup> + <!--Workauround for build error--> <!--https://github.com/dotnet/wpf/pull/6680--> diff --git a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs index 32a93ed809..7640d8d062 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs @@ -20,10 +20,12 @@ using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.FileIO.XML; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider; +using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider.v24; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Interfaces; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Impl; @@ -75,7 +77,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation private IDialogHelper _dialogHelper; private IWindowHelper _windowHelper; - private IDocumentViewModelFactory _documentViewModelFactory; + //private IDocumentViewModelFactory _documentViewModelFactory; private IMultiStageViewModelFactory _multiStageViewModelFactory; private readonly IXMLInputDataReader _inputDataReader; @@ -99,7 +101,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation } - public JobListViewModel(IDocumentViewModelFactory documentViewModelFactory, + public JobListViewModel( IXMLInputDataReader inputDataReader, IDialogHelper dialogHelper, IWindowHelper windowHelper, @@ -107,8 +109,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation ISimulatorFactoryFactory simulatorFactoryFactory, IOutputViewModel outputViewModel) : this() { - _documentViewModelFactory = documentViewModelFactory; - _dialogHelper = dialogHelper; + _dialogHelper = dialogHelper; _windowHelper = windowHelper; _inputDataReader = inputDataReader; _multiStageViewModelFactory = multiStageViewModelFactory; @@ -280,41 +281,43 @@ namespace VECTO3GUI2020.ViewModel.Implementation private Task<IDocumentViewModel> LoadXMLFile([NotNull] string fileName) { - var xElement = new System.Xml.XmlDocument(); - xElement.Load(fileName); - - var documentType = XMLHelper.GetDocumentType(xElement?.DocumentElement?.LocalName); - if (documentType == XmlDocumentType.MultistepOutputData) - { - var inputDataProvider = _inputDataReader.Create(fileName) as IMultistepBusInputDataProvider; - return Task.FromResult(_multiStageViewModelFactory.GetMultiStageJobViewModel(inputDataProvider) as IDocumentViewModel); - } - else if (documentType == XmlDocumentType.DeclarationJobData) + var documentType = XMLHelper.GetDocumentTypeFromFile(fileName); + if (!documentType.IsOneOf(XmlDocumentType.MultistepOutputData, XmlDocumentType.DeclarationJobData)) { - //Remove - var inputDataProvider = _inputDataReader.CreateDeclaration(fileName); - IDocumentViewModel result; - try - { - result = _multiStageViewModelFactory.CreateDocumentViewModel(inputDataProvider); - } - catch (Exception ex) - { - Debug.WriteLine(ex.GetInnerExceptionMessages()); - result = new SimulationOnlyDeclarationJob(inputDataProvider.DataSource, inputDataProvider.JobInputData.JobName, XmlDocumentType.DeclarationJobData) as IDocumentViewModel; - } - return Task.FromResult(result); - } - else { return Task.FromException<IDocumentViewModel>( new VectoXMLException($"{documentType.ToString()} not supported")); - //throw new VectoXMLException($"{documentType.ToString()} not supported"); } - return null; - - - + var inputDataProvider = _inputDataReader.CreateDeclaration(fileName); + var vm = _multiStageViewModelFactory.CreateDocumentViewModel(inputDataProvider); + return Task.FromResult(vm); + + //if (documentType == XmlDocumentType.MultistepOutputData) + //{ + // var inputDataProvider = _inputDataReader.Create(fileName) as IMultistepBusInputDataProvider; + // return Task.FromResult(_multiStageViewModelFactory.GetMultiStageJobViewModel(inputDataProvider) as IDocumentViewModel); + //} + //else if (documentType == XmlDocumentType.DeclarationJobData) + //{ + // //Remove + // var inputDataProvider = _inputDataReader.CreateDeclaration(fileName); + // IDocumentViewModel result; + // try + // { + // result = _multiStageViewModelFactory.CreateDocumentViewModel(inputDataProvider); + // } + // catch (Exception ex) + // { + // Debug.WriteLine(ex.GetInnerExceptionMessages()); + // result = new SimulationOnlyDeclarationJob(inputDataProvider.DataSource, inputDataProvider.JobInputData.JobName, XmlDocumentType.DeclarationJobData) as IDocumentViewModel; + // } + // return Task.FromResult(result); + //} + //else { + // return Task.FromException<IDocumentViewModel>( + // new VectoXMLException($"{documentType.ToString()} not supported")); + // //throw new VectoXMLException($"{documentType.ToString()} not supported"); + //} } #endregion @@ -867,7 +870,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation private void NewCompletedInputCommandExecute(bool exempted) { - var stageInputVm = _multiStageViewModelFactory.GetStageInputViewModel(exempted); + var stageInputVm = _multiStageViewModelFactory.GetCreateNewStepInputViewModel(exempted); AddJob(stageInputVm); @@ -890,7 +893,9 @@ namespace VECTO3GUI2020.ViewModel.Implementation { return _newVifCommand ?? (_newVifCommand = new RelayCommand<bool>((b) => { var newVifViewModel = _multiStageViewModelFactory.GetCreateNewVifViewModel(b); - lock (_jobsLock) { + //var newVifViewModel = _multiStageViewModelFactory.GetCreateNewVifViewModel(b); + lock (_jobsLock) + { _jobs.Add(newVifViewModel); } _windowHelper.ShowWindow(newVifViewModel); diff --git a/VECTO3GUI2020/ViewModel/MultiStage/ClassDiagram1.cd b/VECTO3GUI2020/ViewModel/MultiStage/ClassDiagram1.cd new file mode 100644 index 0000000000..bf78d9e5a6 --- /dev/null +++ b/VECTO3GUI2020/ViewModel/MultiStage/ClassDiagram1.cd @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="utf-8"?> +<ClassDiagram MajorVersion="1" MinorVersion="1"> + <Class Name="VECTO3GUI2020.ViewModel.MultiStage.Implementation.StageInputViewModel"> + <Position X="8" Y="3.75" Width="3.5" /> + <TypeIdentifier> + <HashCode>AAAABAAABAQAAgAAEEAAAAQAAIAABIEAAAAGQACABkI=</HashCode> + <FileName>ViewModel\MultiStage\Implementation\StageInputViewModel.cs</FileName> + </TypeIdentifier> + <Lollipop Position="0.2" /> + </Class> + <Class Name="VECTO3GUI2020.ViewModel.MultiStage.Implementation.MultiStageJobViewModel_v0_1"> + <Position X="1.75" Y="5.5" Width="2.5" /> + <TypeIdentifier> + <HashCode>GAAAFAAIBEQBAgQCBMgCAhQQEIAAAEGAEABAmYGgBgY=</HashCode> + <FileName>ViewModel\MultiStage\Implementation\MultistageJobViewModel_v0_1.cs</FileName> + </TypeIdentifier> + <Lollipop Position="0.2" /> + </Class> + <Class Name="VECTO3GUI2020.ViewModel.MultiStage.Implementation.NullSumWriter" Collapsed="true"> + <Position X="4.5" Y="5.5" Width="2.5" /> + <TypeIdentifier> + <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAg=</HashCode> + <FileName>ViewModel\MultiStage\Implementation\MultistageJobViewModel_v0_1.cs</FileName> + </TypeIdentifier> + </Class> + <Class Name="VECTO3GUI2020.ViewModel.MultiStage.Implementation.InterimStageBusVehicleViewModel_v2_8" BaseTypeListCollapsed="true"> + <Position X="14.5" Y="5" Width="2.75" /> + <TypeIdentifier> + <HashCode>GoqtjOJsdkIQU7J5C/N3qMfFnRmkC4GNAjrL18uimxo=</HashCode> + <FileName>ViewModel\MultiStage\Implementation\InterimStageBusVehicleViewModel_v2_8.cs</FileName> + </TypeIdentifier> + <Lollipop Position="0.2" Collapsed="true" /> + </Class> + <Class Name="VECTO3GUI2020.ViewModel.MultiStage.Implementation.CreateVifViewModel"> + <Position X="11.75" Y="5.25" Width="2" /> + <TypeIdentifier> + <HashCode>BQABhAEChEQAggYAhEiAGAVQgBBAgEEAOAIgRAGEBgo=</HashCode> + <FileName>ViewModel\MultiStage\Implementation\CreateVifViewModel.cs</FileName> + </TypeIdentifier> + <Lollipop Position="0.2" /> + </Class> + <Interface Name="VECTO3GUI2020.ViewModel.Interfaces.Document.IDocumentViewModel" Collapsed="true"> + <Position X="1.25" Y="0.75" Width="4.5" /> + <TypeIdentifier> + <HashCode>AAAABAAABAQAAgAAAAAAAAAAAAAAAAAAAAAAAACABgI=</HashCode> + <FileName>ViewModel\Interfaces\Document\IDocumentViewModel.cs</FileName> + </TypeIdentifier> + </Interface> + <Interface Name="VECTO3GUI2020.ViewModel.Interfaces.Document.IJobViewModel" Collapsed="true"> + <Position X="1.75" Y="2" Width="2" /> + <TypeIdentifier> + <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode> + <FileName>ViewModel\Interfaces\Document\IJobViewModel.cs</FileName> + </TypeIdentifier> + </Interface> + <Interface Name="VECTO3GUI2020.ViewModel.MultiStage.Implementation.ICreateVifViewModel" Collapsed="true"> + <Position X="5" Y="1.75" Width="2" /> + <TypeIdentifier> + <HashCode>AAAAAAACgAAAAAAAAAgAEAAAAAAAAEAACAAARAEAAAA=</HashCode> + <FileName>ViewModel\MultiStage\Implementation\CreateVifViewModel.cs</FileName> + </TypeIdentifier> + </Interface> + <Interface Name="VECTO3GUI2020.ViewModel.MultiStage.Implementation.IMultiStageJobViewModel" Collapsed="true"> + <Position X="1.5" Y="3.5" Width="4.5" /> + <TypeIdentifier> + <HashCode>AAAAAAAAAAAAAAAAAIgAAAAAAAAAAACAAAAAAAAAAAA=</HashCode> + <FileName>ViewModel\MultiStage\Implementation\MultistageJobViewModel_v0_1.cs</FileName> + </TypeIdentifier> + </Interface> + <Interface Name="VECTO3GUI2020.ViewModel.MultiStage.Implementation.IMultistageVehicleViewModel" Collapsed="true"> + <Position X="12" Y="1.25" Width="1.5" /> + <TypeIdentifier> + <HashCode>AAAgAAIAAAAAAQAAAAAAAAEAAAAAAAAIAAAAAgAAAAA=</HashCode> + <FileName>ViewModel\MultiStage\Implementation\InterimStageBusVehicleViewModel_v2_8.cs</FileName> + </TypeIdentifier> + </Interface> + <Enum Name="VECTO3GUI2020.ViewModel.MultiStage.Implementation.AIRDRAGMODIFIED" Collapsed="true"> + <Position X="15" Y="4.25" Width="1.5" /> + <TypeIdentifier> + <HashCode>AAAAAAAAABIAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAA=</HashCode> + <FileName>ViewModel\MultiStage\Implementation\InterimStageBusVehicleViewModel_v2_8.cs</FileName> + </TypeIdentifier> + </Enum> + <Font Name="Segoe UI" Size="9" /> +</ClassDiagram> \ No newline at end of file diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs index a4fe9e81ca..d77c0e4c1d 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCore.Utils; using VECTO3GUI2020.Properties; @@ -45,15 +46,17 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation public StageInputViewModel(IDeclarationInputDataProvider inputData, IMultiStageViewModelFactory multiStageViewModelFactory, IAdditionalJobInfoViewModel additionalJobInfoViewModel) : this(multiStageViewModelFactory,additionalJobInfoViewModel) { _documentName = inputData.JobInputData.JobName; - _vehicleViewModel = - _viewModelFactory.CreateStageInputVehicleViewModel(inputData.JobInputData.Vehicle) as IMultistageVehicleViewModel; - (_vehicleViewModel as InterimStageBusVehicleViewModel_v2_8).ShowConsolidatedData = false; + + //_vehicleViewModel = + // _viewModelFactory.CreateStageInputVehicleViewModel(inputData.JobInputData.Vehicle) as IMultistageVehicleViewModel; + //(_vehicleViewModel as InterimStageBusVehicleViewModel_v2_8).ShowConsolidatedData = false; _dataSource = inputData.DataSource; VehicleInputDataFilePath = _dataSource.SourceFile; Title = $"{GUILabels.Edit_step_input} - {Path.GetFileName(_dataSource.SourceFile)}"; - Init(); + return; + Init(); } #region Overrides of StageViewModelBase diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultiStageViewModelFactory.cs b/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultiStageViewModelFactory.cs index cc48e57667..771f220bd4 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultiStageViewModelFactory.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultiStageViewModelFactory.cs @@ -16,31 +16,21 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Interfaces { public interface IMultiStageViewModelFactory : - IMultiStageViewModelFactoryDefaultInstanceProvider, - IMultiStageViewModelFactoryTypeAsNameInstanceProvider, - IMultistageViewModelFactoryFirstParameterAsNameInstanceProvider - { + IMultiStageViewModelFactoryDefaultInstanceProvider, IDocumentViewModelFactory, +IMultistageViewModelFactoryFirstParameterAsNameInstanceProvider + { } - public interface IMultiStageViewModelFactoryTypeAsNameInstanceProvider - { - IDocumentViewModel CreateDocumentViewModel(IDeclarationInputDataProvider inputData); - IDocumentViewModel CreateDocumentViewModel(IInputDataProvider inputData); - IVehicleViewModel CreateStageInputVehicleViewModel(IVehicleDeclarationInputData inputData); - } public interface IMultistageViewModelFactoryFirstParameterAsNameInstanceProvider { IVehicleViewModel CreateStageInputVehicleViewModel(string inputProviderType); } - - public interface IMultiStageViewModelFactoryDefaultInstanceProvider { - IDocumentViewModel GetStageInputViewModel(bool exemptedVehicle); IViewModelBase GetNewMultistageJobViewModel(); IMultiStageJobViewModel GetMultiStageJobViewModel(IMultistepBusInputDataProvider inputData); @@ -58,20 +48,5 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Interfaces IMultistageAuxiliariesViewModel GetAuxiliariesViewModel(); IMultistageAuxiliariesViewModel GetAuxiliariesViewModel( IBusAuxiliariesDeclarationData consolidatedAuxiliariesInputData); - - ICreateVifViewModel GetCreateNewVifViewModel(bool completed); - ICreateVifViewModel GetCreateNewVifViewModel(); - - //IViewModelBase CreateNewMultiStageJobViewModel(); - - //IMultiStageJobViewModel CreateMultiStageJobViewModel(string inputProviderType, IMultistageBusInputDataProvider inputData); - - //IVehicleViewModel CreateInterimStageVehicleViewModel(string inputProviderType); - - //IVehicleViewModel CreateInterimStageVehicleViewModel(string inputProviderType, IVehicleDeclarationInputData prevStageInputData); - - //IManufacturingStageViewModel CreateManufacturingStageViewModel(string inputProviderType, IManufacturingStageInputData consolidatedManufacturingStageInputData); - - //IMultistageAirdragViewModel CreateMultistageAirdragViewModel(); } } -- GitLab