Exemplo n.º 1
0
        private void WritePredictions(string AssemblyPath)
        {
            PredictWrapper pw = new PredictWrapper(AssemblyPath, 2018, week);
            Dictionary <string, string> predictions = pw.GetPredictions(week);

            int i = 1;

            if (!header)
            {
                DataGridTextColumn col1 = new DataGridTextColumn();
                col1.Header  = "Contestant";
                col1.Binding = new Binding("Contestant");
                PickerGrid.Columns.Add(col1);

                foreach (string key in predictions.Keys)
                {
                    DataGridTemplateColumn col = new DataGridTemplateColumn();
                    col.Header = key;
                    col.Width  = new DataGridLength(80);

                    FrameworkElementFactory factory = new FrameworkElementFactory(typeof(Image));
                    Binding b = new Binding("p" + i);
                    b.Mode = BindingMode.TwoWay;
                    factory.SetValue(Image.SourceProperty, b);
                    DataTemplate cellTemplate = new DataTemplate();
                    cellTemplate.VisualTree = factory;
                    col.CellTemplate        = cellTemplate;

                    PickerGrid.Columns.Add(col);
                    i++;
                }

                header = true;
            }

            Prediction p = new Prediction
            {
                Contestant = pw.PredictorName
            };

            i = 1;
            foreach (DataGridColumn c in PickerGrid.Columns)
            {
                string key = c.Header.ToString();
                if (predictions.ContainsKey(key))
                {
                    PropertyInfo pi   = p.GetType().GetProperty("p" + i);
                    BitmapImage  icon = new BitmapImage(new Uri(@"..\..\icons\" + predictions[key] + ".gif", UriKind.Relative));
                    pi.SetValue(p, icon);
                    i++;
                }
            }

            PickerGrid.Items.Add(p);
        }
        public double EvaluateNumerically(string propertyName)
        {
            PropertyInfo info = typeof(TickDiffPair).GetProperty(propertyName);

            if (info != null)
            {
                return((double)info.GetValue(this));
            }
            else
            {
                info = Prediction.GetType().GetProperty(propertyName);
                if (info != null)
                {
                    return((double)info.GetValue(Prediction));
                }
                else
                {
                    PropertyNotSupportedException e = new PropertyNotSupportedException($"{propertyName} is not a valid property for type {nameof(TickDiffPair)}");
                    throw e;
                }
            }
        }