Exemplo n.º 1
0
        public IEnumerable <ContentTypeResponseItem> GetAll()
        {
            var result = new List <ContentTypeResponseItem>();

            foreach (var contentType in ContentTypeProvider.GetAll())
            {
                result.Add(GetItem(contentType));
            }

            return(result.AsReadOnly());
        }
        public IEnumerable <ContentTypeDescriptor> GetContentTypesFor(string contentTypeGroupId)
        {
            var result = new List <ContentTypeDescriptor>();

            var contentTypeGroup = ContentTypeGroupProvider.Get(contentTypeGroupId);

            foreach (var contentType in ContentTypeProvider.GetAll())
            {
                if (contentTypeGroup.Type.IsAssignableFrom(contentType.Type))
                {
                    result.Add(contentType);
                }
            }

            return(result.AsReadOnly());
        }
Exemplo n.º 3
0
        public IEnumerable <T> GetChildren <T>(string id, string language) where T : class
        {
            var contentTypes = ContentTypeProvider.GetAll().Where(t => typeof(T).IsAssignableFrom(t.Type));

            var documents = DocumentFinder.Find(ContainerConstants.Content).WhereEquals <IHierarchical, string>(x => x.ParentId, id).WhereIn <IContent, string>(x => x.ContentTypeId, contentTypes.Select(t => t.Id)).GetResultAsync().Result.ToList();

            var result = new List <T>();

            foreach (var document in documents)
            {
                var contentTypeId = document.GlobalFacet.Interfaces["IContent"].Properties["ContentTypeId"] as string;

                result.Add((T)ContentDeserializer.Deserialize(document, ContentTypeProvider.Get(contentTypeId), language));
            }

            return(result.AsReadOnly());
        }
        public async Task InitializeAsync()
        {
            var containers = ContentTypeProvider.GetAll().Select(t => t.Container).Distinct();

            foreach (var container in containers)
            {
                var reference = $"cloudy{container}";
                var name      = $"{reference}.cloudy-cms.net";
                var body      = new
                {
                    apiVersion = "apiextensions.k8s.io/v1beta1",
                    metadata   = new { name },
                    spec       = new
                    {
                        group = "cloudy-cms.net",
                        names = new
                        {
                            kind     = reference,
                            plural   = reference,
                            singular = reference
                        },
                        scope    = "Namespaced",
                        versions = new[] { new { name = "v1", served = true, storage = true } }
                    }
                };

                if ((await Client.Http.GetAsync($"apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/{name}", HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false)).StatusCode == HttpStatusCode.OK)
                {
                    continue;
                }

                if (Logger.IsEnabled(LogLevel.Information))
                {
                    Logger.LogInformation($"Sending to Kubernetes:\n\n{JsonConvert.SerializeObject(body)}");
                }

                var response = await Client.Http.PostAsync("apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions", new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json")).ConfigureAwait(false);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception($"{(int)response.StatusCode} {response.ReasonPhrase}: {await response.Content.ReadAsStringAsync().ConfigureAwait(false)}");
                }
            }
        }
Exemplo n.º 5
0
        public IEnumerable <ContentTypeResponseItem> GetContentTypes()
        {
            var result = new List <ContentTypeResponseItem>();

            foreach (var contentType in ContentTypeProvider.GetAll())
            {
                var    name = contentType.Type.GetCustomAttribute <DisplayAttribute>()?.Name ?? contentType.Type.Name;
                string pluralName;

                if (name.Contains(':') && !contentType.Id.Contains(':'))
                {
                    var nameSplit = name.Split(':');

                    name       = nameSplit.First();
                    pluralName = nameSplit.Last();
                }
                else
                {
                    name       = Humanizer.Humanize(name);
                    pluralName = Pluralizer.Pluralize(name);
                }

                var singleton = SingletonProvider.Get(contentType.Id);

                result.Add(new ContentTypeResponseItem
                {
                    Id                       = contentType.Id,
                    Name                     = name,
                    PluralName               = pluralName,
                    IsNameable               = typeof(INameable).IsAssignableFrom(contentType.Type),
                    NameablePropertyName     = typeof(INameable).IsAssignableFrom(contentType.Type) ? CamelCaseNamingStrategy.GetPropertyName(NameExpressionParser.Parse(contentType.Type), false) : null,
                    IsRoutable               = typeof(IRoutable).IsAssignableFrom(contentType.Type),
                    IsSingleton              = singleton != null,
                    Count                    = -1,
                    ContentTypeActionModules = ContentTypeActionModuleProvider.GetContentTypeActionModulesFor(contentType.Id),
                    ListActionModules        = ListActionModuleProvider.GetListActionModulesFor(contentType.Id),
                });
            }

            return(result.AsReadOnly());
        }
Exemplo n.º 6
0
        public IEnumerable <string> FindFor(Type type)
        {
            var result = new List <string>();

            foreach (var contentType in ContentTypeProvider.GetAll())
            {
                if (type.IsAssignableFrom(contentType.Type))
                {
                    throw new CannotInlineContentTypesException(type, contentType);
                }
            }

            foreach (var form in FormProvider.GetAll())
            {
                if (type.IsAssignableFrom(form.Type))
                {
                    result.Add(form.Id);
                }
            }

            return(result.AsReadOnly());
        }
