using System;
using System.Collections.Generic;
using System.Text;
using ScrewTurn.Wiki.PluginFramework;
namespace ScrewTurn.Wiki {
///
/// Manages the Wiki's Recent Changes.
///
public static class RecentChanges {
///
/// Gets all the changes, sorted by date/time ascending.
///
public static RecentChange[] GetAllChanges() {
RecentChange[] changes = Settings.Provider.GetRecentChanges();
RecentChange[] myCopy = new RecentChange[changes.Length];
Array.Copy(changes, myCopy, changes.Length);
Array.Sort(myCopy, (x, y) => { return x.DateTime.CompareTo(y.DateTime); });
return myCopy;
}
///
/// Adds a new change.
///
/// The page name.
/// The page title.
/// The message subject.
/// The date/time.
/// The user.
/// The change.
/// The description (optional).
public static void AddChange(string page, string title, string messageSubject, DateTime dateTime, string user, Change change, string descr) {
RecentChange[] allChanges = GetAllChanges();
if(allChanges.Length > 0) {
RecentChange lastChange = allChanges[allChanges.Length - 1];
if(lastChange.Page == page && lastChange.Title == title &&
lastChange.MessageSubject == messageSubject + "" &&
lastChange.User == user &&
lastChange.Change == change &&
(dateTime - lastChange.DateTime).TotalMinutes <= 60) {
// Skip this change
return;
}
}
Settings.Provider.AddRecentChange(page, title, messageSubject, dateTime, user, change, descr);
}
}
}