示例#1
0
        public void sendSingleValueToConfig(string fieldName)
        {
            PropertyMapping mapping = mappings[fieldName];

            switch (mapping.fieldType.ToString())
            {
            case "System.String":
                _configAdapter.writeString(fieldName, (string)mapping.fieldInfo.GetValue(this), mapping.categoryName);
                break;

            case "System.Int32":
                _configAdapter.writeInteger(fieldName, (int)mapping.fieldInfo.GetValue(this), mapping.categoryName);
                break;

            case "System.Int64":
                _configAdapter.writeInteger(fieldName, (Int64)mapping.fieldInfo.GetValue(this), mapping.categoryName);
                break;

            case "System.Single":
                _configAdapter.writeFloat(fieldName, (float)mapping.fieldInfo.GetValue(this), mapping.categoryName);
                break;

            case "System.Double":
                _configAdapter.writeDouble(fieldName, (double)mapping.fieldInfo.GetValue(this), mapping.categoryName);
                break;

            case "System.Boolean":
                _configAdapter.writeBool(fieldName, (bool)mapping.fieldInfo.GetValue(this), mapping.categoryName);
                break;

            default:
                if (mapping.GetType() == typeof(PropertyMappingEnum) && mapping.fieldType.IsSubclassOf(typeof(System.Enum)))
                {
                    _configAdapter.writeString(fieldName, mapping.fieldInfo.GetValue(this).ToString(), mapping.categoryName);
                }
                else
                {
                    throw new Exception(mapping.fieldType.ToString() + " not implemented for writing to config.");
                }
                break;
            }
        }
		private static string GetColumnNameFromPropertyMapping(EdmProperty edmProperty, PropertyMapping propertyMapping)
		{
			var colMapping = propertyMapping as ScalarPropertyMapping;
			if (colMapping == null)
			{
				throw new EnumGeneratorException(string.Format(
					"Expected ScalarPropertyMapping but found {0} when mapping property {1}", propertyMapping.GetType(), edmProperty));
			}
			return colMapping.Column.Name;
		}
        private static string GetColumnNameFromPropertyMapping(EdmProperty edmProperty, PropertyMapping propertyMapping)
        {
            var colMapping = propertyMapping as ScalarPropertyMapping;

            if (colMapping == null)
            {
                throw new EnumGeneratorException(string.Format(
                                                     "Expected ScalarPropertyMapping but found {0} when mapping property {1}", propertyMapping.GetType(), edmProperty));
            }
            return(colMapping.Column.Name);
        }
