Пример #1
0
        public void TestEndsWith_String_String()
        {
            CMLStack stack = new CMLStack();

            stack.Push("first");
            stack.Push("second");
            Assert.IsFalse(stack.EndsWith("second", "first"));
            Assert.IsTrue(stack.EndsWith("first", "second"));
            stack.Push("third");
            Assert.IsTrue(stack.EndsWith("second", "third"));
        }
Пример #2
0
        /// <summary>
        /// Finish up parsing of elements in mdmolecule.
        /// </summary>
        /// <param name="xpath"></param>
        /// <param name="element"></param>
        public override void EndElement(CMLStack xpath, XElement element)
        {
            if (element.Name.Equals(XName_CML_molecule))
            {
                // add chargeGroup, and then delete them
                if (currentChargeGroup != null)
                {
                    if (CurrentMolecule is MDMolecule)
                    {
                        ((MDMolecule)CurrentMolecule).AddChargeGroup(currentChargeGroup);
                    }
                    else
                    {
                        Trace.TraceError("Need to store a charge group, but the current molecule is not a MDMolecule!");
                    }
                    currentChargeGroup = null;
                }
                else

                // add chargeGroup, and then delete them
                if (currentResidue != null)
                {
                    if (CurrentMolecule is MDMolecule)
                    {
                        ((MDMolecule)CurrentMolecule).AddResidue(currentResidue);
                    }
                    else
                    {
                        Trace.TraceError("Need to store a residue group, but the current molecule is not a MDMolecule!");
                    }
                    currentResidue = null;
                }
                else
                {
                    base.EndElement(xpath, element);
                }
            }
            else if (element.Name == XName_CML_atomArray)
            {
                if (xpath.Count == 2 && xpath.EndsWith("molecule", "atomArray"))
                {
                    StoreAtomData();
                    NewAtomData();
                }
                else if (xpath.Count > 2 && xpath.EndsWith("cml", "molecule", "atomArray"))
                {
                    StoreAtomData();
                    NewAtomData();
                }
            }
            else if (element.Name == XName_CML_bondArray)
            {
                if (xpath.Count == 2 && xpath.EndsWith("molecule", "bondArray"))
                {
                    StoreBondData();
                    NewBondData();
                }
                else if (xpath.Count > 2 && xpath.EndsWith("cml", "molecule", "bondArray"))
                {
                    StoreBondData();
                    NewBondData();
                }
            }
            else if (element.Name == XName_CML_scalar)
            {
                //Residue number
                if (string.Equals("md:resNumber", DictRef, StringComparison.Ordinal))
                {
                    int myInt = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);
                    currentResidue.SetNumber(myInt);
                }
                //ChargeGroup number
                else if (string.Equals("md:cgNumber", DictRef, StringComparison.Ordinal))
                {
                    int myInt = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);
                    currentChargeGroup.SetNumber(myInt);
                }
            }
            else
            {
                base.EndElement(xpath, element);
            }
        }