Esempio n. 1
0
        public static ImageSource GetIcon(IStat stat, string originalValue, string changedValue)
        {
            if (stat.CompareStrategy == CompareStrategy.NotComparable)
            {
                return(null);
            }

            double?difference;

            if (stat.BenchmarkThreshold.Type == BenchmarkThresholdType.Relative)
            {
                difference = stat.GetDifferenceRatio(changedValue, originalValue);
            }
            else
            {
                difference = stat.GetDifference(changedValue, originalValue);
            }

            if (difference == null)
            {
                return(null);
            }

            var imageName = "Comparison";

            if (stat.CompareStrategy == CompareStrategy.Plain)
            {
                imageName += "Plain";
            }

            var differenceLevel = ((int)(difference.Value / stat.BenchmarkThreshold.Value * 4)).Clamp(-3, 3);

            imageName += differenceLevel.ToString();

            return(s_benchmarkIcons.GetOrCreate(imageName,
                                                () =>
            {
                var image = (ImageSource)BitmapImageEx.LoadAsFrozen(string.Format("Resources/Images/{0}_16.png", imageName));
                return image;
            }));
        }