95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
// /**
|
|
// * File: Console.cs
|
|
// * Author: haraldwolff
|
|
// *
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
// *
|
|
// *
|
|
// **/
|
|
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using ln.types;
|
|
using System.Linq;
|
|
namespace ln.manage
|
|
{
|
|
public class ManagedConsole
|
|
{
|
|
ManagedRoot ManagedRoot { get; }
|
|
|
|
public ManagedConsole(ManagedRoot managedRoot)
|
|
{
|
|
ManagedRoot = managedRoot;
|
|
}
|
|
|
|
|
|
public String Export()
|
|
{
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
Export(memoryStream);
|
|
return Encoding.UTF8.GetString(memoryStream.ToArray());
|
|
}
|
|
public void Export(Stream stream)=> Export(stream, ManagedRoot);
|
|
public void Export(Stream stream, IManagedContainer container) => Export(stream, container, true);
|
|
public void Export(Stream stream, IManagedContainer container, bool recurse)
|
|
{
|
|
string[] containerPath = container.GetContainerPath();
|
|
string containerPathString = string.Join("/", containerPath);
|
|
|
|
foreach (IManagedObject managedObject in container.GetManagedObjects())
|
|
{
|
|
if (object.Equals(managedObject.Container, container))
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
stringBuilder.Append(containerPathString);
|
|
stringBuilder.Append(" add");
|
|
foreach (PropertyDescriptor propertyDescriptor in container.PropertyDescriptors)
|
|
{
|
|
stringBuilder.AppendFormat(" {0}={1}", propertyDescriptor.PropertyName, ValueToText(managedObject.GetValue(propertyDescriptor.PropertyName)));
|
|
}
|
|
stringBuilder.AppendLine();
|
|
|
|
if (managedObject.Enabled)
|
|
{
|
|
stringBuilder.AppendFormat("{0} enable {1}", containerPathString, managedObject.Identity.ToString());
|
|
stringBuilder.AppendLine();
|
|
}
|
|
|
|
stream.WriteBytes(Encoding.UTF8.GetBytes(stringBuilder.ToString()));
|
|
}
|
|
}
|
|
|
|
if (recurse)
|
|
{
|
|
foreach (IManagedContainer managedContainer in container.Children)
|
|
Export(stream, managedContainer, true);
|
|
}
|
|
}
|
|
|
|
public void Execute(String command)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ValueToText(object value)
|
|
{
|
|
if (value == null)
|
|
return "";
|
|
|
|
Type valueType = value.GetType();
|
|
if (valueType.IsArray)
|
|
{
|
|
object[] array = (object[])value;
|
|
return string.Join(",", array.Select((e) => ValueToText(e)));
|
|
}
|
|
|
|
return value.ToString();
|
|
}
|
|
|
|
}
|
|
}
|