using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Duplicati.Scheduler.Monitor.SQL
{
///
/// Maintains the server data
///
public class Plugin : Duplicati.Scheduler.Data.IMonitorPlugin
{
public string Name { get { return "Monitor.SQL"; } }
///
/// Update a log entry
///
/// Date
/// XML content
public void UpdateLog(DateTime aLogDate, string aLogContent)
{
SQLHistoryDataSet.Update(Duplicati.Scheduler.Utility.User.UserName, Environment.MachineName, SQLHistoryDataSet.EntryKind.Log,
aLogDate, aLogContent);
}
///
/// Update the scheduler record
///
public void Scheduler()
{
UpdateScheduler(Duplicati.Scheduler.Data.SchedulerDataSet.DefaultPath());
}
///
/// Update the scheduler record
///
/// XML file to load
public void UpdateScheduler(string aScheduler)
{
DateTime LastUpdate = SQLHistoryDataSet.Latest(SQLHistoryDataSet.EntryKind.Schedule);
DateTime LastWrite = System.IO.File.GetLastWriteTime(aScheduler);
if (LastUpdate < LastWrite)
SQLHistoryDataSet.Update(Duplicati.Scheduler.Utility.User.UserName, Environment.MachineName, SQLHistoryDataSet.EntryKind.Schedule,
LastWrite, System.IO.File.ReadAllText(aScheduler));
}
///
/// Update History
///
public void UpdateHistory(string aHistory)
{
using (Duplicati.Scheduler.Data.HistoryDataSet hds = new Duplicati.Scheduler.Data.HistoryDataSet())
{
hds.Load();
History(System.IO.File.GetLastWriteTime(aHistory), hds.History);
}
}
///
/// Update History
///
/// Date
/// XML file name
public void History(DateTime aLastWrite, Duplicati.Scheduler.Data.HistoryDataSet.HistoryDataTable aHistoryTable)
{
DateTime LastUpdate = SQLHistoryDataSet.Latest(SQLHistoryDataSet.EntryKind.Schedule);
Duplicati.Scheduler.Data.HistoryDataSet.HistoryDataTable Changes = new Duplicati.Scheduler.Data.HistoryDataSet.HistoryDataTable();
foreach (Duplicati.Scheduler.Data.HistoryDataSet.HistoryRow Row in
from Duplicati.Scheduler.Data.HistoryDataSet.HistoryRow qR in aHistoryTable
where qR.ActionDate > LastUpdate
select qR)
Changes.ImportRow(Row);
StringBuilder b = new StringBuilder();
Changes.WriteXml(new System.IO.StringWriter(b));
SQLHistoryDataSet.Update(Duplicati.Scheduler.Utility.User.UserName, Environment.MachineName, SQLHistoryDataSet.EntryKind.History,
aLastWrite, b.ToString());
}
public System.Windows.Forms.DialogResult Configure()
{
return new SQLConnectionDialog(Properties.Settings.MonitorConnection).ShowDialog();
}
}
}