// convert ANY incoming type that has city field and a state abbreviation to "City, State"
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            try
            {
                // use a dynamic to allow any type in
                dynamic address = value;
                String  city    = (address.City ?? String.Empty).Trim();
                String  state   = (address.State ?? String.Empty).Trim();

                // look up the state/provincial abbreviation
                if (StateLookup.ContainsKey(state))
                {
                    state = StateLookup[state];
                }

                // return a formatted value
                if (String.IsNullOrEmpty(city))
                {
                    return(state);
                }
                else
                {
                    return(String.Format("{0}, {1}", city, state));
                }
            }
            catch
            {
                // eat the exception (probably from non-existing property on dynamic type) and just return the original value
            }

            return(value);
        }
Exemple #2
0
        double MaxQ(string stateName)
        {
            const double defaultValue = 0;

            if (!StateLookup.ContainsKey(stateName))
            {
                return(defaultValue);
            }

            QState state            = StateLookup[stateName];
            var    actionsFromState = state.Actions;
            double?maxValue         = null;

            foreach (var nextState in actionsFromState)
            {
                foreach (var actionResult in nextState.ActionsResult)
                {
                    double value = actionResult.QEstimated;
                    if (value > maxValue || !maxValue.HasValue)
                    {
                        maxValue = value;
                    }
                }
            }

            // no update
            if (!maxValue.HasValue && ShowWarning)
            {
                QMethod.Log(string.Format("Warning: No MaxQ value for stateName {0}",
                                          stateName));
            }

            return(maxValue.HasValue ? maxValue.Value : defaultValue);
        }