/// <inheritdoc /> public override async Task Start(IConfig config) { // config ConfigHelper c = config as ConfigHelper; // database BaseContext.Setup <UserContext>(); await CheckUser(c.BrokerUser, c.BrokerPass, c.Secret); await CheckUser(c.AuthServiceUser, c.AuthServicePass, c.Secret); // get endpoint for local grpc host IPEndPoint grpcEndPoint = new IPEndPoint(IPAddress.Any, config.PortGrpc);//GetCloudAddress(config); // get endpoint which will be repoted to the network IPHostEntry entry = Dns.GetHostEntry(Dns.GetHostName()); var host = entry.AddressList.LastOrDefault(p => p.AddressFamily == AddressFamily.InterNetwork); var upnpEndpoint = new IPEndPoint(host, CloudLocator.GetConfig().PortGrpc); // Start the server grpc endpoints CommonBaseHandler.Log(this.ToString(), "GRPC IP ADRESS: " + upnpEndpoint, NLog.LogLevel.Info); StartGrpcServer(grpcEndPoint, config.SrcDeviceId); // accept client connections (this.ActionWorker as ActionWorker).ReadyForConnections = true; Console.WriteLine("Auth server started -> ready for connections."); }
/// <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(); } }
/// <inheritdoc /> public override void Register() { CloudLocator.GetCloud = (() => { return(this); }); CloudLocator.GetConfig = (() => { return(new ConfigHelper()); }); // config var config = CloudLocator.GetConfig() as ConfigHelper; // Workers to handle messages (commands /fetch / messages) this.ActionWorker = new ActionWorker(config.SrcDeviceId, config.Secret); this.FetchWorker = new FetchWorker(config.SrcDeviceId, config.Secret); }
/// <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); } }
/// <inheritdoc /> public override void Register() { CloudLocator.GetCloud = (() => { return(this); }); CloudLocator.GetConfig = (() => { return(new ConfigHelper()); }); //config var config = CloudLocator.GetConfig() as ConfigHelper; // init the connection to the authentication server var tokenObserver = new TokenObserver(config.AuthServerAddress, config.SrcDeviceId); tokenObserver.Init(config.SrcDeviceId, config.BrokerPassword, config.Secret).Await(30); // Workers to handle messages (commands /fetch / messages) this.ActionWorker = new ActionWorker(config.SrcDeviceId, tokenObserver); }