Пример #1
0
        /// <summary> Convert a space delimited color tuple string to a color.
        /// <p>
        /// Converts a string value like "255 255 0" to a color constant,
        /// in this case, yellow.
        /// *
        /// </summary>
        /// <param name="key">the name of the property
        /// </param>
        /// <returns> a Color object equivalent to the provided string contents.
        /// Returns white if the string is null or can't be converted.
        ///
        /// </returns>
        public static System.Drawing.Color getColorProperty(System.Configuration.AppSettingsReader properties, System.Object key)
        {
            System.String string_Renamed = (System.String)properties.GetValue(key.ToString(), Type.GetType("System.String"));

            if (string_Renamed == null)
            {
                System.Console.Error.WriteLine("WARN: couldn't find color tuplet under '" + key + "'");
                return(System.Drawing.Color.White);
            }

            SupportClass.Tokenizer st = new SupportClass.Tokenizer(string_Renamed, " ");
            System.Drawing.Color   c;
            try
            {
                c = System.Drawing.Color.FromArgb(System.Int32.Parse(st.NextToken()), System.Int32.Parse(st.NextToken()), System.Int32.Parse(st.NextToken()));
            }
            catch (System.Exception e)
            {
                c = System.Drawing.Color.White;
                System.Console.Error.WriteLine("WARN: invalid color spec '" + string_Renamed + "' in property file");
            }

            return(c);
        }
Пример #2
0
		/// <summary> Convert a space delimited color tuple string to a color.
		/// <p>
		/// Converts a string value like "255 255 0" to a color constant,
		/// in this case, yellow.
		/// *
		/// </summary>
		/// <param name="key">the name of the property
		/// </param>
		/// <returns> a Color object equivalent to the provided string contents. 
		/// Returns white if the string is null or can't be converted.
		/// 
		/// </returns>
		public static System.Drawing.Color getColorProperty(System.Configuration.AppSettingsReader properties, System.Object key)
		{
			System.String string_Renamed = (System.String) properties.GetValue(key.ToString(), Type.GetType("System.String"));
			
			if (string_Renamed == null)
			{
				System.Console.Error.WriteLine("WARN: couldn't find color tuplet under '" + key + "'");
				return System.Drawing.Color.White;
			}
			
			SupportClass.Tokenizer st = new SupportClass.Tokenizer(string_Renamed, " ");
			System.Drawing.Color c;
			try
			{
				c = System.Drawing.Color.FromArgb(System.Int32.Parse(st.NextToken()), System.Int32.Parse(st.NextToken()), System.Int32.Parse(st.NextToken()));
			}
			catch (System.Exception e)
			{
				c = System.Drawing.Color.White;
				System.Console.Error.WriteLine("WARN: invalid color spec '" + string_Renamed + "' in property file");
			}
			
			return c;
		}
Пример #3
0
		/// <summary> Convert a dot-delimited IP address to an integer.
		/// <p>
		/// Converts a string value like "10.0.0.5" to an integer.
		/// *
		/// </summary>
		/// <param name="key">the name of the property
		/// </param>
		/// <returns> the integer value of the specified IP number.
		/// returns zero if the IP number is not valid.
		/// 
		/// </returns>
		public static int getIpProperty(System.Configuration.AppSettingsReader properties, System.Object key)
		{
			System.String string_Renamed=null;
			try
			{
				string_Renamed = (System.String) properties.GetValue(key.ToString(), Type.GetType("System.String"));
			}
			catch//if (string_Renamed == null)
			{
				System.Console.Error.WriteLine("WARN: couldn't find IP value under '" + key + "'");
				return 0;
			}
			
			SupportClass.Tokenizer st = new SupportClass.Tokenizer(string_Renamed, ".");
			int address;
			try
			{
				address = System.Int32.Parse(st.NextToken()) << 24 | System.Int32.Parse(st.NextToken()) << 16 | System.Int32.Parse(st.NextToken()) << 8 | System.Int32.Parse(st.NextToken());
			}
			catch (System.Exception e)
			{
				address = 0;
				System.Console.Error.WriteLine("WARN: invalid color spec '" + string_Renamed + "' in property file");
			}
			
			return address;
		}