/// <summary>Checks the specified output.</summary>
    /// <param name="output">The output.</param>
    /// <param name="item">The item.</param>
    public override void Check(ValidationAnalyzer output, Item item)
    {
      Assert.ArgumentNotNull(output, "output");
      Assert.ArgumentNotNull(item, "item");

      var parametersTemplateId = item[ParametersTemplateFieldId];
      if (string.IsNullOrEmpty(parametersTemplateId))
      {
        return;
      }

      var parameterTemplateItem = item.Database.GetItem(parametersTemplateId);
      if (parameterTemplateItem == null)
      {
        return;
      }

      var template = new TemplateItem(parameterTemplateItem);

      foreach (var templateFieldItem in template.Fields)
      {
        var templateItem = new TemplateItem(templateFieldItem.InnerItem.Parent.Parent);
        if (!templateItem.BaseTemplates.Any())
        {
          continue;
        }

        output.MaxMessages++;

        if (string.IsNullOrEmpty(templateFieldItem.ToolTip))
        {
          output.Write(SeverityLevel.Suggestion, "Parameter must have help text", string.Format("The parameter '{0}' in the '{1}' control does not have a short help text. The short help text is part of documentation and is displayed in the Documentation web site", templateFieldItem.Name, item.Name), "Write a help text.", templateFieldItem.InnerItem);
        }
      }
    }
        public Result Handle()
        {
            var analyzer = new ValidationAnalyzer();

            var analysisResult = analyzer.Analyze(_configuration.InputPath);

            if (!analysisResult.Success)
            {
                return(Result.CreateError($"Source analysis error: {analysisResult.ErrorMessage}"));
            }

            log.Debug("Source analyzed");

            //var converter = new WebApiConverter();
            //var generator = new WebClientGenerator();
            //var emitter = new TypeScriptEmitter();

            //var serviceModels = converter.ConvertControllers(analysisResult.Value);

            //log.Debug("Models converted");

            //foreach (var tsModel in serviceModels)
            //{
            //    var contents = generator.GenerateService(tsModel);

            //    emitter.Emit(_configuration.OutputPath, tsModel.Name, EmittedFileType.Service, contents);

            //    log.Debug($"Service {tsModel.Name} emitted");
            //}

            return(Result.CreateSuccess());
        }
        private string Process([NotNull] string contextName, [NotNull] string databasesAndLanguages, [NotNull] string inactiveValidations, [NotNull] string rootItemPath, bool processSiteValidations)
        {
            Debug.ArgumentNotNull(contextName, nameof(contextName));
            Debug.ArgumentNotNull(databasesAndLanguages, nameof(databasesAndLanguages));
            Debug.ArgumentNotNull(inactiveValidations, nameof(inactiveValidations));
            Debug.ArgumentNotNull(rootItemPath, nameof(rootItemPath));

            using (var writer = new StringWriter())
            {
                var output = new XmlTextWriter(writer)
                {
                    Formatting = Formatting.Indented,
                };

                var options = new ValidationAnalyzerOptions
                {
                    ContextName              = contextName,
                    InactiveValidations      = inactiveValidations,
                    CustomValidations        = string.Empty,
                    ProcessCustomValidations = false,
                    ProcessValidations       = processSiteValidations,
                    Deep = true
                };

                options.ParseDatabaseAndLanguages(databasesAndLanguages);

                if (!string.IsNullOrEmpty(rootItemPath) && rootItemPath != "/" && rootItemPath != "/sitecore")
                {
                    var descriptor = options.DatabasesAndLanguages.FirstOrDefault();
                    if (descriptor == null)
                    {
                        return(string.Empty);
                    }

                    var rootItem = descriptor.Database.GetItem(rootItemPath, descriptor.Language);
                    if (rootItem == null)
                    {
                        return(string.Empty);
                    }

                    options.RootItem = rootItem;
                }

                var analyzer = new ValidationAnalyzer();
                analyzer.Process(output, options);

                output.Flush();
                writer.Flush();
                writer.Close();

                return(writer.ToString());
            }
        }
        public string Process([NotNull] string contextName, [NotNull] string databasesAndLanguages, [NotNull] string inactiveValidations, [NotNull] string customValidations)
        {
            Assert.ArgumentNotNull(contextName, nameof(contextName));
            Assert.ArgumentNotNull(databasesAndLanguages, nameof(databasesAndLanguages));
            Assert.ArgumentNotNull(inactiveValidations, nameof(inactiveValidations));
            Assert.ArgumentNotNull(customValidations, nameof(customValidations));

            TempFolder.EnsureFolder();
            var fileName     = Path.Combine(FileUtil.MapPath(TempFolder.Folder), contextName + "_validation.xml");
            var tempFileName = fileName + ".tmp";

            try
            {
                using (var writer = new FileStream(tempFileName, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    var output = new XmlTextWriter(writer, Encoding.UTF8)
                    {
                        Formatting  = Formatting.Indented,
                        Indentation = 2
                    };

                    var options = new ValidationAnalyzerOptions
                    {
                        ContextName         = contextName,
                        InactiveValidations = inactiveValidations,
                        CustomValidations   = customValidations
                    };

                    options.ParseDatabaseAndLanguages(databasesAndLanguages);

                    var analyzer = new ValidationAnalyzer();
                    analyzer.Process(output, options);

                    output.Flush();
                    writer.Flush();
                    writer.Close();
                }

                File.Delete(fileName);
                File.Move(tempFileName, fileName);
            }
            finally
            {
                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }
            }

            return(fileName);
        }
    /// <summary>Checks the specified output.</summary>
    /// <param name="output">The output.</param>
    /// <param name="item">The item.</param>
    public override void Check(ValidationAnalyzer output, Item item)
    {
      Assert.ArgumentNotNull(output, "output");
      Assert.ArgumentNotNull(item, "item");

      output.MaxMessages += 2;

      if (string.IsNullOrEmpty(item.Help.ToolTip))
      {
        output.Write(SeverityLevel.Suggestion, "Control must have short help text", string.Format("The control '{0}' does not have a short help text. The short help text is part of the documentation and is displayed in the Documentation web site", item.Name), "Write a short help text.", item);
      }

      if (string.IsNullOrEmpty(item.Help.Text))
      {
        output.Write(SeverityLevel.Suggestion, "Control must have long help text", string.Format("The control '{0}' does not have a long help text. The long help text is part of the documentation and is displayed in the Documentation web site", item.Name), "Write a long help text.", item);
      }
    }
    /// <summary>Checks the specified output.</summary>
    /// <param name="output">The output.</param>
    /// <param name="item">The item.</param>
    public override void Check(ValidationAnalyzer output, Item item)
    {
      Assert.ArgumentNotNull(output, "output");
      Assert.ArgumentNotNull(item, "item");

      output.MaxMessages += 2;

      if (!string.IsNullOrEmpty(item.Help.ToolTip) && !item.Help.ToolTip.EndsWith("."))
      {
        output.Write(SeverityLevel.Suggestion, "Control short help text must end with a dot", string.Format("The short help text for the control '{0}' must be a complete sentence and end with a dot.", item.Name), "Add a dot to the short help text.", item);
      }

      if (!string.IsNullOrEmpty(item.Help.Text) && !item.Help.Text.EndsWith("."))
      {
        output.Write(SeverityLevel.Suggestion, "Control long help text must end with a dot", string.Format("The long help text for the control '{0}' must be a complete sentence and end with a dot.", item.Name), "Add a dot to the long help text.", item);
      }
    }
    /// <summary>Checks the specified output.</summary>
    /// <param name="output">The output.</param>
    /// <param name="item">The item.</param>
    public override void Check(ValidationAnalyzer output, Item item)
    {
      Assert.ArgumentNotNull(output, "output");
      Assert.ArgumentNotNull(item, "item");

      var parametersTemplateId = item[ParametersTemplateFieldId];

      output.MaxMessages += 2;

      if (item["Datasource Location"] != "PageSettings")
      {
        output.Write(SeverityLevel.Suggestion, "The 'Datasource Location' should be set to 'PageSettings'", string.Format("The 'Datasource Location' field is currently set to '{0}'. When creating data sources for a SPEAK component, it should be created in the PageSettings section of the page.", item["Datasource Location"]), "Set 'Datasource Location' field to 'PageSettings'", item);
      }

      if (item["Datasource Template"] != parametersTemplateId)
      {
        output.Write(SeverityLevel.Suggestion, "The 'Datasource Template' should be set to the Parameters Template item ID", string.Format("The 'Datasource Template' field is currently set to '{0}'. When creating data sources for a SPEAK component, it should probably create an item with same template as the Parameters Template.", item["Datasource Template"]), string.Format("Set 'Datasource Template' field to '{0}'", parametersTemplateId), item);
      }
    }
    /// <summary>Checks the specified output.</summary>
    /// <param name="output">The output.</param>
    /// <param name="item">The item.</param>
    public override void Check(ValidationAnalyzer output, Item item)
    {
      Assert.ArgumentNotNull(output, "output");
      Assert.ArgumentNotNull(item, "item");

      var parametersTemplateId = item[ParametersTemplateFieldId];

      output.MaxMessages += 2;

      if (string.IsNullOrEmpty(parametersTemplateId))
      {
        output.Write(SeverityLevel.Warning, "Control does not have a Parameter Template", string.Format("The control '{0}' does not have a Parameter Template. Parameter Templates define the parameters that the control accepts. These help the user set parameters correctly and appear in Property Windows when configuring the control in Sitecore Rocks or the Page Editor.", item.Name), "Create an Parameter Template item and set the Parameter Template field in the control.", item);
        return;
      }

      var parameterTemplate = item.Database.GetItem(parametersTemplateId);
      if (parameterTemplate == null)
      {
        output.Write(SeverityLevel.Error, "Parameter Template does not exist", string.Format("The control '{0}' points to a Parameter Templates item that does not exist.", item.Name), "Create an Parameter Template item or remove the reference.", item);
      }
    }
    /// <summary>Checks the specified output.</summary>
    /// <param name="output">The output.</param>
    /// <param name="item">The item.</param>
    public override void Check(ValidationAnalyzer output, Item item)
    {
      Assert.ArgumentNotNull(output, "output");
      Assert.ArgumentNotNull(item, "item");

      var parametersTemplateId = item[ParametersTemplateFieldId];
      if (string.IsNullOrEmpty(parametersTemplateId))
      {
        return;
      }

      var template = TemplateManager.GetTemplate(new ID(parametersTemplateId), item.Database);
      if (template == null)
      {
        return;
      }

      var defaultParameters = new UrlString(item["Default Parameters"]);

      foreach (string key in defaultParameters.Parameters.Keys)
      {
        if (string.IsNullOrEmpty(key))
        {
          continue;
        }

        if (key == "Placeholder")
        {
          continue;
        }

        output.MaxMessages++;

        if (template.GetField(key) == null)
        {
          output.Write(SeverityLevel.Warning, "Control has an invalid default parameter", string.Format("The control '{1}' defines the default parameter '{0}', but this parameter does not exist in the controls Parameter Template.", key, item.Name), "Remove the default parameter or add it to the Parameter Template.", item);
        }
      }
    }
    /// <summary>Checks the specified output.</summary>
    /// <param name="output">The output.</param>
    /// <param name="item">The item.</param>
    public override void Check(ValidationAnalyzer output, Item item)
    {
      Assert.ArgumentNotNull(output, "output");
      Assert.ArgumentNotNull(item, "item");

      var parametersTemplateId = item[ParametersTemplateFieldId];
      if (string.IsNullOrEmpty(parametersTemplateId))
      {
        return;
      }

      var parameterTemplateItem = item.Database.GetItem(parametersTemplateId);
      if (parameterTemplateItem == null)
      {
        return;
      }

      var template = new TemplateItem(parameterTemplateItem);

      foreach (var templateFieldItem in template.Fields)
      {
        var templateItem = new TemplateItem(templateFieldItem.InnerItem.Parent.Parent);
        if (!templateItem.BaseTemplates.Any())
        {
          continue;
        }

        output.MaxMessages++;

        var toolTip = templateFieldItem.ToolTip.Trim();
        if (!string.IsNullOrEmpty(toolTip) && !toolTip.EndsWith("."))
        {
          output.Write(SeverityLevel.Suggestion, "Parameter help text must end with a dot", string.Format("The help text for the '{0}' parameter in the control '{1}' must be a complete sentence and end with a dot.", templateFieldItem.Name, item.Name), "Add a dot to the help text.", templateFieldItem.InnerItem);
        }
      }
    }
        private string Process([NotNull] string contextName, [NotNull] string databasesAndLanguages, [NotNull] string inactiveValidations, [NotNull] string rootItemPath, bool processSiteValidations)
        {
            using (var writer = new StringWriter())
            {
                var output = new XmlTextWriter(writer)
                {
                    Formatting = Formatting.Indented
                };

                var options = new ValidationAnalyzerOptions
                {
                    ContextName = contextName,
                    InactiveValidations = inactiveValidations,
                    CustomValidations = string.Empty,
                    ProcessCustomValidations = false,
                    ProcessValidations = processSiteValidations,
                    Deep = true
                };

                options.ParseDatabaseAndLanguages(databasesAndLanguages);

                if (!string.IsNullOrEmpty(rootItemPath) && rootItemPath != "/" && rootItemPath != "/sitecore")
                {
                    var descriptor = options.DatabasesAndLanguages.FirstOrDefault();
                    if (descriptor == null)
                    {
                        return string.Empty;
                    }

                    var rootItem = descriptor.Database.GetItem(rootItemPath, descriptor.Language);
                    if (rootItem == null)
                    {
                        return string.Empty;
                    }

                    options.RootItem = rootItem;
                }

                var analyzer = new ValidationAnalyzer();
                analyzer.Process(output, options);

                output.Flush();
                writer.Flush();
                writer.Close();

                return writer.ToString();
            }
        }
