using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using RainmeterStudio.Core.Model;
using RainmeterStudio.Core.Utils;
namespace RainmeterStudio.Core.Storage
{
///
/// Helper class to serialize or deserialize project objects
///
public class SerializableProject
{
private Project _project;
private SerializableReference _autoLoadFile;
private List _variableFiles;
private SerializableTree _root;
///
/// Gets or sets the project
///
[XmlIgnore]
public Project Project
{
get
{
_project.AutoLoadFile = _autoLoadFile.Reference;
_project.VariableFiles = _variableFiles.Select(x => x.Reference).ToList();
_project.Root = _root.AsTree().TransformData(x => x.Reference);
return _project;
}
set
{
_project = value;
UpdateSelf();
}
}
///
/// Gets or sets the project name
///
[XmlElement("name")]
public string Name
{
get
{
return Project.Name;
}
set
{
Project.Name = value;
UpdateSelf();
}
}
///
/// Gets or sets the project path
///
[XmlIgnore]
public string Path
{
get
{
return Project.Path;
}
set
{
Project.Path = value;
UpdateSelf();
}
}
///
/// Gets or sets the author of the project
///
[XmlElement("author")]
public string Author
{
get
{
return Project.Author;
}
set
{
Project.Author = value;
UpdateSelf();
}
}
///
/// Gets or sets the project version
///
[XmlElement("version")]
public string Version
{
get
{
return Project.Version.ToString();
}
set
{
Project.Version = new Version(value);
UpdateSelf();
}
}
///
/// Gets or sets the reference to the file to automatically load at package installation
///
[XmlElement("autoLoadFile")]
public SerializableReference AutoLoadFile
{
get
{
return _autoLoadFile;
}
set
{
_autoLoadFile = value;
}
}
///
/// Gets or sets the list of variable files
///
[XmlArray("variableFiles")]
public List VariableFiles
{
get
{
return _variableFiles;
}
set
{
_variableFiles = value;
}
}
///
/// Gets or sets the minimum rainmeter version
///
public string MinimumRainmeter
{
get
{
return Project.MinimumRainmeter.ToString();
}
set
{
Project.MinimumRainmeter = new Version(value);
UpdateSelf();
}
}
///
/// Gets or sets the minimum Windows version
///
public string MinimumWindows
{
get
{
return Project.MinimumWindows.ToString();
}
set
{
Project.MinimumWindows = new Version(value);
UpdateSelf();
}
}
///
/// Gets or sets the root node
///
public SerializableTree Root
{
get
{
return _root;
}
set
{
_root = value;
}
}
///
/// Initializes the serializable project
///
public SerializableProject()
{
Project = new Project();
}
///
/// Initializes the serializable project
///
/// Base project
public SerializableProject(Project project)
{
Project = project;
}
private void UpdateSelf()
{
_autoLoadFile = new SerializableReference(_project.AutoLoadFile);
_variableFiles = _project.VariableFiles.Select(x => new SerializableReference(x)).ToList();
_root = _project.Root.TransformData(x => new SerializableReference(x)).AsSerializableTree();
}
}
}