Exemplo n.º 1
0
 /// <summary>
 /// To Bson
 /// </summary>
 public static BsonDocument ToBson(CommandHandlerRecord record)
 {
     return(new BsonDocument()
     {
         { "HandlerId", record.HandlerId ?? "" },
         { "CommandId", record.CommandId ?? "" },
         { "StartedDate", record.StartedDate },
         { "EndedDate", record.EndedDate },
         { "TypeName", record.TypeName ?? "" },
         { "ErrorMessage", record.ErrorMessage ?? "" },
         { "ErrorStackTrace", record.ErrorStackTrace ?? "" },
     });
 }
Exemplo n.º 2
0
        public static CommandHandlerRecord FromBson(BsonDocument doc)
        {
            var handler = new CommandHandlerRecord()
            {
                HandlerId       = doc.GetString("HandlerId"),
                CommandId       = doc.GetString("CommandId"),
                StartedDate     = doc.GetDateTime("StartedDate"),
                EndedDate       = doc.GetDateTime("EndedDate"),
                ErrorMessage    = doc.GetString("ErrorMessage"),
                ErrorStackTrace = doc.GetString("ErrorStackTrace"),
                TypeName        = doc.GetString("TypeName"),
            };

            return(handler);
        }
Exemplo n.º 3
0
        /// <summary>
        /// From Bson
        /// </summary>
        public static CommandHandlerRecordCollection FromBson(BsonValue doc)
        {
            var list = new List <CommandHandlerRecord>();

            if (!doc.IsBsonArray)
            {
                return(new CommandHandlerRecordCollection(list));
            }

            var evnts = doc.AsBsonArray;

            foreach (var evnt in evnts)
            {
                list.Add(CommandHandlerRecord.FromBson(evnt.AsBsonDocument));
            }

            return(new CommandHandlerRecordCollection(list));
        }
        public void LogCommandHandler(CommandHandlerRecord record)
        {
            try
            {
                var handlerDoc = CommandHandlerRecord.ToBson(record);
                var query      = Query.EQ("_id", record.CommandId);
                var update     = Update.Push("Handlers", handlerDoc);

                if (record.ErrorMessage != "")
                {
                    update.Inc("Errors", 1);
                }

                Logs.Logs.Update(query, update);
            }
            catch (Exception)
            {
                // Catch all errors because logging should not throw errors if unsuccessful
            }
        }