public MainWindow() { InitializeComponent(); ServiceRaccourcis.OnKeyPress += PressionF4; windowsSession = new WindowsSession(); windowsSession.StateChanged += WindowsSession_StateChanged; }
public PluralsightContext CreateDbContext(string[] args) { string postgreSqlConnString = Program.Configuration.GetPostgreSqlConnString(); DbContextOptions options = new DbContextOptionsBuilder <PluralsightContext>() .UseNpgsql(postgreSqlConnString) .Options; var session = new WindowsSession(); return(new PluralsightContext(options, session)); }
public SessionStateForm() { InitializeComponent(); //Initialize the WindowsSession instance. session = new WindowsSession(); //Initialize the timer, but not start. timer = new System.Threading.Timer( new System.Threading.TimerCallback(DetectSessionState), null, System.Threading.Timeout.Infinite, 5000); }
public VkmApplicationContext() { _trayIcon = InitTrayIcon(); using (WindowsSession session = new WindowsSession()) { while (session.IsLocked()) { Thread.Sleep(5000); } } _coreContext = new VkmKernel(); SystemEvents.SessionSwitch += SystemEventsOnSessionSwitch; SystemEvents.SessionEnding += SystemEventsOnSessionEnding; }
/// <summary> /// 获取Windows Session /// </summary> /// <returns>Session集合</returns> public static WindowsSession[] GetSessions() { var serverHandle = Win32Api.WTSOpenServer(Environment.MachineName); try { var sessionInfoPtr = IntPtr.Zero; var sessionCount = 0; var hasSession = Win32Api.WTSEnumerateSessions(serverHandle, 0, 1, ref sessionInfoPtr, ref sessionCount) > 0; if (!hasSession) { return(Array.Empty <WindowsSession>()); } var dataSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO)); var currentSession = sessionInfoPtr; var sessions = new WindowsSession[sessionCount]; for (var i = 0; i < sessionCount; i++) { var si = (WTS_SESSION_INFO)Marshal.PtrToStructure(currentSession, typeof(WTS_SESSION_INFO)); currentSession += dataSize; Win32Api.WTSQuerySessionInformation(serverHandle, si.SessionID, WTS_INFO_CLASS.WTSUserName, out var userPtr, out _); Win32Api.WTSQuerySessionInformation(serverHandle, si.SessionID, WTS_INFO_CLASS.WTSDomainName, out var domainPtr, out _); var userName = Marshal.PtrToStringAnsi(userPtr); var domain = Marshal.PtrToStringAnsi(domainPtr); sessions[i] = new WindowsSession(userName, domain, si.State, si.SessionID); Win32Api.WTSFreeMemory(userPtr); Win32Api.WTSFreeMemory(domainPtr); } Win32Api.WTSFreeMemory(sessionInfoPtr); return(sessions); } finally { if (serverHandle != IntPtr.Zero) { Win32Api.WTSCloseServer(serverHandle); } } }
public static ChannelsReplicator CreateChannelsReplicator(IConfiguration configuration) { string postgreSqlConnString = configuration.GetPostgreSqlConnString(); ILoggerFactory serilogFactory = new LoggerFactory().AddSerilog(); DbContextOptions <PluralsightContext> options = new DbContextOptionsBuilder <PluralsightContext>().UseNpgsql(postgreSqlConnString) .UseLoggerFactory(serilogFactory) .Options; var session = new WindowsSession(); var pluralsightContext = new PluralsightContext(options, session); var entityFactory = new EntityFactory(); return(new ChannelsReplicator(pluralsightContext, entityFactory)); }
public static WindowsSession Get(this WindowsSession session) { Checker.Begin().NotNull(session, nameof(session)); return(Get(session.SessionId)); }