Exemplo n.º 1
0
        /// <summary>
        /// Initialize all Datum values.
        /// </summary>
        public void Initialize()
        {
            PerfDatum perfdatum = new PerfDatum();

            perfdatum.Name = PerfMaximumAttribute;
            perfdatum.Unit = Constants.PerfSubResultUnit;
            perfdatumlist.Add(PerfMaximumAttribute, perfdatum);

            perfdatum      = new PerfDatum();
            perfdatum.Name = PerfMinimumAttribute;
            perfdatum.Unit = Constants.PerfSubResultUnit;
            perfdatumlist.Add(PerfMinimumAttribute, perfdatum);

            perfdatum            = new PerfDatum();
            perfdatum.Name       = PerfAverageAttribute;
            perfdatum.Unit       = Constants.PerfSubResultUnit;
            perfdatum.Comparator = true;
            perfdatumlist.Add(PerfAverageAttribute, perfdatum);

            perfdatum      = new PerfDatum();
            perfdatum.Name = PerfNumberofIterations;
            perfdatum.Unit = null;
            perfdatumlist.Add(PerfNumberofIterations, perfdatum);

            perfdatum      = new PerfDatum();
            perfdatum.Name = PerfElapsedTime;
            perfdatum.Unit = Constants.PerfSubResultUnit;
            perfdatumlist.Add(PerfElapsedTime, perfdatum);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read subresult values from a XmlNode.
        /// </summary>
        /// <param name="subresultnode"></param>
        /// <returns></returns>
        public bool ReadSubResult(XmlNode subresultnode)
        {
            if (subresultnode == null)
            {
                return(false);
            }

            if (subresultnode.Attributes[PerfNameAttribute] == null)
            {
                return(false);
            }

            subresultname = subresultnode.Attributes[PerfNameAttribute].Value;

            // Derive the project file from subresult.
            int index = subresultname.IndexOf('(');

            if (index < 0)
            {
                return(false);
            }

            projectfilename = subresultname.Substring(0, index);

            for (int i = 0; i < subresultnode.ChildNodes.Count; i++)
            {
                XmlNode datumnode = subresultnode.ChildNodes[i];
                if (datumnode.Name != PerfDatumElement)
                {
                    continue;
                }

                for (int j = 0; j < datumnode.Attributes.Count; j++)
                {
                    XmlAttribute datumattribute = datumnode.Attributes[j];
                    PerfDatum    datum;
                    string       millisecondvalue = null;
                    switch (datumattribute.Value)
                    {
                    case PerfMaximumAttribute:
                    case PerfMinimumAttribute:
                    case PerfAverageAttribute:
                    case PerfElapsedTime:
                        datum      = new PerfDatum();
                        datum.Name = datumattribute.Value;
                        if (datumnode.Attributes[PerfValueAttribute] == null)
                        {
                            continue;
                        }

                        millisecondvalue = datumnode.Attributes[PerfValueAttribute].Value;
                        if (String.IsNullOrEmpty(millisecondvalue))
                        {
                            continue;
                        }

                        millisecondvalue = millisecondvalue.Trim();

                        index = millisecondvalue.IndexOf(Constants.PerfSubResultUnit);
                        if (String.IsNullOrEmpty(Constants.PerfSubResultUnit) == false && index >= 0)
                        {
                            datum.Unit       = Constants.PerfSubResultUnit;
                            millisecondvalue = millisecondvalue.Substring(0, index);
                        }

                        if (datumnode.Attributes[PerfComparatorAttribute] != null &&
                            String.IsNullOrEmpty(datumnode.Attributes[PerfComparatorAttribute].Value) == false)
                        {
                            if (datumnode.Attributes[PerfComparatorAttribute].Value.ToLowerInvariant() == PerfComparatorYes)
                            {
                                datum.Comparator = true;
                            }
                        }

                        if (String.IsNullOrEmpty(millisecondvalue) == false)
                        {
                            millisecondvalue = millisecondvalue.Trim();
                            datum.Value      = Convert.ToDecimal(millisecondvalue);
                            if (perfdatumlist.Contains(datum.Name) == false)
                            {
                                this.perfdatumlist.Add(datum.Name, datum);
                            }
                        }
                        break;

                    case PerfNumberofIterations:
                        datum      = new PerfDatum();
                        datum.Name = datumattribute.Value;
                        if (datumnode.Attributes[PerfValueAttribute] == null)
                        {
                            continue;
                        }

                        millisecondvalue = datumnode.Attributes[PerfValueAttribute].Value;
                        if (String.IsNullOrEmpty(millisecondvalue) == false)
                        {
                            millisecondvalue = millisecondvalue.Trim();
                            datum.Value      = Convert.ToInt16(millisecondvalue);
                            if (perfdatumlist.Contains(datum.Name) == false)
                            {
                                this.perfdatumlist.Add(datum.Name, datum);
                            }
                        }
                        break;
                    }
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns SubResults node outerxml.
        /// </summary>
        /// <returns></returns>
        public string GetSubResultXml(bool comparenode)
        {
            XmlDocument         xmldoc      = new XmlDocument();
            XmlDocumentFragment docfragment = xmldoc.CreateDocumentFragment();

            XmlNode subresultnode = xmldoc.CreateElement(Constants.PerfSubResultElement);

            docfragment.AppendChild(subresultnode);

            XmlAttribute attrib = xmldoc.CreateAttribute(PerfNameAttribute);

            attrib.Value = subresultname;
            subresultnode.Attributes.Append(attrib);

            string[] perfdataorder = new string[] {
                "Maximum",
                "Minimum",
                "Average",
                "Elapsed Time",
                "Number of Iterations"
            };

            for (int i = 0; i < perfdataorder.Length; i++)
            {
                string currentperfdata = perfdataorder[i].ToLowerInvariant();

                if (perfdatumlist[PerfAverageAttribute] != null)
                {
                    PerfDatum pd = (PerfDatum)perfdatumlist[PerfAverageAttribute];
                    if ((int)pd.Value == 0)
                    {
                        return(null);
                    }
                }

                IDictionaryEnumerator ide = perfdatumlist.GetEnumerator();
                while (ide.MoveNext())
                {
                    if (currentperfdata == ide.Key.ToString().ToLowerInvariant())
                    {
                        XmlNode node = xmldoc.CreateElement(PerfDatumElement);

                        attrib       = xmldoc.CreateAttribute(PerfNameAttribute);
                        attrib.Value = ide.Key.ToString();
                        node.Attributes.Append(attrib);

                        PerfDatum pd = (PerfDatum)ide.Value;
                        //if (perfdataorder[i].ToLowerInvariant() == "average" &&
                        //    (int)pd.Value == 0)
                        //{
                        //    node = null;
                        //    attrib = null;
                        //    continue;
                        //}

                        attrib = xmldoc.CreateAttribute(PerfValueAttribute);
                        if (String.IsNullOrEmpty(pd.Unit))
                        {
                            attrib.Value = ((int)pd.Value).ToString();
                        }
                        else
                        {
                            attrib.Value = ((int)pd.Value).ToString() + " " + pd.Unit;
                        }
                        node.Attributes.Append(attrib);

                        if (pd.Comparator)
                        {
                            attrib       = xmldoc.CreateAttribute(PerfComparatorAttribute);
                            attrib.Value = PerfComparatorYes;
                            node.Attributes.Append(attrib);
                        }

                        subresultnode.AppendChild(node);
                        node   = null;
                        attrib = null;
                        break;
                    }
                }
            }

            string outerxml = null;

            if (comparenode)
            {
                subresultnode.AppendChild(xmldoc.CreateComment(projectfilename));
                outerxml = subresultnode.InnerXml;
            }
            else
            {
                outerxml = subresultnode.OuterXml;
            }
            subresultnode = null;

            xmldoc      = null;
            docfragment = null;

            return(outerxml);
        }