Exemplo n.º 7
0
        public IEnumerable <Option> GetAll()
        {
            var contentTypes = ContentTypeProvider.GetAll().Where(t => typeof(IHierarchical).IsAssignableFrom(t.Type));

            var result = new List <Option>();

            foreach (var contentType in contentTypes)
            {
                var documents = ContentFinder.Find(contentType.Type).GetResultAsync().Result.ToList();

                foreach (var content in documents)
                {
                    var id = "{" + string.Join(",", PrimaryKeyGetter.Get(content)) + "}";
                    result.Add(new Option((content as INameable).Name ?? id, id));
                }
            }

            result = result.OrderBy(i => i.Value).ToList();

            result.Insert(0, new Option("(root)", null));

            return(result.AsReadOnly());
        }
Exemplo n.º 8
0
        public IEnumerable <Option> GetAll()
        {
            var contentTypes = ContentTypeProvider.GetAll().Where(t => typeof(IHierarchical).IsAssignableFrom(t.Type));

            var result = new List <Option>();

            foreach (var contentType in contentTypes)
            {
                var documents = DocumentFinder.Find(contentType.Container).WhereEquals <IContent, string>(x => x.ContentTypeId, contentType.Id).GetResultAsync().Result.ToList();

                foreach (var document in documents)
                {
                    var content = ContentDeserializer.Deserialize(document, contentType, DocumentLanguageConstants.Global);

                    result.Add(new Option((content as INameable).Name ?? content.Id, content.Id));
                }
            }

            result = result.OrderBy(i => i.Value).ToList();

            result.Insert(0, new Option("(root)", null));

            return(result.AsReadOnly());
        }
Exemplo n.º 9
0
        public IEnumerable <ContentRouteDescriptor> Create()
        {
            var endpointDataSource = EndpointDataSource as CompositeEndpointDataSource;

            if (endpointDataSource == null)
            {
                return(Enumerable.Empty <ContentRouteDescriptor>());
            }

            var result = new Dictionary <string, ContentRouteDescriptor>();

            foreach (var dataSource in endpointDataSource.DataSources)
            {
                foreach (var endpoint in dataSource.Endpoints)
                {
                    var routeEndpoint = endpoint as RouteEndpoint;

                    if (routeEndpoint == null)
                    {
                        continue;
                    }

                    if (result.ContainsKey(routeEndpoint.RoutePattern.RawText))
                    {
                        continue;
                    }

                    if (routeEndpoint.RoutePattern.PathSegments.Any(s => s.Parts.Count == 0 || s.Parts.Count > 1 || !s.IsSimple)) // ignore complex segments (combining several parts between slashes)
                    {
                        continue;
                    }

                    if (routeEndpoint.RoutePattern.Parameters.OfType <RoutePatternParameterPart>().SelectMany(s => s.ParameterPolicies).Count(p => p.Content == "contentroute" || p.Content.StartsWith("contentroute(")) != 1) // ignore non-content routes AND multi-content routes
                    {
                        continue;
                    }

                    if (routeEndpoint.RoutePattern.Parameters.OfType <RoutePatternParameterPart>().Any(s => s.ParameterPolicies.Any(p => p.Content != "contentroute" && !p.Content.StartsWith("contentroute(")))) // ignore routes with non-content parameters
                    {
                        continue;
                    }

                    IEnumerable <ContentTypeDescriptor> contentTypes = null;

                    var path = new List <string>();

                    foreach (var segment in routeEndpoint.RoutePattern.PathSegments)
                    {
                        var part = segment.Parts.Single();

                        var literal = part as RoutePatternLiteralPart;
                        if (literal != null)
                        {
                            path.Add(literal.Content);
                        }

                        var parameter = part as RoutePatternParameterPart;
                        if (parameter != null)
                        {
                            var content = parameter.ParameterPolicies[0].Content;

                            var startParenthesisIndex = content.IndexOf('(');
                            var endParenthesisIndex   = content.IndexOf(')');
                            var name = startParenthesisIndex == -1 ? content : content.Substring(0, startParenthesisIndex);

                            var contentTypeOrGroupIdOrTypeName = startParenthesisIndex == -1 ? null : content.Substring(startParenthesisIndex + 1, endParenthesisIndex - (startParenthesisIndex + 1));

                            if (contentTypeOrGroupIdOrTypeName != null)
                            {
                                contentTypes = ContentTypeExpander.Expand(contentTypeOrGroupIdOrTypeName).ToList().AsReadOnly();
                            }

                            path.Add($"{{{name}}}");
                        }
                    }

                    if (contentTypes == null)
                    {
                        contentTypes = ContentTypeProvider.GetAll().ToList().AsReadOnly();
                    }

                    result[routeEndpoint.RoutePattern.RawText] = new ContentRouteDescriptor(string.Join("/", path), contentTypes);
                }
            }

            return(result.Values.ToList().AsReadOnly());
        }