コード例 #1
0
ファイル: ColorScheme.cs プロジェクト: BartWeyder/mrHelper
        /// <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));
            }
        }
コード例 #2
0
ファイル: ColorScheme.cs プロジェクト: GrimMaple/mrHelper
 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);
     }
 }
コード例 #3
0
ファイル: ColorScheme.cs プロジェクト: GrimMaple/mrHelper
        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());
        }
コード例 #4
0
ファイル: ColorScheme.cs プロジェクト: GrimMaple/mrHelper
        /// <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));
            }
        }
コード例 #5
0
 /// <summary>
 /// Read scheme from file
 /// Throws ArgumentException
 /// </summary>
 internal ColorScheme(string filename, ExpressionResolver expressionResolver)
 {
     _expressionResolver = expressionResolver;
     initializeFromFile(filename);
 }