Exemple #1
0
        private bool ValidateXMLFormat()
        {
            var startArgs = new ProcessStepStartArgs()
            {
                StartTime = DateTime.Now,
                Libelle   = TemplateValidatorResources.XmlValidation_Title,
            };
            var completeArgs = new ProcessStepCompletionArgs(startArgs)
            {
                IsSuccess = true
            };


            _processCompletionArgs.StepProcess.Add(completeArgs);
            OnProcessStepStart(startArgs);


            XmlSchemaSet sc = new XmlSchemaSet();

            sc.Add(null, _processStartArgs.SchemaUri);
            XmlReaderSettings settings = new XmlReaderSettings
            {
                ValidationType = ValidationType.Schema,
                Schemas        = sc
            };


            settings.ValidationEventHandler += (s, e) => AddAnomaly(completeArgs, e.Message, true);

            using (XmlReader reader = XmlReader.Create(_processCompletionArgs.XmlDocumentInformation.FileCompletePath, settings))
            {
                while (reader.Read())
                {
                    ;
                }
            }
            completeArgs.CompletionTime = DateTime.Now;
            OnProcessStepCompletion(completeArgs);
            return(completeArgs.IsSuccess);
        }
Exemple #2
0
        private bool ValidateContent()
        {
            var startArgs = new ProcessStepStartArgs()
            {
                StartTime = DateTime.Now,
                Libelle   = TemplateValidatorResources.ContentValidation_Title,
            };
            var completeArgs = new ProcessStepCompletionArgs(startArgs)
            {
                IsSuccess = true
            };

            _processCompletionArgs.StepProcess.Add(completeArgs);

            OnProcessStepStart(startArgs);

            var rootPath = _processStartArgs.TemplateDirectoryPath;

            string[] fileEntries;
            //List<string> unusedFiles = Directory.GetFiles(rootPath, "*.*", SearchOption.AllDirectories).Where(x => x.Contains(temp_dir)).Select(x => x.ToLowerInvariant()).ToList();
            List <string> unusedFiles = Directory.GetFiles(rootPath, "*.*", SearchOption.AllDirectories).Select(x => x.ToLowerInvariant()).ToList();

            unusedFiles.Remove(_processCompletionArgs.XmlDocumentInformation.FileCompletePath.ToLowerInvariant()); // On remove le .xml racine.
            XmlDocument doc = _processCompletionArgs.XmlDocumentInformation.Document;

            var contentNode   = doc.DocumentElement.GetElementsByTagName("Content");
            var rootAttribute = contentNode[0].Attributes.GetNamedItem("root");

            if (!rootAttribute.Value.Equals("."))
            {
                rootPath = Path.Combine(_processStartArgs.TemplateDirectoryPath, rootAttribute.Value);
            }


            var           variationsElements = contentNode[0].ChildNodes;
            List <string> variationsCodes    = new List <string>();

            // Les variations et parts
            if (variationsElements.Count == 0)
            {
                AddAnomaly(completeArgs, TemplateValidatorResources.ContentValidation_AucuneVariation, true);
            }
            else
            {
                foreach (XmlNode n in variationsElements)
                {
                    if (!n.Name.Equals("Variation"))
                    {
                        continue;
                    }
                    var variationcode = n.Attributes.GetNamedItem("code").Value;
                    variationsCodes.Add(variationcode);

                    foreach (XmlNode t in n.ChildNodes)
                    {
                        var variationContentKind = t.Attributes.GetNamedItem("kind").Value;
                        if (!t.Name.Equals("VariationContent"))
                        {
                            continue;
                        }

                        if (t.ChildNodes.Cast <XmlNode>().Where(p => p.Name.Equals("Folder")).Count() == 1)
                        {
                            bool htmlFound  = false;
                            var  folderNode = t.ChildNodes.Cast <XmlNode>().Where(p => p.Name.Equals("Folder")).FirstOrDefault();
                            var  partPath   = folderNode.Attributes.GetNamedItem("path").Value;
                            var  currDir    = Path.Combine(rootPath, partPath);

                            if (Directory.Exists(currDir))
                            {
                                fileEntries = Directory.GetFiles(currDir, "*", SearchOption.AllDirectories);
                            }
                            else
                            {
                                AddAnomaly(completeArgs, string.Format(TemplateValidatorResources.ContentValidation_DossierNonExistant, currDir), true);
                                continue;
                            }

                            for (int i = 0; i < fileEntries.Length; i++)
                            {
                                var fileName = GetFormatedName(fileEntries[i].ToLowerInvariant());

                                bool shouldNotUse = false;
                                switch (t.Attributes.GetNamedItem("kind").Value.ToLowerInvariant())
                                {
                                case "resources":
                                case "ressources":
                                    break;

                                default:
                                    if (!fileName.Contains(t.Attributes.GetNamedItem("kind").Value.ToLowerInvariant()))
                                    {
                                        shouldNotUse = true;
                                    }

                                    break;
                                }

                                if (shouldNotUse)
                                {
                                    continue;
                                }

                                ReplaceRelativePath(fileEntries[i]);

                                unusedFiles.Remove(fileName);
                                switch (Path.GetExtension(fileName).ToLower())
                                {
                                case ".html":
                                    htmlFound = true;
                                    break;

                                case ".css":
                                    break;

                                case ".js":
                                    break;
                                }
                            }

                            if (!htmlFound)
                            {
                                AddAnomaly(completeArgs, string.Format(TemplateValidatorResources.ContentValidation_FichierHtmlNonExistant, variationContentKind), true);
                            }
                        }
                        else if (t.ChildNodes.Cast <XmlNode>().Where(p => p.Name.Equals("File")).Count() >= 1)
                        {
                            var fileNodes       = t.ChildNodes.Cast <XmlNode>().Where(p => p.Name.Equals("File")).ToList();
                            var dir             = Path.Combine(rootPath, variationcode);
                            var filesDirFounded = false;

                            for (int i = 0; i < fileNodes.Count(); i++)
                            {
                                if (!filesDirFounded && File.Exists(Path.Combine(rootPath, fileNodes[i].Attributes.GetNamedItem("path").Value)))
                                {
                                    fileEntries = Directory.GetFiles(rootPath, fileNodes[i].Attributes.GetNamedItem("path").Value);
                                }
                                else
                                {
                                    AddAnomaly(completeArgs, string.Format(TemplateValidatorResources.ContentValidation_FichierNonExistant, fileNodes[i].Attributes.GetNamedItem("path").Value, variationContentKind), true);
                                    continue;
                                }

                                var  fileAttributeValue = fileNodes[i].Attributes.GetNamedItem("path").Value;
                                bool fileFound          = false;
                                for (int z = 0; z < fileEntries.Length; z++)
                                {
                                    var fileName = GetFormatedName(fileEntries[z].ToLowerInvariant());

                                    ReplaceRelativePath(fileEntries[z]);

                                    switch (t.Attributes.GetNamedItem("kind").Value.ToLowerInvariant())
                                    {
                                    case "resources":
                                    case "ressources":
                                        fileFound = true;
                                        break;
                                    }

                                    unusedFiles.Remove(fileName);
                                    switch (Path.GetExtension(fileName).ToLower())
                                    {
                                    case ".html":
                                        fileFound = true;
                                        break;

                                    case ".css":
                                        fileFound = true;
                                        break;

                                    case ".js":
                                        fileFound = true;
                                        break;
                                    }
                                }
                                if (!fileFound)
                                {
                                    AddAnomaly(completeArgs, string.Format(TemplateValidatorResources.ContentValidation_FichierNonExistant, fileNodes[i].Attributes.GetNamedItem("path").Value, variationContentKind), true);
                                }
                            }
                        }
                    }
                }
            }



            CheckPublishSettings(doc, rootPath, variationsCodes, unusedFiles, completeArgs);
            CheckSharedFiles(doc, rootPath, unusedFiles, completeArgs);

            for (int i = 0; i < unusedFiles.Count; i++)
            {
                AddAnomaly(completeArgs, string.Format(TemplateValidatorResources.ContentValidation_FichierInutile, unusedFiles[i]), false);
            }


            _unusedFiles = unusedFiles.ToArray();
            completeArgs.CompletionTime = DateTime.Now;
            OnProcessStepCompletion(completeArgs);
            return(completeArgs.IsSuccess);
        }
