public AttachmentDetailsDto(AttachmentValue fieldValue) { if (fieldValue == null) { throw new ArgumentNullException(nameof(fieldValue)); } if (fieldValue.FieldValueAttachment == null) { throw new ArgumentNullException(nameof(fieldValue.FieldValueAttachment)); } Id = fieldValue.FieldValueAttachment.Id; FileName = fieldValue.FieldValueAttachment.FileName; }
public void Deserialize(string content) { // make sure that the parameter starts with ATTACH if (!content.ToUpper().StartsWith(Markup)) { throw new ArgumentException($"Invalid attachment detected! Component property needs to start with { Markup } keyword!"); } // deserialize parameters Parameters = content.Substring(Markup.Length, content.IndexOf(':') - Markup.Length) .Split(';', StringSplitOptions.RemoveEmptyEntries) .Select(x => CalendarFactory.DeserializePropertyParameter(x)) .ToList(); // extract the value content string valueContent = content.Substring(content.IndexOf(':') + 1).Trim(); // deserialize inline attachment if (Encoding != null) { // make sure that encoding and value type parameter are valid if (Encoding.Encoding != InlineEncodingType.Base64) { throw new ArgumentException("Invalid parameter detected! Encoding needs to be set to base64!"); } if (ValueType.ValueType != PropertyValueType.Binary) { throw new ArgumentException("Invalid parameter detected! Value type needs to be set to binary!"); } // deserialize binary content Content = new AttachmentValue(ObjectSerializer.Deserialize <BinaryValue>(valueContent)); } // deserialize relative attachment else { Content = new AttachmentValue(ObjectSerializer.Deserialize <UriValue>(valueContent)); } // make sure that the format type parameter only occurs once if (Parameters.Where(x => x.GetType() == typeof(FormatTypeParameter)).Count() > 1) { throw new ArgumentException("Invalid parameter detected! Format type parameter needs to be unique!"); } }
public AttachmentProperty(AttachmentValue content, IEnumerable <IPropertyParameter> parameters) { Content = content; Parameters = parameters; }