public DynamoDbParameterModel(string parameterName, DynamoDBEntryType dynamoDBEntryType, string parameterValue) { switch (dynamoDBEntryType) { case DynamoDBEntryType.Numeric: parameterDictionary.Add(parameterName, new AttributeValue() { N = parameterValue }); break; case DynamoDBEntryType.Binary: parameterDictionary.Add(parameterName, new AttributeValue() { B = new MemoryStream(Encoding.UTF8.GetBytes(parameterValue ?? "")) }); break; case DynamoDBEntryType.String: parameterDictionary.Add(parameterName, new AttributeValue() { S = parameterValue }); break; default: parameterDictionary.Add(parameterName, new AttributeValue() { S = parameterValue }); break; } }
// Write the contents of a Primitive object as JSON data private static void WritePrimitive(JsonWriter writer, DynamoDBEntryType type, object value) { var stringValue = value as string; switch (type) { case DynamoDBEntryType.Numeric: writer.WriteRaw(stringValue); break; case DynamoDBEntryType.String: writer.Write(stringValue); break; case DynamoDBEntryType.Binary: var bytes = value as byte[]; var base64 = Convert.ToBase64String(bytes); writer.Write(base64); break; default: throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unsupport DynamoDBEntryType: {0}", type)); } }
public void AddParameter(string parameterName, DynamoDBEntryType dynamoDBEntryType, string parameterValue) { if (!parameterName.StartsWith(":")) { throw (new ArgumentException(ErrorStrings.ParameterMissingColon)); } if (!Regex.IsMatch(parameterName.TrimStart(':'), ResourceStrings.RegexParameterValidation)) { throw (new ArgumentException(ErrorStrings.ParameterNonAlphaNumeric)); } switch (dynamoDBEntryType) { case DynamoDBEntryType.Numeric: parameterDictionary.Add(parameterName, new AttributeValue() { N = parameterValue }); break; case DynamoDBEntryType.Binary: parameterDictionary.Add(parameterName, new AttributeValue() { B = new MemoryStream(Encoding.UTF8.GetBytes(parameterValue ?? "")) }); break; case DynamoDBEntryType.String: parameterDictionary.Add(parameterName, new AttributeValue() { S = parameterValue }); break; default: parameterDictionary.Add(parameterName, new AttributeValue() { S = parameterValue }); break; } }
ScalarAttributeType ConvertToScalarAttributeType(DynamoDBEntryType type) { switch (type) { case DynamoDBEntryType.Binary: return(ScalarAttributeType.S); case DynamoDBEntryType.Numeric: return(ScalarAttributeType.N); case DynamoDBEntryType.String: return(ScalarAttributeType.S); default: throw new Exception("Unsupported Dynamo entry type") { Data = { ["Type"] = type } }; } }
internal Primitive(object value, DynamoDBEntryType type) { Value = value; Type = type; }
/// <summary> /// Constructs an empty PrimitiveList and specifies /// the type of its elements. /// </summary> /// <param name="type"></param> public PrimitiveList(DynamoDBEntryType type) { Entries = new List <Primitive>(); Type = type; }
// Write the contents of a Primitive object as JSON data private static void WritePrimitive(JsonWriter writer, DynamoDBEntryType type, object value) { var stringValue = value as string; switch (type) { case DynamoDBEntryType.Numeric: writer.WriteRaw(stringValue); break; case DynamoDBEntryType.String: writer.Write(stringValue); break; case DynamoDBEntryType.Binary: var bytes = value as byte[]; var base64 = Convert.ToBase64String(bytes); writer.Write(base64); break; default: throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unsupport DynamoDBEntryType: {0}", type)); } }
/// <summary> /// Constructs an empty PrimitiveList and specifies /// the type of its elements. /// </summary> /// <param name="type"></param> public PrimitiveList(DynamoDBEntryType type) { Entries = new List<Primitive>(); Type = type; }
internal Primitive(object value, DynamoDBEntryType type) { Value = value; Type = type; }