Exemplo n.º 1
0
        /// <summary>
        /// Read scheme from file
        /// Throws ArgumentException
        /// Throws ArgumentNullException
        /// Throws InvalidOperationException
        /// </summary>
        internal ColorScheme(string filename, ExpressionResolver expressionResolver)
        {
            _expressionResolver = expressionResolver;

            if (!System.IO.File.Exists(filename))
            {
                throw new ArgumentException(String.Format("Cannot find file \"{0}\"", filename));
            }

            Dictionary <string, object> colors = JsonUtils.LoadFromFile <Dictionary <string, object> >(filename);

            foreach (KeyValuePair <string, object> record in colors)
            {
                string[] rgbs = record.Value.ToString().Split(',');
                if (rgbs.Length != 3)
                {
                    continue;
                }

                if (!int.TryParse(rgbs[0], out int r) ||
                    !int.TryParse(rgbs[1], out int g) ||
                    !int.TryParse(rgbs[2], out int b))
                {
                    continue;
                }

                setColor(record.Key, Color.FromArgb(r, g, b));
            }
        }
Exemplo n.º 2
0
 public IEnumerator <KeyValuePair <string, Color> > GetEnumerator()
 {
     foreach (KeyValuePair <string, Color> color in _colors)
     {
         string resolvedKey = ExpressionResolver.Resolve(color.Key);
         KeyValuePair <string, Color> keyValuePair =
             new KeyValuePair <string, Color>(resolvedKey, color.Value);
         yield return(keyValuePair);
     }
 }
Exemplo n.º 3
0
        private T findColor <T>(string name, Func <Color, T> found, Func <T> notFound)
        {
            foreach (KeyValuePair <string, Color> color in _colors)
            {
                string resolvedKey = ExpressionResolver.Resolve(color.Key);
                if (name == resolvedKey)
                {
                    return(found(color.Value));
                }
            }

            return(notFound());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Read scheme from file
        /// Throws ArgumentException
        /// Throws ArgumentNullException
        /// Throws InvalidOperationException
        /// </summary>
        internal ColorScheme(string filename, ExpressionResolver expressionResolver)
        {
            ExpressionResolver = expressionResolver;

            if (!System.IO.File.Exists(filename))
            {
                throw new ArgumentException(String.Format("Cannot find file \"{0}\"", filename));
            }

            string json = System.IO.File.ReadAllText(filename);

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            Dictionary <string, object> colors;

            try
            {
                colors = (Dictionary <string, object>)serializer.DeserializeObject(json);
            }
            catch (Exception) // whatever JSON exception
            {
                throw;
            }

            foreach (var record in colors)
            {
                string[] rgbs = record.Value.ToString().Split(',');
                if (rgbs.Length != 3)
                {
                    continue;
                }

                if (!int.TryParse(rgbs[0], out int r) ||
                    !int.TryParse(rgbs[1], out int g) ||
                    !int.TryParse(rgbs[2], out int b))
                {
                    continue;
                }

                setColor(record.Key, Color.FromArgb(r, g, b));
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Read scheme from file
 /// Throws ArgumentException
 /// </summary>
 internal ColorScheme(string filename, ExpressionResolver expressionResolver)
 {
     _expressionResolver = expressionResolver;
     initializeFromFile(filename);
 }