示例#4
0
        public void readSingleValueFromGUI(string fieldName)
        {
            PropertyMapping mapping = mappings[fieldName];

            switch (mapping.fieldType.ToString())
            {
            case "System.String":
                if (mapping.mappedName == null)
                {
                    break;
                }                                             // If no element is mapped to this particular element, we can't read it.
                string guiString = _dataContext.getAsString(mapping.mappedName);
                if (guiString != null)
                {
                    mapping.fieldInfo.SetValue(this, guiString);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Int32":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't read it.
                Int64?guiInt = _dataContext.getAsInteger(mapping.mappedName);
                if (guiInt.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, (int)Math.Min(Int32.MaxValue, Math.Max(Int32.MinValue, guiInt.Value)));
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Int64":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't read it.
                Int64?guiInt64 = _dataContext.getAsInteger(mapping.mappedName);
                if (guiInt64.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, guiInt64.Value);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Single":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't read it.
                float?guiFloat = _dataContext.getAsFloat(mapping.mappedName);
                if (guiFloat.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, guiFloat.Value);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Double":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't read it.
                double?guiDouble = _dataContext.getAsDouble(mapping.mappedName);
                if (guiDouble.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, guiDouble.Value);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Boolean":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't read it.
                bool?guiBool = _dataContext.getAsBool(mapping.mappedName);
                if (guiBool.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, guiBool.Value);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            default:
                if (mapping.GetType() == typeof(PropertyMappingEnum) && mapping.fieldType.IsSubclassOf(typeof(System.Enum)))
                {
                    // Radio buttons
                    int enumNumber   = -1;
                    int activeRadios = 0;
                    foreach (KeyValuePair <int, string> subMapping in (mapping as PropertyMappingEnum).mappedNames)
                    {
                        if (subMapping.Value == null)
                        {
                            continue;
                        }                                              // If no element is mapped to this particular element, we can't read it.
                        if (_dataContext.getAsBool(subMapping.Value) == true)
                        {
                            enumNumber = subMapping.Key;
                            activeRadios++;
                        }
                        if (activeRadios > 1)
                        {
                            throw new Exception(fieldName + ": Multiple simmultaneously active radio buttons for enum mapping are not allowed.");
                        }
                    }
                    if (enumNumber == -1)
                    {
                        if (mapping.defaultValue != null)
                        {
                            enumNumber = (int)mapping.defaultValue;
                        }
                    }
                    mapping.fieldInfo.SetValue(this, enumNumber);
                }
                else
                {
                    throw new Exception(mapping.fieldType.ToString() + " not implemented for reading from GUI.");
                }
                break;
            }
        }
示例#5
0
        public void sendSingleValueToGUI(string fieldName)
        {
            PropertyMapping mapping = mappings[fieldName];

            switch (mapping.fieldType.ToString())
            {
            case "System.String":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't write it.
                _dataContext.writeString(mapping.mappedName, (string)mapping.fieldInfo.GetValue(this));
                break;

            case "System.Int32":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't write it.
                _dataContext.writeInteger(mapping.mappedName, (int)mapping.fieldInfo.GetValue(this));
                break;

            case "System.Int64":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't write it.
                _dataContext.writeInteger(mapping.mappedName, (Int64)mapping.fieldInfo.GetValue(this));
                break;

            case "System.Single":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't write it.
                _dataContext.writeFloat(mapping.mappedName, (float)mapping.fieldInfo.GetValue(this));
                break;

            case "System.Double":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't write it.
                _dataContext.writeDouble(mapping.mappedName, (double)mapping.fieldInfo.GetValue(this));
                break;

            case "System.Boolean":
                if (mapping.mappedName == null)
                {
                    break;
                }                                              // If no element is mapped to this particular element, we can't write it.
                _dataContext.writeBool(mapping.mappedName, (bool)mapping.fieldInfo.GetValue(this));
                break;

            default:
                if (mapping.GetType() == typeof(PropertyMappingEnum) && mapping.fieldType.IsSubclassOf(typeof(System.Enum)))
                {
                    // Radio buttons
                    int activeRadios = 0;
                    int valueToSet   = (int)mapping.fieldInfo.GetValue(this);
                    foreach (KeyValuePair <int, string> subMapping in (mapping as PropertyMappingEnum).mappedNames)
                    {
                        if (subMapping.Value == null)
                        {
                            continue;
                        }                                               // If no element is mapped to this particular element, we can't write it.
                        if (subMapping.Key == valueToSet)
                        {
                            _dataContext.writeBool(subMapping.Value, true);
                            activeRadios++;
                        }
                        else
                        {
                            _dataContext.writeBool(subMapping.Value, false);
                        }
                        if (activeRadios > 1)
                        {
                            throw new Exception(fieldName + ": Multiple simmultaneously active radio buttons for enum mapping are not allowed.");
                        }
                    }
                }
                else
                {
                    throw new Exception(mapping.fieldType.ToString() + " not implemented for writing to GUI.");
                }
                break;
            }
        }
示例#6
0
        public void readSingleValueFromConfig(string fieldName)
        {
            PropertyMapping mapping = mappings[fieldName];

            switch (mapping.fieldType.ToString())
            {
            case "System.String":
                string guiString = _configAdapter.getAsString(fieldName, mapping.categoryName);
                if (guiString != null)
                {
                    mapping.fieldInfo.SetValue(this, guiString);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Int32":
                Int64?guiInt = _configAdapter.getAsInteger(fieldName, mapping.categoryName);
                if (guiInt.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, (int)Math.Min(Int32.MaxValue, Math.Max(Int32.MinValue, guiInt.Value)));
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Int64":
                Int64?guiInt64 = _configAdapter.getAsInteger(fieldName, mapping.categoryName);
                if (guiInt64.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, guiInt64.Value);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Single":
                float?guiFloat = _configAdapter.getAsFloat(fieldName, mapping.categoryName);
                if (guiFloat.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, guiFloat.Value);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Double":
                double?guiDouble = _configAdapter.getAsDouble(fieldName, mapping.categoryName);
                if (guiDouble.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, guiDouble.Value);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            case "System.Boolean":
                bool?guiBool = _configAdapter.getAsBool(fieldName, mapping.categoryName);
                if (guiBool.HasValue)
                {
                    mapping.fieldInfo.SetValue(this, guiBool.Value);
                }
                else if (mapping.defaultValue != null)
                {
                    mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                }
                break;

            default:
                if (mapping.GetType() == typeof(PropertyMappingEnum) && mapping.fieldType.IsSubclassOf(typeof(System.Enum)))
                {
                    string enumName = _configAdapter.getAsString(fieldName, mapping.categoryName);
                    if (enumName != null)
                    {
                        //try
                        //{
                        mapping.fieldInfo.SetValue(this, Enum.Parse(mapping.fieldType, enumName, true));     // This will throw an exception if there is an string value in the config that does not correlate to any of the enum values. But that's okay maybe.
                        //}
                        //mapping.fieldInfo.SetValue(this, (int)guiInt642.Value);
                    }
                    else if (mapping.defaultValue != null)
                    {
                        mapping.fieldInfo.SetValue(this, mapping.defaultValue);
                    }
                }
                else
                {
                    throw new Exception(mapping.fieldType.ToString() + " not implemented for reading from config.");
                }
                break;
            }
        }