Exemplo n.º 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);
        }
Exemplo n.º 2
0
        IDictionary <string, PathItem> GeneratePaths()
        {
            var paths = new Dictionary <string, PathItem>();

            foreach (var path in _artifactMapper.ApiPaths)
            {
                var tags = new List <string> {
                    { path.Split('/')[1] }
                };
                var pathItem = new PathItem();
                if (_isPost)
                {
                    pathItem.Post = GenerateOperation(_artifactMapper.GetTypeFor(path), tags);
                }
                else
                {
                    pathItem.Get = GenerateOperation(_artifactMapper.GetTypeFor(path), tags);
                }
                paths.Add(path, pathItem);
            }
            return(paths);
        }