Exemplo n.º 1
0
    public void LoadEconomicUnit(EuSavable savedEu)
    {
        GameObject newEu = Instantiate(euPrefab, this.gameObject.transform);

        EconomicUnit euComponent = newEu.GetComponent <EconomicUnit> ();

        euComponent.euname      = savedEu.euname;
        euComponent.latency     = savedEu.latency;
        euComponent.description = savedEu.description;
        euComponent.GetComponentInChildren <Text> ().text = savedEu.euname;

        euComponent.setActive(savedEu.active);

        for (int i = 0; i < savedEu.assets.Count; i++)
        {
            GameObject asset = GameObject.Find(savedEu.assets [i]);
            euComponent.addAsset(ref asset, savedEu.qty[i]);
        }
    }
Exemplo n.º 2
0
    public void save()
    {
        string jsonData;

        //delete all files in directory before proceeding
        DirectoryInfo directory = new DirectoryInfo(path);

        FileInfo[] info = directory.GetFiles();

        for (int i = 0; i < info.Length; i++)
        {
            info [i].Delete();
        }

        foreach (Transform child in assetContainer.transform)
        {
            //save all the assets
            Asset        asset     = child.GetComponent <Asset> ();
            AssetSavable assetSave = new AssetSavable();

            assetSave.nameIndex = asset.nameIndex;
            assetSave.aname     = asset.aname;
            assetSave.latency   = asset.latency;
            assetSave.agilityP  = asset.agilityP;
            assetSave.agilityQ  = asset.agilityQ;
            assetSave.maxP      = asset.maxP;
            assetSave.maxQ      = asset.maxQ;
            assetSave.energy    = asset.energy;
            assetSave.active    = asset.active;

            assetSave.palpha1 = asset.palpha1;
            assetSave.palpha2 = asset.palpha2;
            assetSave.palpha3 = asset.palpha3;
            assetSave.pbeta1  = asset.pbeta1;
            assetSave.pbeta2  = asset.pbeta2;
            assetSave.pbeta3  = asset.pbeta3;

            assetSave.qalpha1 = asset.qalpha1;
            assetSave.qalpha2 = asset.qalpha2;
            assetSave.qalpha3 = asset.qalpha3;
            assetSave.qbeta1  = asset.qbeta1;
            assetSave.qbeta2  = asset.qbeta2;
            assetSave.qbeta3  = asset.qbeta3;

            assetSave.load = asset.load;

            //Convert to Json
            jsonData = JsonUtility.ToJson(assetSave);

            //Save Json string
            string fileName = "device" + assetSave.aname;
            File.WriteAllText(path + fileName, jsonData);
        }

        // save all the economic units
        foreach (Transform child in euContainer.transform)
        {
            EconomicUnit eu     = child.GetComponent <EconomicUnit> ();
            EuSavable    euSave = new EuSavable();
            euSave.assets  = new List <string> ();
            euSave.qty     = new List <int> ();
            euSave.euname  = eu.euname;
            euSave.active  = eu.active;
            euSave.latency = eu.latency;

            Transform listingContainer = child.Find("Scroll View/Viewport/Content");

            // save each device and the quantity
            foreach (Transform listing in listingContainer)
            {
                euSave.assets.Add(listing.GetComponentInChildren <Text>().text);
                euSave.qty.Add(int.Parse(listing.GetComponentInChildren <InputField>().text));
            }

            //Convert to Json
            jsonData = JsonUtility.ToJson(euSave);

            //Save Json string
            File.WriteAllText(path + "eu" + euSave.euname, jsonData);
        }

        // save generation settings
        jsonData = JsonUtility.ToJson(settings.GetSettings());

        //save Json string
        File.WriteAllText(path + "settings", jsonData);
    }
Exemplo n.º 3
0
    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);
            }
        }
    }