[WP] Refactoring so its in common to C#
This commit is contained in:
parent
a7ce209510
commit
0fe8437e0d
15
FileMutex.cs
15
FileMutex.cs
@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace BlubbFish.Utils
|
||||
{
|
||||
public class FileMutex
|
||||
public class FileMutex : IDisposable
|
||||
{
|
||||
private static FileMutex instance;
|
||||
private String filename;
|
||||
@ -54,5 +54,18 @@ namespace BlubbFish.Utils
|
||||
File.Delete(this.filename);
|
||||
return !File.Exists(this.filename);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(Boolean disposing) {
|
||||
if (disposing) {
|
||||
if(this.file != null) {
|
||||
this.file.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
InIReader.cs
12
InIReader.cs
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BlubbFish.Utils
|
||||
{
|
||||
public class InIReader
|
||||
public class InIReader : IDisposable
|
||||
{
|
||||
private Dictionary<String, Dictionary<String, String>> cont;
|
||||
private FileSystemWatcher k = new FileSystemWatcher(Directory.GetCurrentDirectory(), "*.ini");
|
||||
@ -171,5 +171,15 @@ namespace BlubbFish.Utils
|
||||
this.Changed();
|
||||
return false;
|
||||
}
|
||||
protected virtual void Dispose(Boolean disposing) {
|
||||
if (disposing) {
|
||||
this.k.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
OwnObject.cs
29
OwnObject.cs
@ -37,9 +37,23 @@ namespace BlubbFish.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public class LogEventArgs : EventArgs {
|
||||
public LogEventArgs(String location, String message, LogLevel level, DateTime date) {
|
||||
this.Location = location;
|
||||
this.Message = message;
|
||||
this.Level = level;
|
||||
this.Date = date;
|
||||
}
|
||||
|
||||
public String Location { get; private set; }
|
||||
public String Message { get; private set; }
|
||||
public LogLevel Level { get; private set; }
|
||||
public DateTime Date { get; private set; }
|
||||
}
|
||||
|
||||
private List<LogObject> loglist = new List<LogObject>();
|
||||
|
||||
public delegate void LogEvent(String location, String message, LogLevel level, DateTime date);
|
||||
public delegate void LogEvent(Object sender, LogEventArgs e);
|
||||
public enum LogLevel : Int32 {
|
||||
Debug = 1,
|
||||
Notice = 2,
|
||||
@ -88,22 +102,23 @@ namespace BlubbFish.Utils
|
||||
/// <param name="date">Date of the message</param>
|
||||
protected void AddLog(String location, String message, LogLevel level, DateTime date)
|
||||
{
|
||||
LogEventArgs e = new LogEventArgs(location, message, level, date);
|
||||
if (EventDebug != null && level >= LogLevel.Debug) {
|
||||
EventDebug(location, message, level, date);
|
||||
EventDebug(this, e);
|
||||
}
|
||||
if (EventNotice != null && level >= LogLevel.Notice) {
|
||||
EventNotice(location, message, level, date);
|
||||
EventNotice(this, e);
|
||||
}
|
||||
if (EventInfo != null && level >= LogLevel.Info) {
|
||||
EventInfo(location, message, level, date);
|
||||
EventInfo(this, e);
|
||||
}
|
||||
if (EventWarn != null && level >= LogLevel.Warn) {
|
||||
EventWarn(location, message, level, date);
|
||||
EventWarn(this, e);
|
||||
}
|
||||
if (EventError != null && level >= LogLevel.Error) {
|
||||
EventError(location, message, level, date);
|
||||
EventError(this, e);
|
||||
}
|
||||
EventLog?.Invoke(location, message, level, date);
|
||||
EventLog?.Invoke(this, e);
|
||||
|
||||
this.loglist.Add(new LogObject(date, location, message, level));
|
||||
}
|
||||
|
12
Updater.cs
12
Updater.cs
@ -6,7 +6,17 @@ namespace BlubbFish.Utils {
|
||||
private static Updater instances;
|
||||
private String url;
|
||||
|
||||
public delegate void UpdateStatus(Boolean hasUpdates, String message);
|
||||
public class UpdaterEventArgs : EventArgs {
|
||||
public UpdaterEventArgs(Boolean hasUpdates, String message) {
|
||||
this.HasUpdates = hasUpdates;
|
||||
this.Message = message;
|
||||
}
|
||||
|
||||
public String Message { get; private set; }
|
||||
public Boolean HasUpdates { get; private set; }
|
||||
}
|
||||
|
||||
public delegate void UpdateStatus(Object sender, UpdaterEventArgs e);
|
||||
|
||||
public event UpdateStatus UpdateResult;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user