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);
        }
        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();
            }
        }
Exemplo n.º 4
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);
                }
            }
        }