///////////////////////////////////////////////////////////////////////
        /// <summary>Looks for an attribute of type int with this name.
        /// </summary>
        /// <param name="name">attribute name</param>
        /// <param name="value">value to set if the attribute is found</param>
        /// <returns>true if an attribute was found, in which case
        /// the value will have been set.</returns>
        ///////////////////////////////////////////////////////////////////////
        public bool ExtractIntAttribute(string name, out int value)
        {
            String stringValue = GetAttributeAsString(name, GBaseAttributeType.Int);

            if (stringValue == null)
            {
                value = 0;
                return(false);
            }
            value = NumberFormat.ToInt(stringValue);
            return(true);
        }
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Returns the values of all the attribute of type
        /// int with this name.</summary>
        /// <param name="name">attribute name</param>
        /// <returns>all the values found, never nul</returns>
        ///////////////////////////////////////////////////////////////////////
        public List <int> GetIntAttributes(string name)
        {
            List <int> retval = new List <int>();

            foreach (GBaseAttribute attribute
                     in GetAttributes(name, GBaseAttributeType.Int))
            {
                String content = attribute.Content;
                if (content != null)
                {
                    retval.Add(NumberFormat.ToInt(content));
                }
            }
            return(retval);
        }
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Parses the Google-Base specific parameters
        /// in the Uri.</summary>
        ///////////////////////////////////////////////////////////////////////
        protected override Uri ParseUri(Uri targetUri)
        {
            base.ParseUri(targetUri);
            if (targetUri != null)
            {
                char[] deli = { '?', '&' };

                TokenCollection tokens = new TokenCollection(targetUri.Query, deli);
                foreach (String token in tokens)
                {
                    if (token.Length > 0)
                    {
                        char[]   otherDeli  = { '=' };
                        String[] parameters = token.Split(otherDeli, 2);
                        switch (parameters[0])
                        {
                        case BqParameter:
                            this.bq = System.Web.HttpUtility.UrlDecode(parameters[1]);
                            break;

                        case MaxValuesParameter:
                            this.maxValues = NumberFormat.ToInt(parameters[1]);
                            break;

                        case OrderByParameter:
                            this.orderby = System.Web.HttpUtility.UrlDecode(parameters[1]);
                            break;

                        case SortOrderParameter:
                            this.ascending = "ascending".Equals(parameters[1]);
                            break;

                        case RefineParameter:
                            this.refine = Utilities.XSDTrue.Equals(parameters[1]);
                            break;

                        case ContentParameter:
                            this.content = System.Web.HttpUtility.UrlDecode(parameters[1]);
                            break;
                        }
                    }
                }
            }
            return(this.Uri);
        }
예제 #4
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Parses a gm:attribute tag and create the corresponding
        /// AttributeHistogram object.</summary>
        ///////////////////////////////////////////////////////////////////////
        public static AttributeHistogram Parse(XmlNode node)
        {
            if (node.Attributes != null)
            {
                string             name  = null;
                int                count = 0;
                GBaseAttributeType type  = null;

                name = Utilities.GetAttributeValue("name", node);
                String value = Utilities.GetAttributeValue("type", node);
                if (value != null)
                {
                    type = GBaseAttributeType.ForName(value);
                }
                value = Utilities.GetAttributeValue("count", node);
                if (value != null)
                {
                    count = NumberFormat.ToInt(value);
                }

                if (name != null && type != null)
                {
                    //TODO determine if this is correct.
                    List <HistogramValue> values = new List <HistogramValue>();
                    for (XmlNode child = node.FirstChild;
                         child != null;
                         child = child.NextSibling)
                    {
                        if (child.LocalName == "value")
                        {
                            value = Utilities.GetAttributeValue("count", child);

                            if (value != null)
                            {
                                int valueCount = NumberFormat.ToInt(value);
                                values.Add(new HistogramValue(child.InnerText, valueCount));
                            }
                        }
                    }
                    return(new AttributeHistogram(name, type, count, values));
                }
            }
            return(null);
        }
예제 #5
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Parses an XML representation and updates the object</summary>
        ///////////////////////////////////////////////////////////////////////
        public void Parse(XmlNode xml)
        {
            Reset();
            String value = Utilities.GetAttributeValue("total", xml);

            if (value != null)
            {
                total = NumberFormat.ToInt(value);
            }

            for (XmlNode child = xml.FirstChild; child != null; child = child.NextSibling)
            {
                if ("source".Equals(child.LocalName) && GBaseNameTable.NSGBaseMeta.Equals(child.NamespaceURI))
                {
                    string name        = Utilities.GetAttributeValue("name", child);
                    string countString = Utilities.GetAttributeValue("count", child);
                    if (name != null && countString != null)
                    {
                        this[name] = NumberFormat.ToInt(countString);
                    }
                }
            }
        }
예제 #6
0
 ///////////////////////////////////////////////////////////////////////
 /// <summary>Extracts the number and unit from a string
 /// of the form: <c>number " " unit</c></summary>
 /// <exception cref="FormatException">Thrown when the string
 /// representation could not be used to generate a valid
 /// IntUnit.</exception>
 ///////////////////////////////////////////////////////////////////////
 public IntUnit(string str)
     : base(ExtractUnit(str))
 {
     this.number = NumberFormat.ToInt(ExtractNumber(str));
 }