Пример #1
0
        /// <summary>
        /// Tries to resolve tenant and artifact based on the incoming request
        /// </summary>
        /// <param name="path">The request path</param>
        /// <param name="request">The request data</param>
        /// <param name="tenant">The resolved tenant</param>
        /// <param name="artifact">The created artifact</param>
        /// <returns>Whether the resolution worked</returns>
        protected bool TryResolveTenantAndArtifact(string path, IDictionary <string, StringValues> request, out TenantId tenant, out T artifact)
        {
            if (path[0] != '/')
            {
                path = $"/{path}";
            }

            var artifactType = _artifactTypes.GetTypeFor(path);
            var properties   = new NullFreeDictionary <string, object>();

            tenant = request["TenantId"].First().ParseTo(typeof(TenantId)) as TenantId;

            foreach (var property in artifactType.GetProperties())
            {
                if (request.TryGetValue(property.Name, out var values))
                {
                    if (TryConvertFormValuesTo(property.PropertyType, values, out var result))
                    {
                        if (result.GetType().IsConcept())
                        {
                            result = result.GetConceptValue();
                        }
                        properties.Add(property.Name, result);
                    }
                }
            }

            artifact = _objectFactory.Build(artifactType, new PropertyBag(properties)) as T;

            return(artifact != null);
        }
Пример #2
0
        public IActionResult Handle([FromBody] HandleCommandRequest request)
        {
            var type    = _artifactTypeMap.GetTypeFor(request.Artifact);
            var command = _objectFactory.Build(type, request.Command) as ICommand;
            var result  = _coordinator.Handle(request.Tenant, command);

            return(Ok(result));
        }
Пример #3
0
        CommittedEvent ToCommittedEvent(CommitSequenceNumber commitSequenceNumber, EventEnvelope @event)
        {
            var eventType             = _artifactTypeMap.GetTypeFor(@event.Metadata.Artifact);
            var eventInstance         = _objectFactory.Build(eventType, @event.Event) as IEvent;
            var committedEventVersion = new CommittedEventVersion(commitSequenceNumber, @event.Metadata.VersionedEventSource.Version.Commit, @event.Metadata.VersionedEventSource.Version.Sequence);

            return(new CommittedEvent(committedEventVersion, @event.Metadata, eventInstance));
        }
Пример #4
0
        public IActionResult Execute([FromBody] ExecuteQueryRequest request)
        {
            var type    = _artifactTypeMap.GetTypeFor(request.Artifact);
            var command = _objectFactory.Build(type, request.Query) as IQuery;
            var result  = _coordinator.Execute(request.Tenant, command);

            return(Ok(result));
        }
Пример #5
0
        public ActionResult Insert([FromBody] InjectEventRequest request)
        {
            var type   = _artifactTypeMap.GetTypeFor(request.Artifact);
            var @event = _objectFactory.Build(type, request.Event) as IEvent;

            _injector.InjectEvent(
                request.Tenant,
                request.EventSource,
                @event
                );
            return(Ok());
        }
Пример #6
0
        static dynamic ConstructInstanceOfType(PropertyBag pb, Type targetType, string pbKey, IObjectFactory factory)
        {
            if (!pb.ContainsKey(pbKey))
            {
                return(null);
            }

            var value = pb[pbKey];

            if (value == null)
            {
                return(null);
            }
            if (targetType.IsDate())
            {
                return(BuildDate(value));
            }
            if (targetType.IsDateTimeOffset())
            {
                return(BuildDateTimeOffset(value));
            }
            if (targetType.IsAPrimitiveType() || targetType == typeof(PropertyBag))
            {
                return(targetType == typeof(PropertyBag)? (PropertyBag)value : value);
            }
            if (targetType.IsConcept())
            {
                return(ConceptFactory.CreateConceptInstance(targetType, value));
            }
            if (targetType.IsEnumerable())
            {
                return(targetType.ConstructEnumerable(factory, value));
            }

            return(factory.Build(targetType, value as PropertyBag));
        }