348 lines
12 KiB
C#
348 lines
12 KiB
C#
using Disco.Models.Repository;
|
|
using Disco.Services.Logging;
|
|
using Disco.Services.Logging.Models;
|
|
|
|
namespace Disco.Services.Plugins.Features.CertificateProvider
|
|
{
|
|
public class CertificateProvidersLog : LogBase
|
|
{
|
|
public enum EventTypeIds
|
|
{
|
|
RetrievalStarting = 10,
|
|
RetrievalProgress,
|
|
RetrievalFinished,
|
|
RetrievalWarning = 15,
|
|
RetrievalError,
|
|
RetrievalCertificateStarting = 20,
|
|
RetrievalCertificateFinished = 22,
|
|
RetrievalCertificateWarning = 25,
|
|
RetrievalCertificateError,
|
|
Allocated = 40,
|
|
AllocationFailed = 50,
|
|
DisabledCertificate = 100,
|
|
EnabledCertificate = 110,
|
|
DeletedCertificate = 120,
|
|
UpdatedCertificate = 130
|
|
}
|
|
private const int _ModuleId = 60;
|
|
private static bool _IsCertificateRetrievalProcessing;
|
|
private static string _CertificateRetrievalStatus;
|
|
private static int _CertificateRetrievalProgress;
|
|
public static CertificateProvidersLog Current
|
|
{
|
|
get
|
|
{
|
|
return (CertificateProvidersLog)LogContext.LogModules[60];
|
|
}
|
|
}
|
|
public static bool IsCertificateRetrievalProcessing
|
|
{
|
|
get
|
|
{
|
|
return _IsCertificateRetrievalProcessing;
|
|
}
|
|
}
|
|
public override string ModuleDescription
|
|
{
|
|
get
|
|
{
|
|
return "Certificate Providers";
|
|
}
|
|
}
|
|
public override int ModuleId
|
|
{
|
|
get
|
|
{
|
|
return 60;
|
|
}
|
|
}
|
|
public override string ModuleName
|
|
{
|
|
get
|
|
{
|
|
return "CertificateProviders";
|
|
}
|
|
}
|
|
[System.Diagnostics.DebuggerNonUserCode]
|
|
public CertificateProvidersLog()
|
|
{
|
|
}
|
|
private static void Log(EventTypeIds EventTypeId, params object[] Args)
|
|
{
|
|
Current.Log((int)EventTypeId, Args);
|
|
}
|
|
public static void LogRetrievalStarting(int CertificateCount, int CertificateIdFrom, int CertificateIdTo)
|
|
{
|
|
Log(EventTypeIds.RetrievalStarting, new object[]
|
|
{
|
|
CertificateCount,
|
|
CertificateIdFrom,
|
|
CertificateIdTo
|
|
});
|
|
}
|
|
public static void LogRetrievalFinished()
|
|
{
|
|
Log(EventTypeIds.RetrievalFinished, new object[0]);
|
|
}
|
|
public static void LogRetrievalWarning(string Message)
|
|
{
|
|
Log(EventTypeIds.RetrievalWarning, new object[]
|
|
{
|
|
Message
|
|
});
|
|
}
|
|
public static void LogRetrievalError(string Message)
|
|
{
|
|
Log(EventTypeIds.RetrievalError, new object[]
|
|
{
|
|
Message
|
|
});
|
|
}
|
|
public static void LogRetrievalCertificateStarting(string CertificateId)
|
|
{
|
|
Log(EventTypeIds.RetrievalCertificateStarting, CertificateId);
|
|
}
|
|
public static void LogRetrievalCertificateFinished(string CertificateId)
|
|
{
|
|
Log(EventTypeIds.RetrievalCertificateFinished, CertificateId);
|
|
}
|
|
public static void LogRetrievalCertificateWarning(string CertificateId, string Message)
|
|
{
|
|
Log(EventTypeIds.RetrievalCertificateWarning, CertificateId, Message);
|
|
}
|
|
public static void LogRetrievalCertificateError(string CertificateId, string Message)
|
|
{
|
|
Log(EventTypeIds.RetrievalCertificateError, CertificateId, Message);
|
|
}
|
|
public static void LogAllocated(string CertificateId, string DeviceSerialNumber)
|
|
{
|
|
Log(EventTypeIds.Allocated, CertificateId, DeviceSerialNumber);
|
|
}
|
|
public static void LogAllocationFailed(string DeviceSerialNumber)
|
|
{
|
|
Log(EventTypeIds.AllocationFailed, DeviceSerialNumber);
|
|
}
|
|
public static void LogDisabledCertificate(DeviceCertificate Certificate, string Reason)
|
|
{
|
|
Log(EventTypeIds.DisabledCertificate, Certificate.Name, Certificate.Id, Reason);
|
|
}
|
|
public static void LogEnabledCertificate(DeviceCertificate Certificate, string Reason)
|
|
{
|
|
Log(EventTypeIds.EnabledCertificate, Certificate.Name, Certificate.Id, Reason);
|
|
}
|
|
public static void LogDeletedCertificate(DeviceCertificate Certificate, string Reason)
|
|
{
|
|
Log(EventTypeIds.DeletedCertificate, Certificate.Name, Certificate.Id, Reason);
|
|
}
|
|
public static void LogUpdatedCertificate(DeviceCertificate Certificate, string Reason)
|
|
{
|
|
Log(EventTypeIds.UpdatedCertificate, Certificate.Name, Certificate.Id, Reason);
|
|
}
|
|
|
|
public static void LogCertificateRetrievalProgress(bool? IsProcessing, int? Progress, string Status)
|
|
{
|
|
bool flag = IsProcessing.HasValue;
|
|
if (flag)
|
|
{
|
|
_IsCertificateRetrievalProcessing = IsProcessing.Value;
|
|
}
|
|
flag = _IsCertificateRetrievalProcessing;
|
|
if (flag)
|
|
{
|
|
bool flag2 = Status != null;
|
|
if (flag2)
|
|
{
|
|
_CertificateRetrievalStatus = Status;
|
|
}
|
|
flag2 = Progress.HasValue;
|
|
if (flag2)
|
|
{
|
|
_CertificateRetrievalProgress = Progress.Value;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_CertificateRetrievalStatus = null;
|
|
_CertificateRetrievalProgress = 0;
|
|
}
|
|
Log(EventTypeIds.RetrievalProgress, new object[]
|
|
{
|
|
_IsCertificateRetrievalProcessing,
|
|
_CertificateRetrievalProgress,
|
|
_CertificateRetrievalStatus
|
|
});
|
|
}
|
|
protected override System.Collections.Generic.List<LogEventType> LoadEventTypes()
|
|
{
|
|
return new System.Collections.Generic.List<LogEventType>
|
|
{
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.RetrievalStarting,
|
|
ModuleId = 60,
|
|
Name = "Retrieval Starting",
|
|
Format = "Starting retrieval of {0} certificate/s ({1} to {2})",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.RetrievalProgress,
|
|
ModuleId = 60,
|
|
Name = "Retrieval Progress",
|
|
Format = "Processing: {0}; {1}% Complete; Status: {2}",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = false,
|
|
UseDisplay = false
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.RetrievalFinished,
|
|
ModuleId = 60,
|
|
Name = "Retrieval Finished",
|
|
Format = "Retrieval of Certificates Complete",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.RetrievalWarning,
|
|
ModuleId = 60,
|
|
Name = "Retrieval Warning",
|
|
Format = "Retrieval Warning: {0}",
|
|
Severity = 1,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.RetrievalError,
|
|
ModuleId = 60,
|
|
Name = "Retrieval Error",
|
|
Format = "Retrieval Error: {0}",
|
|
Severity = 2,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.RetrievalCertificateStarting,
|
|
ModuleId = 60,
|
|
Name = "Retrieval Certificate Starting",
|
|
Format = "Retrieving Certificate: {0}",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.RetrievalCertificateFinished,
|
|
ModuleId = 60,
|
|
Name = "Retrieval Certificate Finished",
|
|
Format = "Certificate Retrieved: {0}",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.RetrievalCertificateWarning,
|
|
ModuleId = 60,
|
|
Name = "Retrieval Certificate Warning",
|
|
Format = "{0} Certificate Warning: {1}",
|
|
Severity = 1,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.RetrievalCertificateError,
|
|
ModuleId = 60,
|
|
Name = "Retrieval Certificate Error",
|
|
Format = "{0} Certificate Error: {1}",
|
|
Severity = 2,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.Allocated,
|
|
ModuleId = 60,
|
|
Name = "Allocated",
|
|
Format = "Certificate {0} allocated to {1}",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.AllocationFailed,
|
|
ModuleId = 60,
|
|
Name = "Allocation Failed",
|
|
Format = "No certificates available for Device: {0}",
|
|
Severity = 2,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.DisabledCertificate,
|
|
ModuleId = 60,
|
|
Name = "Disabled Certificate",
|
|
Format = "Certificate Disabled: {0} [{1}], Reason: {2}",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.EnabledCertificate,
|
|
ModuleId = 60,
|
|
Name = "Enabled Certificate",
|
|
Format = "Certificate Disabled: {0} [{1}], Reason: {2}",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.DeletedCertificate,
|
|
ModuleId = 60,
|
|
Name = "Deleted Certificate",
|
|
Format = "Certificate Deleted: {0} [{1}], Reason: {2}",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
},
|
|
new LogEventType
|
|
{
|
|
Id = (int)EventTypeIds.UpdatedCertificate,
|
|
ModuleId = 60,
|
|
Name = "Updated Certificate",
|
|
Format = "Certificate Updated: {0} [{1}], Reason: {2}",
|
|
Severity = 0,
|
|
UseLive = true,
|
|
UsePersist = true,
|
|
UseDisplay = true
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|