Exemplo n.º 1
0
        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 ConfigImpl()
        {
            CurrentState.Hosts.DisposeWith(this);

            HostApi.CreateOrGet(Context.System)
            .Event <HostEntryChanged>()
            .DisposeWith(this);

            (from evt in CurrentState.EventPublisher
             where evt is ServerConfigurationEvent
             from state in UpdateAndSyncActor((ServerConfigurationEvent)evt)
             select state.State with {
                ServerConfigugration = state.Event.Configugration
            })
        public ApplicationsViewModel(ILifetimeScope lifetimeScope, Dispatcher dispatcher)
            : base(lifetimeScope, dispatcher)
        {
            var modelView = LifetimeScope.Resolve <IViewModel <ApplicationManagerTabViewModel> >();

            modelView.InitModel(Context, "Application_Manager");

            Items = this.RegisterUiCollection <TabItem>(nameof(Items))
                    .AndInitialElements(new TabItem(LocLocalizer.Inst.ApplicationsView.GlobalManagerHeader, modelView))
                    .AndAsync();

            CurrentTab = RegisterProperty <int>(nameof(CurrentTab));

            var hostApi = HostApi.CreateOrGet(Context.System);

            AddResource(hostApi.Event <HostEntryChanged>());

            Receive <HostEntryChanged>(e =>
            {
        //TODO Refactor for StateManager

        public SetupBuilderViewModel(ILifetimeScope lifetimeScope, Dispatcher dispatcher, AppConfig config, DeploymentServices deploymentServices, IActionInvoker actionInvoker)
            : base(lifetimeScope, dispatcher, actionInvoker)
        {
            _config        = config;
            _server        = new SetupServer(s => UICall(() => TerminalLines !.Add(s)), Context.System.Settings.Config);
            _deploymentApi = DeploymentApi.CreateProxy(Context.System, "SetupBuilder_DeploymentApi");
            _repositoryApi = RepositoryApi.CreateProxy(Context.System, "SetupBuilder_RepositoryApi");

            AddShortcut   = RegisterProperty <bool>(nameof(AddShortcut));
            CurrentError  = RegisterProperty <string>(nameof(CurrentError));
            AddSeed       = RegisterProperty <bool>(nameof(AddSeed));
            TerminalLines = this.RegisterUiCollection <string>(nameof(TerminalLines)).AndAsync();

            var hostEntrys = new HashSet <string>();

            _api = HostApi.CreateOrGet(Context.System);
            Receive <HostEntryChanged>(e =>
            {
                if (string.IsNullOrWhiteSpace(e.Name))
                {
                    return;
                }

                if (e.Removed)
                {
                    hostEntrys.Remove(e.Name);
                }
                else
                {
                    hostEntrys.Add(e.Name);
                }
            });

            Func <string, string?> HostNameValidator(Func <UIProperty <string> > counterPart)
            {
                return(s =>
                {
                    if (string.IsNullOrWhiteSpace(s))
                    {
                        return LocLocalizer.Inst.SetupBuilderView.ErrorEmptyHostName;
                    }
                    return hostEntrys.Contains(s) || s == counterPart().Value ? LocLocalizer.Inst.SetupBuilderView.ErrorDuplicateHostName : null;
                });
            }

            HostName = RegisterProperty <string>(nameof(HostName))
                       .WithValidator(SetError(HostNameValidator(() => SeedHostName !)))
                       .OnChange(s => SeedHostName += s + "_Seed");

            SeedHostName = RegisterProperty <string>(nameof(SeedHostName))
                           .WithValidator(SetError(HostNameValidator(() => HostName)));

            NewCommad
            .WithCanExecute(b =>
                            b.And(
                                deploymentServices.IsReadyQuery(b),
                                b.FromProperty(_buildRunning, i => i == 0),
                                b.FromProperty(HostName.IsValid),
                                b.Or(
                                    b.FromProperty(AddSeed, s => !s),
                                    b.FromProperty(SeedHostName.IsValid))))
            .WithExecute(ExecuteBuild)
            .ThenRegister("CreateSeupCommand");
        }
 public static IPreparedFeature New(string name, IObservable <IConfigEvent> publisher, ServerConfigugration serverConfigugration, IRepository <SeedUrlEntity, string> seeds)
 => Feature.Create(() => new HostMonitor(), c => new State(name, publisher, serverConfigugration, ImmutableList <HostApp> .Empty,
                                                           HostApi.CreateOrGet(c.System), seeds));
 public record State(string Name, IObservable <IConfigEvent> Publisher, ServerConfigugration ServerConfigugration, ImmutableList <HostApp> Apps, HostApi Api,
                     IRepository <SeedUrlEntity, string> Seeds);