/// <summary>
        ///     Ctor.
        /// </summary>
        /// <param name="revisionEventTypeName">name</param>
        /// <param name="spec">specification</param>
        /// <param name="statementStopService">for stop handling</param>
        /// <param name="eventAdapterService">for nested property handling</param>
        /// <param name="eventTypeIdGenerator">The event type id generator.</param>
        public VAERevisionProcessorDeclared(
            string revisionEventTypeName,
            RevisionSpec spec,
            StatementStopService statementStopService,
            EventAdapterService eventAdapterService,
            EventTypeIdGenerator eventTypeIdGenerator)
            : base(spec, revisionEventTypeName, eventAdapterService)
        {
            // on statement stop, remove versions
            statementStopService.StatementStopped += () => _statePerKey.Clear();

            _statePerKey    = new Dictionary <object, RevisionStateDeclared>().WithNullSupport();
            _baseEventType  = spec.BaseEventType;
            _fullKeyGetters = PropertyUtility.GetGetters(_baseEventType, spec.KeyPropertyNames);

            // sort non-key properties, removing keys
            _groups = PropertyUtility.AnalyzeGroups(spec.ChangesetPropertyNames, spec.DeltaTypes, spec.DeltaNames);
            var propertyDesc = CreatePropertyDescriptors(spec, _groups);

            TypeDescriptors = PropertyUtility.GetPerType(_groups, spec.ChangesetPropertyNames, spec.KeyPropertyNames);
            var metadata = EventTypeMetadata.CreateValueAdd(revisionEventTypeName, TypeClass.REVISION);

            RevisionEventType = new RevisionEventType(metadata, eventTypeIdGenerator.GetTypeId(revisionEventTypeName),
                                                      propertyDesc, eventAdapterService);
        }
Exemple #2
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="variantSpec">specifies how to handle the disparate events</param>
        /// <param name="eventTypeIdGenerator">The event type id generator.</param>
        /// <param name="config">The config.</param>
        public VAEVariantProcessor(VariantSpec variantSpec, EventTypeIdGenerator eventTypeIdGenerator, ConfigurationVariantStream config)
        {
            VariantSpec = variantSpec;

            VariantPropResolutionStrategy strategy;

            if (variantSpec.TypeVariance == TypeVarianceEnum.ANY)
            {
                strategy = new VariantPropResolutionStrategyAny(variantSpec);
            }
            else
            {
                strategy = new VariantPropResolutionStrategyDefault(variantSpec);
            }

            EventTypeMetadata metadata = EventTypeMetadata.CreateValueAdd(variantSpec.VariantStreamName, TypeClass.VARIANT);

            VariantEventType = new VariantEventType(metadata, eventTypeIdGenerator.GetTypeId(variantSpec.VariantStreamName), variantSpec, strategy, config);
        }
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="revisioneventTypeName">name</param>
        /// <param name="spec">specification</param>
        /// <param name="statementStopService">for stop handling</param>
        /// <param name="eventAdapterService">for nested property handling</param>
        /// <param name="eventTypeIdGenerator">The event type id generator.</param>
        public VAERevisionProcessorMerge(String revisioneventTypeName, RevisionSpec spec, StatementStopService statementStopService, EventAdapterService eventAdapterService, EventTypeIdGenerator eventTypeIdGenerator)
            : base(spec, revisioneventTypeName, eventAdapterService)
        {
            // on statement stop, remove versions
            statementStopService.StatementStopped += () => _statePerKey.Clear();
            _statePerKey = new Dictionary <Object, RevisionStateMerge>();

            // For all changeset properties, add type descriptors (property number, getter etc)
            var propertyDesc = new Dictionary <String, RevisionPropertyTypeDesc>();
            var count        = 0;

            foreach (String property in spec.ChangesetPropertyNames)
            {
                var fullGetter     = spec.BaseEventType.GetGetter(property);
                var propertyNumber = count;
                var paramList      = new RevisionGetterParameters(property, propertyNumber, fullGetter, null);

                // if there are no groups (full event property only), then simply use the full event getter
                EventPropertyGetter revisionGetter = new ProxyEventPropertyGetter(
                    eventBean =>
                {
                    var riv = (RevisionEventBeanMerge)eventBean;
                    return(riv.GetVersionedValue(paramList));
                },
                    eventBean => null,
                    eventBean => true);

                var type = spec.BaseEventType.GetPropertyType(property);
                if (type == null)
                {
                    foreach (EventType deltaType in spec.DeltaTypes)
                    {
                        var dtype = deltaType.GetPropertyType(property);
                        if (dtype != null)
                        {
                            type = dtype;
                            break;
                        }
                    }
                }

                var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, paramList, type);
                propertyDesc.Put(property, propertyTypeDesc);
                count++;
            }

            count = 0;
            foreach (String property in spec.KeyPropertyNames)
            {
                var keyPropertyNumber = count;
                EventPropertyGetter revisionGetter;
                if (spec.KeyPropertyNames.Length == 1)
                {
                    revisionGetter = new ProxyEventPropertyGetter
                    {
                        ProcGet = eventBean => ((RevisionEventBeanMerge)eventBean).Key,
                        ProcIsExistsProperty = eventBean => true,
                        ProcGetFragment      = eventBean => null
                    };
                }
                else
                {
                    revisionGetter = new ProxyEventPropertyGetter
                    {
                        ProcGet = eventBean =>
                        {
                            var riv = (RevisionEventBeanMerge)eventBean;
                            return(((MultiKeyUntyped)riv.Key).Keys[keyPropertyNumber]);
                        },
                        ProcIsExistsProperty = eventBean => true,
                        ProcGetFragment      = eventBean => null
                    };
                }

                var type = spec.BaseEventType.GetPropertyType(property);
                if (type == null)
                {
                    foreach (EventType deltaType in spec.DeltaTypes)
                    {
                        var dtype = deltaType.GetPropertyType(property);
                        if (dtype != null)
                        {
                            type = dtype;
                            break;
                        }
                    }
                }
                var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, null, type);
                propertyDesc.Put(property, propertyTypeDesc);
                count++;
            }

            // compile for each event type a list of getters and indexes within the overlay
            foreach (EventType deltaType in spec.DeltaTypes)
            {
                RevisionTypeDesc typeDesc = MakeTypeDesc(deltaType, spec.PropertyRevision);
                TypeDescriptors.Put(deltaType, typeDesc);
            }
            _infoFullType = MakeTypeDesc(spec.BaseEventType, spec.PropertyRevision);

            // how to handle updates to a full event
            if (spec.PropertyRevision == PropertyRevisionEnum.MERGE_DECLARED)
            {
                _updateStrategy = new UpdateStrategyDeclared(spec);
            }
            else if (spec.PropertyRevision == PropertyRevisionEnum.MERGE_NON_NULL)
            {
                _updateStrategy = new UpdateStrategyNonNull(spec);
            }
            else if (spec.PropertyRevision == PropertyRevisionEnum.MERGE_EXISTS)
            {
                _updateStrategy = new UpdateStrategyExists(spec);
            }
            else
            {
                throw new ArgumentException("Unknown revision type '" + spec.PropertyRevision + "'");
            }

            EventTypeMetadata metadata = EventTypeMetadata.CreateValueAdd(revisioneventTypeName, TypeClass.REVISION);

            RevisionEventType = new RevisionEventType(metadata, eventTypeIdGenerator.GetTypeId(revisioneventTypeName), propertyDesc, eventAdapterService);
        }