using System;
using JD.Kernel.StaticHelpers;
using JD.Kernel.Structs;
using JD.LogService;
namespace JD.TeaBoxAddinSystem.Addins.Description
{
///
/// An object that is owned by a particular module of an .
///
public abstract class AddinObject
{
#region Variables
private Module m_module;
private FileLocation? m_fileLocation;
#endregion
#region Properties
///
/// Addin that owns this object. Can be null.
///
public Addin Addin
{
get
{
if (Module == null)
{
return null;
}
return Module.GetAddin();
}
}
///
/// Module that owns this object. Can be null.
///
public Module Module
{
get
{
return m_module;
}
internal set
{
if (m_module != value)
{
Throw.InvalidOperationIf(m_module != null && value != null, "Addin object already belongs to another module.");
m_module = value;
OnModuleChanged(EventArgs.Empty);
}
}
}
///
/// Location where this element is defined, if any.
///
public FileLocation? FileLocation
{
get
{
return m_fileLocation;
}
set
{
ThrowIfLoaded();
m_fileLocation = value;
}
}
#endregion
#region Methods
///
/// Throws an if loaded.
///
internal void ThrowIfLoaded()
{
if (Addin != null)
{
Addin.ThrowIfLoaded();
}
}
///
/// GetAddin.
///
///
internal virtual Addin GetAddin()
{
return null;
}
///
/// Called when the that owns this object changes.
///
///
internal virtual void OnModuleChanged(EventArgs e)
{
}
#region Logging
internal void LogError(string msg, params object[] args)
{
LogError(LogCategory.Error, msg, args);
}
internal void LogWarning(string msg, params object[] args)
{
LogError(LogCategory.Warning, msg, args);
}
private void LogError(LogCategory category, string msg, params object[] args)
{
AddinManager.Log(new Error(category, msg, args) { Origin = FileLocation.GetValueOrDefault() });
}
#endregion
#endregion
}
}