using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Duplicati.Scheduler.Monitor.SQL { /// /// Support for the remote database /// /// /// The goal here was to hit the server as little as possible. /// So, the data is not parsed from its XML and only the changes are sent. /// public partial class SQLHistoryDataSet { /// /// Get the time that the last update was done for this user/machine/entryType /// /// Kind to search for /// Last time or Time.Min if never public static DateTime Latest(EntryKind aEntryKind) { SQLHistoryDataSetTableAdapters.HistoryTableAdapter TableAdapter = new SQLHistoryDataSetTableAdapters.HistoryTableAdapter(); DateTime? re = TableAdapter.LatestQuery(Duplicati.Scheduler.Utility.User.UserName, Environment.MachineName, aEntryKind.ToString()); if (re == null) return DateTime.MinValue; return (DateTime)re; } /// /// Update a record /// /// Domain/User /// Yeah /// Kind of entry to update /// Entry time /// XML to send public static void Update(string aUserName, string aMachineName, EntryKind aEntryType, DateTime aModificationDate, string aContent) { SQLHistoryDataSetTableAdapters.HistoryTableAdapter TableAdapter = new SQLHistoryDataSetTableAdapters.HistoryTableAdapter(); SQLHistoryDataSet.HistoryDataTable Table = TableAdapter.GetDataBy(aUserName, aMachineName, aEntryType.ToString(), aModificationDate); HistoryRow Row = null; if (Table.Count == 0) Row = Table.AddHistoryRow(aUserName, aMachineName, aEntryType.ToString(), aModificationDate, aContent); else Row = ((HistoryRow)Table.Rows[0]); Row.XmlContent = aContent; TableAdapter.Update(Table); //Console.WriteLine(Row.EntryType + ":" + Row.XmlContent); } /// /// Entry may be one of these, note that Schedule includes Settings /// public enum EntryKind { Schedule, History, Log, None }; /// /// Row tools /// public partial class HistoryRow { /// /// Convert string to EntryKind /// public EntryKind ToEntryKind(string aType) { if (System.Enum.IsDefined(typeof(EntryKind), aType)) return EntryKind.None; return (EntryKind)System.Enum.Parse(typeof(EntryKind), aType); } /// /// Sets Entry Type /// public EntryKind Entry { get { return ToEntryKind(this.EntryType); } set { this.EntryType = value.ToString(); } } } } }