Exemplo n.º 1
0
 /// <summary>
 /// Raises the <see cref="MessageReceived"/> event.
 /// </summary>
 /// <param name="message">The <see cref="INExternMsg"/> object that was received.</param>
 protected void OnMessageReceived(INExternMsg message)
 {
     if (message != null)
     {
         MessageReceived?.Invoke(message, EventArgs.Empty);
     }
 }
Exemplo n.º 2
0
        public static INExternMsg BuildMessage(SqlDataReader sqlReader,
                                               StringComparison stringComparison = StringComparison.InvariantCultureIgnoreCase)
        {
            var message = default(INExternMsg);

            if (sqlReader is null || sqlReader.IsClosed || !sqlReader.HasRows)
            {
                return(message);
            }

            try
            {
                var msgStat = sqlReader[STATUS_COL] is DBNull ? 0 : (int)sqlReader[STATUS_COL];
                var msgDir  = sqlReader[DIRECTION_COL] is DBNull ? 0 : (int)sqlReader[DIRECTION_COL];

                if (!Enum.IsDefined(typeof(ExternMsgDirection), msgDir))
                {
                    throw new INExternMsgException(string.Format(
                                                       "Message direction '{0}' is not valid.", msgDir));
                }

                if (!Enum.IsDefined(typeof(ExternMsgStatus), msgStat))
                {
                    throw new INExternMsgException(string.Format(
                                                       "Message status '{0}' is not valid.", msgStat));
                }

                message = new INExternMsg(sqlReader[TYPE_COL] is DBNull ? string.Empty :
                                          (string)sqlReader[TYPE_COL], sqlReader[NAME_COL] is DBNull ? string.Empty :
                                          (string)sqlReader[NAME_COL], (ExternMsgDirection)msgDir,
                                          (ExternMsgStatus)msgStat, sqlReader[START_TIME_COL] is DBNull ? IMAGENOW_DEFAULT_DATE :
                                          (DateTime)sqlReader[START_TIME_COL], sqlReader[END_TIME_COL] is DBNull ? (DateTime?)null :
                                          (DateTime)sqlReader[END_TIME_COL], stringComparison)
                {
                    MessageId = sqlReader[MESSAGE_ID_COL] is DBNull ? null :
                                (string)sqlReader[MESSAGE_ID_COL],
                };

                if (string.IsNullOrWhiteSpace(message.MessageId))
                {
                    throw new INExternMsgException("Invalid message ID encountered.");
                }
            }
            catch (Exception ex)
            {
                throw new INExternMsgException(
                          string.Format("Error while reading message contents: {0}", ex.Message), ex);
            }

            return(message);
        }