Exemple #3
0
        private List <Variable> GetVariables(XmlDocument doc)
        {
            var startArgs = new ProcessStepStartArgs()
            {
                StartTime = DateTime.Now,
                Libelle   = TemplateValidatorResources.XmlRecuperation_Variables,
            };
            var completeArgs = new ProcessStepCompletionArgs(startArgs)
            {
                IsSuccess = true
            };

            OnProcessStepStart(startArgs);
            _processCompletionArgs.StepProcess.Add(completeArgs);


            // Récupération des variables
            List <Variable> variables = new List <Variable>();
            var             vars      = doc.DocumentElement.SelectNodes("//*[local-name()='Variable']");

            if (vars.Count > 0)
            {
                foreach (XmlNode variableNode in vars)
                {
                    var variableCode         = variableNode.Attributes.GetNamedItem("code").Value;
                    var variableLabel        = variableNode.Attributes.GetNamedItem("label").Value;
                    var variableKind         = variableNode.Attributes.GetNamedItem("kind").Value;
                    var variableDefaultValue = variableNode.Attributes.GetNamedItem("defaultValue");


                    if (!Enum.TryParse(variableKind, out VariableKind vk))
                    {
                        AddAnomaly(completeArgs, string.Format(TemplateValidatorResources.XmlRecuperation_TypeVariableInvalide, variableLabel), true);
                    }
                    Variable variable = new Variable(variableCode, variableLabel, vk, variableDefaultValue == null ? "" : variableDefaultValue.Value);


                    XmlNode currentNode = variableNode;
                    while (currentNode.ParentNode != null && !currentNode.Name.Equals("Settings"))
                    {
                        var parent = currentNode.ParentNode;
                        switch (parent.Name)
                        {
                        case "SettingsPage":
                            variable.SettingsPage = parent.Attributes.GetNamedItem("kind").Value;
                            break;

                        case "Group":
                            variable.Group = parent.Attributes.GetNamedItem("code").Value;
                            break;

                        case "Variation":
                            variable.Variation = parent.Attributes.GetNamedItem("code").Value;
                            break;
                        }
                        currentNode = currentNode.ParentNode;
                    }
                    if (!variables.Contains(variable))
                    {
                        variables.Add(variable);
                    }
                }
            }

            completeArgs.CompletionTime = DateTime.Now;
            OnProcessStepCompletion(completeArgs);
            return(variables);
        }
