From: hjhun <36876573+hjhun@users.noreply.github.com> Date: Tue, 8 Aug 2023 04:47:40 +0000 (+0900) Subject: [NUI.Gadget] Add a new method to load assembly (#5455) X-Git-Tag: accepted/tizen/unified/20231205.024657~218 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2f9ae07630480699551754103e9f6e2fd4359868;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI.Gadget] Add a new method to load assembly (#5455) The Load() method is added to load the assembly of the NUIGadget. Signed-off-by: Hwankyu Jhun --- diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs index dc06bc9..022d975 100755 --- a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs +++ b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs @@ -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; + } + /// - /// Adds a NUIGadget to the NUIGadgetManager. + /// Loads an assembly of the NUIGadget. /// /// The resource type of the NUIGadget package. - /// The class name of the NUIGadget. - /// The NUIGadget object. /// Thrown when failed because of a invalid argument. /// Thrown when failed because of an invalid operation. /// 10 - 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 + " --"); } } + } + + /// + /// Adds a NUIGadget to the NUIGadgetManager. + /// + /// The resource type of the NUIGadget package. + /// The class name of the NUIGadget. + /// The NUIGadget object. + /// Thrown when failed because of a invalid argument. + /// Thrown when failed because of an invalid operation. + /// 10 + 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);