private List <PreImportMessage> FindProblems(XmlDocument xml, TreeNode node) { var result = new List <PreImportMessage>(); var resource = node.Tag as CmsResource; // We don't need to look for the root node (or empty helper nodes we created) if ((node.Checked || node.HasCheckedDescendents()) && resource != null && resource.AssetId != 0) { var xmlNode = xml.SelectSingleNode("//*[id='" + resource.AssetId + "']"); if (xmlNode == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Cannot find asset", Status = MessageStatus.Error, Type = ProblemType.Other }); } else { var pathNode = xmlNode.SelectSingleNode("path"); var path = ""; if (pathNode == null || string.IsNullOrWhiteSpace(pathNode.InnerText)) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Cannot find asset path", Status = MessageStatus.Error, Type = ProblemType.Other }); } else { path = pathNode.InnerText; var modelPathNode = xmlNode.SelectSingleNode("model_path"); if (modelPathNode != null) { var modelPath = modelPathNode.InnerText; if (!_modelMaps.ContainsKey(modelPath)) { if (string.IsNullOrWhiteSpace(modelPath)) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "No model provided", Path = path, Status = MessageStatus.Warning, Type = ProblemType.Model }); } else { // First look in the import to see if the model is there and selected var modelNode = FindNodeById(node.TreeView, int.Parse(xmlNode.SelectSingleNode("model_id").InnerText)); if (modelNode == null || !modelNode.Checked) { var modelAsset = _migrationEngine.GetAsset(modelPath); if (modelAsset == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Model not found: " + modelPath, Path = path, Status = MessageStatus.Warning, Type = ProblemType.Model }); } else { _modelMaps.Add(modelPath, modelAsset.id); resource.ModelId = _modelMaps[modelPath]; } } } } else { resource.ModelId = _modelMaps[modelPath]; } } var workflowIdNode = xmlNode.SelectSingleNode("workflow_id"); if (workflowIdNode == null) { if (xmlNode.Name != "folder") { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "No workflow provided", Path = path, Status = MessageStatus.Warning, Type = ProblemType.Workflow }); } } else { var workflowNameNode = xmlNode.SelectSingleNode("workflow_name"); if (workflowNameNode == null) { if (!string.IsNullOrEmpty(workflowIdNode.InnerText) && workflowIdNode.InnerText != "0") { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "No workflow provided", Path = path, Status = MessageStatus.Warning, Type = ProblemType.Workflow }); } } else { var workflowName = workflowNameNode.InnerText; if (!_workflowMaps.ContainsKey(workflowName)) { if (!string.IsNullOrWhiteSpace(workflowName)) { // First look in the import to see if the workflow is there and selected TreeNode workflowNode = null; var workflowAssetNode = xmlNode.SelectSingleNode("/*/asset[workflow/id=\"" + workflowIdNode.InnerText + "\"]/id"); if (workflowAssetNode != null) { workflowNode = FindNodeById(node.TreeView, int.Parse(workflowAssetNode.InnerText)); } if (workflowNode == null || !workflowNode.Checked) { var workflow = _migrationEngine.GetWorkflow(workflowName); if (workflow == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Workflow not found: " + workflowName, Path = path, Status = MessageStatus.Warning, Type = ProblemType.Workflow }); } else if (_migrationEngine.IsWorkflowDuplicateName(workflowName)) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Duplicate workflow name found: " + workflowName, Path = path, Status = MessageStatus.Warning, Type = ProblemType.Workflow }); } else { _workflowMaps.Add(workflowName, workflow.Id); resource.WorkflowId = workflow.Id; } } } } else { resource.WorkflowId = _workflowMaps[workflowName]; } } } var templatePathNode = xmlNode.SelectSingleNode("template_path"); if (templatePathNode == null) { // Don't report no template for folders or workflows or digital assets if (xmlNode.Name == "asset" && xmlNode.SelectSingleNode("binaryContent") == null && xmlNode.SelectSingleNode("workflow") == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "No template provided", Path = path, Status = MessageStatus.Warning, Type = ProblemType.Template }); } } else { var templatePath = templatePathNode.InnerText; if (!_templateMaps.ContainsKey(templatePath)) { if (string.IsNullOrWhiteSpace(templatePath)) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "No template provided", Path = path, Status = MessageStatus.Warning, Type = ProblemType.Template }); } else { // First look in the import to see if the template is there and selected var templateNode = FindNodeById(node.TreeView, int.Parse(xmlNode.SelectSingleNode("template_id").InnerText)); if (templateNode == null || !templateNode.Checked) { var templateAsset = _migrationEngine.GetAsset(templatePath); if (templateAsset == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Template not found: " + templatePath, Path = path, Status = MessageStatus.Warning, Type = ProblemType.Template }); } else { _templateMaps.Add(templatePath, templateAsset.id); resource.TemplateId = _templateMaps[templatePath]; } } } } else { resource.TemplateId = _templateMaps[templatePath]; } } // TODO: check for branch id and that we're importing the asset with that branch id if (xmlNode.SelectSingleNode("publishing_properties/property/package") != null) { foreach (var packageNode in xmlNode.SelectNodes("publishing_properties/property/package")) { var packageName = ((XmlNode)packageNode).InnerText; if (!_packageMaps.ContainsKey(packageName)) { var package = _migrationEngine.GetPublishingPackage(packageName); if (package == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Package not found: " + packageName, Path = path, Status = MessageStatus.Warning, Type = ProblemType.Package, Key = packageName }); } else { _packageMaps.Add(packageName, package.Id); } } } } if (xmlNode.SelectSingleNode("workflow") != null) { // This is a workflow item var workflowNode = xmlNode.SelectSingleNode("workflow"); // First check step/accessFile nodes foreach (var accessFileNode in workflowNode.SelectNodes("steps/step/accessFile")) { var accessPath = ((XmlNode)accessFileNode).InnerText; if (!_accessMaps.ContainsKey(accessPath)) { var accessAsset = _migrationEngine.GetAsset(accessPath); if (accessAsset == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Access asset not found: " + accessPath, Path = path, Status = MessageStatus.Warning, Type = ProblemType.Access, Key = accessPath }); } else { _accessMaps.Add(accessPath, accessAsset.id); } } } // Next check step/statusName foreach (var statusNameNode in workflowNode.SelectNodes("steps/step/statusName")) { var statusName = ((XmlNode)statusNameNode).InnerText; if (!_stateMaps.ContainsKey(statusName)) { var statusAsset = _migrationEngine.GetAsset("/System/States/" + statusName); if (statusAsset == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "State not found: " + statusName, Path = path, Status = MessageStatus.Warning, Type = ProblemType.State, Key = statusName }); } else { _stateMaps.Add(statusName, statusAsset.id); } } } // Next check step/commands/command/filterName foreach (var filterNameNode in workflowNode.SelectNodes("steps/step/commands/command/filterName")) { var filterName = ((XmlNode)filterNameNode).InnerText; if (!_workflowFilterMaps.ContainsKey(filterName)) { var workflowFilter = _migrationEngine.GetWorkflowFilter(filterName); if (workflowFilter == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Workflow filter not found: " + filterName, Path = path, Status = MessageStatus.Warning, Type = ProblemType.WorkflowFilter, Key = filterName }); } else { _workflowFilterMaps.Add(filterName, workflowFilter.Id); } } } // Next check step/publishes/publish/statusName foreach (var statusNameNode in workflowNode.SelectNodes("steps/step/publishes/publish/statusName")) { var statusName = ((XmlNode)statusNameNode).InnerText; if (!_stateMaps.ContainsKey(statusName)) { var statusAsset = _migrationEngine.GetAsset("/System/States/" + statusName); if (statusAsset == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "State not found: " + statusName, Path = path, Status = MessageStatus.Warning, Type = ProblemType.State, Key = statusName }); } else { _stateMaps.Add(statusName, statusAsset.id); } } } // Next check step/publishes/publish/packageName foreach (var packageNameNode in workflowNode.SelectNodes("steps/step/publishes/publish/packageName")) { var packageName = ((XmlNode)packageNameNode).InnerText; if (!_packageMaps.ContainsKey(packageName)) { var package = _migrationEngine.GetPublishingPackage(packageName); if (package == null) { result.Add(new PreImportMessage { AssetId = resource.AssetId, Message = "Package not found: " + packageName, Path = path, Status = MessageStatus.Warning, Type = ProblemType.Package, Key = packageName }); } else { _packageMaps.Add(packageName, package.Id); } } } } } } // Make sure the tag is up-to-date node.Tag = resource; } // Recurse to our children foreach (TreeNode child in node.Nodes) { result.AddRange(FindProblems(xml, child)); } return(result); }