示例#1
0
        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);
        }
示例#2
0
        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));
        }