private object?BuildState(WidgetDescription description) { if (description.Variant?.StateType == null) { return(null); } object?state; (bool stateCanBeStored, string stateKey) = WidgetDescription.BuildKey(description); if (stateCanBeStored && (state = stateStore.Get(stateKey)) != null) { logger.Trace($"The state with key [{stateKey}] has been restored."); return(state); } state = provider.GetRequiredService(description.Variant.StateType); if (stateCanBeStored) { logger.Trace($"The state with key [{stateKey}] has been stored."); stateStore.Add(stateKey, state); } return(state); }
private IWidgetPresenter?BuildPresenter(WidgetDescription description) { if (description.Variant?.PresenterType == null) { return(null); } return((IWidgetPresenter)provider.GetRequiredService(description.Variant.PresenterType)); }
private void SetState(WidgetDescription description, IWidgetMediatorBuildContract contract) { object?state = BuildState(description); if (state != null) { contract.SetState(state); } }
private void SetCustomisation(WidgetDescription description, IWidgetMediatorBuildContract contract) { object?customisation = GetCustomisation(description); if (customisation != null) { contract.SetCustomisation(customisation); } }
public WidgetInfo Start(WidgetDescription description) { WidgetInfo info = Build(description); if (!string.IsNullOrEmpty(description.Position)) { ActivateMediator(info.Mediator, description.Position); } return(info); }
public WidgetInfo Build(WidgetDescription description) { CheckAndTryUpdateDescription(description); object mediator = BuildMediator(description); Guid id = widgetStore.GetNewGuid(); widgetStore.Add(id, mediator); logger.Trace($"Widget {id:B} [{WidgetDescription.BuildKey(description).key}] has been created."); return(new WidgetInfo(id, mediator)); }
private void TryFillMediatorContract(object mediator, WidgetDescription description) { if (!(mediator is IWidgetMediatorBuildContract contract)) { return; } contract.SetLogger(logger); SetCustomisation(description, contract); SetState(description, contract); SetPresenter(mediator, contract, description); }
private object?GetCustomisation(WidgetDescription description) { if (description.Variant?.Customisation == null) { return(description.Customisation); } object customisation = description.Variant.Customisation; if (Customisation.IsMergable(description.Customisation)) { Customisation.Merge(customisation, description.Customisation, customisation.GetType()); } return(customisation); }
private object BuildMediator(WidgetDescription description) { if (description.Variant == null) { throw new ArgumentException("No widget variant has been specified.", nameof(description)); } Type mediatorType = description.Variant.MediatorType; object mediator = provider.GetRequiredService(mediatorType); TryFillMediatorContract(mediator, description); TryInitialise(mediator); if (mediator == null) { logger.Error($"No mediator for a widget of type [{description.Variant.MediatorType.Name}]."); } return(mediator); }
public WidgetInfo Build(WidgetDescription description) { throw CreateException(nameof(IWidgetFactory)); }
public WidgetInfo Build(WidgetDescription description) { return(factory.Build(description)); }
private void SetPresenter(object mediator, IWidgetMediatorBuildContract contract, WidgetDescription description) { IWidgetPresenter?presenter = BuildPresenter(description); if (presenter == null) { if (mediator is IWidgetPresenterProvider presenterProvider) { // TODO: solve this in more elegant way presenter = presenterProvider.Presenter; } else { logger.Warning($"No presenter for a widget of type [{description.Variant?.MediatorType.Name}]."); return; } } TryFillPresenterContract(presenter); TryInitialise(presenter); contract.SetPresenter(presenter); }