Beispiel #1
0
        internal RootManager(WorkspaceSuperviser superviser, IStateDispatcherConfigurator stateDispatcher, IEnumerable <StateBuilderBase> states,
                             IEnumerable <IEffect?> effects, IEnumerable <IMiddleware?> middlewares, bool sendBackSetting, Maybe <IComponentContext> componentContext)
        {
            _sendBackSetting = sendBackSetting;
            _engine          = MutatingEngine.Create(superviser, stateDispatcher.Configurate);
            _effects         = effects.Where(e => e != null).ToArray() !;
            _middlewares     = middlewares.Where(m => m != null).ToArray() !;

            foreach (var stateBuilder in states)
            {
                var(container, key) = stateBuilder.Materialize(_engine, componentContext);

                _stateContainers.GetOrAdd(key.OrElse(string.Empty), _ => new ConcurrentBag <StateContainer>()).Add(container);
            }

            _states = _stateContainers.SelectMany(b => b.Value).ToArray();

            foreach (var middleware in _middlewares)
            {
                middleware.Initialize(this);
            }

            foreach (var middleware in _middlewares)
            {
                middleware.AfterInitializeAllMiddlewares();
            }
        }
        public ProjectMutator(MutatingEngine <MutatingContext <ProjectFile> > engine, ProjectFileWorkspace workspace)
        {
            _engine    = engine;
            _workspace = workspace;

            NewProject = engine.EventSource(mc => new AddProject(mc.GetChange <NewProjectChange>().Project),
                                            context => context.Change is NewProjectChange);
            RemovedProject = engine.EventSource(mc => new RemoveProject(mc.GetChange <RemoveProjectChange>().Project),
                                                context => context.Change is RemoveProjectChange);
            NewLanguage = engine.EventSource(mc => mc.GetChange <LanguageChange>().ToEventData(),
                                             context => context.Change is LanguageChange);
            NewImport = engine.EventSource(mc => mc.GetChange <AddImportChange>().ToEventData(),
                                           context => context.Change is AddImportChange);
            RemoveImport = engine.EventSource(mc => mc.GetChange <RemoveImportChange>().ToData(),
                                              context => context.Change is RemoveImportChange);

            NewLanguage.RespondOn(null, newLang =>
            {
                if (workspace.ProjectFile.GlobalLanguages.Contains(newLang.ActiveLanguage))
                {
                    return;
                }

                if (!Projects.All(p => p.ActiveLanguages.Contains(newLang.ActiveLanguage)))
                {
                    return;
                }

                _engine.Mutate(nameof(AddLanguage) + "Global-Single",
                               obs => obs.Select(context => context.Update(new GlobalLanguageChange(newLang.ActiveLanguage),
                                                                           context.Data with
                {
                    GlobalLanguages = context.Data.GlobalLanguages.Add(newLang.ActiveLanguage)
                })));
            });
Beispiel #3
0
 public BuildMutator(MutatingEngine <MutatingContext <ProjectFile> > engine)
 {
     _engine   = engine;
     Intigrate = engine.EventSource(mc => mc.GetChange <IntigrateImportChange>().ToEvent(),
                                    mc => mc.Change is IntigrateImportChange);
     ProjectPath = engine.EventSource(mc => mc.GetChange <ProjectPathChange>().ToEventData(),
                                      context => context.Change is ProjectPathChange);
 }
Beispiel #4
0
 public SourceMutator(MutatingEngine <MutatingContext <ProjectFile> > engine, ProjectFileWorkspace workspace)
 {
     _engine      = engine;
     _workspace   = workspace;
     SaveRequest  = engine.EventSource(mc => new SaveRequest(_workspace.ProjectFile), context => !(context.Change is ResetChange));
     ProjectReset = engine.EventSource(mc => new ProjectRest(_workspace.ProjectFile), context => context.Change is ResetChange);
     SourceUpdate = engine.EventSource(mc => new SourceUpdated(mc.Data.Source), context => context.Change is SourceChange);
 }
Beispiel #5
0
 public ResultInvoker(EffectInvoker effectInvoker, MutatingEngine mutatingEngine, IActorRef sender, bool sendBack, IStateAction action)
 {
     _effectInvoker  = effectInvoker;
     _mutatingEngine = mutatingEngine;
     _sender         = sender;
     _sendBack       = sendBack;
     _action         = action;
 }
Beispiel #6
0
        public EntryMutator(MutatingEngine <MutatingContext <ProjectFile> > engine)
        {
            _engine = engine;

            EntryRemove = engine.EventSource(context => new EntryRemove(context.GetChange <RemoveEntryChange>().Entry),
                                             context => context.Change is RemoveEntryChange);
            EntryUpdate = engine.EventSource(context => new EntryUpdate(context.GetChange <EntryChange>().Entry),
                                             context => context.Change is EntryChange);
            EntryAdd = engine.EventSource(context => context.GetChange <NewEntryChange>().ToData(),
                                          context => context.Change is NewEntryChange);
        }
        public EntryMutator(MutatingEngine <MutatingContext <ProjectFile> > engine)
        {
            _engine = engine;

            EntryRemove = engine.EventSource(c => c.Select(cc => new EntryRemove(cc.GetChange <RemoveEntryChange>().Entry)),
                                             c => from constext in c
                                             from change in constext.Change
                                             select change is RemoveEntryChange);

            EntryUpdate = engine.EventSource(c => c.Select(cc => new EntryUpdate(cc.GetChange <EntryChange>().Entry)),
                                             c => from context in c
                                             from change in context.Change
                                             select change is EntryChange);

            EntryAdd = engine.EventSource(c => c.Select(cc => cc.GetChange <NewEntryChange>().ToData()),
                                          c => from context in c
                                          from change in context.Change
                                          select change is NewEntryChange);
        }
Beispiel #8
0
        public ProjectMutator(MutatingEngine <MutatingContext <ProjectFile> > engine, ProjectFileWorkspace workspace)
        {
            _engine    = engine;
            _workspace = workspace;

            NewProject = engine.EventSource(
                c => c.Select(mc => new AddProject(mc.GetChange <NewProjectChange>().Project)),
                c => from context in c
                from change in context.Change
                select change is NewProjectChange);

            RemovedProject = engine.EventSource(c => c.Select(mc => new RemoveProject(mc.GetChange <RemoveProjectChange>().Project)),
                                                c => from context in c
                                                from change in context.Change
                                                select change is RemoveProjectChange);

            NewLanguage = engine.EventSource(c => c.Select(mc => mc.GetChange <LanguageChange>().ToEventData()),
                                             c => from context in c
                                             from change in context.Change
                                             select change is LanguageChange);

            NewImport = engine.EventSource(c => c.Select(mc => mc.GetChange <AddImportChange>().ToEventData()),
                                           c => from context in c
                                           from change in context.Change
                                           select change is AddImportChange);

            RemoveImport = engine.EventSource(c => c.Select(mc => mc.GetChange <RemoveImportChange>().ToData()),
                                              c => from context in c
                                              from change in context.Change
                                              select change is RemoveImportChange);

            NewLanguage.RespondOn(null, mayNewLang =>
                                  Do(from newlang in mayNewLang
                                     where !workspace.ProjectFile.GlobalLanguages.Contains(newlang.ActiveLanguage)
                                     where Projects.All(p => p.ActiveLanguages.Contains(newlang.ActiveLanguage))
                                     select Action(() => _engine.Mutate(nameof(AddLanguage) + "Global-Single",
                                                                        c => from context in c
                                                                        select context.WithChange(new GlobalLanguageChange(newlang.ActiveLanguage))))));
        }
 public static ExtendedMutatingEngine <TData> From <TData>(IExtendedDataSource <TData> source, MutatingEngine parent)
     where TData : class
 => new(parent._mutator, source, parent.Superviser);
 protected WorkspaceBase(WorkspaceSuperviser superviser)
 {
     Engine = MutatingEngine.From(this, superviser);
 }
Beispiel #11
0
 public abstract (StateContainer State, Maybe <string> Key) Materialize(MutatingEngine engine, Maybe <IComponentContext> mayComponentContext);