Cleans up static loggers
Adds test projects for different frameworks and architectures Adds registration tool assembly
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Lithnet.CredentialProvider.Samples
|
||||
{
|
||||
public static class CredUI
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
public struct CREDUI_INFO
|
||||
{
|
||||
public int cbSize;
|
||||
public IntPtr hwndParent;
|
||||
public string pszMessageText;
|
||||
public string pszCaptionText;
|
||||
public IntPtr hbmBanner;
|
||||
}
|
||||
|
||||
[DllImport("credui.dll", CharSet = CharSet.Auto)]
|
||||
public static extern int CredUIPromptForWindowsCredentials(
|
||||
ref CREDUI_INFO uiInfo,
|
||||
int authError,
|
||||
ref uint authPackage,
|
||||
IntPtr InAuthBuffer,
|
||||
uint InAuthBufferSize,
|
||||
out IntPtr refOutAuthBuffer,
|
||||
out uint refOutAuthBufferSize,
|
||||
ref bool fSave,
|
||||
uint flags
|
||||
);
|
||||
|
||||
public static void Prompt(string caption, string message)
|
||||
{
|
||||
var uiInfo = new CREDUI_INFO()
|
||||
{
|
||||
pszCaptionText = caption,
|
||||
pszMessageText = message
|
||||
};
|
||||
|
||||
uiInfo.cbSize = Marshal.SizeOf(uiInfo);
|
||||
|
||||
uint authPackage = 0;
|
||||
|
||||
var save = false;
|
||||
|
||||
CredUIPromptForWindowsCredentials(
|
||||
ref uiInfo,
|
||||
0,
|
||||
ref authPackage,
|
||||
IntPtr.Zero,
|
||||
0,
|
||||
out IntPtr outCredBuffer,
|
||||
out uint outCredSize,
|
||||
ref save,
|
||||
0
|
||||
);
|
||||
|
||||
Marshal.FreeCoTaskMem(outCredBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<Platform>x64</Platform>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.1.1" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
namespace Lithnet.CredentialProvider.Samples
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
internal static ILoggerFactory LoggerFactory { get; }
|
||||
|
||||
static Program()
|
||||
{
|
||||
/*
|
||||
This sample uses NLog to capture trace events from the provider, but you can use any
|
||||
logging system compatible with Microsoft.Extensions.Logging;
|
||||
*/
|
||||
|
||||
var config = new NLog.Config.LoggingConfiguration();
|
||||
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
|
||||
|
||||
/*
|
||||
|
||||
Add file based logging if required
|
||||
|
||||
*/
|
||||
|
||||
// var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "c:\\file.txt" };
|
||||
//config.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, logfile);
|
||||
|
||||
config.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, logconsole);
|
||||
|
||||
LogManager.Configuration = config;
|
||||
Program.LoggerFactory = new NLogLoggerFactory(new NLogLoggerProvider(new NLogProviderOptions() { ReplaceLoggerFactory = true }, LogManager.LogFactory));
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
CredUI.Prompt("Login with Cred UI", "Select your favorite credential provider");
|
||||
Console.WriteLine("Done! Press any key to exit");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user