Exemple #12
0
        public void Process([NotNull] string contextName, [NotNull] string databaseName, [NotNull] string itemId, [NotNull] string languageName, [NotNull] string version, [NotNull] string inactiveValidations, [NotNull] string customValidations, bool deep)
        {
            Assert.ArgumentNotNull(contextName, nameof(contextName));
            Assert.ArgumentNotNull(databaseName, nameof(databaseName));
            Assert.ArgumentNotNull(itemId, nameof(itemId));
            Assert.ArgumentNotNull(languageName, nameof(languageName));
            Assert.ArgumentNotNull(version, nameof(version));
            Assert.ArgumentNotNull(inactiveValidations, nameof(inactiveValidations));
            Assert.ArgumentNotNull(customValidations, nameof(customValidations));

            var v = Version.Latest;

            if (!string.IsNullOrEmpty(version))
            {
                v = Version.Parse(version);
            }

            var database = Factory.GetDatabase(databaseName);
            var language = LanguageManager.GetLanguage(languageName);
            var rootItem = database.GetItem(itemId, language, v);

            TempFolder.EnsureFolder();
            var fileName     = Path.Combine(FileUtil.MapPath(TempFolder.Folder), string.Format("validation_{0}_{1}_{2}_{3}_{4}{5}.xml", contextName, database.Name, rootItem.ID.ToShortID(), language.Name, v, deep ? "_deep" : string.Empty));
            var tempFileName = fileName + ".tmp";

            try
            {
                using (var writer = new FileStream(tempFileName, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    var output = new XmlTextWriter(writer, Encoding.UTF8)
                    {
                        Formatting = Formatting.Indented,
                    };

                    var options = new ValidationAnalyzerOptions
                    {
                        ContextName              = contextName,
                        InactiveValidations      = inactiveValidations,
                        CustomValidations        = customValidations,
                        RootItem                 = rootItem,
                        ProcessValidations       = false,
                        ProcessCustomValidations = false,
                        Deep = deep
                    };

                    options.DatabasesAndLanguages.Add(new DatabaseLanguageDescriptor(database, language));

                    var analyzer = new ValidationAnalyzer();
                    analyzer.Process(output, options);

                    output.Flush();
                    writer.Flush();
                    writer.Close();
                }

                File.Delete(fileName);
                File.Move(tempFileName, fileName);
            }
            finally
            {
                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }
            }
        }