Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit ef4aaaa0 authored by Harald Martini's avatar Harald Martini
Browse files

added possibility to save and open JSON v7 job files

parent 7d420dc7
No related branches found
No related tags found
No related merge requests found
Showing
with 222 additions and 110 deletions
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="VECTO3GUI2020.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="VECTO3GUI2020.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<VECTO3GUI2020.Properties.Settings>
<setting name="EngineeringMode" serializeAs="String">
<value>False</value>
</setting>
<setting name="DefaultFilePath" serializeAs="String">
<value />
</setting>
<setting name="WriteModalResults" serializeAs="String">
<value>True</value>
</setting>
<setting name="Validate" serializeAs="String">
<value>True</value>
</setting>
<setting name="SerializeVectoRunData" serializeAs="String">
<value>True</value>
</setting>
<setting name="DefaultOutputPath" serializeAs="String">
<value />
</setting>
</VECTO3GUI2020.Properties.Settings>
</userSettings>
<applicationSettings>
<VECTO3GUI2020.Properties.Settings>
<setting name="ModalResults1Hz" serializeAs="String">
<value>False</value>
</setting>
<setting name="ActualModalData" serializeAs="String">
<value>False</value>
</setting>
</VECTO3GUI2020.Properties.Settings>
</applicationSettings>
</configuration>
\ No newline at end of file
using System;
using System.Diagnostics;
using Newtonsoft.Json;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCore;
using VECTO3GUI2020.ViewModel.Implementation.Common;
......@@ -25,12 +26,17 @@ namespace VECTO3GUI2020.Model.Multistage
}
}
public class JSONCompletedBusJob
{
public JSONJobHeader Header { get; set; }
public JSONJobBodyCompletedBus Body { get; set; }
}
public class JSONJobHeader : ObservableObject
{
public static int PrimaryAndInterimVersion = 10;
//public const int CompletedBusFileVersion = 7;
public static int CompletedBusFileVersion = 7;
private string _createdBy;
private DateTime _dateTime;
......@@ -99,4 +105,13 @@ namespace VECTO3GUI2020.Model.Multistage
set => SetProperty(ref _runSimulation, value);
}
}
public class JSONJobBodyCompletedBus
{
public string CompletedVehicle { get; set; }
public string PrimaryVehicleResults { get; set; }
public bool RunSimulation { get; set; }
}
}
\ No newline at end of file
......@@ -27,8 +27,9 @@ namespace VECTO3GUI2020.Ninject.Factories
public const string PrimaryAndStageInputScope = nameof(IPrimaryAndStageInputViewModelFactory);
private const string CompletedBusScope = nameof(ICreateVifViewModelFactory);
public override void Load()
public override void Load()
{
Bind<IDocumentViewModelFactory>().To<DocumentViewModelFactory>().InSingletonScope().Named(DocumentViewModelFactoryScope);
......@@ -103,8 +104,12 @@ namespace VECTO3GUI2020.Ninject.Factories
#endregion
Bind<IPrimaryAndStageInputViewModelFactory>().ToFactory().Named(PrimaryAndStageInputScope);
Bind<IDocumentViewModel>().To<CreateVifViewModel>().WhenParentNamed(PrimaryAndStageInputScope);
}
Bind<ICreateVifViewModelFactory>().ToFactory().Named(CompletedBusScope);
Bind<IDocumentViewModel>().To<CompletedBusV7ViewModel>().WhenParentNamed(CompletedBusScope);
}
#endregion
}
}
......@@ -123,9 +123,10 @@ namespace VECTO3GUI2020.Ninject.Factories
public IDocumentViewModel CreateDocumentViewModel(IInputDataProvider declarationInput)
{
return _documentViewModelFactory.CreateDocumentViewModel(declarationInput);
return _documentViewModelFactory.CreateDocumentViewModel(declarationInput);
}
public IDocumentViewModel GetCreateNewStepInputViewModel(bool exemptedVehicle)
{
return _documentViewModelFactory.GetCreateNewStepInputViewModel(exemptedVehicle);
......
......@@ -10,39 +10,45 @@ using TUGraz.VectoCore.Utils;
using VECTO3GUI2020.ViewModel.Implementation.Common;
using VECTO3GUI2020.ViewModel.Interfaces;
using VECTO3GUI2020.ViewModel.Interfaces.Document;
using VECTO3GUI2020.ViewModel.MultiStage.Implementation;
using VECTO3GUI2020.ViewModel.MultiStage.Interfaces;
namespace VECTO3GUI2020.ViewModel.Implementation.Document
{
internal class CompletedBusV7ViewModel : ViewModelBase, IJobViewModel
internal class CompletedBusV7ViewModel : ViewModelBase, IJobViewModel, IMultistageVIFInputData
{
private bool _selected;
private DataSource _dataSource;
private IMultistageVIFInputData _inputData;
private string _documentName;
private readonly IMultiStageJobViewModel _multistageViewModel;
#region Implementation of IDocumentViewModel
public CompletedBusV7ViewModel(IInputDataProvider inputData)
public CompletedBusV7ViewModel(IMultistageVIFInputData multistep, IMultiStageViewModelFactory vmFactory)
{
_dataSource = inputData.DataSource;
_inputData = inputData as IMultistageVIFInputData;
_dataSource = multistep.DataSource;
_inputData = multistep;
if (_inputData == null) {
throw new VectoException("Invalid input file");
}
_documentName = Path.GetFileNameWithoutExtension(_inputData.DataSource.SourceFile);
_multistageViewModel = vmFactory.GetMultiStageJobViewModel(multistep.MultistageJobInputData);
_multistageViewModel.ManufacturingStageViewModel.LoadStageInputData(multistep.VehicleInputData.DataSource.SourceFile);
}
public string DocumentName => _documentName;
public XmlDocumentType? DocumentType => null;
public XmlDocumentType? DocumentType => throw new NotImplementedException();
public string DocumentTypeName => "CompletedBus";
public DataSource DataSource => _dataSource;
public IEditViewModel EditViewModel => null;
public IEditViewModel EditViewModel => _multistageViewModel.EditViewModel;
public bool Selected
{
......@@ -62,6 +68,22 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Document
set => throw new NotImplementedException();
}
#endregion
#region Implementation of IMultistageVIFInputData
public IVehicleDeclarationInputData VehicleInputData => _inputData.VehicleInputData;
public IMultistepBusInputDataProvider MultistageJobInputData => _inputData.MultistageJobInputData;
public bool SimulateResultingVIF => _inputData.SimulateResultingVIF;
#endregion
}
}
......@@ -15,18 +15,21 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Document
private readonly IDeclarationInputViewModelFactory _declarationInputViewModelFactory;
private readonly INewDocumentViewModelFactory _newDocumentViewModelFactory;
private readonly IPrimaryAndStageInputViewModelFactory _primaryAndStageViewModelFactory;
private readonly ICreateVifViewModelFactory _createVifViewModelFactory;
public DocumentViewModelFactory(
public DocumentViewModelFactory(
IMultiStepInputViewModelFactory multiStepInputFactory,
IDeclarationInputViewModelFactory declarationInputViewModelFactory,
INewDocumentViewModelFactory newDocumentViewModelFactory,
IPrimaryAndStageInputViewModelFactory primaryAndStageFactory)
IPrimaryAndStageInputViewModelFactory primaryAndStageFactory,
ICreateVifViewModelFactory createVifViewModelFactory)
{
_multistepInputFactory = multiStepInputFactory;
_declarationInputViewModelFactory = declarationInputViewModelFactory;
_newDocumentViewModelFactory = newDocumentViewModelFactory;
_primaryAndStageViewModelFactory = primaryAndStageFactory;
_createVifViewModelFactory = createVifViewModelFactory;
}
......@@ -75,7 +78,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Document
/// <returns></returns>
private IDocumentViewModel CreateVifViewModel(IMultistageVIFInputData createVif)
{
throw new VectoException($"No viewmodel for {nameof(IMultistageVIFInputData)}");
return _createVifViewModelFactory.CreateVifViewModel(createVif);
}
public IDocumentViewModel GetCreateNewStepInputViewModel(bool exemptedVehicle)
......
......@@ -529,9 +529,9 @@ namespace VECTO3GUI2020.ViewModel.Implementation
var runsFactory = _simFactoryFactory.Factory(mode, input, fileWriter, null, null);
//var runsFactory = SimulatorFactory.CreateSimulatorFactory(mode, input, fileWriter);
runsFactory.WriteModalResults = Settings.Default.WriteModalResults;
runsFactory.ModalResults1Hz = Settings.Default.ModalResults1Hz;
runsFactory.ModalResults1Hz = false; //Settings.Default.ModalResults1Hz;
runsFactory.Validate = Settings.Default.Validate;
runsFactory.ActualModalData = Settings.Default.ActualModalData;
runsFactory.ActualModalData = false; //Settings.Default.ActualModalData;
runsFactory.SerializeVectoRunData = Settings.Default.SerializeVectoRunData;
var stopwatch = new Stopwatch();
......
......@@ -166,7 +166,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation
public bool ModalResults1Hz
{
get => _modalResults1Hz;
get => false;
set
{
if (SetProperty(ref _modalResults1Hz, value))
......
......@@ -46,6 +46,8 @@ namespace VECTO3GUI2020.ViewModel.Interfaces.Document
IDocumentViewModel CreateDeclarationViewModel(IMultistagePrimaryAndStageInputDataProvider inputData);
}
public interface INewDocumentViewModelFactory
{
IDocumentViewModel GetCreateNewStepInputViewModel(bool exemptedVehicle);
......
......@@ -292,30 +292,35 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
if (path == null) {
return null;
}
var jsonJob = new JSONJob() {
Header = new JSONJobHeader() {
AppVersion = "Vecto3GUI2020",
CreatedBy = Environment.UserName,
Date = DateTime.Today,
FileVersion = JSONJobHeader.PrimaryAndInterimVersion
},
Body = new JSONJobBody() {
PrimaryVehicle = PathHelper.GetRelativePath(path, PrimaryInputPath),
InterimStep = PathHelper.GetRelativePath(path, StageInputPath),
Completed = Completed,
RunSimulation = RunSimulation,
}
};
string jsonString = JsonConvert.SerializeObject(jsonJob, Formatting.Indented);
try {
var jsonJob = new JSONJob() {
Header = new JSONJobHeader() {
AppVersion = "Vecto3GUI2020",
CreatedBy = Environment.UserName,
Date = DateTime.Today,
FileVersion = JSONJobHeader.PrimaryAndInterimVersion
},
Body = new JSONJobBody() {
PrimaryVehicle = PathHelper.GetRelativePath(path, PrimaryInputPath),
InterimStep = PathHelper.GetRelativePath(path, StageInputPath),
Completed = Completed,
RunSimulation = RunSimulation,
}
};
string jsonString = JsonConvert.SerializeObject(jsonJob, Formatting.Indented);
Debug.WriteLine(jsonString);
File.WriteAllText(path, jsonString);
SetInputData(JSONInputDataFactory.ReadJsonJob(path));
_backingStorage.SaveChanges();
} catch (Exception ex) {
_dialogHelper.ShowErrorMessage(ex.Message);
}
Debug.WriteLine(jsonString);
File.WriteAllText(path, jsonString);
SetInputData(JSONInputDataFactory.ReadJsonJob(path));
_backingStorage.SaveChanges();
return path;
}
......
......@@ -8,6 +8,7 @@ using System.Windows;
using System.Windows.Input;
using System.Xml.Linq;
using CommunityToolkit.Mvvm.Input;
using Newtonsoft.Json;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCore.InputData.FileIO.XML;
......@@ -19,9 +20,11 @@ using TUGraz.VectoCore.OutputData;
using TUGraz.VectoCore.OutputData.FileIO;
using TUGraz.VectoCore.Utils;
using VECTO3GUI2020.Helper;
using VECTO3GUI2020.Model.Multistage;
using VECTO3GUI2020.Ninject;
using VECTO3GUI2020.Properties;
using VECTO3GUI2020.ViewModel.Implementation.Common;
using VECTO3GUI2020.ViewModel.Implementation.JobEdit.Vehicle;
using VECTO3GUI2020.ViewModel.Interfaces;
using VECTO3GUI2020.ViewModel.Interfaces.Document;
using VECTO3GUI2020.ViewModel.MultiStage.Interfaces;
......@@ -233,80 +236,72 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
return null;
}
// private bool WriteTempVIFAndValidate(XMLDeclarationVIFInputData inputData, FileOutputVIFWriter writer, IDialogHelper dialogHelper)
// {
// var tempWriter = new TempFileOutputWriter(writer);
// var factory = new SimulatorFactory(ExecutionMode.Declaration, inputData, tempWriter);
// var jobContainer = new JobContainer(new NullSumWriter());
// jobContainer.AddRuns(factory);
// jobContainer.Execute();
// jobContainer.WaitFinished();
// var resultXDoc = tempWriter.GetDocument(ReportType.DeclarationReportMultistageVehicleXML);
// using (var reader = resultXDoc.Root.CreateReader())
// {
// var validator = new XMLValidator(reader);
// var valid = validator.ValidateXML(XmlDocumentType.MultistepOutputData);
// if (!valid)
// {
// dialogHelper?.ShowMessageBox($"Error writing VIF {validator.ValidationError}", "Error",
// MessageBoxButton.OK, MessageBoxImage.Error);
// Debug.WriteLine("Invalid Outputfile");
// return false;
// }
// }
// using (var reader = resultXDoc.Root.CreateReader())
// {
// if (inputData.VehicleInputData.VehicleDeclarationType == VehicleDeclarationType.final)
// {
// var inputDataProvider = _inputDataReader.Create(reader) as IMultistageBusInputDataProvider;
// if (!inputDataProvider.JobInputData.InputComplete)
// {
// var errorCaption = "Step marked as final with incomplete/invalid input";
// var errorStringBuilder = new StringBuilder();
// errorStringBuilder.AppendLine("The following parameters are invalid:\n");
// var converter = new PropertyNameToLabelTextConverter();
// var resourceManagers = new List<ResourceManager>()
// {
// GUILabels.ResourceManager,
// BusStrings.ResourceManager,
// Strings.ResourceManager
// };
// foreach (var invalidEntry in inputDataProvider.JobInputData.InvalidEntries)
// {
// string name;
// var conversionResult = converter.Convert(invalidEntry,
// typeof(string),
// resourceManagers,
// System.Globalization.CultureInfo.CurrentCulture);
// if (conversionResult is string convString)
// {
// name = convString;
// }
// else
// {
// name = invalidEntry;
// }
// errorStringBuilder.AppendLine(name);
// }
// dialogHelper?.ShowErrorMessage(errorStringBuilder.ToString(), errorCaption);
// return false;
// }
// }
// }
public ICommand SaveAsJSONCommand => _saveAsJsonCommand ?? new RelayCommand(
() => { SaveAsJSONExecute(null); },
() => VehicleInputDataFilePath != null
);
private void SaveAsJSONExecute(string fileName)
{
if (fileName == null)
{
var dialogHelper = _multistageDependencies.DialogHelper;
var targetFile = dialogHelper.SaveToVectoJobDialog();
if (targetFile == null)
{
return;
}
SaveAsJSON(targetFile);
}
}
private void SaveAsJSON(string fileName)
{
if (fileName == null || VehicleInputDataFilePath == null)
{
return;
}
try {
var jsonJob = new JSONCompletedBusJob() {
Header = new JSONJobHeader() {
AppVersion = "Vecto3GUI2020",
CreatedBy = Environment.UserName,
Date = DateTime.Today,
FileVersion = JSONJobHeader.CompletedBusFileVersion,
},
Body = new JSONJobBodyCompletedBus() {
PrimaryVehicleResults = PathHelper.GetRelativePath(fileName,
this.MultistageJobInputData.PrimaryVehicleData.DataSource.SourceFile),
CompletedVehicle = PathHelper.GetRelativePath(fileName, this.VehicleInputDataFilePath),
RunSimulation = VehicleInputData.VehicleDeclarationType == VehicleDeclarationType.final,
}
};
string jsonString = JsonConvert.SerializeObject(jsonJob, Formatting.Indented);
Debug.WriteLine(jsonString);
File.WriteAllText(fileName, jsonString);
} catch (Exception ex) {
_dialogHelper.Value.ShowErrorMessage(ex.Message, "Error");
}
}
// return true;
//}
private readonly Lazy<IDialogHelper> _dialogHelper;
private readonly IMultistageDependencies _multistageDependencies;
......@@ -317,6 +312,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
private readonly IJobListViewModel _jobListViewModel;
private readonly IList<string> _invalidEntries;
private readonly ISimulatorFactoryFactory _simFactoryFactory;
private IRelayCommand _saveAsJsonCommand;
public string VehicleInputDataFilePath
......@@ -325,6 +321,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
set
{
ManufacturingStageViewModel.VehicleInputDataFilePath = value;
_saveAsJsonCommand?.NotifyCanExecuteChanged();
OnPropertyChanged();
}
}
......
......@@ -4,15 +4,19 @@ using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Forms.Design;
using System.Windows.Input;
using System.Xml.Linq;
using CommunityToolkit.Mvvm.Input;
using Newtonsoft.Json;
using Ninject;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCommon.Resources;
using TUGraz.VectoCore.InputData.FileIO.JSON;
using TUGraz.VectoCore.InputData.FileIO.XML;
using TUGraz.VectoCore.Utils;
using VECTO3GUI2020.Helper;
using VECTO3GUI2020.Model.Multistage;
using VECTO3GUI2020.Ninject;
using VECTO3GUI2020.Properties;
using VECTO3GUI2020.Util.XML;
......@@ -78,6 +82,8 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
private bool _showSaveAndCloseButtons = false;
public bool ShowSaveAndCloseButtons
{
get => _showSaveAndCloseButtons;
......@@ -124,10 +130,15 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
_saveInputDataAsCommand ?? new RelayCommand(() => { SaveInputDataExecute(filename: null); }, () => true);
private ICommand _loadVehicleDataCommand;
private ICommand _loadVehicleDataCommand;
private string _vehicleInputDataFilePath;
public ICommand LoadVehicleDataCommand
{
get { return _loadVehicleDataCommand ?? new RelayCommand(LoadVehicleDataExecute, () => true); }
......@@ -260,9 +271,12 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
}
}
#endregion
}
}
}
\ No newline at end of file
......@@ -36,6 +36,11 @@
Width="100"
Style="{DynamicResource MultiStageButtonStyle1}"
Command="{Binding ManufacturingStageViewModel.SaveInputDataAsCommand}">Save Input As ... </Button>
<Button
DockPanel.Dock="Right"
Width="100"
Style="{DynamicResource MultiStageButtonStyle1}"
Command="{Binding SaveAsJSONCommand}">Save as JSON ... </Button>
</DockPanel>
</Border>
<ContentControl DockPanel.Dock="Top" Content="{Binding ManufacturingStageViewModel}"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment