86 lines
2.5 KiB
C#
86 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using JD.Kernel.Classes;
|
|
using JD.LogService;
|
|
using JD.TeaBoxAddinSystem.Bootstrap;
|
|
|
|
namespace JD.TeaBoxAddinSystem.Addins.Management
|
|
{
|
|
/// <summary>
|
|
/// Generates an addin xml schema
|
|
/// </summary>
|
|
internal class GenerateAddinXmlSchemaCommand : AbstractCommandLineHandler
|
|
{
|
|
#region Constants
|
|
|
|
private const string GenerateAddinXmlSchemaSwitchName = "generate_addin_xml_schema";
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
public override IEnumerable<string> ArgumentNames
|
|
{
|
|
get
|
|
{
|
|
yield return GenerateAddinXmlSchemaSwitchName;
|
|
}
|
|
}
|
|
|
|
public override string ShortHelpDescription
|
|
{
|
|
get { return "Generates an addin xml schema."; }
|
|
}
|
|
|
|
protected override void ExecuteImpl()
|
|
{
|
|
if (Runtime.Arguments.Parameters.Count == 0)
|
|
{
|
|
Console.Out.WriteLine("Must specify a schema file.");
|
|
return;
|
|
}
|
|
|
|
string filename = Runtime.Arguments.Parameters[0];
|
|
|
|
filename = Path.GetFullPath(filename);
|
|
|
|
LoggingContext loggingContext = new LoggingContext();
|
|
|
|
loggingContext.ErrorAdded += delegate(object sender, ItemEventArgs<Error> e)
|
|
{
|
|
Console.Out.WriteLine(e.Item.ToCanonicalString());
|
|
};
|
|
|
|
loggingContext.WarningAdded += delegate(object sender, ItemEventArgs<Error> e)
|
|
{
|
|
Console.Out.WriteLine(e.Item.ToCanonicalString());
|
|
};
|
|
|
|
loggingContext.MessageAdded += delegate(object sender, ItemEventArgs<Message> e)
|
|
{
|
|
Console.Out.WriteLine(e.Item.Message);
|
|
};
|
|
|
|
foreach (LogEvent @event in ApplicationStartup.Instance.BootstrapLoggingContext.FullLog)
|
|
{
|
|
loggingContext.Log(@event);
|
|
}
|
|
|
|
try
|
|
{
|
|
AddinXmlSchemaGenerator generator = new AddinXmlSchemaGenerator(Runtime.AddinRepository, loggingContext);
|
|
generator.GenerateAndSaveTo(filename);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.Out.WriteLine("Unexpected error while generating schema: {0}", e.Message);
|
|
return;
|
|
}
|
|
|
|
Console.Out.WriteLine("Generated addin schema in {0}.", filename);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|