Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono-addins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez <llsan@microsoft.com>2022-04-26 11:47:10 +0300
committerGitHub <noreply@github.com>2022-04-26 11:47:10 +0300
commit19076081e251457dbfc33bdf60f55e6892feedf2 (patch)
tree282da7726835e0c244384bbcef446111a639c306
parenta5580e7ca669befe90a41288ccd9bad0169c9b68 (diff)
parentfc822fa50805ef2eb797c5f8216bf63378986762 (diff)
Merge pull request #184 from mono/dev/lluis/lazy-load-improvements
Delay add-in assembly load by lazy creating objects
-rw-r--r--[-rwxr-xr-x]Mono.Addins/Mono.Addins/AddinEngine.cs42
-rw-r--r--Mono.Addins/Mono.Addins/ExtensionContext.cs54
-rw-r--r--Mono.Addins/Mono.Addins/RuntimeAddin.cs37
3 files changed, 81 insertions, 52 deletions
diff --git a/Mono.Addins/Mono.Addins/AddinEngine.cs b/Mono.Addins/Mono.Addins/AddinEngine.cs
index 3e4122d..9b361a0 100755..100644
--- a/Mono.Addins/Mono.Addins/AddinEngine.cs
+++ b/Mono.Addins/Mono.Addins/AddinEngine.cs
@@ -1,4 +1,4 @@
-//
+//
// AddinService.cs
//
// Author:
@@ -62,7 +62,7 @@ namespace Mono.Addins
bool checkAssemblyLoadConflicts;
Dictionary<string,RuntimeAddin> loadedAddins = new Dictionary<string,RuntimeAddin> ();
Dictionary<string,ExtensionNodeSet> nodeSets = new Dictionary<string, ExtensionNodeSet> ();
- Hashtable autoExtensionTypes = new Hashtable ();
+ Dictionary<string,string> autoExtensionTypes = new Dictionary<string, string> ();
Dictionary<string, RuntimeAddin> assemblyResolvePaths = new Dictionary<string, RuntimeAddin>();
AddinLocalizer defaultLocalizer;
IProgressStatus defaultProgressStatus = new ConsoleProgressStatus (false);
@@ -583,16 +583,16 @@ namespace Mono.Addins
bool InsertAddin (IProgressStatus statusMonitor, Addin iad)
{
try {
- RuntimeAddin p = new RuntimeAddin (this);
+ RuntimeAddin runtimeAddin = new RuntimeAddin (this);
- RegisterAssemblyResolvePaths (p, iad.Description.MainModule);
+ RegisterAssemblyResolvePaths (runtimeAddin, iad.Description.MainModule);
// Read the config file and load the add-in assemblies
- AddinDescription description = p.Load (iad);
+ AddinDescription description = runtimeAddin.Load (iad);
// Register the add-in
var loadedAddinsCopy = new Dictionary<string,RuntimeAddin> (loadedAddins);
- loadedAddinsCopy [Addin.GetIdName (p.Id)] = p;
+ loadedAddinsCopy [Addin.GetIdName (runtimeAddin.Id)] = runtimeAddin;
loadedAddins = loadedAddinsCopy;
if (!AddinDatabase.RunningSetupProcess) {
@@ -600,18 +600,16 @@ namespace Mono.Addins
RegisterNodeSets (iad.Id, description.ExtensionNodeSets);
- foreach (ConditionTypeDescription cond in description.ConditionTypes) {
- Type ctype = p.GetType (cond.TypeName, true);
- RegisterCondition (cond.Id, ctype);
- }
+ foreach (ConditionTypeDescription cond in description.ConditionTypes)
+ RegisterCondition (cond.Id, runtimeAddin, cond.TypeName);
}
foreach (ExtensionPoint ep in description.ExtensionPoints)
- InsertExtensionPoint (p, ep);
+ InsertExtensionPoint (runtimeAddin, ep);
// Fire loaded event
- NotifyAddinLoaded (p);
- ReportAddinLoad (p.Id);
+ NotifyAddinLoaded (runtimeAddin);
+ ReportAddinLoad (runtimeAddin.Id);
return true;
}
catch (Exception ex) {
@@ -637,8 +635,7 @@ namespace Mono.Addins
CreateExtensionPoint (ep);
foreach (ExtensionNodeType nt in ep.NodeSet.NodeTypes) {
if (nt.ObjectTypeName.Length > 0) {
- Type ntype = addin.GetType (nt.ObjectTypeName, true);
- RegisterAutoTypeExtensionPoint (ntype, ep.Path);
+ RegisterAutoTypeExtensionPoint (nt.ObjectTypeName, ep.Path);
}
}
}
@@ -754,19 +751,24 @@ namespace Mono.Addins
return null;
}
- internal void RegisterAutoTypeExtensionPoint (Type type, string path)
+ internal void RegisterAutoTypeExtensionPoint (string typeName, string path)
{
- autoExtensionTypes [type] = path;
+ if (Util.TryParseTypeName (typeName, out var t, out var _))
+ typeName = t;
+ autoExtensionTypes [typeName] = path;
}
- internal void UnregisterAutoTypeExtensionPoint (Type type, string path)
+ internal void UnregisterAutoTypeExtensionPoint (string typeName, string path)
{
- autoExtensionTypes.Remove (type);
+ if (Util.TryParseTypeName (typeName, out var t, out var _))
+ typeName = t;
+ autoExtensionTypes.Remove (typeName);
}
internal string GetAutoTypeExtensionPoint (Type type)
{
- return autoExtensionTypes [type] as string;
+ autoExtensionTypes.TryGetValue (type.FullName, out var path);
+ return path;
}
void OnAssemblyLoaded (object s, AssemblyLoadEventArgs a)
diff --git a/Mono.Addins/Mono.Addins/ExtensionContext.cs b/Mono.Addins/Mono.Addins/ExtensionContext.cs
index 46bc0b1..7b510a3 100644
--- a/Mono.Addins/Mono.Addins/ExtensionContext.cs
+++ b/Mono.Addins/Mono.Addins/ExtensionContext.cs
@@ -1,4 +1,4 @@
-//
+//
// ExtensionContext.cs
//
// Author:
@@ -181,7 +181,20 @@ namespace Mono.Addins
ot.Changed -= new EventHandler (OnConditionChanged);
info.CondType = type;
}
-
+
+ internal void RegisterCondition (string id, RuntimeAddin addin, string typeName)
+ {
+ // Allows delayed creation of condition types
+ ConditionInfo info = CreateConditionInfo (id);
+ ConditionType ot = info.CondType as ConditionType;
+ if (ot != null)
+ ot.Changed -= new EventHandler (OnConditionChanged);
+ info.CondType = new ConditionTypeData {
+ TypeName = typeName,
+ Addin = addin
+ };
+ }
+
ConditionInfo CreateConditionInfo (string id)
{
ConditionInfo info = conditionTypes [id] as ConditionInfo;
@@ -198,22 +211,28 @@ namespace Mono.Addins
internal ConditionType GetCondition (string id)
{
- ConditionType ct;
ConditionInfo info = (ConditionInfo) conditionTypes [id];
if (info != null) {
- if (info.CondType is Type) {
- // The condition was registered as a type, create an instance now
- ct = (ConditionType) Activator.CreateInstance ((Type)info.CondType);
- ct.Id = id;
- ct.Changed += new EventHandler (OnConditionChanged);
- info.CondType = ct;
+ if (info.CondType is ConditionType condition) {
+ return condition;
}
- else
- ct = info.CondType as ConditionType;
+ else {
+ // The condition was registered as a type, create an instance now
+ Type type;
+ if (info.CondType is ConditionTypeData data) {
+ type = data.Addin.GetType (data.TypeName, true);
+ } else
+ type = info.CondType as Type;
- if (ct != null)
- return ct;
+ if (type != null) {
+ var ct = (ConditionType)Activator.CreateInstance (type);
+ ct.Id = id;
+ ct.Changed += new EventHandler (OnConditionChanged);
+ info.CondType = ct;
+ return ct;
+ }
+ }
}
if (parentContext != null)
@@ -233,9 +252,6 @@ namespace Mono.Addins
foreach (string cid in conditionTypeIds) {
- // Make sure the condition is properly created
- GetCondition (cid);
-
ConditionInfo info = CreateConditionInfo (cid);
if (info.BoundConditions == null)
info.BoundConditions = new List<BaseCondition> ();
@@ -1357,4 +1373,10 @@ namespace Mono.Addins
public string AddinName;
public List<Extension> Extensions;
}
+
+ class ConditionTypeData
+ {
+ public string TypeName { get; set; }
+ public RuntimeAddin Addin { get; set; }
+ }
}
diff --git a/Mono.Addins/Mono.Addins/RuntimeAddin.cs b/Mono.Addins/Mono.Addins/RuntimeAddin.cs
index 920e55f..9b05ba2 100644
--- a/Mono.Addins/Mono.Addins/RuntimeAddin.cs
+++ b/Mono.Addins/Mono.Addins/RuntimeAddin.cs
@@ -1,4 +1,4 @@
-//
+//
// RuntimeAddin.cs
//
// Author:
@@ -63,6 +63,7 @@ namespace Mono.Addins
AddinLocalizer localizer;
ModuleDescription module;
AddinEngine addinEngine;
+ ExtensionNodeDescription localizerDescription;
internal RuntimeAddin (AddinEngine addinEngine)
{
@@ -78,7 +79,6 @@ namespace Mono.Addins
baseDirectory = parentAddin.baseDirectory;
privatePath = parentAddin.privatePath;
ainfo = parentAddin.ainfo;
- localizer = parentAddin.localizer;
module.RuntimeAddin = this;
}
@@ -598,10 +598,11 @@ namespace Mono.Addins
/// </summary>
public AddinLocalizer Localizer {
get {
- if (localizer != null)
- return localizer;
+ // If this is an optional module, the localizer is defined in the parent
+ if (parentAddin != null)
+ return parentAddin.Localizer;
else
- return addinEngine.DefaultLocalizer;
+ return LoadLocalizer () ?? addinEngine.DefaultLocalizer;
}
}
@@ -627,33 +628,37 @@ namespace Mono.Addins
baseDirectory = description.BasePath;
module = description.MainModule;
module.RuntimeAddin = this;
+ localizerDescription = description.Localizer;
+ return description;
+ }
- // Load the assemblies
- if (description.Localizer != null) {
- string cls = description.Localizer.GetAttribute ("type");
+ AddinLocalizer LoadLocalizer ()
+ {
+ if (localizerDescription != null) {
+ string cls = localizerDescription.GetAttribute ("type");
// First try getting one of the stock localizers. If none of found try getting the type.
// They are not encoded as an assembly qualified name
object fob = null;
if (cls.IndexOf (',') == -1) {
- Type t = GetType().Assembly.GetType ("Mono.Addins.Localization." + cls + "Localizer", false);
+ Type t = GetType ().Assembly.GetType ("Mono.Addins.Localization." + cls + "Localizer", false);
if (t != null)
fob = Activator.CreateInstance (t);
}
-
+
if (fob == null)
fob = CreateInstance (cls, true);
-
+
IAddinLocalizerFactory factory = fob as IAddinLocalizerFactory;
if (factory == null)
throw new InvalidOperationException ("Localizer factory type '" + cls + "' must implement IAddinLocalizerFactory");
- localizer = new AddinLocalizer (factory.CreateLocalizer (this, description.Localizer));
+ localizer = new AddinLocalizer (factory.CreateLocalizer (this, localizerDescription));
+ localizerDescription = null;
}
-
- return description;
+ return localizer;
}
-
- RuntimeAddin[] GetDepAddins ()
+
+ RuntimeAddin [] GetDepAddins ()
{
if (depAddins != null)
return depAddins;