/* * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Reflection; using System.Runtime.Loader; using System.IO; using System.Collections.Generic; namespace Tizen.Init { class TypeLoader { // key : assembly name, value : list of types static IDictionary> assem_type = new Dictionary> { {"ElmSharp", new List(){ "ElmSharp.Box", "ElmSharp.Button", "ElmSharp.Check", "ElmSharp.Color", "ElmSharp.Conformant", "ElmSharp.DateTimeSelector", "ElmSharp.DisplayRotation", "ElmSharp.EdjeObject", "ElmSharp.EdjeObject+SignalData", "ElmSharp.EdjeTextPartObject", "ElmSharp.Elementary", "ElmSharp.Entry", "ElmSharp.EvasKeyEventArgs", "ElmSharp.EvasMap", "ElmSharp.EvasObject", "ElmSharp.FocusDirection", "ElmSharp.GenList", "ElmSharp.GestureLayer+GestureType", "ElmSharp.IInvalidatable", "ElmSharp.Image", "ElmSharp.ItemObject+SignalData", "ElmSharp.Label", "ElmSharp.Layout", "ElmSharp.Naviframe", "ElmSharp.NaviItem", "ElmSharp.Point3D", "ElmSharp.ProgressBar", "ElmSharp.Radio", "ElmSharp.Rect", "ElmSharp.Rectangle", "ElmSharp.Scroller", "ElmSharp.Size", "ElmSharp.Slider", "ElmSharp.Spinner", "ElmSharp.Widget", "ElmSharp.Window", "ElmSharp.WrapType", "Interop"}}, {"ElmSharp.Wearable", new List(){ "ElmSharp.Wearable.CircleDateTimeSelector", "ElmSharp.Wearable.CircleGenList", "ElmSharp.Wearable.CircleScroller", "ElmSharp.Wearable.CircleSpinner", "ElmSharp.Wearable.ICircleWidget", "ElmSharp.Wearable.IRotaryActionWidget", "Interop"}}, {"System.IO.FileSystem", new List(){ "Interop", "", "System.IO.File"}}, {"System.Security.Cryptography.Algorithms", new List(){ "Interop", "System.Security.Cryptography.MD5"}}, {"System.Collections", new List(){ "", "System.Collections.Generic.HashSet`1", "System.Collections.Generic.Queue`1"}}, {"System.Private.Uri", new List(){ "", "System.Uri"}}, {"System.Private.Xml", new List(){ "", "System.Xml.IXmlLineInfo", "System.Xml.IXmlNamespaceResolver"}}, {"System.Runtime", new List(){ "System.Collections.Generic.ISet`1", "System.Reflection.RuntimeReflectionExtensions"}}, {"System.ObjectModel", new List(){ "System.Collections.ObjectModel.ObservableCollection`1", "System.Collections.Specialized.INotifyCollectionChanged", "System.Collections.Specialized.NotifyCollectionChangedAction", "System.Collections.Specialized.NotifyCollectionChangedEventArgs", "System.Collections.Specialized.NotifyCollectionChangedEventHandler", "System.ComponentModel.INotifyPropertyChanged", "System.ComponentModel.PropertyChangedEventArgs", "System.ComponentModel.PropertyChangedEventHandler", "System.Windows.Input.ICommand"}}, {"System.ComponentModel", new List(){ "System.IServiceProvider"}}, {"System.Linq", new List(){ "System.Linq.Enumerable", "System.Linq.EnumerableSorter`1", "System.Linq.IIListProvider`1", "System.Linq.IOrderedEnumerable`1", "System.Linq.IPartition`1", "System.Linq.OrderedEnumerable`1"}}, {"System.Linq.Expressions", new List(){ "System.Linq.Expressions.ExpressionVisitor"}}, {"System.Security.Cryptography.Primitives", new List(){ "System.Security.Cryptography.HashAlgorithm"}}, {"Tizen.Applications.Common", new List(){ "Interop", "Tizen.Applications.Application", "Tizen.Applications.CoreApplication", "Tizen.Applications.CoreBackend.EventType", "Tizen.Applications.TizenSynchronizationContext"}}, {"Tizen.Applications.UI", new List(){ "Tizen.Applications.CoreUIApplication", "Interop"}}, {"Tizen", new List(){ "Interop"}}, {"Tizen.Log", new List(){ "Interop", "Tizen.Log"}}, {"Tizen.System.Information", new List(){ "Tizen.System.Information"}} }; static void PreloadEnd() { assem_type = null; GC.Collect(); GC.WaitForPendingFinalizers(); } static void PreloadTypes() { foreach (KeyValuePair> item in assem_type) { Assembly asm = LoadAssembly(item.Key); if (asm != null) { foreach (string t in item.Value) { LoadType(asm, t); } } } PreloadLibICU(); PreloadEnd(); } static Assembly LoadAssembly(string name) { var context = AssemblyLoadContext.Default; Assembly ret = null; try { ret = context.LoadFromAssemblyName(new AssemblyName(name)); } catch (Exception e) { Console.WriteLine(e.ToString()); return null; } return ret; } static void LoadType(Assembly assem, string typeName) { try { var tp = assem.GetType(typeName); } catch { Console.WriteLine("Tizen.Init.TypeLoader.PreloadTypes can't load type " + typeName + " from assembly " + assem.ToString()); } } // CU loading makes launching time much slower. // To prevent that kind of overhead, preload ICU by calling String.ToLower() static void PreloadLibICU() { // to preinitialize icu, do string compare if ("A".ToLower() != "a") { Console.WriteLine("Failed to String.ToLower()"); } } } }