Exemple #4
0
 protected virtual void OnProcessStepStart(ProcessStepStartArgs e) => ProcessStepStart?.Invoke(this, e);
Exemple #5
0
        private XmlDocumentInformation GetXMLContent()
        {
            var startArgs = new ProcessStepStartArgs()
            {
                StartTime = DateTime.Now,
                Libelle   = TemplateValidatorResources.XmlRecuperation_Title,
            };
            var completeArgs = new ProcessStepCompletionArgs(startArgs)
            {
                IsSuccess = true
            };

            OnProcessStepStart(startArgs);
            _processCompletionArgs.StepProcess.Add(completeArgs);


            XmlDocumentInformation xdi = new XmlDocumentInformation();

            string[] rootFiles = Directory.GetFiles(_processStartArgs.TemplateDirectoryPath, "*.xml", SearchOption.TopDirectoryOnly);

            if (rootFiles.Length != 1)
            {
                if (rootFiles.Length > 1)
                {
                    AddAnomaly(completeArgs, TemplateValidatorResources.XmlValidation_TooManyXml, true);
                }
                else if (rootFiles.Length == 0)
                {
                    AddAnomaly(completeArgs, TemplateValidatorResources.XmlValidation_NoXml, true);
                }

                completeArgs.CompletionTime = DateTime.Now;
                OnProcessStepCompletion(completeArgs);
                return(xdi);
            }

            foreach (var r in rootFiles)
            {
                ReplaceEnvVar(r);
            }

            XmlDocument doc = new XmlDocument();

            foreach (string fileName in rootFiles)
            {
                var completePath = Path.Combine(_processStartArgs.TemplateDirectoryPath, Path.GetFileName(fileName));
                switch (Path.GetExtension(fileName).ToLowerInvariant())
                {
                case ".xml":
                    using (var entryStream = File.OpenRead(completePath))
                    {
                        try
                        {
                            doc.Load(entryStream);
                            xdi.FileCompletePath = completePath;
                            xdi.IsLoaded         = true;
                        }
                        catch (Exception e)
                        {
                            AddAnomaly(completeArgs, e.Message, true);
                            throw;
                        }
                    }
                    break;
                }
            }
            xdi.Document = doc;


            completeArgs.CompletionTime = DateTime.Now;
            OnProcessStepCompletion(completeArgs);
            return(xdi);
        }
Exemple #6
0
 public ProcessStepCompletionArgs(ProcessStepStartArgs startArgs) : base()
 {
     Libelle   = startArgs.Libelle;
     StartTime = startArgs.StartTime;
     Anomalies = new List <ProcessAnomaly>();
 }