示例#1
0
        public void SendEmails()
        {
            RecordManager recMan = new RecordManager();

            var response = recMan.Find(new EntityQuery("system_log", "*", EntityQuery.QueryEQ("notification_status", (int)LogNotificationStatus.NotNotified)));

            if (!response.Success || response.Object == null || response.Object.Data == null || response.Object.Data.Count == 0)
            {
                return;
            }

            foreach (EntityRecord log in response.Object.Data)
            {
                Guid id = (Guid)log["id"];
                LogNotificationStatus notificationStatus = LogNotificationStatus.Notified;

                //TODO: SendEmail method have to be implemented
                //try
                //{
                //	SendEmail(string toEmailAddress, string subject, string body)
                //}
                //catch (Exception)
                //{
                //	notificationStatus = LogNotificationStatus.NotificationFailed;
                //}

                UpdateNotificationStatus(id, notificationStatus);
            }
        }
示例#2
0
        public void UpdateNotificationStatus(Guid id, LogNotificationStatus notificationStatus)
        {
            RecordManager recMan = new RecordManager();

            var response = recMan.Find(new EntityQuery("system_log", "*", EntityQuery.QueryEQ("id", id)));

            if (!response.Success || response.Object == null || response.Object.Data == null || response.Object.Data.Count == 0)
            {
                return;                 //Maybe it have to throw exception here
            }
            EntityRecord logRecord = response.Object.Data[0];

            logRecord["notification_status"] = ((int)notificationStatus).ToString();
            logRecord["last_modified_on"]    = DateTime.UtcNow;

            recMan.UpdateRecord("system_log", logRecord);
        }
示例#3
0
        public void Create(LogType type, string source, string message, Exception ex, HttpRequest request = null, LogNotificationStatus notificationStatus = LogNotificationStatus.NotNotified)
        {
            string details = MakeDetailsJson("", ex, request);

            Create(type, source, message, details, notificationStatus);
        }
示例#4
0
 public void Create(LogType type, string source, string message, string details, LogNotificationStatus notificationStatus = LogNotificationStatus.NotNotified, bool saveDetailsAsJson = false)
 {
     using (var connection = DbContext.Current.CreateConnection())
     {
         var cmd = connection.CreateCommand("INSERT INTO system_log(id,created_on,type,message,source,details,notification_status) VALUES(@id,@created_on,@type,@message,@source,@details,@notification_status);");
         cmd.Parameters.Add(new NpgsqlParameter("@id", Guid.NewGuid()));
         cmd.Parameters.Add(new NpgsqlParameter("@type", ((int)type)));
         cmd.Parameters.Add(new NpgsqlParameter("@source", source ?? string.Empty));
         cmd.Parameters.Add(new NpgsqlParameter("@message", message ?? string.Empty));
         cmd.Parameters.Add(new NpgsqlParameter("@notification_status", ((int)notificationStatus)));
         cmd.Parameters.Add(new NpgsqlParameter("@details", details ?? string.Empty));
         cmd.Parameters.Add(new NpgsqlParameter("@created_on", DateTime.UtcNow));
         cmd.ExecuteNonQuery();
     }
 }
示例#5
0
        public void Create(LogType type, string source, string message, string details, LogNotificationStatus notificationStatus = LogNotificationStatus.NotNotified, bool saveDetailsAsJson = false)
        {
            EntityRecord logRecord = new EntityRecord();

            logRecord["id"]                  = Guid.NewGuid();
            logRecord["type"]                = ((int)type).ToString();
            logRecord["source"]              = source;
            logRecord["message"]             = message;
            logRecord["notification_status"] = ((int)notificationStatus).ToString();
            logRecord["details"]             = saveDetailsAsJson ? MakeDetailsJson(details) : details;
            logRecord["created_by"]          = SystemIds.SystemUserId;
            logRecord["last_modified_by"]    = SystemIds.SystemUserId;
            logRecord["created_on"]          = DateTime.UtcNow;
            logRecord["last_modified_on"]    = DateTime.UtcNow;

            RecordManager recMan   = new RecordManager();
            var           response = recMan.CreateRecord("system_log", logRecord);
        }
示例#6
0
        /// <summary>
        ///  Creates log of specified type and send email notification.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="source">The source.</param>
        /// <param name="message">The message.</param>
        /// <param name="ex">The ex.</param>
        /// <param name="request">The request.</param>
        /// <param name="notificationStatus">The notification status.</param>
        public void Create(LogType type, string source, string message, Exception ex, HttpRequest request = null, LogNotificationStatus notificationStatus = LogNotificationStatus.NotNotified)
        {
            if (notificationStatus == LogNotificationStatus.NotNotified)
            {
                string details     = Log.MakeDetailsJson("", ex, request);
                bool   messageSent = new MailService().SendLogMessage(type, source, message, details, request == null ? null : request.Host.ToString());
                if (messageSent)
                {
                    notificationStatus = LogNotificationStatus.Notified;
                }
            }

            Log log = new Log();

            log.Create(type, source, message, ex, request, notificationStatus);
        }
示例#7
0
        /// <summary>
        /// Creates log of specified type and send email notification.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="source">The source.</param>
        /// <param name="message">The message.</param>
        /// <param name="details">The details.</param>
        /// <param name="notificationStatus">The notification status.</param>
        /// <param name="saveDetailsAsJson">if set to <c>true</c> [save details as json].</param>
        public void Create(LogType type, string source, string message, string details, LogNotificationStatus notificationStatus = LogNotificationStatus.NotNotified, bool saveDetailsAsJson = false)
        {
            if (notificationStatus == LogNotificationStatus.NotNotified)
            {
                bool messageSent = new MailService().SendLogMessage(type, source, message, details);

                if (messageSent)
                {
                    notificationStatus = LogNotificationStatus.Notified;
                }
            }

            Log log = new Log();

            log.Create(type, source, message, details, notificationStatus, saveDetailsAsJson);
        }