public void ReadSources(Dictionary <long, ResourceDescription> cimSources, Dictionary <long, ResourceDescription> cimTerminals) { Dictionary <long, MPNode> nodes = internalModel.Nodes; Dictionary <long, MPRoot> roots = internalModel.Roots; Dictionary <long, MPBranch> branches = internalModel.Branches; foreach (ResourceDescription source in cimSources.Values) { long rootId = source.Id; List <long> terminalsID = source.GetProperty(ModelCode.CONDEQ_TERMINALS).AsReferences(); if (terminalsID.Count < 1) { string message = "Invalid CIM model. Root must have at least one terminal"; Logger.LogError(message); throw new Exception(message); } //TODO: svi treba da imaju istu faznost ResourceDescription firstTerminal = cimTerminals[terminalsID[0]]; EPhaseCode phaseCode = (EPhaseCode)firstTerminal.GetProperty(ModelCode.TERMINAL_PHASES).AsEnum(); if (nodes.ContainsKey(rootId)) { string message = $"Bad input file. There is already root node with specific gid ({rootId:X16})."; Logger.LogError(message); throw new Exception(message); } if (!roots.ContainsKey(rootId)) { MPRootNode rootNode = new MPRootNode(rootId, rootId, phaseCode); nodes.Add(rootId, rootNode); MPRoot root = new MPRoot(rootId, rootId); roots.Add(rootId, root); long rootConnNode = firstTerminal.GetProperty(ModelCode.TERMINAL_CONNECTIVITYNODE).AsReference(); MPBranch rootBranch = new MPLine(rootId, phaseCode, rootId, rootConnNode); branches.Add(rootId, rootBranch); } } isRootsInitialized = true; }
public void ReadRootsFromFile() { String file_name = "Roots.xml"; Dictionary <long, MPNode> listOfNodes = internalModel.Nodes; Dictionary <long, MPBranch> listOfBranches = internalModel.Branches; Dictionary <long, MPRoot> roots = internalModel.Roots; XmlDocument xml_doc = new XmlDocument(); xml_doc.Load(file_path + file_name); XmlNodeList xnList = xml_doc.SelectNodes("/Roots/Root"); foreach (XmlElement xml_elem in xnList) { long root_lid = UInt32.Parse(xml_elem.GetAttribute("LID")); long node_lid = UInt32.Parse(xml_elem["Node"].InnerText); EPhaseCode phases = (EPhaseCode)Byte.Parse(xml_elem["Phases"].InnerText); if (listOfNodes.ContainsKey(node_lid)) { throw new Exception("Bad input file. There is already root node with specific lid."); } if (!roots.ContainsKey(root_lid)) { MPRootNode rootNode = new MPRootNode(node_lid, root_lid, EPhaseCode.ABC); listOfNodes.Add(node_lid, rootNode); MPRoot root = new MPRoot(root_lid, node_lid); roots.Add(root_lid, root); } } }