public HostViewModel(ILifetimeScope lifetimeScope, Dispatcher dispatcher, LocLocalizer localizer) : base(lifetimeScope, dispatcher) { var eventSystem = Context.System.EventStream; var showApps = new SimpleCommand(o => { if (o != null) { eventSystem.Publish(new DisplayApplications((string)o)); } }); HostApi hostConnector = HostApi.CreateOrGet(Context.System); var commandExecutor = Context.ActorOf(Props.Create <CommandExutor>(), "HostCommand-Executor"); HostEntries = this.RegisterUiCollection <UIHostEntry>(nameof(HostEntries)).AndAsync(); Flow <HostEntryChanged>(b => { b.Action(he => { var entry = HostEntries.FirstOrDefault(e => e.ActorPath == he.Path); if (he.Removed) { if (entry == null) { return; } Log.Info("Removing Host Entry {Name}", entry.Name); HostEntries.Remove(entry); } else { if (entry == null) { Log.Info("Addinf Host Entry {Path}", he.Path); HostEntries.Add(new UIHostEntry(he.Path, he.Name, showApps, localizer, hostConnector, commandExecutor, InvalidateRequerySuggested, this, hostConnector)); } else { Log.Info("Changing Host Name {Name} {Path}", he.Name, he.Path); entry.Name = he.Name; } } }); }); AddResource(hostConnector.Event <HostEntryChanged>()); }
protected override void PreStart() { _subscribtion = _api.Event <HostEntryChanged>(); base.PreStart(); }