public static void fromTypedValue(VariableValueDto dto, TypedValue typedValue, bool preferSerializedValue) { ValueType type = typedValue.Type; if (type != null) { string typeName = type.Name; dto.Type = toRestApiTypeName(typeName); dto.ValueInfo = type.getValueInfo(typedValue); } if (typedValue is SerializableValue) { SerializableValue serializableValue = (SerializableValue)typedValue; if (serializableValue.Deserialized && !preferSerializedValue) { dto.Value = serializableValue.Value; } else { dto.Value = serializableValue.ValueSerialized; } } else if (typedValue is FileValue) { //do not set the value for FileValues since we don't want to send megabytes over the network without explicit request } else { dto.Value = typedValue.Value; } }
public static VariableValueDto fromTypedValue(TypedValue typedValue, bool preferSerializedValue) { VariableValueDto dto = new VariableValueDto(); fromTypedValue(dto, typedValue, preferSerializedValue); return(dto); }
public static VariableValueDto fromTypedValue(TypedValue typedValue) { VariableValueDto dto = new VariableValueDto(); fromTypedValue(dto, typedValue); return(dto); }
public static IDictionary <string, VariableValueDto> fromMap(VariableMap variables, bool preferSerializedValue) { IDictionary <string, VariableValueDto> result = new Dictionary <string, VariableValueDto>(); foreach (string variableName in variables.Keys) { VariableValueDto valueDto = VariableValueDto.fromTypedValue(variables.getValueTyped(variableName), preferSerializedValue); result[variableName] = valueDto; } return(result); }
public static VariableValueDto fromFormPart(string type, FormPart binaryDataFormPart) { VariableValueDto dto = new VariableValueDto(); dto.type = type; dto.value = binaryDataFormPart.BinaryContent; if (ValueType.FILE.Name.Equals(fromRestApiTypeName(type))) { string contentType = binaryDataFormPart.ContentType; if (string.ReferenceEquals(contentType, null)) { contentType = MediaType.APPLICATION_OCTET_STREAM; } dto.valueInfo = new Dictionary <>(); dto.valueInfo[FileValueType.VALUE_INFO_FILE_NAME] = binaryDataFormPart.FileName; MimeType mimeType = null; try { mimeType = new MimeType(contentType); } catch (MimeTypeParseException) { throw new RestException(Status.BAD_REQUEST, "Invalid mime type given"); } dto.valueInfo[FileValueType.VALUE_INFO_FILE_MIME_TYPE] = mimeType.BaseType; string encoding = mimeType.getParameter("encoding"); if (!string.ReferenceEquals(encoding, null)) { dto.valueInfo[FileValueType.VALUE_INFO_FILE_ENCODING] = encoding; } string transientString = mimeType.getParameter("transient"); bool isTransient = bool.Parse(transientString); if (isTransient) { dto.valueInfo[AbstractValueTypeImpl.VALUE_INFO_TRANSIENT] = isTransient; } } return(dto); }
public static void fromTypedValue(VariableValueDto dto, TypedValue typedValue) { fromTypedValue(dto, typedValue, false); }