mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Split into smaller projects, now uses plugins.
This commit is contained in:
39
RainmeterStudio.Core/Storage/IDocumentStorage.cs
Normal file
39
RainmeterStudio.Core/Storage/IDocumentStorage.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using RainmeterStudio.Core.Model;
|
||||
|
||||
namespace RainmeterStudio.Core.Storage
|
||||
{
|
||||
public interface IDocumentStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads a document from file
|
||||
/// </summary>
|
||||
/// <param name="path">Path to file</param>
|
||||
/// <returns>Read document</returns>
|
||||
IDocument Read(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a document to a file
|
||||
/// </summary>
|
||||
/// <param name="path">Path to file</param>
|
||||
/// <param name="document">Document to write</param>
|
||||
void Write(string path, IDocument document);
|
||||
|
||||
/// <summary>
|
||||
/// Tests if the file can be read by this storage
|
||||
/// </summary>
|
||||
/// <param name="path">Path to file</param>
|
||||
/// <returns>True if file can be read</returns>
|
||||
bool CanRead(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Tests if the document can be written by this storage
|
||||
/// </summary>
|
||||
/// <param name="documentType">Document type</param>
|
||||
/// <returns>True if the document can be written</returns>
|
||||
bool CanWrite(Type documentType);
|
||||
}
|
||||
}
|
92
RainmeterStudio.Core/Storage/SerializableTree.cs
Normal file
92
RainmeterStudio.Core/Storage/SerializableTree.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using RainmeterStudio.Core.Model;
|
||||
|
||||
namespace RainmeterStudio.Core.Storage
|
||||
{
|
||||
/// <summary>
|
||||
/// A special type of tree that implements a very small subset of tree operations, and can be serialized
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class SerializableTree<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the attached data
|
||||
/// </summary>
|
||||
[XmlElement("data")]
|
||||
public T Data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of children
|
||||
/// </summary>
|
||||
[XmlArray("children"), XmlArrayItem("child")]
|
||||
public List<SerializableTree<T>> Children { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the serializable tree
|
||||
/// </summary>
|
||||
public SerializableTree()
|
||||
{
|
||||
Children = new List<SerializableTree<T>>();
|
||||
Data = default(T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the serializable tree with specified data
|
||||
/// </summary>
|
||||
/// <param name="data">Data</param>
|
||||
public SerializableTree(T data)
|
||||
{
|
||||
Children = new List<SerializableTree<T>>();
|
||||
Data = data;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting to and from serializable trees
|
||||
/// </summary>
|
||||
public static class SerializableTreeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts tree into a serializable tree
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Data type of tree</typeparam>
|
||||
/// <param name="root">Root node</param>
|
||||
/// <returns>Serializable tree</returns>
|
||||
public static SerializableTree<T> AsSerializableTree<T>(this Tree<T> root)
|
||||
{
|
||||
// Convert current node
|
||||
SerializableTree<T> sRoot = new SerializableTree<T>(root.Data);
|
||||
|
||||
// Add children
|
||||
foreach (var child in root.Children)
|
||||
sRoot.Children.Add(AsSerializableTree(child));
|
||||
|
||||
// Return root
|
||||
return sRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts serializable tree into a tree
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Data type of tree</typeparam>
|
||||
/// <param name="root">Root node</param>
|
||||
/// <returns>Tree</returns>
|
||||
public static Tree<T> AsTree<T>(this SerializableTree<T> root)
|
||||
{
|
||||
// Convert current node
|
||||
Tree<T> sRoot = new Tree<T>(root.Data);
|
||||
|
||||
// Add children
|
||||
foreach (var child in root.Children)
|
||||
sRoot.Add(AsTree(child));
|
||||
|
||||
// Return root
|
||||
return sRoot;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user