Ejemplo n.º 1
0
        /// <summary>
        /// Write plant to a xml file
        /// </summary>
        /// <param name="XMLfile"></param>
        public void saveAsXML(string XMLfile)
        {
            //XmlWriterSettings settings = new XmlWriterSettings();
            //settings.OmitXmlDeclaration = true;
            //settings.ConformanceLevel = ConformanceLevel.Fragment;
            //settings.Encoding = Encoding.UTF8;

            StreamWriter writer = File.CreateText(XMLfile); //new System.IO.StreamWriter(XMLfile);//, Encoding.Default);

            //XmlWriter writer = XmlWriter.Create(XMLfile, settings);
            //File.CreateText(XMLfile);

            writer.Write/*Raw*/ ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");

            writer.Write/*Raw*/ (String.Format("<plant id= \"{0}\">\n", id));

            writer.Write/*Raw*/ (xmlInterface.setXMLTag("name", name));
            writer.Write(xmlInterface.setXMLTag("construct_year", construct_year));
            writer.Write/*Raw*/ (g.getParamsAsXMLString());
            writer.Write/*Raw*/ (Tout.getParamsAsXMLString());

            writer.Write/*Raw*/ (myDigesters.getParamsAsXMLString());

            writer.Write/*Raw*/ (myCHPs.getParamsAsXMLString());

            writer.Write/*Raw*/ (myTransportation.getParamsAsXMLString());

            writer.Write/*Raw*/ (myFinances.getParamsAsXMLString());

            writer.Write/*Raw*/ ("</plant>\n");

            writer.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Print the plant to a string, such that it can be displayed on a
        /// console.
        /// </summary>
        /// <returns></returns>
        public string print()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("   ----------   PLANT:   " + name + "   ----------   \n");

            sb.Append("id: " + id + "\n");

            sb.Append("construction year: " + construct_year + "\n");

            sb.Append("g: " + g.printValue() + "\t\t\t");
            sb.Append("Tout: " + Tout.printValue() + "\r\n");

            //

            sb.Append(myDigesters.print());

            sb.Append(myCHPs.print());

            sb.Append(myTransportation.print());

            sb.Append(myFinances.print());

            //

            sb.Append("   ----------     END PLANT     ----------   \n");

            return(sb.ToString());
        }
Ejemplo n.º 3
0
 public void Run()
 {
     ToutPlOne = Tout + (Ts / Theta_t) * (-Tout + Kh * uk[time] + Tenv);
     ToutF     = filter.LowPassFilter(Tout);
     dateTime  = DateTime.Now;
     Plot(Tout, "Temperature Un-Filtered", chart1, 26, 20, dateTime);
     Plot(ToutF, "Temperature Filtered", chart1, 26, 20, dateTime);
     Plot(uk[time], "Control Signal", chart2, 5, 0, dateTime);
     txtPV.Text = Tout.ToString("N1");
     txtMV.Text = uk[time].ToString("N1");
     try
     {
         _writer.WriteValue(Tout);
         _writer2.WriteValue(uk[time]);
     }
     catch (TimeoutException)
     {
         MessageBox.Show("The read has timed out.", "Timeout");
         return;
     }
     Tout = ToutPlOne;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Transforms the calling instance into a regular repository class that inherits from RepositoryBase.
        /// </summary>
        /// <typeparam name="Tout">the concrete type, that the calling object will be converted into.</typeparam>
        /// <returns>The repository isntance where all mathing properties and the Items list are copied.</returns>
        public Tout To <Tout>() where Tout : IterativeRepositoryBase <T>, new()
        {
            // items
            Tout repository = new Tout();

            repository.AddRange(this.Items.ToArray());

            // properties
            var infos = GetInfo(repository);

            foreach (PropertyInfo pi in infos)
            {
                if (pi.CanWrite &&
                    Properties.ContainsKey(pi.Name))
                {
                    var raw  = Properties[pi.Name];
                    var data = Convert.ChangeType(raw, pi.PropertyType);
                    pi.SetValue(repository, data);
                }
            }

            return(repository);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor creating the plant by reading from the given xml file.
        /// </summary>
        /// <param name="XMLfile"></param>
        public plant(string XMLfile)
        {
            XmlTextReader reader = new System.Xml.XmlTextReader(XMLfile);

            string xml_tag = "";
            string param   = "";

            set_params_of();

            string plant_id = "";

            //bool finances_tag= false;      // true after finances xml tag was found <finances>

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case System.Xml.XmlNodeType.Element: // this knot is an element
                    xml_tag = reader.Name;

                    while (reader.MoveToNextAttribute())
                    { // read the attributes, here only the attribute of plant, digester and chp
                      // are of interest, all other attributes are ignored,
                      // actually there usally are no other attributes
                        if (xml_tag == "plant" && reader.Name == "id")
                        {
                            _id      = reader.Value;
                            plant_id = _id;

                            break;
                        }
                        else if (xml_tag == "physValue" && reader.Name == "symbol")
                        {
                            // found a new parameter
                            param = reader.Value;

                            switch (param)
                            {
                            case "g":
                                g.getParamsFromXMLReader(ref reader, param);
                                break;

                            case "Tout":
                                Tout.getParamsFromXMLReader(ref reader, param);
                                break;
                            }
                            break;
                        }
                    }

                    if (xml_tag == "digesters")
                    {
                        myDigesters.getParamsFromXMLReader(ref reader);
                        plant_id = "";
                    }
                    else if (xml_tag == "chps")
                    {
                        myCHPs.getParamsFromXMLReader(ref reader);
                        plant_id = "";
                    }
                    else if (xml_tag == "transportation")
                    {
                        myTransportation.getParamsFromXMLReader(ref reader);
                        plant_id = "";
                    }
                    else if (xml_tag == "finances")// && !finances_tag)
                    {
                        myFinances.getParamsFromXMLReader(ref reader);
                        plant_id = "";
                        //finances_tag= true;
                    }

                    break;

                case System.Xml.XmlNodeType.Text: // text, thus value, of each element

                    if (plant_id != "")           // ignore the text before the plant is found
                    {
                        switch (xml_tag)
                        {
                        case "name":
                            _name = reader.Value;
                            break;

                        case "construct_year": // construction year
                            _construct_year = System.Xml.XmlConvert.ToInt32(reader.Value);
                            break;
                        }
                    }
                    // löschen
                    //else if (finances_tag)
                    //{
                    //  double value = System.Xml.XmlConvert.ToDouble(reader.Value);//Convert.ToDouble(reader.Value);

                    //  myFinances.set_params_of(xml_tag, value);
                    //}
                    break;
                } // switch
            }     // while

            //

            reader.Close();
        }