123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Windows;
- using System.Windows.Controls;
- using System.Xml;
- using Aitex.Core.UI.View.Common;
- using Caliburn.Micro.Core;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
- using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
- using MECF.Framework.UI.Client.CenterViews.Parameter;
- namespace MECF.Framework.UI.Client.CenterViews.Editors
- {
- public class ParameterTreeBuilder
- {
- static ParameterProvider _parameterProvider = new ParameterProvider();
- public static List<FileNode> GetFiles(string prefixPath, List<string> filenames)
- {
- List<FileNode> folders = new List<FileNode>();
- FileNode root = new FileNode() { Name = "Files", IsFile = false, FullPath = "", PrefixPath = prefixPath };
- folders.Add(root);
- foreach (string filename in filenames)
- {
- string[] filesplits = filename.Split('\\');
- FileNode parent = root;
- if (filesplits.Length > 1)
- {
- for (var index = 0; index < filesplits.Length - 1; index++)
- {
- bool found = false;
- for (var j = 0; j < parent.Files.Count; j++)
- {
- if (parent.Files[j].Name == filesplits[index] && !parent.Files[j].IsFile)
- {
- found = true;
- parent = parent.Files[j];
- break;
- }
- }
- if (!found)
- {
- FileNode folder = new FileNode() { Name = filesplits[index], IsFile = false, PrefixPath = prefixPath };
- folder.FullPath = (parent.FullPath == string.Empty ? filesplits[index] : parent.FullPath + "\\" + filesplits[index]);
- folder.Parent = parent;
- parent.Files.Add(folder);
- parent = folder;
- }
- }
- }
- FileNode file = new FileNode() { Name = filesplits[filesplits.Length - 1], IsFile = true, PrefixPath = prefixPath };
- file.FullPath = (parent.FullPath == string.Empty ? filesplits[filesplits.Length - 1] : parent.FullPath + "\\" + filesplits[filesplits.Length - 1]);
- file.Parent = parent;
- parent.Files.Add(file);
- }
- return folders;
- }
- static string GetAttributeValue(string prefixPath, string parameterName, string attributeName)
- {
-
- string content = _parameterProvider.LoadParameter(prefixPath, parameterName);
- XmlDocument _doc = new XmlDocument();
- _doc.LoadXml(content);
- XmlElement nodeData = _doc.SelectSingleNode($"Aitex/TableParameterData") as XmlElement;
- return nodeData.GetAttribute(attributeName);
- }
- public static void CreateTreeViewItems(XmlElement curElementNode, FileNode parent, string prefixPath, string selectionName, bool selectionIsFolder)
- {
- selectionIsFolder = false;
- foreach (XmlElement ele in curElementNode.ChildNodes)
- {
- if (ele.Name == "File")
- {
- string fileName = ele.Attributes["Name"].Value;
- fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
- string fullPath = string.IsNullOrEmpty(parent.FullPath)
- ? fileName
- : parent.FullPath + "\\" + fileName;
- ParameterProvider _parameterProvider = new ParameterProvider();
- string content = _parameterProvider.LoadParameter(prefixPath, fullPath);
- if ((content == null) || (content == ""))
- {
- continue;
- }
- FileNode file = new FileNode()
- {
- Name = fileName,
- IsFile = true,
- PrefixPath = prefixPath,
- Parent = parent,
- FullPath = fullPath,
- Creator = GetAttributeValue(prefixPath, fullPath, "CreatedBy"),
- Description = GetAttributeValue(prefixPath, fullPath, "Description"),
- CreatTime = GetAttributeValue(prefixPath, fullPath, "CreationTime"),
- ReviseTime = GetAttributeValue(prefixPath, fullPath, "LastRevisionTime"),
- Revisor = GetAttributeValue(prefixPath, fullPath, "LastRevisedBy"),
- Permission = GetAttributeValue(prefixPath, fullPath, "Permission"),
- Level = GetAttributeValue(prefixPath, fullPath, "Level"),
- IsChecked = GetAttributeValue(prefixPath, fullPath, "CheckResult") == "Correct",
- };
- string fileMode = string.Empty;
- string currentMode = QueryDataClient.Instance.Service.GetConfig("System.Engineeringmode")?.ToString();
- if (!string.IsNullOrEmpty(currentMode) && currentMode.Equals("Normal"))
- file.IsEnable = GetAttributeValue(prefixPath, fullPath, "NormalMode") != "Notuseable";
- else
- file.IsEnable = GetAttributeValue(prefixPath, fullPath, "EngineeringMode") != "Notuseable";
- if (!selectionIsFolder)
- {
- if (selectionName == file.FullPath)
- file.IsSelected = true;
- else
- file.IsSelected = false;
- FileNode node = file.Parent;
- while (node.FullPath.Contains("\\"))
- {
- node.IsExpanded = true;
- node = node.Parent;
- }
- parent.Files.Add(file);
- }
- }
- else if (ele.Name == "Folder")
- {
- string folderName = ele.Attributes["Name"].Value;
- folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
- string fullPath = string.IsNullOrEmpty(parent.FullPath)
- ? folderName
- : parent.FullPath + "\\" + folderName;
- FileNode folder = new FileNode()
- {
- Name = folderName,
- IsFile = false,
- PrefixPath = prefixPath,
- Parent = parent,
- FullPath = fullPath,
- IsExpanded = !fullPath.Contains("\\"),
- IsChecked = true,
- IsEnable = true
- };
- parent.Files.Add(folder);
- if (selectionIsFolder && selectionName == folder.FullPath)
- {
- folder.IsSelected = true;
- FileNode node = folder;
- while (node.FullPath.Contains("\\"))
- {
- node.IsExpanded = true;
- node = node.Parent;
- }
- }
- CreateTreeViewItems(ele, folder, prefixPath, selectionName, selectionIsFolder);
- }
- }
- }
- static string GetRestoreAttributeValue(string prefixPath, string recipeName, string attributeName)
- {
- ParameterProvider _parameterProvider = new ParameterProvider();
- string content = _parameterProvider.LoadRestoreParameter(prefixPath, recipeName);
- XmlDocument _doc = new XmlDocument();
- _doc.LoadXml(content);
- XmlElement nodeData = _doc.SelectSingleNode($"Aitex/TableParameterData") as XmlElement;
- return nodeData.GetAttribute(attributeName);
- }
- public static void CreateRestoreTreeViewItems(XmlElement curElementNode, FileNode parent, string prefixPath, string selectionName, bool selectionIsFolder)
- {
- selectionIsFolder = false;
- foreach (XmlElement ele in curElementNode.ChildNodes)
- {
- if (ele.Name == "File")
- {
- string fileName = ele.Attributes["Name"].Value;
- fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
- string fullPath = string.IsNullOrEmpty(parent.FullPath)
- ? fileName
- : parent.FullPath + "\\" + fileName;
- FileNode file = new FileNode()
- {
- Name = fileName,
- IsFile = true,
- PrefixPath = prefixPath,
- Parent = parent,
- FullPath = fullPath,
- Creator = GetRestoreAttributeValue(prefixPath, fullPath, "CreatedBy"),
- Description = GetRestoreAttributeValue(prefixPath, fullPath, "Description"),
- CreatTime = GetRestoreAttributeValue(prefixPath, fullPath, "CreationTime"),
- ReviseTime = GetRestoreAttributeValue(prefixPath, fullPath, "LastRevisionTime"),
- Revisor = GetRestoreAttributeValue(prefixPath, fullPath, "LastRevisedBy"),
- Permission = GetRestoreAttributeValue(prefixPath, fullPath, "RecipePermission"),
- Level = GetRestoreAttributeValue(prefixPath, fullPath, "RecipeLevel"),
- };
- if (!selectionIsFolder)
- {
- file.IsSelected = true;
- FileNode node = file.Parent;
- while (node.FullPath.Contains("\\"))
- {
- node.IsExpanded = true;
- node = node.Parent;
- }
- parent.Files.Add(file);
- }
- }
- else if (ele.Name == "Folder")
- {
- string folderName = ele.Attributes["Name"].Value;
- folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
- string fullPath = string.IsNullOrEmpty(parent.FullPath)
- ? folderName
- : parent.FullPath + "\\" + folderName;
- FileNode folder = new FileNode()
- {
- Name = folderName,
- IsFile = false,
- PrefixPath = prefixPath,
- Parent = parent,
- FullPath = fullPath,
- IsExpanded = !fullPath.Contains("\\"),
- };
- parent.Files.Add(folder);
- if (selectionIsFolder && selectionName == folder.FullPath)
- {
- folder.IsSelected = true;
- FileNode node = folder;
- while (node.FullPath.Contains("\\"))
- {
- node.IsExpanded = true;
- node = node.Parent;
- }
- }
- CreateRestoreTreeViewItems(ele, folder, prefixPath, selectionName, selectionIsFolder);
- }
- }
- }
- public static List<FileNode> BuildFileNode(string prefixPath, string selectionName, bool selectionIsFolder, string fileListInXml)
- {
- List<FileNode> folders = new List<FileNode>();
- FileNode root = new FileNode() { Name = "Files", IsFile = false, FullPath = "", PrefixPath = prefixPath };
- folders.Add(root);
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(fileListInXml);
- CreateTreeViewItems(doc.DocumentElement, root, prefixPath, selectionName, selectionIsFolder);
- return folders;
- }
- public static List<FileNode> BuildRestoreFileNode(string prefixPath, string selectionName, bool selectionIsFolder, string fileListInXml)
- {
- List<FileNode> folders = new List<FileNode>();
- FileNode root = new FileNode() { Name = "Files", IsFile = false, FullPath = "", PrefixPath = prefixPath };
- folders.Add(root);
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(fileListInXml);
- CreateRestoreTreeViewItems(doc.DocumentElement, root, prefixPath, selectionName, selectionIsFolder);
- return folders;
- }
- public static ObservableCollection<FileNode> GetFileNodeParameterList(string prefixPath)
- {
- ObservableCollection<FileNode> fileList = new ObservableCollection<FileNode>();
- var tempfiles=_parameterProvider.GetFileNodeParameterList(prefixPath);
- FileNodeItemToFileNode(fileList, tempfiles);
- return fileList;
- }
- private static void FileNodeItemToFileNode(ObservableCollection<FileNode> fileList, List<FileNodeItem> fileNodeItems)
- {
- foreach (var item in fileNodeItems)
- {
- if (item.IsFile)
- {
- fileList.Add(new FileNode(item));
- }
- else
- {
- GetSubFiles(item).ForEach(x=>fileList.Add(x));
- }
- }
- }
- private static List<FileNode> GetSubFiles(FileNodeItem fileNodeItem)
- {
- List<FileNode> fileNodeList = new List<FileNode>();
- foreach (var item in fileNodeItem.Files)
- {
- if (item.IsFile)
- {
- fileNodeList.Add(new FileNode(item));
- }
- else
- {
- FileNode fileNode = new FileNode();
- GetSubFiles(item).ForEach(x => fileNode.Files.Add(x));
- fileNodeList.Add(fileNode);
- }
- }
- return fileNodeList;
- }
- }
- }
|