public void YamlContentItemTest() { var projectItem = Project.ProjectItems.FirstOrDefault(i => i.QualifiedName == "/sitecore/content/Yaml/Home"); Assert.IsNotNull(projectItem); Assert.AreEqual("Home", projectItem.ShortName); Assert.AreEqual("/sitecore/content/Yaml/Home", projectItem.QualifiedName); var item = projectItem as Item; Assert.IsNotNull(item); Assert.AreEqual("Home", item.ItemName); Assert.AreEqual("/sitecore/content/Yaml/Home", item.ItemIdOrPath); Assert.AreEqual("Sample Item", item.TemplateIdOrPath); Assert.AreNotEqual(item.ItemNameProperty.SourceTextNode, TextNode.Empty); Assert.IsInstanceOfType(item.TemplateIdOrPathProperty.SourceTextNode, typeof(AttributeNameTextNode)); Assert.AreEqual("Sample Item", TraceHelper.GetTextNode(item.TemplateIdOrPathProperty).Value); var field = item.Fields.FirstOrDefault(f => f.FieldName == "Text"); Assert.IsNotNull(field); Assert.AreEqual("Welcome to Sitecore", field.Value); Assert.IsInstanceOfType(field.ValueProperty.SourceTextNode, typeof(TextNode)); Assert.AreEqual("Welcome to Sitecore", field.ValueProperty.SourceTextNode.Value); Assert.AreEqual("Text", field.ValueProperty.SourceTextNode.Key); var textDocument = projectItem.Snapshot as ITextSnapshot; Assert.IsNotNull(textDocument); var treeNode = textDocument.Root; Assert.AreEqual("Sample Item", treeNode.Key); Assert.AreEqual(2, treeNode.Attributes.Count()); }
public override string Compile(IFieldCompileContext context, Field field) { var qualifiedName = field.Value.Trim(); if (string.IsNullOrEmpty(qualifiedName)) { return(string.Empty); } if (qualifiedName == "<link />" || qualifiedName == "<link/>") { return(string.Empty); } var item = field.Item.Project.Indexes.FindQualifiedItem <IProjectItem>(qualifiedName); if (item == null) { item = field.Item.Project.Files.FirstOrDefault(f => string.Equals(f.FilePath, qualifiedName, StringComparison.OrdinalIgnoreCase)); } if (item == null) { Trace.TraceError(Msg.C1049, Texts.Link_field_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), qualifiedName); return(string.Empty); } return($"<link text=\"\" linktype=\"internal\" url=\"\" anchor=\"\" title=\"\" class=\"\" target=\"\" querystring=\"\" id=\"{item.Uri.Guid.Format()}\" />"); }
public void SerializedItemTest() { var projectItem = Project.ProjectItems.FirstOrDefault(i => i.QualifiedName == "/sitecore/content/Home/SerializedItem"); Assert.IsNotNull(projectItem); Assert.AreEqual("SerializedItem", projectItem.ShortName); Assert.AreEqual("/sitecore/content/Home/SerializedItem", projectItem.QualifiedName); var item = projectItem as Item; Assert.IsNotNull(item); Assert.AreEqual("SerializedItem", item.ItemName); Assert.AreEqual("/sitecore/content/Home/SerializedItem", item.ItemIdOrPath); Assert.AreEqual("{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", item.TemplateIdOrPath); Assert.AreNotEqual(item.ItemNameProperty.SourceTextNode, TextNode.Empty); Assert.IsInstanceOfType(item.ItemNameProperty.SourceTextNode, typeof(TextNode)); Assert.IsInstanceOfType(item.TemplateIdOrPathProperty.SourceTextNode, typeof(TextNode)); Assert.AreEqual("{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", TraceHelper.GetTextNode(item.TemplateIdOrPathProperty).Value); var field = item.Fields.FirstOrDefault(f => f.FieldName == "Text"); Assert.IsNotNull(field); Assert.AreEqual("Pip 2", field.Value); Assert.IsInstanceOfType(field.ValueProperty.SourceTextNode, typeof(TextNode)); Assert.AreEqual("Pip 2", field.ValueProperty.SourceTextNode?.Value); var textDocument = projectItem.Snapshot as ITextSnapshot; Assert.IsNotNull(textDocument); }
protected override void Process(TemplateParserPipeline pipeline) { var layoutFileTextNode = pipeline.TextNode.GetAttribute(LayoutFileItemParser.LayoutFile); if (layoutFileTextNode == null || string.IsNullOrEmpty(layoutFileTextNode.Value)) { return; } var template = pipeline.Template; var standardValuesItem = template.StandardValuesItem; if (standardValuesItem == null) { return; } var layoutFileProperty = ((ISourcePropertyBag)standardValuesItem).GetSourceProperty <string>(LayoutFileItemParser.LayoutFile) ?? ((ISourcePropertyBag)standardValuesItem).NewSourceProperty(LayoutFileItemParser.LayoutFile, string.Empty); layoutFileProperty.SetValue(layoutFileTextNode); var fieldValue = layoutFileProperty.GetValue(); if (!fieldValue.StartsWith("~/")) { Trace.TraceWarning(Msg.P1016, Texts.File_path_must_start_with____, TraceHelper.GetTextNode(layoutFileProperty), fieldValue); } }
public override string Compile(IFieldCompileContext context, Field field) { var qualifiedName = field.Value.Trim(); if (string.IsNullOrEmpty(qualifiedName)) { return(string.Empty); } if (qualifiedName == "<image />" || qualifiedName == "<image/>") { return(string.Empty); } var item = field.Item.Project.Indexes.FindQualifiedItem <IProjectItem>(qualifiedName); if (item == null) { var mediaFile = field.Item.Project.Files.FirstOrDefault(f => string.Equals(f.FilePath, qualifiedName, StringComparison.OrdinalIgnoreCase)) as MediaFile; if (mediaFile != null) { item = field.Item.Project.Indexes.FindQualifiedItem <Item>(mediaFile.MediaItemUri); } } if (item == null) { Trace.TraceError(Msg.C1044, Texts.Image_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), qualifiedName); return(string.Empty); } return($"<image mediapath=\"\" alt=\"\" width=\"\" height=\"\" hspace=\"\" vspace=\"\" showineditor=\"\" usethumbnail=\"\" src=\"\" mediaid=\"{item.Uri.Guid.Format()}\" />"); }
public IEnumerable <IDiagnostic> DateTimeCannotBeParsed([NotNull] ICheckerContext context) { DateTime dateTime; return(from field in context.Project.Items.SelectMany(i => i.Fields).Where(f => string.Equals(f.TemplateField.Type, "Datetime", StringComparison.OrdinalIgnoreCase)) where !string.IsNullOrEmpty(field.Value) && field.Value != "00010101T000000" && field.Value.FromIsoToDateTime() == DateTime.MinValue where !DateTime.TryParse(field.Value, context.Culture, DateTimeStyles.None, out dateTime) select Warning(context, Msg.C1058, "Datetime cannot be parsed", TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field), $"The field \"{field.FieldName}\" has a type of 'Datetime', but the value is not a valid date. Replace or remove the value.")); }
public override bool CanCompile(IFieldCompileContext context, Field field) { var textNode = TraceHelper.GetTextNode(field.ValueProperty); if (!(textNode is JsonTextNode)) { return(false); } return(string.Equals(field.TemplateField.Type, "layout", StringComparison.OrdinalIgnoreCase)); }
public override bool CanCompile(IFieldCompileContext context, Field field) { // avoid being called by Json var textNode = TraceHelper.GetTextNode(field.ValueProperty); if (!(textNode is XmlTextNode)) { return(false); } return(string.Equals(field.TemplateField.Type, "layout", StringComparison.OrdinalIgnoreCase) || field.FieldName == "__Renderings" || field.FieldName == "Final __Renderings"); }
public IEnumerable <IDiagnostic> GuidClash([NotNull] ICheckerContext context) { var items = context.Project.ProjectItems.ToArray(); for (var i = 0; i < items.Length; i++) { var projectItem1 = items[i]; var item1 = projectItem1 as DatabaseProjectItem; if (item1 != null && item1.IsImport) { continue; } for (var j = i + 1; j < items.Length; j++) { var projectItem2 = items[j]; var item2 = items[j] as DatabaseProjectItem; if (item2 != null && item2.IsImport) { continue; } if (projectItem1.Uri.Guid != projectItem2.Uri.Guid) { continue; } if (item1 != null && item2 != null && !string.Equals(item1.DatabaseName, item2.DatabaseName, StringComparison.OrdinalIgnoreCase)) { continue; } // todo: not good if (item1 is Item && item2 is Template) { continue; } if (item1 is Template && item2 is Item) { continue; } yield return(Error(context, Msg.C1001, Texts.Unique_ID_clash, TraceHelper.GetTextNode(item2, item1), PathHelper.UnmapPath(context.Project.ProjectDirectory, projectItem2.Snapshot.SourceFile.AbsoluteFileName))); } } }
public IEnumerable <IReference> ParseReferences(Field field) { var databaseName = field.DatabaseName; var value = field.Value; // todo: templates may not be loaded at this point // look for database name if (field.TemplateField.Source.IndexOf("database", StringComparison.OrdinalIgnoreCase) >= 0) { var parameters = new UrlString(field.TemplateField.Source); databaseName = parameters["databasename"] ?? string.Empty; if (string.IsNullOrEmpty(databaseName)) { databaseName = parameters["database"] ?? string.Empty; } } // check for fields that contains paths var pathFields = Configuration.GetArray(Constants.Configuration.CheckProject.PathFields); if (pathFields.Contains(field.FieldId.Format())) { var sourceProperty = field.ValueProperty; if (sourceProperty.SourceTextNode == TextNode.Empty) { sourceProperty = field.FieldNameProperty; } var referenceText = PathHelper.NormalizeItemPath(value); if (!referenceText.StartsWith("~/")) { referenceText = "~/" + referenceText.TrimStart('/'); } yield return(Factory.FileReference(field.Item, sourceProperty, referenceText)); yield break; } var database = field.Item.Project.GetDatabase(databaseName); var textNode = TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field); foreach (var reference in ParseReferences(field.Item, textNode, field.Value, database)) { yield return(reference); } }
public IEnumerable <IDiagnostic> NumberIsNotValid([NotNull] ICheckerContext context) { foreach (var field in context.Project.Items.SelectMany(i => i.Fields).Where(f => string.Equals(f.TemplateField.Type, "Number", StringComparison.OrdinalIgnoreCase))) { if (string.IsNullOrEmpty(field.Value)) { continue; } int value; if (!int.TryParse(field.Value, out value)) { yield return(Warning(context, Msg.C1057, "Number is not valid", TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field), $"The field \"{field.FieldName}\" has a type of 'Number', but the value is not a valid number. Replace or remove the value.")); } } }
private string CompileInlineValue([NotNull] Field field, [NotNull] string value) { var start = value.IndexOf("/sitecore", StringComparison.OrdinalIgnoreCase); var end = value.IndexOf(',', start); if (end < 0) { end = value.IndexOf('|', start); } if (end < 0) { end = value.IndexOf('&', start); } if (end < 0) { end = value.IndexOf(';', start); } if (end < 0) { end = value.Length; } var qualifiedName = value.Mid(start, end - start); if (!PathHelper.IsProbablyItemPath(value)) { return(value); } if (ReferenceParser.IsIgnoredReference(value)) { return(value); } var item = field.Item.Project.Indexes.FindQualifiedItem <IProjectItem>(qualifiedName); if (item == null) { Trace.TraceError(Msg.C1045, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field), value); return(value); } return(value.Left(start) + item.Uri.Guid.Format() + value.Mid(end)); }
public override string Compile(IFieldCompileContext context, Field field) { var value = field.Value.Trim(); if (string.IsNullOrEmpty(value)) { return(string.Empty); } var item = field.Item.Project.Indexes.FindQualifiedItem <IProjectItem>(value); if (item == null) { Trace.TraceError(Msg.C1045, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field), value); return(value); } return(item.Uri.Guid.Format()); }
public override string Compile(IFieldCompileContext context, Field field) { var textNode = TraceHelper.GetTextNode(field.ValueProperty); if (textNode == TextNode.Empty) { return(field.Value); } var textSnapshot = textNode.Snapshot as ITextSnapshot; if (textSnapshot == null) { return(field.Value); } var layoutCompileContext = Factory.LayoutCompileContext(field.Item.Project, field.Database, textSnapshot); var layoutCompiler = Factory.LayoutCompiler(); return(layoutCompiler.Compile(layoutCompileContext, textNode)); }
public override void Compile(ICompileContext context, IProjectItem projectItem, SourceProperty <string> property) { var item = projectItem as Item; Assert.Cast(item, nameof(item)); var value = property.GetValue().Trim(); if (string.IsNullOrEmpty(value)) { return; } var renderings = item.Project.Indexes.GetByFileName <Rendering>(value).Where(r => r.Database == item.Database).ToList(); if (!renderings.Any()) { Trace.TraceError(Msg.C1060, Texts.Rendering_reference_not_found, TraceHelper.GetTextNode(property), value); return; } if (renderings.Count > 1) { Trace.TraceError(Msg.C1062, Texts.Ambiguous_file_name, TraceHelper.GetTextNode(property), value); return; } var rendering = renderings.First(); var renderingItemUri = rendering.RenderingItemUri; if (renderingItemUri == ProjectItemUri.Empty) { RetryCompilation(projectItem); return; } CreateLayout(context, item, renderingItemUri.Guid); }
private string CompileDirectLink([NotNull] Field field, [NotNull] string value) { if (!PathHelper.IsProbablyItemPath(value)) { return(value); } if (ReferenceParser.IsIgnoredReference(value)) { return(value); } var item = field.Item.Project.Indexes.FindQualifiedItem <IProjectItem>(value); if (item == null) { Trace.TraceError(Msg.C1045, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field), value); return(value); } return(item.Uri.Guid.Format()); }
public override void Compile(ICompileContext context, IProjectItem projectItem) { var sourcePropertyBag = projectItem as ISourcePropertyBag; Assert.Cast(sourcePropertyBag, nameof(sourcePropertyBag)); var property = sourcePropertyBag.GetSourceProperty <string>(LayoutFileItemParser.LayoutFile); if (property == null) { return; } var compiled = false; foreach (var layoutFileCompiler in LayoutFileCompilers) { if (!layoutFileCompiler.CanCompile(context, projectItem, property)) { continue; } layoutFileCompiler.Compile(context, projectItem, property); compiled = true; break; } if (!compiled) { Trace.TraceError(Msg.C1063, Texts.Element_has_a__Layout_File__attribute__but_it_could_not_be_compiled, TraceHelper.GetTextNode(property), property.GetValue()); } }
public override void Compile(ICompileContext context, IProjectItem projectItem) { var item = projectItem as Item; Assert.Cast(item, nameof(item)); var standardTemplate = item.Database.FindQualifiedItem <Template>(Constants.Templates.StandardTemplateId); if (standardTemplate == null) { Trace.TraceWarning(Msg.C1135, "Standard Template not found - are you missing a reference?"); return; } var standardFields = standardTemplate.GetAllFields().ToArray(); var templateIdOrPathTextNode = item.GetTextNodes().Select(n => n.GetAttribute("Template")).FirstOrDefault(t => t != null); if (templateIdOrPathTextNode == null) { Trace.TraceError(Msg.C1051, Texts.The__Template__attribute_must_be_specified_when__Template_CreateFromFields__equals_true_, TraceHelper.GetTextNode(item)); } var itemTextNode = item.SourceTextNode; var itemIdOrPath = item.TemplateIdOrPath; var itemName = itemIdOrPath.Mid(itemIdOrPath.LastIndexOf('/') + 1); var guid = StringHelper.GetGuid(item.Project, itemTextNode.GetAttributeValue("Template.Id", itemIdOrPath)); var template = Factory.Template(item.Database, guid, itemName, itemIdOrPath).With(itemTextNode); template.ItemNameProperty.AddSourceTextNode(templateIdOrPathTextNode); template.ItemNameProperty.Flags = SourcePropertyFlags.IsQualified; template.IconProperty.Parse("Template.Icon", itemTextNode); template.BaseTemplatesProperty.Parse("Template.BaseTemplates", itemTextNode, Constants.Templates.StandardTemplateId); template.ShortHelpProperty.Parse("Template.ShortHelp", itemTextNode); template.LongHelpProperty.Parse("Template.LongHelp", itemTextNode); template.IsEmittable = item.IsEmittable; template.IsImport = item.IsImport || string.Equals(itemTextNode.GetAttributeValue(Constants.Fields.IsImport), "True", StringComparison.OrdinalIgnoreCase); if (!template.IsImport) { template.References.AddRange(ReferenceParser.ParseReferences(template, template.BaseTemplatesProperty)); } if (item.Fields.Any()) { var templateSectionGuid = StringHelper.GetGuid(projectItem.Project, template.ItemIdOrPath + "/Fields"); // section var templateSection = Factory.TemplateSection(template, templateSectionGuid); template.Sections.Add(templateSection); templateSection.SectionNameProperty.SetValue("Fields"); templateSection.IconProperty.SetValue("Applications/16x16/form_blue.png"); // fields var nextSortOrder = 0; foreach (var field in item.Fields) { var childNode = field.SourceTextNode; // ignore standard fields if (standardFields.Any(f => string.Equals(f.FieldName, field.FieldName, StringComparison.OrdinalIgnoreCase))) { continue; } var templateField = template.Sections.SelectMany(s => s.Fields).FirstOrDefault(f => f.FieldName == field.FieldName); if (templateField == null) { var templateFieldGuid = StringHelper.GetGuid(projectItem.Project, template.ItemIdOrPath + "/Fields/" + field.FieldName); templateField = Factory.TemplateField(template, templateFieldGuid).With(childNode); templateSection.Fields.Add(templateField); templateField.FieldNameProperty.SetValue(field.FieldNameProperty); templateField.TypeProperty.Parse("Field.Type", childNode, "Single-Line Text"); templateField.SortorderProperty.Parse("Field.SortOrder", childNode, nextSortOrder); } else { // todo: multiple sources? templateField.FieldNameProperty.AddSourceTextNode(field.FieldNameProperty.SourceTextNode); templateField.TypeProperty.ParseIfHasAttribute("Field.Type", childNode); templateField.SortorderProperty.ParseIfHasAttribute("Field.SortOrder", childNode); } templateField.Shared |= string.Equals(childNode.GetAttributeValue("Field.Sharing"), "Shared", StringComparison.OrdinalIgnoreCase); templateField.Unversioned |= string.Equals(childNode.GetAttributeValue("Field.Sharing"), "Unversioned", StringComparison.OrdinalIgnoreCase); templateField.SourceProperty.ParseIfHasAttribute("Field.Source", childNode); templateField.ShortHelpProperty.ParseIfHasAttribute("Field.ShortHelp", childNode); templateField.LongHelpProperty.ParseIfHasAttribute("Field.LongHelp", childNode); nextSortOrder = templateField.Sortorder + 100; // todo: added multiple times if merged template.References.AddRange(ReferenceParser.ParseReferences(template, templateField.SourceProperty)); } } context.Project.AddOrMerge(template); }
public IEnumerable <IDiagnostic> ItemsWithSameDisplayName([NotNull] ICheckerContext context) { var parents = new HashSet <Item>(); foreach (var item in context.Project.Items) { var parent = item.GetParent(); if (parent == null) { continue; } if (parents.Contains(parent)) { continue; } parents.Add(parent); var children = parent.Children.ToArray(); for (var i0 = 0; i0 < children.Length - 2; i0++) { var child0 = children[i0]; for (var i1 = i0 + 1; i1 < children.Length - 1; i1++) { var child1 = children[i1]; var languages = child0.Versions.GetLanguages().Intersect(child1.Versions.GetLanguages()); foreach (var language in languages) { var displayNames0 = child0.Fields.Where(f => string.Equals(f.FieldName, "__Display Name", StringComparison.OrdinalIgnoreCase) && f.Language == language).Select(f => f.Value); var displayNames1 = child1.Fields.Where(f => string.Equals(f.FieldName, "__Display Name", StringComparison.OrdinalIgnoreCase) && f.Language == language).Select(f => f.Value); var same = displayNames0.Intersect(displayNames1); if (same.Any()) { yield return(Error(context, Msg.C1006, "Items with same display name on same level", TraceHelper.GetTextNode(child0, child1), details: $"Two or more items have the same display name \"{displayNames0.First()}\" on the same level. Change the display name of one or more of the items.")); } } } } } }
public IEnumerable <IDiagnostic> FieldIsNotDefinedInTemplate([NotNull] ICheckerContext context) { return(from item in context.Project.Items where item.Template != Template.Empty let templateFields = item.Template.GetAllFields().ToList() from field in item.Fields let templateField = templateFields.FirstOrDefault(f => string.Equals(f.FieldName, field.FieldName, StringComparison.OrdinalIgnoreCase)) where templateField == null select Error(context, Msg.C1005, "Field is not defined in the template", TraceHelper.GetTextNode(field.FieldNameProperty, field, field.Item), details : "field: " + field.FieldName + ", template: " + item.TemplateName)); }
public IEnumerable <IDiagnostic> AvoidSpacesInItemNames([NotNull] ICheckerContext context) { return(from item in context.Project.Items where item.ItemName.IndexOf(' ') >= 0 && !item.Paths.IsStandardValuesHolder select Warning(context, Msg.C1003, "Avoid spaces in item names. Use a display name instead", TraceHelper.GetTextNode(item.ItemNameProperty), item.ItemName)); }
private string CompileUrlString([NotNull] Field field, [NotNull] string value) { var url = new UrlString(value); var result = new UrlString(); IDatabase database = null; var project = field.Item.Project; foreach (var key in url.Parameters.Keys) { if (string.Equals(key, "database", StringComparison.OrdinalIgnoreCase) || string.Equals(key, "databasename", StringComparison.OrdinalIgnoreCase)) { database = project.GetDatabase(url.Parameters[key]); } } foreach (var pair in url.Parameters) { var v = pair.Value; if (PathHelper.IsProbablyItemPath(v) && !ReferenceParser.IsIgnoredReference(v)) { var i = database == null?project.Indexes.FindQualifiedItem <IProjectItem>(v) : database.FindQualifiedItem <DatabaseProjectItem>(v); if (i != null) { v = i.Uri.Guid.Format(); } else { if (database != null && !string.Equals(database.DatabaseName, field.Item.DatabaseName, StringComparison.OrdinalIgnoreCase)) { Trace.TraceWarning(Msg.C1064, Texts.Item_path_reference_not_found__but_may_be_in_another_database, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field), database.DatabaseName + ":/" + v); } else { Trace.TraceError(Msg.C1046, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field), v); } } } result[pair.Key] = v; } return(result.ToString()); }
public IEnumerable <IDiagnostic> AvoidManyChildren([NotNull] ICheckerContext context) { return(from item in context.Project.Items let count = item.Children.Count() where count > 100 select Warning(context, Msg.C1009, "Avoid items with many children", TraceHelper.GetTextNode(item), $"The item has {count} children. Items with more than 100 children decrease performance. Change the structure of the tree to reduce the number of children")); }
public IEnumerable <IDiagnostic> ValidToDateIsBeforeValidFromDate([NotNull] ICheckerContext context) { return(from item in context.Project.Items where !item.Publishing.NeverPublish let validFrom = item.Publishing.ValidFrom let validTo = item.Publishing.ValidTo where validFrom != DateTime.MinValue && validTo != DateTime.MinValue && validFrom > validTo select Warning(context, Msg.C1021, "The Valid From date is after the Valid To date", TraceHelper.GetTextNode(item.Fields[Constants.Fields.ValidFrom], item.Fields[Constants.Fields.ValidTo], item), "Change either the Valid From date or the Valid To date")); }
public IEnumerable <IDiagnostic> UnpublishDateIsBeforePublishDate([NotNull] ICheckerContext context) { return(from item in context.Project.Items where !item.Publishing.NeverPublish let publishDate = item.Publishing.PublishDate let unpublishDate = item.Publishing.PublishDate where publishDate != DateTime.MinValue && unpublishDate != DateTime.MinValue && publishDate > unpublishDate select Warning(context, Msg.C1011, "The Publish date is after the Unpublish date", TraceHelper.GetTextNode(item.Fields[Constants.Fields.PublishDate], item.Fields[Constants.Fields.UnpublishDate], item), "Change either the Publish date or the Unpublish date")); }
public IEnumerable <IDiagnostic> ReminderDateIsAfterArchiveDate([NotNull] ICheckerContext context) { return(from item in context.Project.Items let archiveDate = item[Constants.Fields.ArchiveDate].FromIsoToDateTime() let reminderDate = item[Constants.Fields.ReminderDate].FromIsoToDateTime() where reminderDate != DateTime.MinValue && archiveDate != DateTime.MinValue && reminderDate > archiveDate select Warning(context, Msg.C1002, "The Reminder date is after the Archive date", TraceHelper.GetTextNode(item.Fields[Constants.Fields.ArchiveDate], item.Fields[Constants.Fields.ReminderDate], item), "Change either the Reminder date or the Archive date.")); }
public IEnumerable <IDiagnostic> ItemTemplateNotFound([NotNull] ICheckerContext context) { return(from item in context.Project.Items where item.Template == Template.Empty select Error(context, Msg.C1004, "Template not found", TraceHelper.GetTextNode(item.TemplateIdOrPathProperty, item, item.ItemNameProperty), details : item.TemplateIdOrPath)); }
private string CompilePipeList([NotNull] Field field, [NotNull] string value) { var sb = new StringBuilder(); foreach (var itemPath in value.Split(Constants.Pipe, StringSplitOptions.RemoveEmptyEntries)) { var path = itemPath; if (PathHelper.IsProbablyItemPath(path) && !ReferenceParser.IsIgnoredReference(value)) { var i = field.Item.Project.Indexes.FindQualifiedItem <IProjectItem>(path); if (i != null) { path = i.Uri.Guid.Format(); } else { Trace.TraceError(Msg.C1046, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field), path); } } if (sb.Length > 0) { sb.Append('|'); } sb.Append(path); } return(sb.ToString()); }
public IEnumerable <IDiagnostic> ItemsWithSameName([NotNull] ICheckerContext context) { var parents = new HashSet <Item>(); foreach (var item in context.Project.Items) { var parent = item.GetParent(); if (parent == null) { continue; } if (parents.Contains(parent)) { continue; } parents.Add(parent); var children = parent.Children.ToArray(); for (var i0 = 0; i0 < children.Length - 2; i0++) { var child0 = children[i0]; for (var i1 = i0 + 1; i1 < children.Length - 1; i1++) { var child1 = children[i1]; if (string.Equals(child0.ItemName, child1.ItemName, StringComparison.OrdinalIgnoreCase)) { yield return(Error(context, Msg.C1007, "Items with same name on same level", TraceHelper.GetTextNode(child0.ItemNameProperty, child1.ItemNameProperty, child0, child1), details: $"Two or more items have the same name \"{child0.ItemName}\" on the same level. Change the name of one or more of the items.")); } } } } }
public IEnumerable <IDiagnostic> AvoidManyVersions([NotNull] ICheckerContext context) { return(from item in context.Project.Items from language in item.Versions.GetLanguages() let count = item.Versions.GetVersions(language).Count() where count >= 10 select Warning(context, Msg.C1010, "Avoid items with many version", TraceHelper.GetTextNode(item), $"The item has {count} versions in the {language} language. Items with more than 10 version decrease performance. Remove some of the older versions.")); }