Beispiel #1
0
        public string Serialize(IClaptrapIdentity identity, IStateData stateData)
        {
            var design        = _claptrapDesignStore.FindDesign(identity);
            var stateDataType = design.StateDataType;
            var re            = JsonConvert.SerializeObject(stateData, stateDataType, new JsonSerializerSettings
            {
                Formatting = Formatting.None
            });

            return(re);
        }
Beispiel #2
0
        public IEventHandler Create(IEventContext eventContext)
        {
            try
            {
                return(CreateCore());
            }
            catch (Exception e)
            {
                _logger.LogError(e, "failed to create handler for {@Context}", eventContext);
                throw;
            }

            IEventHandler CreateCore()
            {
                var eventScope         = _lifetimeScope.BeginLifetimeScope();
                var claptrapDesign     = _claptrapDesignStore.FindDesign(eventContext.State.Identity);
                var eventEventTypeCode = eventContext.Event.EventTypeCode;

                if (!claptrapDesign.EventHandlerDesigns.TryGetValue(eventEventTypeCode,
                                                                    out var handlerDesign))
                {
                    throw new EventHandlerNotFoundException(eventContext.State.Identity.TypeCode, eventEventTypeCode);
                }

                var handler = (IEventHandler)eventScope.Resolve(handlerDesign.EventHandlerType);

                return(handler);
            }
        }
        public Task <IStateData> Create(IClaptrapIdentity identity)
        {
            var design            = _claptrapDesignStore.FindDesign(identity);
            var findStateDataType = design.StateDataType;
            var stateData         = (IStateData)Activator.CreateInstance(findStateDataType);

            return(Task.FromResult(stateData));
        }
Beispiel #4
0
        public IEventData Deserialize(IClaptrapIdentity identity, string eventTypeCode, string source)
        {
            var design = _claptrapDesignStore.FindDesign(identity);

            var(_, value) = design.EventHandlerDesigns.Single(x => x.Key == eventTypeCode);
            var re = (IEventData)JsonConvert.DeserializeObject(source, value.EventDataType) !;

            return(re);
        }
        public string FindEventTypeCode <TEventDataType>(IClaptrapBox claptrapBox, TEventDataType eventDataType)
        {
            var claptrapDesign = _claptrapDesignStore.FindDesign(claptrapBox.Claptrap.State.Identity);

            var(key, _) =
                claptrapDesign.EventHandlerDesigns.SingleOrDefault(x =>
                                                                   x.Value.EventDataType == typeof(TEventDataType));
            return(key);
        }
Beispiel #6
0
        public IEnumerable <IClaptrapMasterModule> GetClaptrapMasterClaptrapModules(IClaptrapIdentity identity)
        {
            var design = _claptrapDesignStore.FindDesign(identity);

            if (design.ClaptrapOptions.EventCenterOptions.EventCenterType == EventCenterType.DaprClient)
            {
                var re = new DaprEventCenterModule();
                yield return(re);
            }
        }
Beispiel #7
0
        public ILifetimeScope BuildClaptrapLifetimeScope(IClaptrapIdentity identity)
        {
            var claptrapDesign = _claptrapDesignStore.FindDesign(identity);
            var actorScope     = _lifetimeScope.BeginLifetimeScope(builder =>
            {
                var sharedModules = _claptrapModuleProviders
                                    .SelectMany(x => x.GetClaptrapSharedModules(identity))
                                    .OfType <Module>()
                                    .ToArray();
                _logger.LogTrace("Found {count} shared modules : {modules}",
                                 sharedModules.Length,
                                 sharedModules);
                RegisterModules(sharedModules);

                var masterDesign = claptrapDesign.ClaptrapMasterDesign;
                if (masterDesign != null)
                {
                    _logger.LogTrace(_l[LK.IsMinion], masterDesign.ClaptrapTypeCode);
                    var minionModules = _claptrapModuleProviders
                                        .SelectMany(x => x.GetClaptrapMinionModules(identity))
                                        .OfType <Module>()
                                        .ToArray();
                    _logger.LogTrace("Found {count} minion modules : {modules}",
                                     minionModules.Length,
                                     minionModules);
                    RegisterModules(minionModules);
                }
                else
                {
                    _logger.LogTrace(_l[LK.This_is_a_master_claptrap__type_code____typeCode_], identity.TypeCode);
                    var masterModules = _claptrapModuleProviders
                                        .SelectMany(x => x.GetClaptrapMasterClaptrapModules(identity))
                                        .OfType <Module>()
                                        .ToArray();
                    _logger.LogTrace("Found {count} master claptrap modules : {modules}",
                                     masterModules.Length,
                                     masterModules);
                    RegisterModules(masterModules);
                }

                void RegisterModules(IEnumerable <Module> modules)
                {
                    foreach (var module in modules)
                    {
                        builder.RegisterModule(module);
                    }
                }
            });

            return(actorScope);
        }