public AttachmentName[] GetNames(object entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (DocumentsByEntity.TryGetValue(entity, out var document) == false)
            {
                ThrowEntityNotInSession(entity);
            }

            if (document.Metadata.TryGet(Constants.Documents.Metadata.Attachments, out BlittableJsonReaderArray attachments) == false)
            {
                return(Array.Empty <AttachmentName>());
            }

            var results = new AttachmentName[attachments.Length];

            for (var i = 0; i < attachments.Length; i++)
            {
                var attachment = (BlittableJsonReaderObject)attachments[i];
                results[i] = JsonDeserializationClient.AttachmentName(attachment);
            }
            return(results);
        }
        /// <inheritdoc/>
        public void WriteYaml(IEmitter emitter, object value, Type type)
        {
            AttachmentName name = default;

            if (value is AttachmentName locAttachment)
            {
                name = locAttachment;
            }

            emitter.Emit(new Scalar(name.ToString()));
        }
Exemple #3
0
        /// <summary>
        /// Converts the string representation of a <see cref="AttachmentName"/> to its <see cref="AttachmentName"/> equivalent.
        /// A return value indicates whether the conversion is succeeded or failed.
        /// </summary>
        /// <param name="s">The <see cref="string"/> to convert.</param>
        /// <param name="name">The converted <see cref="string"/>.</param>
        /// <returns><see langword="true"/> if <see cref="string"/> was converted successfully; otherwise, <see langword="false"/>.</returns>
        public static bool TryParse(string s, out AttachmentName name)
        {
            name = default;

            foreach (AttachmentName attachmentNameTranslation in Enum.GetValues(typeof(AttachmentName)))
            {
                if (attachmentNameTranslation.ToString() != s)
                {
                    continue;
                }

                name = attachmentNameTranslation;
                return(true);
            }

            return(false);
        }
        public AttachmentName[] GetNames(object entity)
        {
            if (entity == null ||
                DocumentsByEntity.TryGetValue(entity, out DocumentInfo document) == false ||
                document.Metadata.TryGet(Constants.Documents.Metadata.Attachments, out BlittableJsonReaderArray attachments) == false)
            {
                return(Array.Empty <AttachmentName>());
            }

            var results = new AttachmentName[attachments.Length];

            for (var i = 0; i < attachments.Length; i++)
            {
                var attachment = (BlittableJsonReaderObject)attachments[i];
                results[i] = JsonDeserializationClient.AttachmentName(attachment);
            }
            return(results);
        }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AttachmentIdentifier"/> struct.
 /// </summary>
 /// <param name="code">The code of the attachment.</param>
 /// <param name="name">The name of the attachment.</param>
 /// <param name="slot">The slot of the attachment.</param>
 internal AttachmentIdentifier(uint code, AttachmentName name, AttachmentSlot slot)
 {
     Code = code;
     Name = name;
     Slot = slot;
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AttachmentIdentifier"/> struct.
 /// </summary>
 /// <param name="name">The name of the attachment.</param>
 /// <param name="slot">The slot of the attachment.</param>
 public AttachmentIdentifier(AttachmentName name, AttachmentSlot slot)
 {
     Code = 0;
     Name = name;
     Slot = slot;
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AttachmentIdentifier"/> struct.
 /// </summary>
 /// <param name="name">The name of the attachment.</param>
 public AttachmentIdentifier(AttachmentName name)
 {
     Code = 0;
     Name = name;
     Slot = default;
 }
 public override int GetHashCode()
 {
     return(AttachmentName.GetHashCode() ^ FileName.GetHashCode() ^
            (SelectedType == null ? -1 : (int)SelectedType));
 }