2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.ComponentModel;
20 using Tizen.Applications;
21 using Tizen.Applications.ComponentBased.Common;
26 /// The class for supporting multi-components application model.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class NUIComponentApplication : CoreApplication
31 private Dictionary<Type, ComponentStateManger> componentFactories = new Dictionary<Type, ComponentStateManger>();
34 /// Initializes the ComponentApplication class.
36 /// <param name="typeInfo">The component type information.
37 /// The key should be a class type of FrameComponent or SubComponent subclass.
38 /// The value should be a component id which is declared in tizen-manifest.xml.
40 [EditorBrowsable(EditorBrowsableState.Never)]
41 public NUIComponentApplication(IDictionary<Type, string> typeInfo) : base(new NUIComponentCoreBackend())
45 foreach (var component in typeInfo)
47 RegisterComponent(component.Key, component.Value);
50 (Backend as NUIComponentCoreBackend).ComponentFactories = componentFactories;
54 /// Registers a component.
56 /// <param name="compType">Class type</param>
57 /// <param name="compId">Component ID</param>
58 /// <exception cref="ArgumentException">Thrown when component type is already added or not sub-class of FrameComponent or ServiceComponent</exception>
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public void RegisterComponent(Type compType, string compId)
62 if (componentFactories.ContainsKey(compType))
64 throw new ArgumentException("Already exist type");
67 if (typeof(FrameComponent).IsAssignableFrom(compType))
69 componentFactories.Add(compType, new FrameComponentStateManager(compType, compId, null));
71 else if (typeof(ServiceComponent).IsAssignableFrom(compType))
73 componentFactories.Add(compType, new ServiceComponentStateManager(compType, compId, null));
77 throw new ArgumentException("compType must be sub type of FrameComponent or ServiceComponent", nameof(compType));
82 /// Runs the application's main loop.
84 /// <param name="args">Arguments from commandline.</param>
85 /// <exception cref="InvalidOperationException">Thrown when component type is already added to the component.</exception>
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public override void Run(string[] args)
94 /// Exits the main loop of the application.
96 [EditorBrowsable(EditorBrowsableState.Never)]
97 public override void Exit()
103 /// This method will be called before running main-loop
105 [EditorBrowsable(EditorBrowsableState.Never)]
106 protected override void OnCreate()
112 /// This method will be called after exiting main-loop
114 [EditorBrowsable(EditorBrowsableState.Never)]
115 protected override void OnTerminate()