protected bool LoadPCDInfo() { UnloadPCDInfo(); try { if (!File.Exists(PCDFile)) { return(false); } PadtCodeRepository repository = new PadtCodeRepository(); if (repository.LoadRepositoryEx(PCDFile, 1) == 0) { Trace.WriteLine(string.Format("Load repository from PCD file [{0}] failed!", PCDFile)); return(false); } IPadtCRDNode root = repository.GetBaseNode() as IPadtCRDNode; if (root == null) { return(false); } ResourceType type = (ResourceType)root.GetType(); if (type != ResourceType.kCrdExeNode) { Trace.WriteLine(string.Format("Root node's type is {0}, it should be {1}!", type, ResourceType.kCrdExeNode)); return(false); } string path = root.GetInstancePath(); if (string.Compare(CrdPath, path, true) != 0) { Trace.WriteLine(string.Format("CPU name in PCD file is {0}, it should be {1}!", path, CrdPath)); return(false); } string shownText = ShownText; if (!CreateResource(root)) { return(false); } CrdPath = path.ToUpper(); ShownText = shownText; CreateTasks(root.GetChildList() as IPadtCRDNodeList); CreateDVariables(); } catch (Exception ee) { Trace.WriteLine("### [" + ee.Source + "] Exception: " + ee.Message); Trace.WriteLine("### " + ee.StackTrace); return(false); } return(true); }
protected void CreateTasks(IPadtCRDNodeList nodes) { if (nodes == null || nodes.GetCount() <= 0) { return; } nodes.SetToHeadPos(); while (true) { IPadtCRDNode node = nodes.GetNext() as IPadtCRDNode; if (node == null) { break; } switch ((ResourceType)node.GetType()) { case ResourceType.kCrdTaskNode: case ResourceType.kCrdTaskContainerNode: CreateTasks(node.GetChildList() as IPadtCRDNodeList); break; case ResourceType.kCrdTuiTaskNode: ViGETResTask task = new ViGETResTask(); if (task.CreateTask(node)) { if (DTasks.ContainsKey(task.Key)) { DTasks[task.Key].DBlocks = task.DBlocks; DTasks[task.Key].DVariables = task.DVariables; } else { string shownPath = task.ShownPath; if (DTasks.ContainsKey(shownPath)) { ViGETResTask exist = DTasks[shownPath]; exist.CrdPath = task.CrdPath; exist.DBlocks = task.DBlocks; exist.DVariables = task.DVariables; } else { DTasks[task.Key] = task; } } } break; } } }
/// <summary> /// 根据 PADT 的 Node 信息,创建 Task。 /// </summary> /// <param name="node">PADT Task Node</param> /// <returns>成功与否?</returns> public bool CreateTask(IPadtCRDNode node) { if (!CreateResource(node)) { return(false); } IPadtCRDNodeList children = node.GetChildList() as IPadtCRDNodeList; if (children == null || children.GetCount() <= 0) { return(true); } children.SetToHeadPos(); while (true) { node = children.GetNext() as IPadtCRDNode; if (node == null) { break; } switch ((ResourceType)node.GetType()) { case ResourceType.kCrdProgramNode: case ResourceType.kCrdFbNode: case ResourceType.kCrdFunctionNode: ViGETResBlock block = new ViGETResBlock(); if (block.CreateBlock(node)) { DBlocks[block.Key] = block; } break; case ResourceType.kCrdVariableNode: ViGETResVariable variable = new ViGETResVariable(); if (variable.CreateVariable(node)) { DVariables[variable.Key] = variable; } break; } } return(true); }