/// <summary> /// Runs the grpc and kestrel host. /// </summary> /// <param name="startKestrelHost">The startKestrelHost<see cref="bool"/></param> /// <param name="startGrpcHost">The startGrpcHost<see cref="bool"/></param> /// <param name="customAssemblyPath">The customAssemblyPath<see cref="string"/></param> public static void Run(bool startKestrelHost = true, bool startGrpcHost = true, string customAssemblyPath = null) { try { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; //Locate cloud assembly and call register method on clound instance CloudLocator.Locate(customAssemblyPath); // Get cloud instance -> Decission is made dependinig on the assembly inside the bin folder RunningCloud = CloudLocator.GetCloud(); // Get config IConfig config = CloudLocator.GetConfig(); if (config == null) { throw new Exception("No config registered"); } // grpc host if (startGrpcHost) { StartGrpcHost(); } // kestrel host if (startKestrelHost) { // Get the cloud address KestrelEndpoint = RunningCloud.GetCloudAddress(config); // start kestrel host var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup <Startup>() .UseApplicationInsights() .UseUrls(string.Format("http://{0}:{1}", KestrelEndpoint.Address.MapToIPv4(), config.PortApi)) .Build(); host.Run(); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
/// <summary> /// Starts the GRPC host. /// </summary> public static void StartGrpcHost() { IConfig config = CloudLocator.GetConfig(); // start grpc host try { // Logging Logger.Initialize(config.SrcDeviceId); CommonBaseHandler.OnLog = (sender, msg, level) => { Logger.Log(sender, msg, level); }; // Run Cloud new Task(async() => { await RunningCloud.Start(config); }).Start(); } catch (Exception ex) { Logger.Log("CLOUD", ex.Message, NLog.LogLevel.Error); } }