private static NVDRS_SETTING_UNION ConvertStringToSettingUnion(SettingValueType valueType, string valueString) { var union = new NVDRS_SETTING_UNION(); switch (valueType) { case SettingValueType.Dword: union.dwordValue = uint.Parse(valueString); break; case SettingValueType.String: union.stringValue = valueString; break; case SettingValueType.AnsiString: union.ansiStringValue = valueString; break; case SettingValueType.Binary: union.binaryValue = Convert.FromBase64String(valueString); break; default: throw new Exception("invalid value type"); } return(union); }
public string ToString(SettingValueType valueType, IFormatProvider formatProvider) { switch (valueType) { case SettingValueType.Boolean: return(BooleanValue.ToString()); case SettingValueType.DateTime: return(DateTimeValue == null ? null : DateTimeValue.Value.ToString(formatProvider)); case SettingValueType.Decimal: return(DecimalValue.ToString(formatProvider)); case SettingValueType.Integer: return(IntegerValue.ToString(formatProvider)); case SettingValueType.LongText: case SettingValueType.Json: return(LongTextValue); case SettingValueType.ShortText: case SettingValueType.SecureString: return(ShortTextValue); default: return(base.ToString()); } }
public static SettingValueEntity ToEntity(this string value, SettingValueType valueType) { var result = new SettingValueEntity { ValueType = valueType.ToString() }; if (valueType == SettingValueType.Boolean) { result.BooleanValue = Convert.ToBoolean(value); } else if (valueType == SettingValueType.DateTime) { result.DateTimeValue = Convert.ToDateTime(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.Decimal) { result.DecimalValue = Convert.ToDecimal(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.Integer) { result.IntegerValue = Convert.ToInt32(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.LongText) { result.LongTextValue = value; } else if (valueType == SettingValueType.SecureString) { result.ShortTextValue = value; } else { result.ShortTextValue = value; } return result; }
private static NVDRS_SETTING_TYPE MapValueType(SettingValueType input) { switch (input) { case SettingValueType.Binary: return(NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE); case SettingValueType.AnsiString: return(NVDRS_SETTING_TYPE.NVDRS_STRING_TYPE); case SettingValueType.String: return(NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE); default: return(NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE); } }
public SettingValueEntity SetValue(SettingValueType valueType, object value) { ValueType = valueType.ToString(); // Todo update to switch from C# 9.0 with or feature if (valueType == SettingValueType.Boolean) { BooleanValue = Convert.ToBoolean(value); } else if (valueType == SettingValueType.DateTime) { DateTimeValue = Convert.ToDateTime(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.Decimal) { DecimalValue = Convert.ToDecimal(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.Integer) { IntegerValue = Convert.ToInt32(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.PositiveInteger) { IntegerValue = Convert.ToInt32(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.LongText) { LongTextValue = Convert.ToString(value); } else if (valueType == SettingValueType.Json) { LongTextValue = Convert.ToString(value); } else if (valueType == SettingValueType.SecureString) { ShortTextValue = Convert.ToString(value); } else { ShortTextValue = Convert.ToString(value); } ShortTextValue = string.IsNullOrWhiteSpace(ShortTextValue) ? null : ShortTextValue; LongTextValue = string.IsNullOrWhiteSpace(LongTextValue) ? null : LongTextValue; return(this); }
public static SettingValueEntity ToEntity(this string value, SettingValueType valueType) { var result = new SettingValueEntity { ValueType = valueType.ToString() }; if (valueType == SettingValueType.Boolean) { result.BooleanValue = Convert.ToBoolean(value); } else if (valueType == SettingValueType.DateTime) { result.DateTimeValue = Convert.ToDateTime(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.Decimal) { result.DecimalValue = Convert.ToDecimal(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.Integer) { result.IntegerValue = Convert.ToInt32(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.LongText) { result.LongTextValue = value; } else if (valueType == SettingValueType.Json) { result.LongTextValue = value; } else if (valueType == SettingValueType.SecureString) { result.ShortTextValue = value; } else { result.ShortTextValue = value; } return(result); }
public virtual SettingValueEntity SetValue(SettingValueType valueType, string value) { ValueType = valueType.ToString(); if (valueType == SettingValueType.Boolean) { BooleanValue = Convert.ToBoolean(value); } else if (valueType == SettingValueType.DateTime) { DateTimeValue = Convert.ToDateTime(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.Decimal) { DecimalValue = Convert.ToDecimal(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.Integer) { IntegerValue = Convert.ToInt32(value, CultureInfo.InvariantCulture); } else if (valueType == SettingValueType.LongText) { LongTextValue = value; } else if (valueType == SettingValueType.Json) { LongTextValue = value; } else if (valueType == SettingValueType.SecureString) { ShortTextValue = value; } else { ShortTextValue = value; } return(this); }
public virtual object GetValue(SettingValueType valueType) { switch (valueType) { case SettingValueType.Boolean: return(BooleanValue); case SettingValueType.DateTime: return(DateTimeValue); case SettingValueType.Decimal: return(DecimalValue); case SettingValueType.Integer: return(IntegerValue); case SettingValueType.ShortText: case SettingValueType.SecureString: return(ShortTextValue); default: return(LongTextValue); } }
private void LoadCategory(SettingCategoryMetaData category, List <string> categories, XmlNode node) { string categoryText = Helper.GetAttributeValue(node, "UIText", "Uncategorised"); if (categories.Contains(categoryText) == false) { categories.Add(categoryText); } foreach (XmlNode subNode in node.ChildNodes) { if (subNode.Name == "Setting") { XmlNode settingNode = subNode; SettingValueType type = Helper.GetAttributeValue(settingNode, "Type", (SettingValueType)(-1)); string memberName = Helper.GetAttributeValue(settingNode, "MemberName", null); string uiText = Helper.GetAttributeValue(settingNode, "UIText", null); string documentationTitle = Helper.GetAttributeValue(settingNode, "DocumentationTitle", uiText); string oscAddress = Helper.GetAttributeValue(settingNode, "OscAddress", null); bool isReadonly = Helper.GetAttributeValue(settingNode, "Readonly", false); bool isHidden = Helper.GetAttributeValue(settingNode, "Hidden", false); string documentationBody = settingNode.InnerText.Trim(); if (Helper.IsNullOrEmpty(memberName) == true) { throw new Exception("One or more setting does not have a \"MemberName\" attribute."); } if (Helper.IsNullOrEmpty(uiText) == true) { throw new Exception("One or more setting does not have a \"Text\" attribute."); } if (Helper.IsNullOrEmpty(oscAddress) == true) { throw new Exception("One or more setting does not have a \"OscAddress\" attribute."); } SettingValue var = new SettingValue() { Category = categoryText, MemberName = memberName, UIText = uiText, DocumentationTitle = documentationTitle, DocumentationBody = documentationBody, OscAddress = oscAddress, IsReadOnly = isReadonly, IsHidden = isHidden, SettingValueType = type, CategoryFullMemberName = category.CategoryFullMemberName, }; allVariables.Add(var); variableLookup.Add(var.OscAddress, var); category.variables.Add(var); category.items.Add(var); } else if (subNode.Name == "Category") { XmlNode categoryNode = subNode; string subCategoryMemberName = Helper.GetAttributeValue(categoryNode, "MemberName", "Uncategorised"); string subCategoryText = Helper.GetAttributeValue(categoryNode, "UIText", "Uncategorised"); bool isHidden = Helper.GetAttributeValue(categoryNode, "Hidden", false); SettingCategoryMetaData settingCategory = new SettingCategoryMetaData() { UIText = subCategoryText, MemberName = subCategoryMemberName, Category = categoryText, CategoryFullMemberName = category.CategoryFullMemberName + "." + subCategoryMemberName, IsHidden = isHidden, }; List <string> categoriesList = new List <string>(); LoadCategory(settingCategory, categoriesList, categoryNode); ApplyOrderToCategories(settingCategory, categoriesList); category.items.Add(settingCategory); } } }