[NUI.Gadget] Add a new method to load assembly (#5455)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Tue, 8 Aug 2023 04:47:40 +0000 (13:47 +0900)
committerGitHub <noreply@github.com>
Tue, 8 Aug 2023 04:47:40 +0000 (13:47 +0900)
The Load() method is added to load the assembly of the NUIGadget.

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs

index dc06bc9..022d975 100755 (executable)
@@ -22,6 +22,7 @@ using Tizen.Applications;
 using System.ComponentModel;
 using System.Runtime.InteropServices;
 using System.Reflection;
+using System.Threading.Tasks;
 
 namespace Tizen.NUI
 {
@@ -118,28 +119,49 @@ namespace Tizen.NUI
             }
         }
 
+        private static NUIGadgetInfo Find(string resourceType)
+        {
+            if (!_gadgetInfos.TryGetValue(resourceType, out NUIGadgetInfo info))
+            {
+                throw new ArgumentException("Failed to find NUIGadgetInfo. resource type: " + resourceType);
+            }
+
+            return info;
+        }
+
         /// <summary>
-        /// Adds a NUIGadget to the NUIGadgetManager.
+        /// Loads an assembly of the NUIGadget.
         /// </summary>
         /// <param name="resourceType">The resource type of the NUIGadget package.</param>
-        /// <param name="className">The class name of the NUIGadget.</param>
-        /// <returns>The NUIGadget object.</returns>
         /// <exception cref="ArgumentException">Thrown when failed because of a invalid argument.</exception>
         /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation.</exception>
         /// <since_tizen> 10 </since_tizen>
-        public static NUIGadget Add(string resourceType, string className)
+        public static void Load(string resourceType)
         {
-            if (string.IsNullOrEmpty(resourceType) || string.IsNullOrEmpty(className))
+            if (string.IsNullOrEmpty(resourceType))
             {
                 throw new ArgumentException("Invalid argument");
             }
 
-            if (!_gadgetInfos.TryGetValue(resourceType, out NUIGadgetInfo info))
+            NUIGadgetInfo info = Find(resourceType);
+            try
             {
-                throw new ArgumentException("Failed to find NUIGadgetInfo. resource type: " + resourceType);
+                Load(info);
+            }
+            catch (FileLoadException e)
+            {
+                throw new InvalidOperationException(e.Message);
             }
+        }
 
-            try
+        private static void Load(NUIGadgetInfo info)
+        {
+            if (info == null)
+            {
+                throw new ArgumentException("Invalid argument");
+            }
+
+            lock (info)
             {
                 if (info.Assembly == null)
                 {
@@ -148,6 +170,29 @@ namespace Tizen.NUI
                     Log.Warn("NUIGadgetAssembly.Load(): " + info.ResourcePath + info.ExecutableFile + " --");
                 }
             }
+        }
+
+        /// <summary>
+        /// Adds a NUIGadget to the NUIGadgetManager.
+        /// </summary>
+        /// <param name="resourceType">The resource type of the NUIGadget package.</param>
+        /// <param name="className">The class name of the NUIGadget.</param>
+        /// <returns>The NUIGadget object.</returns>
+        /// <exception cref="ArgumentException">Thrown when failed because of a invalid argument.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation.</exception>
+        /// <since_tizen> 10 </since_tizen>
+        public static NUIGadget Add(string resourceType, string className)
+        {
+            if (string.IsNullOrEmpty(resourceType) || string.IsNullOrEmpty(className))
+            {
+                throw new ArgumentException("Invalid argument");
+            }
+
+            NUIGadgetInfo info = Find(resourceType);
+            try
+            {
+                Load(info);
+            }
             catch (FileLoadException e)
             {
                 throw new InvalidOperationException(e.Message);