public IpcConnection(bool masterExists, IpcApplicationType type, Action <string, Exception> errorHandler) { try { switch (type) { case IpcApplicationType.Server: if (masterExists) { IsReady = false; ErrorMessage = "Duplicate Server Start"; return; } _dataServer = new SharmServer(IpcName, errorHandler); _dataServer.OnMessageReceived += (_, args) => _messageHandler.OnNext(args.Message); break; case IpcApplicationType.Client: if (!masterExists) { IsReady = false; ErrorMessage = "No Server Found"; return; } _dataClient = new SharmClient(IpcName, errorHandler); _dataClient.OnMessageReceived += (_, args) => _messageHandler.OnNext(args.Message); break; case IpcApplicationType.NoIpc: IsReady = false; ErrorMessage = "Ipc Disabled"; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } } catch (Exception e) { ErrorMessage = e.Message; IsReady = false; } }
public static IHostBuilder StartNode(this IHostBuilder builder, KillRecpientType type, IpcApplicationType ipcType, Action <IActorApplicationBuilder>?build = null, bool consoleLog = false) { var masterReady = false; if (ipcType != IpcApplicationType.NoIpc) { masterReady = SharmComunicator.MasterIpcReady(IpcName); } var ipc = new IpcConnection(masterReady, ipcType, (s, exception) => LogManager.GetCurrentClassLogger().Error(exception, "Ipc Error: {Info}", s)); return(builder.ConfigureLogging((context, configuration) => { System.Console.Title = context.HostingEnvironment.ApplicationName; if (consoleLog) { configuration.AddConsole(); } }) .ConfigurateNode(ab => { ab.ConfigureAutoFac(cb => { cb.RegisterType <NodeAppService>().As <IHostedService>(); cb.RegisterType <KillHelper>().As <IStartUpAction>(); cb.RegisterInstance(ipc).As <IIpcConnection>(); }) .ConfigureAkkaSystem((_, system) => { switch (type) { case KillRecpientType.Seed: KillSwitch.Setup(system); break; default: KillSwitch.Subscribe(system, type); break; } }); build?.Invoke(ab); })); }
public static IHostBuilder StartNode(string[] args, KillRecpientType type, IpcApplicationType ipcType, Action <IActorApplicationBuilder>?build = null, bool consoleLog = false) => StartNode(Host.CreateDefaultBuilder(args), type, ipcType, build, consoleLog);