Newer
Older
using System;
using System.Collections.Generic;
using System.IO;
using Castle.Core.Internal;
using VECTO3GUI.Helper;
using VECTO3GUI.ViewModel.Impl;
namespace VECTO3GUI.Model
{
public class JobListEntry
{

Franz KOBER josef
committed
public string JobTypeName { get; set; }
public bool IsSelected { get; set; }
public string JobFilePath { get; set; }
}
public class JobListModel
{
private const string ConfigFolderName = "Config";
private const string JobListFileName = "JobList.txt";
private string _jobListFilePath = Path.Combine(".", ConfigFolderName, JobListFileName);
public List<JobListEntry> JobList { get; set; }
public JobListModel()
{
SetConfigFolder();
LoadJobList();
}
private void SetConfigFolder()
{

Franz KOBER josef
committed
if (!Directory.Exists($"./{ConfigFolderName}"))
{
Directory.CreateDirectory($"{ConfigFolderName}");
}
}
private void LoadJobList()
{
var jobList = new List<JobListEntry>();
if (File.Exists(_jobListFilePath))
jobList = SerializeHelper.DeserializeToObject<List<JobListEntry>>(_jobListFilePath);
JobList = jobList;
}

Franz KOBER josef
committed
public void SaveJobList(IList<JobEntry> jobEntries)
{
SetJobList(jobEntries);
SerializeHelper.SerializeToFile(_jobListFilePath, JobList);
}

Franz KOBER josef
committed
private void SetJobList(IList<JobEntry> jobEntries)
{
if (jobEntries == null)
return;
JobList = new List<JobListEntry>();
for (int i = 0; i < jobEntries.Count; i++)
{
JobList.Add
(
new JobListEntry
{

Franz KOBER josef
committed
JobTypeName = jobEntries[i].Header.JobType.GetLabel(),
IsSelected = jobEntries[i].Selected,
JobFilePath = jobEntries[i].JobEntryFilePath
}
);
}
}

Franz KOBER josef
committed
public IList<JobEntry> GetJobEntries()
{
var jobEntries = new List<JobEntry>();
if (JobList.IsNullOrEmpty())
return jobEntries;

Franz KOBER josef
committed
for (int i = 0; i < JobList.Count; i++)
{
var jobType = JobTypeHelper.Parse(JobList[i].JobTypeName);
JobEntry jobEntry;
if (jobType == JobType.CompletedBusJob || jobType == JobType.SingleBusJob)
{
jobEntry = SerializeHelper.DeserializeToObject<JobEntry>(JobList[i].JobFilePath);
}
else
{
jobEntry = new JobEntry
{
Header = new JobHeader { JobType = jobType},
Body = new JobBody {
CompletedVehicle = JobType.CompletedXml == jobType ? JobList[i].JobFilePath : null
}
};
}
if (jobEntry != null) {
jobEntry.JobEntryFilePath = JobList[i].JobFilePath;
jobEntry.Selected = JobList[i].IsSelected;
jobEntries.Add(jobEntry);
}
}
return jobEntries;
}
}
}