예제 #1
0
        /// <summary>
        /// Creates a visualization of the <paramref name="payload"/>.
        /// </summary>
        /// <param name="payload">An event payload to visualize.</param>
        /// <returns>A visualization of the <paramref name="payload"/>.</returns>
        public ObjectVisualization Create(IEvent payload)
        {
            Ensure.NotNull(payload, "payload");
            IModelDefinition payloadDefinition;

            if (!modelDefinitionProvider.TryGet(payload.GetType(), out payloadDefinition))
            {
                Debug.Fail(String.Format("Can't find a model definition for event '{0}'.", payload.GetType()));
                return(null);
            }

            IModelValueGetter            paylodValueGetter = modelValueGetterFactory.Create(payload);
            DictionaryModelValueProvider stringValueGetter = new DictionaryModelValueProvider();

            foreach (IFieldDefinition fieldDefinition in payloadDefinition.Fields)
            {
                object fieldValue;
                if (paylodValueGetter.TryGetValue(fieldDefinition.Identifier, out fieldValue))
                {
                    object rawValue;
                    if (converters.TryConvert(fieldDefinition.FieldType, typeof(string), fieldValue, out rawValue))
                    {
                        stringValueGetter.TrySetValue(fieldDefinition.Identifier, rawValue);
                    }
                    else
                    {
                        stringValueGetter.TrySetValue(fieldDefinition.Identifier, fieldValue);
                    }
                }
            }

            ObjectVisualization model = new ObjectVisualization(payloadDefinition, stringValueGetter, new KeyValueCollection());

            return(model);
        }
예제 #2
0
        /// <summary>
        /// Creates a visualization of the <paramref name="envelope"/>.
        /// </summary>
        /// <param name="envelope">An event envelope to visualize.</param>
        /// <returns>A visualization of the <paramref name="envelope"/>.</returns>
        public ObjectVisualization Create(Envelope <IEvent> envelope)
        {
            Ensure.NotNull(envelope, "envelope");

            ObjectVisualization result = Create(envelope.Body);

            if (result == null)
            {
                return(null);
            }

            return(new ObjectVisualization(
                       result.Definition,
                       result.Getter,
                       envelope.Metadata
                       ));
        }
예제 #3
0
        private AggregateRootVisualization Create(IKey aggregateKey, IEnumerable <EventModel> entities)
        {
            List <ObjectVisualization> models = new List <ObjectVisualization>();

            foreach (EventModel entity in entities.OrderBy(e => e.Version))
            {
                object source             = eventDeserializer.Deserialize(Type.GetType(entity.EventKey.Type), entity.Payload);
                ObjectVisualization model = null;
                IEvent payload            = source as IEvent;
                if (payload == null)
                {
                    Envelope <IEvent> envelope = source as Envelope <IEvent>;
                    if (envelope == null)
                    {
                        Debug.Fail("Event is not an event.");
                    }

                    model = Create(envelope);
                }
                else
                {
                    model = Create(payload);
                }

                if (model == null)
                {
                    continue;
                }

                models.Add(model);
            }

            Type             aggregateRootType = Type.GetType(aggregateKey.Type);
            IModelDefinition aggregateRootDefinition;

            if (modelDefinitionProvider.TryGet(aggregateRootType, out aggregateRootDefinition))
            {
                return(new AggregateRootVisualization(aggregateKey, aggregateRootDefinition, models));
            }

            Debug.Fail(String.Format("Can't find a model definition for event '{0}'.", aggregateRootType));
            return(null);
        }