using System; using System.Collections.Generic; using System.Collections.ObjectModel; namespace Artemis.Core.ScriptingProviders { /// /// Allows you to implement and register your own scripting provider. /// public abstract class ScriptingProvider : ScriptingProvider where TGlobalScript : GlobalScript where TProfileScript : ProfileScript where TLayerScript : LayerScript where TPropertyScript : PropertyScript { /// /// Called when the UI needs a script editor for a /// /// The script the editor must edit public abstract IScriptEditorViewModel CreateGlobalScriptEditor(TGlobalScript script); /// /// Called when the UI needs a script editor for a /// /// The script the editor must edit public abstract IScriptEditorViewModel CreateProfileScriptEditor(TProfileScript script); /// /// Called when the UI needs a script editor for a /// /// The script the editor must edit public abstract IScriptEditorViewModel CreateLayerScriptScriptEditor(TLayerScript script); /// /// Called when the UI needs a script editor for a /// /// The script the editor must edit public abstract IScriptEditorViewModel CreatePropertyScriptEditor(TPropertyScript script); #region Overrides of ScriptingProvider /// internal override Type GlobalScriptType => typeof(TGlobalScript); /// internal override Type ProfileScriptType => typeof(TProfileScript); /// internal override Type LayerScriptType => typeof(TLayerScript); /// internal override Type PropertyScriptType => typeof(TPropertyScript); /// /// Called when the UI needs a script editor for a /// /// The script the editor must edit public override IScriptEditorViewModel CreateGlobalScriptEditor(GlobalScript script) { if (script == null) throw new ArgumentNullException(nameof(script)); if (script.GetType() != GlobalScriptType) throw new ArtemisCoreException($"This scripting provider only supports global scripts of type {GlobalScriptType.Name}"); return CreateGlobalScriptEditor((TGlobalScript) script); } /// /// Called when the UI needs a script editor for a /// /// The script the editor must edit public override IScriptEditorViewModel CreateProfileScriptEditor(ProfileScript script) { if (script == null) throw new ArgumentNullException(nameof(script)); if (script.GetType() != ProfileScriptType) throw new ArtemisCoreException($"This scripting provider only supports profile scripts of type {ProfileScriptType.Name}"); return CreateProfileScriptEditor((TProfileScript) script); } /// /// Called when the UI needs a script editor for a /// /// The script the editor must edit public override IScriptEditorViewModel CreateLayerScriptScriptEditor(LayerScript script) { if (script == null) throw new ArgumentNullException(nameof(script)); if (script.GetType() != LayerScriptType) throw new ArtemisCoreException($"This scripting provider only supports layer scripts of type {LayerScriptType.Name}"); return CreateLayerScriptScriptEditor((TLayerScript) script); } /// /// Called when the UI needs a script editor for a /// /// The script the editor must edit public override IScriptEditorViewModel CreatePropertyScriptEditor(PropertyScript script) { if (script == null) throw new ArgumentNullException(nameof(script)); if (script.GetType() != PropertyScriptType) throw new ArtemisCoreException($"This scripting provider only supports property scripts of type {PropertyScriptType.Name}"); return CreatePropertyScriptEditor((TPropertyScript) script); } #endregion #region Overrides of PluginFeature /// internal override void InternalDisable() { base.InternalDisable(); while (Scripts.Count > 0) Scripts[0].Dispose(); } #endregion } /// /// Allows you to implement and register your own scripting provider. /// /// Note: You can't implement this, implement /// instead. /// /// public abstract class ScriptingProvider : PluginFeature { internal abstract Type GlobalScriptType { get; } internal abstract Type PropertyScriptType { get; } internal abstract Type LayerScriptType { get; } internal abstract Type ProfileScriptType { get; } internal List