protected override void CompareChildren() { base.CompareChildren(); if (!IsNew) { var prevalues = dataTypeService.GetPreValuesCollectionByDataTypeId(Existing.Id).PreValuesAsDictionary; Comparisons.AddRange(Configuration.Prevalues.Select(kvp => CreateExistingComparison(kvp, prevalues))); } else { Comparisons.AddRange(Configuration.Prevalues.Select(kvp => new Comparison("Prevalues", kvp.Key, ComparisonResult.New))); } IsModified = Comparisons.Any(c => c.Key == "Prevalues" && (c.Result == ComparisonResult.Modified || c.Result == ComparisonResult.New)); IsUnsafe = Comparisons.Any(c => c.Key == "Prevalues" && c.Result == ComparisonResult.Modified); }
private void CompareAllowedChildren() { var extChildren = Existing.AllowedContentTypes.Select(t => t.Alias).ToArray(); var newChildren = Configuration.AllowedChildren.Except(extChildren).ToArray(); var validNewChildren = newChildren .Where(c => ServiceContext.ContentTypeService.GetContentType(c) != null) .Union(newChildren.Where(c => diffgram.DocumentTypes.ContainsKey(c))) .ToArray(); var invalidNewChildren = newChildren.Except(validNewChildren); Comparisons.AddRange(validNewChildren.Select(c => new Comparison("AllowedChildren", c, ComparisonResult.New))); Comparisons.AddRange(newChildren.Intersect(extChildren) .Select(c => new Comparison("AllowedChildren", c, ComparisonResult.Unchanged))); Comparisons.AddRange(invalidNewChildren.Select(c => new Comparison("AllowedChildren", c, ComparisonResult.Invalid))); IsModified |= Comparisons.Any(c => c.Key == "AllowedChildren" && c.Result != ComparisonResult.Unchanged); IsUnsafe |= Comparisons.Any(c => c.Key == "AllowedChildren" && c.Result == ComparisonResult.Invalid); }
// TODO: Generalize string list comparisons private void CompareCompositions() { var existingCompositions = Existing.ContentTypeComposition.Select(c => c.Alias).ToArray(); var matchingCompositions = Configuration.Compositions.Intersect(existingCompositions).ToArray(); var newCompositions = Configuration.Compositions.Except(existingCompositions).ToArray(); var validNewContentTypes = newCompositions .Select(alias => ServiceContext.ContentTypeService.GetContentType(alias)?.Alias) .Where(alias => alias != null) .Union(diffgram.DocumentTypes.Select(t => t.Key).Intersect(Configuration.Compositions)) .Distinct() .Except(matchingCompositions) .ToArray(); var invalidContentTypes = newCompositions.Except(validNewContentTypes); Comparisons.AddRange(matchingCompositions.Select(c => new Comparison("Compositions", c, ComparisonResult.Unchanged))); Comparisons.AddRange(validNewContentTypes.Select(c => new Comparison("Compositions", c, ComparisonResult.New))); Comparisons.AddRange(invalidContentTypes.Select(c => new Comparison("Compositions", c, ComparisonResult.Invalid))); IsModified |= Comparisons.Any(c => c.Key == "Compositions" && c.Result != ComparisonResult.Unchanged); IsUnsafe |= Comparisons.Any(c => c.Key == "Compositions" && c.Result == ComparisonResult.Invalid); }
private void CompareAllowedTemplates() { var existingTemplates = Existing.AllowedTemplates.Select(t => t.Alias).ToArray(); var matchingTemplates = Configuration.AllowedTemplates.Intersect(existingTemplates).ToArray(); var newTemplates = Configuration.AllowedTemplates.Except(existingTemplates).ToArray(); var validNewTemplates = newTemplates .Select(alias => ServiceContext.FileService.GetTemplate(alias)?.Alias) .Where(alias => alias != null) .Union(diffgram.Templates.Select(t => t.Key).Intersect(Configuration.AllowedTemplates)) .Distinct() // TODO: Test both configured and existing dependency, also for compositions. .Except(matchingTemplates) .ToArray(); var invalidTemplates = newTemplates.Except(validNewTemplates); Comparisons.AddRange(matchingTemplates.Select(c => new Comparison("AllowedTemplates", c, ComparisonResult.Unchanged))); Comparisons.AddRange(validNewTemplates.Select(c => new Comparison("AllowedTemplates", c, ComparisonResult.New))); Comparisons.AddRange(invalidTemplates.Select(c => new Comparison("AllowedTemplates", c, ComparisonResult.Invalid))); IsModified |= Comparisons.Any(c => c.Key == "AllowedTemplates" && c.Result != ComparisonResult.Unchanged); IsUnsafe |= Comparisons.Any(c => c.Key == "AllowedTemplates" && c.Result == ComparisonResult.Invalid); }