S7Explorer/Models/S7Project.cs

96 lines
2.5 KiB
C#

using System;
using System.ComponentModel;
using System.IO;
namespace S7Explorer.Models
{
public class S7Project : S7Object
{
private string _filePath;
private string _version;
private DateTime _created;
private DateTime _lastModified;
[DisplayName("Ruta de Archivo")]
public string FilePath
{
get => _filePath;
set
{
if (_filePath != value)
{
_filePath = value;
OnPropertyChanged(nameof(FilePath));
}
}
}
[DisplayName("Versión STEP7")]
public string Version
{
get => _version;
set
{
if (_version != value)
{
_version = value;
OnPropertyChanged(nameof(Version));
}
}
}
[DisplayName("Creado")]
public DateTime Created
{
get => _created;
set
{
if (_created != value)
{
_created = value;
OnPropertyChanged(nameof(Created));
}
}
}
[DisplayName("Última Modificación")]
public DateTime LastModified
{
get => _lastModified;
set
{
if (_lastModified != value)
{
_lastModified = value;
OnPropertyChanged(nameof(LastModified));
}
}
}
// Directorio base del proyecto (donde están las carpetas ombstx, YDBs, etc.)
[Browsable(false)]
public string ProjectDirectory => Path.GetDirectoryName(FilePath);
public S7Project()
{
ObjectType = S7ObjectType.Project;
Created = DateTime.Now;
LastModified = DateTime.Now;
}
// Inicializa un proyecto a partir de un archivo .s7p
public S7Project(string filePath) : this()
{
FilePath = filePath;
Name = Path.GetFileNameWithoutExtension(filePath);
// Trata de obtener fechas del archivo
if (File.Exists(filePath))
{
var fileInfo = new FileInfo(filePath);
Created = fileInfo.CreationTime;
LastModified = fileInfo.LastWriteTime;
}
}
}
}