public void Load() { DirectoryInfo directory; if (!Directory.Exists(path)) { directory = Directory.CreateDirectory(path); } else { directory = new DirectoryInfo(path); } FileInfo[] info = directory.GetFiles(); //sort by file name Array.Sort(info, delegate(FileInfo f1, FileInfo f2) { return(f1.Name.CompareTo(f2.Name)); }); //search for XML file first, and if found skip the other files bool foundXml = false; for (int i = 0; i < info.Length; i++) { if (info [i].Name.Contains("fileconfig") && !info [i].Extension.Contains("meta")) { List <IGCAPTReader> components = new List <IGCAPTReader> (); xmlReader.loadIGCAPNetwork(path + info[i].Name, components); foundXml = true; break; } } for (int i = 0; i < info.Length && !foundXml; i++) { string json = File.ReadAllText(info[i].FullName); if (info [i].Name.Contains("device") && !info [i].Extension.Contains("meta")) { assetAdder.LoadAsset(JsonUtility.FromJson <AssetSavable> (json)); } else if (info [i].Name.Contains("eu") && !info [i].Extension.Contains("meta")) { euAdder.LoadEconomicUnit(JsonUtility.FromJson <EuSavable> (json)); } else if (info [i].Name.Contains("settings") && !info [i].Extension.Contains("meta")) { settings.setSettings(JsonUtility.FromJson <GenerationSettings> (json)); } } }
public void loadIGCAPNetwork(String fileName, List <IGCAPTReader> components) { // IGCAPTReader tempRecord = new IGCAPTReader(); XmlDocument xmlDoc = new XmlDocument(); _endpoints = new List <int>(); if (File.Exists(fileName)) { xmlDoc.Load(fileName); XmlNodeList componentNodes = xmlDoc.SelectNodes("/Gen/Nodes/node"); // list of all the euobjects, needed to add assets to this Dictionary <int, EuSavable> euList = new Dictionary <int, EuSavable>(); Dictionary <int, string> assetList = new Dictionary <int, string>(); Dictionary <string, List <int> > assetConnections = new Dictionary <string, List <int> >(); Dictionary <int, List <int> > euConnections = new Dictionary <int, List <int> >(); foreach (XmlNode compNode in componentNodes) { // tempRecord.setID (Int32.Parse (compNode.SelectSingleNode("id").InnerText)); // tempRecord.setType(compNode.SelectSingleNode("type").InnerText); // String temp = compNode.SelectSingleNode("enableDataSending").InnerText; // if (temp.Equals("true")){ // tempRecord.setSending (true); // } // else tempRecord.setSending (false); // temp = compNode.SelectSingleNode("enableDataPassThrough").InnerText; // if (temp.Equals("true")) { // tempRecord.setPass(true); // } // else tempRecord.setPass(false); // tempRecord.setPayLoad(Int32.Parse(compNode.SelectSingleNode("payload").InnerText)); // tempRecord.setInterval (Int32.Parse(compNode.SelectSingleNode("interval").InnerText)); // tempRecord.setXCoordinate(Double.Parse(compNode.SelectSingleNode("xCoord").InnerText)); // tempRecord.setYCoordinate (Double.Parse(compNode.SelectSingleNode("yCoord").InnerText)); // tempRecord.setLat (Double.Parse (compNode.SelectSingleNode("lat").InnerText)); // tempRecord.setLong (Double.Parse (compNode.SelectSingleNode("long").InnerText)); // tempRecord.setName(compNode.SelectSingleNode("name").InnerText); // tempRecord.setLatency (float.Parse (compNode.SelectSingleNode("latency").InnerText)); // tempRecord.setAgilityP (float.Parse (compNode.SelectSingleNode("agilityp").InnerText)); // tempRecord.setAgilityQ (float.Parse (compNode.SelectSingleNode("agilityq").InnerText)); // tempRecord.setMaxP (float.Parse (compNode.SelectSingleNode("maxp").InnerText)); // tempRecord.setMaxQ (float.Parse (compNode.SelectSingleNode("maxq").InnerText)); // tempRecord.setEngergy (float.Parse (compNode.SelectSingleNode("energy").InnerText)); // tempRecord.setB1coef (float.Parse (compNode.SelectSingleNode("bcoef1").InnerText)); // tempRecord.setB2coef (float.Parse (compNode.SelectSingleNode("bcoef2").InnerText)); // tempRecord.setB3coef (float.Parse (compNode.SelectSingleNode("bcoef3").InnerText)); // tempRecord.setS1coef (float.Parse (compNode.SelectSingleNode("scoef1").InnerText)); // tempRecord.setS2coef (float.Parse (compNode.SelectSingleNode("scoef2").InnerText)); // tempRecord.setS3coef (float.Parse (compNode.SelectSingleNode("scoef3").InnerText)); // tempRecord.setIpAddress(compNode.SelectSingleNode("ipaddress").InnerText); if (compNode.SelectSingleNode("type").InnerText == "0b78060e-978d-4132-b38d-8155f4741d11") { //add eu EuSavable newEu = new EuSavable(); newEu.active = true; newEu.euname = compNode.SelectSingleNode("name").InnerText; newEu.latency = float.Parse(compNode.SelectSingleNode("latency").InnerText); newEu.assets = new List <string> (); newEu.qty = new List <int> (); euList.Add(Int32.Parse(compNode.SelectSingleNode("id").InnerText), newEu); //save the connection information List <int> endPtList = new List <int>(); XmlNodeList ElementNodes = compNode.SelectSingleNode("endPoints").SelectNodes("endPoint"); foreach (XmlNode endpoint in ElementNodes) { endPtList.Add(int.Parse(endpoint.InnerText)); } euConnections.Add(int.Parse(compNode.SelectSingleNode("id").InnerText), endPtList); } else { //add asset AssetSavable newAsset = new AssetSavable(); newAsset.aname = compNode.SelectSingleNode("name").InnerText; newAsset.active = true; newAsset.agilityP = float.Parse(compNode.SelectSingleNode("agilityp").InnerText); newAsset.agilityQ = float.Parse(compNode.SelectSingleNode("agilityq").InnerText); newAsset.maxP = float.Parse(compNode.SelectSingleNode("maxp").InnerText); newAsset.maxQ = float.Parse(compNode.SelectSingleNode("maxq").InnerText); newAsset.latency = float.Parse(compNode.SelectSingleNode("latency").InnerText); newAsset.energy = float.Parse(compNode.SelectSingleNode("energy").InnerText); if (compNode.SelectSingleNode("pacoef1") != null && compNode.SelectSingleNode("qacoef1") != null) { newAsset.palpha1 = float.Parse(compNode.SelectSingleNode("pacoef1").InnerText); newAsset.palpha2 = float.Parse(compNode.SelectSingleNode("pacoef2").InnerText); newAsset.palpha3 = float.Parse(compNode.SelectSingleNode("pacoef3").InnerText); newAsset.pbeta1 = float.Parse(compNode.SelectSingleNode("pbcoef1").InnerText); newAsset.pbeta2 = float.Parse(compNode.SelectSingleNode("pbcoef2").InnerText); newAsset.pbeta3 = float.Parse(compNode.SelectSingleNode("pbcoef3").InnerText); newAsset.qalpha1 = float.Parse(compNode.SelectSingleNode("qacoef1").InnerText); newAsset.qalpha2 = float.Parse(compNode.SelectSingleNode("qacoef2").InnerText); newAsset.qalpha3 = float.Parse(compNode.SelectSingleNode("qacoef3").InnerText); newAsset.qbeta1 = float.Parse(compNode.SelectSingleNode("qbcoef1").InnerText); newAsset.qbeta2 = float.Parse(compNode.SelectSingleNode("qbcoef2").InnerText); newAsset.qbeta3 = float.Parse(compNode.SelectSingleNode("qbcoef3").InnerText); } //create and add the unity game object assetAdder.LoadAsset(newAsset); assetList.Add(Int32.Parse(compNode.SelectSingleNode("id").InnerText), newAsset.aname); List <int> endPtList = new List <int> (); XmlNodeList ElementNodes = compNode.SelectSingleNode("endPoints").SelectNodes("endPoint"); foreach (XmlNode endpoint in ElementNodes) { endPtList.Add(int.Parse(endpoint.InnerText)); } assetConnections.Add(newAsset.aname, endPtList); } //components.Add (tempRecord); } // similar to "visited" flag in traditional graphs List <int> processedPts = new List <int> (); //process the connections on each economic unit foreach (KeyValuePair <int, List <int> > connections in euConnections) { processedPts.Clear(); foreach (int endPt in connections.Value) { List <int> toProcess = new List <int> (); toProcess.Add(endPt); for (int i = 0; i < toProcess.Count; i++) { int pt = toProcess [i]; if (processedPts.Contains(pt)) { continue; } //if this point is an asset if (assetList.ContainsKey(pt)) { //add this asset to the eu's list of assets euList [connections.Key].assets.Add(assetList [pt]); euList [connections.Key].qty.Add(1); // add all the connection points on the asset for further processing, ignoring economic units and previously processed points foreach (int nextPt in assetConnections[assetList[pt]]) { if (assetList.ContainsKey(nextPt) && !processedPts.Contains(nextPt)) { toProcess.Add(nextPt); } } } processedPts.Add(pt); } } } foreach (KeyValuePair <int, EuSavable> eu in euList) { euAdder.LoadEconomicUnit(eu.Value); } } }