public RunnablesViewModel Map(SubWorkspaceVm workspace)
        {
            foreach (var r in Map(workspace))
            {
                Items.Add(r);
            }
            return(this);

            IEnumerable <RunnableVm> Map(SubWorkspaceVm w)
            {
                IEnumerable <RunnableVm> DeDupe(IEnumerable <RunnableVm> rs) => rs.GroupBy(r => r.DisplayName).Select(x => x.First());

                return(DeDupe(w.Runnables).Concat(w.Imports.Any() ? DeDupe(w.Imports.SelectMany(Map)) : Enumerable.Empty <RunnableVm>()));
            }
        }
 public WorkspaceViewModel(SolutionStateMachine solutionMachine,
                           WorkspaceStateMachine workspaceMachine,
                           Action <string> writeLog,
                           ISender <IRingCommand> commandSender)
 {
     _writeLog        = writeLog;
     _commandSender   = commandSender;
     _runnables       = new RunnablesViewModel(writeLog);
     _solutionMachine = solutionMachine;
     _workspaceFsm    = workspaceMachine;
     _root            = new SubWorkspaceVm(commandSender, writeLog, new WorkspaceInfo("", new RunnableInfo[0], ServerState.IDLE, WorkspaceState.IDLE));
     Status           = new WorkspaceStatusVm();
     Status.None();
     IsSyncButtonEnabled = true;
     IsOpenButtonEnabled = false;
     FilePathVisibility  = Visibility.Collapsed;
     Configure(_workspaceFsm);
 }
Пример #3
0
        public SubWorkspaceVm MapWorkspace(WorkspaceInfo config)
        {
            ModelRef = config;
            return(MapWorkspace(this, config));

            SubWorkspaceVm MapWorkspace(SubWorkspaceVm parent, WorkspaceInfo cfg)
            {
                var w = new SubWorkspaceVm(_sender, _writeLog, cfg)
                {
                    Parent = parent
                };

                MapRunnables(w, cfg);
                return(w);

                void MapRunnables(SubWorkspaceVm p, WorkspaceInfo c)
                {
                    var runnables = c.Runnables;

                    if (!runnables.Any())
                    {
                        return;
                    }

                    foreach (var r in runnables.Select(r => MapRunnable(p, r)))
                    {
                        p.Runnables.Add(r);
                    }
                }

                RunnableVm MapRunnable(SubWorkspaceVm p, RunnableInfo c)
                => new RunnableVm(_sender, _writeLog, c)
                {
                    Parent = p
                };
            }
        }