private void SetParentNodeType(TContentType[] contentTypes)
        {
            Func <TModel, bool> hasParent = model => model.ParentNodeType != null;

            foreach (var model in Models.Where(hasParent))
            {
                var contentType = _contentTypeFinder.Find(model, contentTypes).SingleOrDefault() as IContentTypeComposition;

                if (contentType == null)
                {
                    continue;
                }

                var parentContentType = _contentTypeFinder.Find(model.ParentNodeType, Models, contentTypes).SingleOrDefault() as IContentTypeComposition;

                if (parentContentType == null)
                {
                    continue;
                }

                var aliases = contentType.CompositionAliases().ToArray();

                // Inheritance and composition cannot be mixed. Remove all compositions.
                foreach (var alias in aliases)
                {
                    contentType.RemoveContentType(alias);
                }

                contentType.ParentId = parentContentType.Id;
                contentType.AddContentType(parentContentType);

                SaveContentType((TContentType)contentType);
            }
        }
Exemple #2
0
        private void Synchronize(TModel model, TContentType[] contentTypes)
        {
            var contentType = _contentTypeFinder.Find(model, contentTypes).SingleOrDefault();

            contentType = contentType == null
                ? CreateContentType(model)
                : UpdateContentType(contentType, model);

            SynchronizePropertyTypes(model, contentType);

            SaveContentType(contentType);

            // We get the content type once more to refresh it after saving it.
            contentType = GetContentTypes().SingleOrDefault(ct => ct.Alias.Equals(contentType.Alias, StringComparison.InvariantCultureIgnoreCase));

            // Set/update tracking.
            SetContentTypeId(model, contentType);
            SetPropertyTypeId(model, contentType);
        }