Inheritance: System.Data.Objects.DataClasses.EntityObject
Esempio n. 1
0
        /// <summary>
        /// Database saving handler
        /// </summary>
        /// <param name="repeatedly">should it go indefinatly? just for background thread</param>
        private static void DatabaseHandler(bool repeatedly)
        {
            DateTime lastcheck = DateTime.MinValue;

            while (true)
            {
                //store all audit records
                using (DNSAdminEntities db = new DNSAdminEntities())
                {
                    AuditRecord auditrec = null;
                    while (auditrecords.TryDequeue(out auditrec))
                    {
                        db.AuditRecords.AddObject(auditrec);
                    }
                    db.SaveChanges();
                    db.AcceptAllChanges();
                }


                //check 10 minutes passed
                if ((DateTime.UtcNow - lastcheck).TotalMinutes > 10)
                {
                    lastcheck = DateTime.UtcNow;
                    //remove old records
                    int removeitems = 0;
                    using (DNSAdminEntities db = new DNSAdminEntities())
                    {
                        var deletelist = db.AuditRecords.OrderByDescending(i => i.TimestampUTC).ToList().Skip(AuditMediaDBMaximumRecords).ToList();
                        removeitems = deletelist.Count();
                        foreach (var item in deletelist)
                        {
                            db.DeleteObject(item);
                        }
                        db.SaveChanges();
                        db.AcceptAllChanges();
                    }
                    //if any records removed, compact database
                    if (removeitems > 0)
                    {
                        using (SqlCeEngine engine = new SqlCeEngine("Data Source = |DataDirectory|\\DNSAdmin.sdf"))
                        {
                            engine.Shrink();
                        }
                    }
                }

                if (repeatedly)
                {
                    Thread.Sleep(5000);
                }
                else
                {
                    break;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create a new AuditRecord object.
        /// </summary>
        /// <param name="id">Initial value of the Id property.</param>
        /// <param name="username">Initial value of the Username property.</param>
        /// <param name="timestampUTC">Initial value of the TimestampUTC property.</param>
        /// <param name="text">Initial value of the Text property.</param>
        /// <param name="type">Initial value of the Type property.</param>
        /// <param name="server">Initial value of the Server property.</param>
        /// <param name="clientIP">Initial value of the ClientIP property.</param>
        public static AuditRecord CreateAuditRecord(global::System.Guid id, global::System.String username, global::System.DateTime timestampUTC, global::System.String text, global::System.String type, global::System.String server, global::System.String clientIP)
        {
            AuditRecord auditRecord = new AuditRecord();

            auditRecord.Id           = id;
            auditRecord.Username     = username;
            auditRecord.TimestampUTC = timestampUTC;
            auditRecord.Text         = text;
            auditRecord.Type         = type;
            auditRecord.Server       = server;
            auditRecord.ClientIP     = clientIP;
            return(auditRecord);
        }
Esempio n. 3
0
 /// <summary>
 /// Create a new AuditRecord object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="username">Initial value of the Username property.</param>
 /// <param name="timestampUTC">Initial value of the TimestampUTC property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="type">Initial value of the Type property.</param>
 /// <param name="server">Initial value of the Server property.</param>
 /// <param name="clientIP">Initial value of the ClientIP property.</param>
 public static AuditRecord CreateAuditRecord(global::System.Guid id, global::System.String username, global::System.DateTime timestampUTC, global::System.String text, global::System.String type, global::System.String server, global::System.String clientIP)
 {
     AuditRecord auditRecord = new AuditRecord();
     auditRecord.Id = id;
     auditRecord.Username = username;
     auditRecord.TimestampUTC = timestampUTC;
     auditRecord.Text = text;
     auditRecord.Type = type;
     auditRecord.Server = server;
     auditRecord.ClientIP = clientIP;
     return auditRecord;
 }
Esempio n. 4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the AuditRecords EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAuditRecords(AuditRecord auditRecord)
 {
     base.AddObject("AuditRecords", auditRecord);
 }
Esempio n. 5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the AuditRecords EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAuditRecords(AuditRecord auditRecord)
 {
     base.AddObject("AuditRecords", auditRecord);
 }