///<inheritdoc/> public App() { this.startupProfiler = new Profiler("Startup", ProfilerThreadType.Sequential); // Comment out to remove startup profiling. this.startupProfiler?.Start(); this.startupProfiler?.NewState("Init"); AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; InitializeComponent(); try { this.startupProfiler?.NewState("Types"); Assembly appAssembly = this.GetType().Assembly; if (!Types.IsInitialized) { // Define the scope and reach of Runtime.Inventory (Script, Serialization, Persistence, IoC, etc.): Types.Initialize( appAssembly, // Allows for objects defined in this assembly, to be instantiated and persisted. typeof(Database).Assembly, // Indexes default attributes typeof(ObjectSerializer).Assembly, // Indexes general serializers typeof(FilesProvider).Assembly, // Indexes special serializers typeof(RuntimeSettings).Assembly, // Allows for persistence of settings in the object database typeof(InternetContent).Assembly, // Common Content-Types typeof(XML).Assembly, // XML Content-Type typeof(MarkdownDocument).Assembly, // Markdown support typeof(XmppClient).Assembly, // Serialization of general XMPP objects typeof(ContractsClient).Assembly, // Serialization of XMPP objects related to digital identities and smart contracts typeof(ProvisioningClient).Assembly, // Serialization of XMPP objects related to thing registries, provisioning and decision support. typeof(SensorClient).Assembly, // Serialization of XMPP objects related to sensors typeof(ControlClient).Assembly, // Serialization of XMPP objects related to actuators typeof(ConcentratorClient).Assembly, // Serialization of XMPP objects related to concentrators typeof(Expression).Assembly, // Indexes basic script functions typeof(XmppServerlessMessaging).Assembly, // Indexes End-to-End encryption mechanisms typeof(TagConfiguration).Assembly, // Indexes persistable objects typeof(RegistrationStep).Assembly); // Indexes persistable objects } this.startupProfiler?.NewState("SDK"); // Create Services this.sdk = TagIdSdk.Create(appAssembly, this.startupProfiler, new XmppConfiguration().ToArray()); this.imageCacheService = new ImageCacheService(this.sdk.SettingsService, this.sdk.LogService); this.sdk.RegisterSingleton <IImageCacheService, ImageCacheService>(this.imageCacheService); this.contractOrchestratorService = new ContractOrchestratorService(this.sdk.TagProfile, this.sdk.UiDispatcher, this.sdk.NeuronService, this.sdk.NavigationService, this.sdk.LogService, this.sdk.NetworkService, this.sdk.SettingsService); this.sdk.RegisterSingleton <IContractOrchestratorService, ContractOrchestratorService>(this.contractOrchestratorService); this.thingRegistryOrchestratorService = new ThingRegistryOrchestratorService(this.sdk.TagProfile, this.sdk.UiDispatcher, this.sdk.NeuronService, this.sdk.NavigationService, this.sdk.LogService, this.sdk.NetworkService); this.sdk.RegisterSingleton <IThingRegistryOrchestratorService, ThingRegistryOrchestratorService>(this.thingRegistryOrchestratorService); // Set resolver DependencyResolver.ResolveUsing(type => { object obj = this.sdk.Resolve(type); if (!(obj is null)) { return(obj); } if (Types.GetType(type.FullName) is null) { return(null); // Type not managed by Runtime.Inventory. Xamarin.Forms resolves this using its default mechanism. } return(Types.Instantiate(true, type)); }); // Get the db started right away to save startup time. this.sdk.StorageService.Init(this.startupProfiler?.CreateThread("Database", ProfilerThreadType.Sequential)); // Register log listener (optional) this.sdk.LogService.AddListener(new AppCenterEventSink(this.sdk.LogService)); } catch (Exception e) { e = Waher.Events.Log.UnnestException(e); this.startupProfiler?.Exception(e); DisplayBootstrapErrorPage(e.Message, e.StackTrace); return; } // Start page try { this.startupProfiler?.NewState("MainPage"); this.MainPage = new AppShell(); } catch (Exception e) { e = Waher.Events.Log.UnnestException(e); this.startupProfiler?.Exception(e); this.sdk.LogService.SaveExceptionDump("StartPage", e.ToString()); } this.startupProfiler?.MainThread.Idle(); }
/// <summary> /// Creates an instance of the <see cref="ITagIdSdk"/>. This is a factory method. /// </summary> /// <param name="appAssembly">The assembly containing the main App class.</param> /// <param name="startupProfiler">Optional Startup profiler. May be null.</param> /// <param name="domains">Featured domains.</param> /// <returns>Tag ID SDK instance reference.</returns> public static ITagIdSdk Create(Assembly appAssembly, Profiler startupProfiler, params DomainModel[] domains) { return(_instance ?? (_instance = new TagIdSdk(appAssembly, startupProfiler, domains))); }