コード例 #1
0
ファイル: SynTypeFileReader.cs プロジェクト: panbaked/SynType
        private static ObservableCollection<Compound> ReadBlock(XmlNodeList compoundList, COMPOUND_TYPES type)
        {
            ObservableCollection<Compound> returnList = new ObservableCollection<Compound>();
            foreach (XmlNode node in compoundList)
            {
                string localid = string.Empty;
                string name = string.Empty;
                string refid = string.Empty;
                int fileid = 0; //In the files each compound is recognized by a five digit number, so we can attach mol data
                int state = 0;
                string formula = string.Empty;
                float density = 0.0f;
                Unit mols = new Unit(0, "mol", (int)UNIT_POWERS.none);
                Unit mass = new Unit(0, "g", (int)UNIT_POWERS.none);
                Unit volume = new Unit(0, "l", (int)UNIT_POWERS.none);
                Solution solvent = new Solution("null", new Unit(0, "mol/l", (int)UNIT_POWERS.none));
                bool isLimiting = false;
                bool isTarget = false;

                foreach (XmlNode inner in node.ChildNodes)
                {

                    switch (inner.Name)
                    {
                        case "fileid":
                            fileid = int.Parse(inner.InnerText); break;
                        case "localid":
                            localid = inner.InnerText; break;
                        case "name":
                            name = inner.InnerText; break;
                        case "refid":
                            refid = inner.InnerText; break;
                        case "formula":
                            formula = inner.InnerText; break;
                        case "state":
                            string text = inner.InnerText;
                            if (text == "solid") state = 0;
                            if (text == "liquid") state = 1;
                            if (text == "gas") state = 2;
                            if (text == "solvated") state = 3;
                            break;
                        case "islimiting":
                            isLimiting = bool.Parse(inner.InnerText);
                            break;
                        case "istarget":
                            isTarget = bool.Parse(inner.InnerText);
                            break;
                        case "density":
                            if (inner.InnerText == "null") break;
                            density = float.Parse(inner.InnerText); break;
                        case "mols":
                            if(inner.InnerText == "null") break;
                            mols = new Unit(double.Parse(inner.InnerText), inner.Attributes["unit"].Value, int.Parse(inner.Attributes["unit_power"].Value));
                            break;
                        case "mass":
                            if (inner.InnerText == "null") break;
                            mass = new Unit(double.Parse(inner.InnerText), inner.Attributes["unit"].Value, int.Parse(inner.Attributes["unit_power"].Value));
                            break;
                        case "volume":
                            if (inner.InnerText == "null") break;
                            volume = new Unit(double.Parse(inner.InnerText), inner.Attributes["unit"].Value, int.Parse(inner.Attributes["unit_power"].Value));
                            break;
                        case "solvent":
                            if (inner.InnerText == "null") break;
                            solvent = new Solution(inner.InnerText, new Unit(float.Parse(inner.Attributes["conc"].Value), inner.Attributes["conc_unit"].Value, int.Parse(inner.Attributes["unit_power"].Value)));
                            break;

                    }

                }
                Compound c = new Compound(name, refid, localid, fileid, (int)type, state, isLimiting, isTarget, formula, density, mols, mass, volume, solvent);
                Console.WriteLine(c.ToString());
                returnList.Add(c);
            }
            return returnList;
        }