try {
logKey = eventLogKey.OpenSubKey (sourceData.LogName, true);
if (logKey == null) {
+ ValidateCustomerLogName (sourceData.LogName,
+ sourceData.MachineName);
+
logKey = eventLogKey.CreateSubKey (sourceData.LogName);
logKey.SetValue ("Sources", new string [] { sourceData.LogName,
sourceData.Source });
}
}
- public override EventLog [] GetEventLogs (string machineName)
- {
- using (RegistryKey eventLogKey = GetEventLogKey (machineName, false)) {
- if (eventLogKey == null) {
- throw new InvalidOperationException ("TODO");
- }
- string [] logNames = eventLogKey.GetSubKeyNames ();
- EventLog [] eventLogs = new EventLog [logNames.Length];
- for (int i = 0; i < logNames.Length; i++) {
- EventLog eventLog = new EventLog (logNames [i], machineName);
- eventLogs [i] = eventLog;
- }
- return eventLogs;
- }
- }
-
[MonoTODO]
protected override string GetLogDisplayName ()
{
return CoreEventLog.Log;
}
+ protected override string [] GetLogNames (string machineName)
+ {
+ using (RegistryKey eventLogKey = GetEventLogKey (machineName, true)) {
+ if (eventLogKey == null)
+ return new string [0];
+
+ return eventLogKey.GetSubKeyNames ();
+ }
+ }
+
public override string LogNameFromSourceName (string source, string machineName)
{
using (RegistryKey logKey = FindLogKeyBySource (source, machineName, false)) {
// http://www.pinvoke.net/default.aspx/advapi32/LookupAccountSid.html
// http://msdn.microsoft.com/library/en-us/secauthz/security/lookupaccountsid.asp
- // FIXME: StringBuilders should not have to be initialized with a
- // specific capacity => bug #79152
-
- StringBuilder name = new StringBuilder (16);
+ StringBuilder name = new StringBuilder ();
uint cchName = (uint) name.Capacity;
- StringBuilder referencedDomainName = new StringBuilder (16);
+ StringBuilder referencedDomainName = new StringBuilder ();
uint cchReferencedDomainName = (uint) referencedDomainName.Capacity;
SidNameUse sidUse;
// http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/
// http://msdn.microsoft.com/netframework/programming/netcf/cffaq/default.aspx
- // FIXME: we should be using Marshal.StringToHGlobalAuto and
- // Marshal.PtrToStringAuto => bug #79117
-
IntPtr msgDllHandle = PInvoke.LoadLibraryEx (msgDll, IntPtr.Zero,
LoadFlags.LibraryAsDataFile);
if (msgDllHandle == IntPtr.Zero)
try {
for (int i = 0; i < replacementStrings.Length; i++) {
- // TODO: use StringToHGlobalAuto once bug #79117 is fixed
- arguments [i] = Marshal.StringToHGlobalUni (
+ arguments [i] = Marshal.StringToHGlobalAuto (
replacementStrings [i]);
}
FormatMessageFlags.FromHModule | FormatMessageFlags.AllocateBuffer,
msgDllHandle, messageID, 0, ref lpMsgBuf, 0, arguments);
if (ret != 0) {
- // TODO: use PtrToStringAuto once bug #79117 is fixed
- string sRet = Marshal.PtrToStringUni (lpMsgBuf);
+ string sRet = Marshal.PtrToStringAuto (lpMsgBuf);
lpMsgBuf = PInvoke.LocalFree (lpMsgBuf);
// remove trailing whitespace (CRLF)
return sRet.TrimEnd (null);
}
}
} finally {
+ // release unmanaged memory allocated for replacement strings
+ for (int i = 0; i < arguments.Length; i++) {
+ IntPtr argument = arguments [i];
+ if (argument != IntPtr.Zero)
+ Marshal.FreeHGlobal (argument);
+ }
+
PInvoke.FreeLibrary (msgDllHandle);
}
return null;
if (hEventLog == IntPtr.Zero) {
throw new InvalidOperationException (string.Format (
CultureInfo.InvariantCulture, "Event Log '{0}' on computer"
- + " '{1}' cannot be opened."), new Win32Exception ());
+ + " '{1}' cannot be opened.", logName, CoreEventLog.MachineName),
+ new Win32Exception ());
}
return hEventLog;
}
private IntPtr RegisterEventSource ()
{
- IntPtr hEventLog = PInvoke.OpenEventLog (CoreEventLog.MachineName,
- CoreEventLog.Source);
+ IntPtr hEventLog = PInvoke.RegisterEventSource (
+ CoreEventLog.MachineName, CoreEventLog.Source);
if (hEventLog == IntPtr.Zero) {
throw new InvalidOperationException (string.Format (
- CultureInfo.InvariantCulture, "Event Log '{0}' on computer"
- + " '{1}' cannot be opened."), new Win32Exception ());
+ CultureInfo.InvariantCulture, "Event source '{0}' on computer"
+ + " '{1}' cannot be opened.", CoreEventLog.Source,
+ CoreEventLog.MachineName), new Win32Exception ());
}
return hEventLog;
}
[DllImport ("advapi32.dll", SetLastError=true)]
public static extern int DeregisterEventSource (IntPtr hEventLog);
- // FIXME: CharSet.Unicode can be removed once bug #79117 is fixed
- [DllImport ("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
+ [DllImport ("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int FormatMessage (FormatMessageFlags dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, ref IntPtr lpBuffer, int nSize, IntPtr [] arguments);
[DllImport ("kernel32.dll", SetLastError=true)]
[DllImport ("kernel32.dll", SetLastError=true)]
public static extern IntPtr LocalFree (IntPtr hMem);
- // FIXME: CharSet.Unicode can be removed once bug #79117 is fixed
- [DllImport ("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
+ [DllImport ("advapi32.dll", SetLastError=true)]
public static extern bool LookupAccountSid (
string lpSystemName,
[MarshalAs (UnmanagedType.LPArray)] byte [] Sid,
[DllImport ("advapi32.dll", SetLastError=true)]
public static extern IntPtr RegisterEventSource (string machineName, string sourceName);
- [DllImport ("Advapi32.dll", SetLastError = true)]
+ [DllImport ("Advapi32.dll", SetLastError=true)]
public static extern int ReportEvent (IntPtr hHandle, ushort wType,
ushort wCategory, uint dwEventID, IntPtr sid, ushort wNumStrings,
uint dwDataSize, string [] lpStrings, byte [] lpRawData);