diff --git a/VECTO3GUI2020/Model/Multistage/JSONJob.cs b/VECTO3GUI2020/Model/Multistage/JSONJob.cs new file mode 100644 index 0000000000000000000000000000000000000000..b220d2fb977103539cd69bb940e6b139de746c56 --- /dev/null +++ b/VECTO3GUI2020/Model/Multistage/JSONJob.cs @@ -0,0 +1,89 @@ +using System; +using Newtonsoft.Json; +using VECTO3GUI2020.ViewModel.Implementation.Common; + +namespace VECTO3GUI2020.Model.Multistage +{ + public class JSONJob : ObservableObject + { + private JSONJobHeader _jobHeader; + + public JSONJobHeader JobHeader + { + get => _jobHeader; + set => SetProperty(ref _jobHeader, value); + } + + private JSONJobBody _jobBody; + + private JSONJobBody JobBody + { + get => _jobBody; + set => SetProperty(ref _jobBody, value); + } + } + + + + public class JSONJobHeader : ObservableObject + { + public class JobHeader : ObservableObject + { + public const int PrimaryAndInterimVersion = 10; + //public const int CompletedBusFileVersion = 7; + + private string _createdBy; + private DateTime _dateTime; + private string _appVersion; + private int _fileVersion; + + + public string CreatedBy + { + get { return _createdBy; } + set { SetProperty(ref _createdBy, value); } + } + + public DateTime Date + { + get { return _dateTime; } + set { SetProperty(ref _dateTime, value); } + } + + public string AppVersion + { + get { return _appVersion; } + set { SetProperty(ref _appVersion, value); } + } + + public int FileVersion + { + get { return _fileVersion; } + set + { + SetProperty(ref _fileVersion, value); + //JobType = JobTypeHelper.GetJobTypeByFileVersion(_fileVersion); + } + } + } + } + + + public class JSONJobBody : ObservableObject + { + private string _interimVehicle; + private string _primaryVehicle; + + public string InterimVehicle + { + get { return _interimVehicle; } + set { SetProperty(ref _interimVehicle, value); } + } + + public string PrimaryVehicle + { + get { return _primaryVehicle; } + set { SetProperty(ref _primaryVehicle, value); } + } + } +} \ No newline at end of file diff --git a/VECTO3GUI2020/Ninject/MultistageModule.cs b/VECTO3GUI2020/Ninject/MultistageModule.cs index 5e8c636d1ed7c8fcea45a2305d4e85fdc7df9a47..e315a3c3276fc78cd9af4b1a75b85b345268155c 100644 --- a/VECTO3GUI2020/Ninject/MultistageModule.cs +++ b/VECTO3GUI2020/Ninject/MultistageModule.cs @@ -9,6 +9,7 @@ using Ninject.Modules; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider; using TUGraz.VectoCore.Models.SimulationComponent; +using VECTO3GUI2020.Model.Multistage; using VECTO3GUI2020.Ninject.Util; using VECTO3GUI2020.ViewModel.Implementation; using VECTO3GUI2020.ViewModel.Implementation.Common; @@ -59,6 +60,8 @@ namespace VECTO3GUI2020.Ninject Bind<IAdditionalJobInfoViewModel>().To<AdditionalJobInfoViewModelNewVif>() .WhenInjectedInto(typeof(ICreateVifViewModel)); + + Bind<JSONJob>().ToSelf(); } } } diff --git a/VECTO3GUI2020/Util/JSON/IJsonWriterFactory.cs b/VECTO3GUI2020/Util/JSON/IJsonWriterFactory.cs deleted file mode 100644 index 42801aea99729f28dde26846003575ae2b76e4d5..0000000000000000000000000000000000000000 --- a/VECTO3GUI2020/Util/JSON/IJsonWriterFactory.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace VECTO3GUI2020.Util.JSON -{ - public interface IJsonWriterFactory - { - - } -} \ No newline at end of file diff --git a/VECTO3GUI2020/VECTO3GUI2020.csproj b/VECTO3GUI2020/VECTO3GUI2020.csproj index ee22af2bcbef02e31069a360a3e74189d8640b24..55a7e7d84935c69de38d360a01dac9a20a7d07ef 100644 --- a/VECTO3GUI2020/VECTO3GUI2020.csproj +++ b/VECTO3GUI2020/VECTO3GUI2020.csproj @@ -183,6 +183,7 @@ <Compile Include="Helper\ProcessHelper.cs" /> <Compile Include="Helper\VisualTreeHelperExtensions.cs" /> <Compile Include="Helper\TemplateSelector\MultistageParameterDataTemplateSelector.cs" /> + <Compile Include="Model\Multistage\JSONJob.cs" /> <Compile Include="Properties\GUILabels.Designer.cs"> <AutoGen>True</AutoGen> <DesignTime>True</DesignTime> @@ -217,7 +218,6 @@ <DependentUpon>Test.xaml</DependentUpon> </Compile> <Compile Include="TestViewModel.cs" /> - <Compile Include="Util\JSON\IJsonWriterFactory.cs" /> <Compile Include="Util\XML\Implementation\ComponentWriter\XMLBusAuxiliariesWriter.cs" /> <Compile Include="Util\XML\Implementation\ComponentWriter\XMLPTOWriter.cs" /> <Compile Include="ViewModel\Implementation\AboutViewModel.cs" /> @@ -879,11 +879,7 @@ <ItemGroup> <Resource Include="Resources\Icons\folderpicker.ico" /> </ItemGroup> - <ItemGroup> - <Folder Include="Model\Multistage\" /> - <Folder Include="Util\JSON\Implementation\" /> - <Folder Include="Util\JSON\Interfaces\" /> - </ItemGroup> + <ItemGroup /> <ItemGroup> <Resource Include="Resources\Icons\Trash_16x.ico" /> </ItemGroup> diff --git a/VECTO3GUI2020/ViewModel/Implementation/Common/AdditionalJobInfoViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/Common/AdditionalJobInfoViewModel.cs index 1a8ddeec42c470b3a1c553fbe4af8fda4ffe2d9a..a89b024e995a4a7656269d0f566136fc0837a498 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/Common/AdditionalJobInfoViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/Common/AdditionalJobInfoViewModel.cs @@ -99,7 +99,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common _parent = parent as CreateVifViewModel; Debug.Assert(_parent != null); - if() + //if() } diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/CreateVifViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/CreateVifViewModel.cs index 810ca078780c0c9f318418ab4ea04194b6ae263a..98eb4b0c3e74b4e7a2d99f1898fc58ddebbea132 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/CreateVifViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/CreateVifViewModel.cs @@ -11,6 +11,7 @@ using TUGraz.VectoCore.InputData.FileIO.XML.Declaration; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider; using TUGraz.VectoCore.Utils; using VECTO3GUI2020.Helper; +using VECTO3GUI2020.Model.Multistage; using VECTO3GUI2020.ViewModel.Implementation.Common; using VECTO3GUI2020.ViewModel.Interfaces; using VECTO3GUI2020.ViewModel.Interfaces.Document; @@ -33,6 +34,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation private readonly IDialogHelper _dialogHelper; private readonly IXMLInputDataReader _inputDataReader; private static uint _newVifCounter = 0; + private readonly JSONJob _jsonJob; private bool? _exemptedPrimary; @@ -50,8 +52,9 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation set => SetProperty(ref _stageInputExempted, value); } - public CreateVifViewModel(IDialogHelper dialogHelper, IXMLInputDataReader inputDataReader) + public CreateVifViewModel(IDialogHelper dialogHelper, IXMLInputDataReader inputDataReader, IAdditionalJobInfoViewModel additionalJobInfo, JSONJob jsonJob) { + _jsonJob = jsonJob; _dialogHelper = dialogHelper; _inputDataReader = inputDataReader; Title = "Create VIF"; @@ -83,6 +86,10 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation } } + #region Commands + + private ICommand _selectPrimaryInputFileCommand; + private ICommand _selectCompletedInputFileCommand; public ICommand SelectCompletedInputFileCommand { get => _selectCompletedInputFileCommand ?? (_selectCompletedInputFileCommand = new RelayCommand(() => { @@ -95,29 +102,36 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation public bool LoadStageInput(string fileName) { - if (fileName == null) { + if (fileName == null) + { return false; } var valid = true; IVehicleDeclarationInputData vehicleInputData = null; - try { + try + { var inputData = _inputDataReader.Create(fileName) as IDeclarationInputDataProvider; vehicleInputData = inputData.JobInputData.Vehicle; var type = vehicleInputData.GetType(); valid = (inputData != null) && (vehicleInputData is XMLDeclarationInterimStageBusDataProviderV28) || (vehicleInputData is XMLDeclarationExemptedInterimStageBusDataProviderV28); - } catch (Exception e) { + } + catch (Exception e) + { valid = false; } valid = valid && SetStageInputExempted(vehicleInputData.ExemptedVehicle); - if (valid) { + if (valid) + { StageInputPath = fileName; - } else { + } + else + { _dialogHelper.ShowMessageBox("Invalid File", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } - + @@ -135,16 +149,20 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation public bool LoadPrimaryInput(string fileName) { - if (fileName == null) { + if (fileName == null) + { return false; } var valid = true; IDeclarationInputDataProvider inputData = null; - try { + try + { inputData = _inputDataReader.Create(fileName) as IDeclarationInputDataProvider; valid = inputData != null && inputData.JobInputData.Vehicle.VehicleCategory.IsBus(); - } catch (Exception ex) { + } + catch (Exception ex) + { valid = false; } @@ -152,9 +170,12 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation - if (valid) { + if (valid) + { PrimaryInputPath = fileName; - } else { + } + else + { _dialogHelper.ShowMessageBox("Invalid File", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } @@ -166,16 +187,19 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation { var valid = StageInputExempted == null || StageInputExempted == primaryExempted; - if (valid) { + if (valid) + { ExemptedPrimary = primaryExempted; - } else { + } + else + { _dialogHelper.ShowMessageBox( caption: "Error", button: MessageBoxButton.OK, icon: MessageBoxImage.Error, messageBoxText: (primaryExempted ? "Exempted primary vehicle not allowed for non-exempted interim/completed input" - : "Only exempted input allowed for selected interim/completed input")); + : "Only exempted input allowed for exempted interim/completed input")); } return valid; } @@ -184,9 +208,12 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation { var valid = ExemptedPrimary == null || ExemptedPrimary == stageInputExempted; - if (valid) { + if (valid) + { StageInputExempted = stageInputExempted; - } else { + } + else + { _dialogHelper.ShowMessageBox( caption: "Error", button: MessageBoxButton.OK, @@ -199,17 +226,16 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation } - #region Commands - private ICommand _selectPrimaryInputFileCommand; - private ICommand _selectCompletedInputFileCommand; - private bool _selected; - private string _documentName; - #endregion + + #endregion + #region Implementation of IDocumentViewModel + private bool _selected; + private string _documentName; public string DocumentName { get => _documentName; diff --git a/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs b/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs index e74e5aa1df286bc34b47fe54c56dc459760441c8..66e6a172bab78bd27aaa89d0dbbecbaf2c1e3677 100644 --- a/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs +++ b/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs @@ -88,6 +88,8 @@ namespace TUGraz.VectoCommon.InputData IVehicleDeclarationInputData CompletedVehicle { get; } } + + public interface IMultistageBusInputDataProvider : IDeclarationInputDataProvider { diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index 07b7db4ab710862123b087c404253d0929d8a5cd..345588267160660a3afa1c20ccdc53d9bd1f5fdf 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -1122,4 +1122,37 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON ? null : JSONInputDataFactory.ReadShiftParameters(Path.Combine(BasePath, Body.GetEx<string>("TCU")), false); } + + + public class JSONInputDataV10_PrimaryAndInterimBus : JSONFile, IInputDataProvider + { + private readonly IXMLInputDataReader _xmlInputReader; + private string _primaryVehicleInputDataPath; + private IVehicleDeclarationInputData _primaryVehicleInputData; + public IVehicleDeclarationInputData PrimaryVehicle => + _primaryVehicleInputData ?? (_primaryVehicleInputData = + _xmlInputReader.CreateDeclaration(_primaryVehicleInputDataPath).JobInputData.Vehicle); + + private string _stageInputDataPath; + private IVehicleDeclarationInputData _stageInputData; + + public IVehicleDeclarationInputData StageInputData => + _stageInputData ?? (_stageInputData = + _xmlInputReader.CreateDeclaration(_stageInputDataPath).JobInputData.Vehicle); + + + + public JSONInputDataV10_PrimaryAndInterimBus(JObject data, string filename, bool tolerateMissing = false) : + base(data, filename, tolerateMissing) + { + var kernel = new StandardKernel(new VectoNinjectModule()); + _xmlInputReader = kernel.Get<IXMLInputDataReader>(); + _primaryVehicleInputDataPath = default(string); + _stageInputDataPath = default(string); + + + + + } + } } diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs index 656b79d22c4e4872186d4753210265fac1bcb168..52295c92cd4314a9686f86ffa169b3642f196a1f 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs @@ -101,6 +101,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON return new JSONInputDataV8_Hybrid(json, filename, tolerateMissing); case 9: return new JSONInputDataV9_BEV(json, filename, tolerateMissing); + case 10: + return new JSONInputDataV10_PrimaryAndInterimBus(json, filename, tolerateMissing); default: throw new VectoException("Job-File: Unsupported FileVersion. Got: {0} ", version); }