示例#1
0
        /// <summary>
        /// Adds a piece of metadata.
        /// </summary>
        /// <param name="host">Host.</param>
        /// <param name="exc">Exchange.</param>
        /// <param name="topic">Topic.</param>
        /// <param name="recvAt">When the message was received.</param>
        /// <param name="path">Filepath of the message.</param>
        /// <param name="name">Message name.</param>
        /// <param name="payload">Message payload summarised.</param>
        /// <exception cref="ArgumentException">Thrown if DateTime kind is not UTC.</exception>
        /// <exception cref="ObjectDisposedException">Thrown if disposed.</exception>
        public void Add(Metadata metadata)
        {
            ExpectNotDisposed(); // throws ObjectDisposedException

            // Require UTC time
            ExpectUtc(metadata.ReceivedAt);

            // Convert to the Entity Framework class
            var efMetadata = new DbMetadataItem()
            {
                Host           = metadata.Host,
                Exchange       = metadata.Exchange,
                Topic          = metadata.Topic,
                ReceivedAt     = metadata.ReceivedAt.Ticks,
                Name           = metadata.Name,
                PayloadSummary = metadata.PayloadSummary,
                PayloadType    = metadata.PayloadType.ToString(),
                Filepath       = metadata.Filepath
            };

            // Add and save
            m_messageContext.DbMetadataItem.Add(efMetadata);
            m_messageContext.SaveChanges();
        }
示例#2
0
        private Metadata ConvertForOutput(DbMetadataItem efMeta)
        {
            // Recognising payload type
            var payloadType = PayloadTypeType.Other;

            try
            {
                payloadType = (PayloadTypeType)Enum.Parse(typeof(PayloadTypeType), efMeta.PayloadType);
            }
            catch { } // Failed to parse - preserve default value

            // Converting Entity Framework class to the neutral metadata class
            return(new Metadata(
                       id: efMeta.DbMetadataItemId,
                       host: efMeta.Host,
                       exc: efMeta.Exchange,
                       topic: efMeta.Topic,
                       recvAt: DateTime.SpecifyKind(new DateTime(efMeta.ReceivedAt), DateTimeKind.Utc),
                       name: efMeta.Name,
                       payload: efMeta.PayloadSummary,
                       paylType: payloadType,
                       path: efMeta.Filepath
                       ));
        }