/// <summary> /// Returns a <see cref="NTAccount" /> object containing information about the desktop owner of a specific /// <see cref="Process" /> /// </summary> /// <param name="process"><see cref="Process" /> to get information about</param> /// <returns>A newly created <see cref="NTAccount" /> object</returns> public static NTAccount GetProcessDesktopOwner(Process process) { try { var sessionId = process.SessionId; IntPtr buffer; int bufferSize; if ( WindowsTerminal.QuerySessionInformation(IntPtr.Zero, sessionId, WindowsTerminalInfoClass.UserName, out buffer, out bufferSize) && bufferSize > 0) { var accountName = Marshal.PtrToStringUni(buffer); WindowsTerminal.FreeMemory(buffer); if (accountName != null) { if ( WindowsTerminal.QuerySessionInformation(IntPtr.Zero, sessionId, WindowsTerminalInfoClass.DomainName, out buffer, out bufferSize) && bufferSize > 0) { var domainName = Marshal.PtrToStringUni(buffer); WindowsTerminal.FreeMemory(buffer); return(new NTAccount(domainName, accountName)); } return(new NTAccount(accountName)); } } return(new NTAccount(@"SYSTEM")); } catch (EntryPointNotFoundException) { throw new NotSupportedException(); } }
public CommandContext() { Streams = new StandardStreams(); Trace = new Trace(); FileSystem = new FileSystem(); var git = new LibGit2(); var envars = new EnvironmentVariables(Environment.GetEnvironmentVariables()); Settings = new Settings(envars, git) { RepositoryPath = git.GetRepositoryPath(FileSystem.GetCurrentDirectory()) }; HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams); if (PlatformUtils.IsWindows()) { Terminal = new WindowsTerminal(Trace); CredentialStore = WindowsCredentialManager.Open(); } else if (PlatformUtils.IsPosix()) { Terminal = new PosixTerminal(Trace); if (PlatformUtils.IsMacOS()) { CredentialStore = MacOSKeychain.Open(); } else if (PlatformUtils.IsLinux()) { throw new NotImplementedException(); } } }
public CommandContext() { Streams = new StandardStreams(); Trace = new Trace(); Git = new LibGit2(Trace); if (PlatformUtils.IsWindows()) { FileSystem = new WindowsFileSystem(); Environment = new WindowsEnvironment(FileSystem); Terminal = new WindowsTerminal(Trace); CredentialStore = WindowsCredentialManager.Open(); } else if (PlatformUtils.IsPosix()) { if (PlatformUtils.IsMacOS()) { FileSystem = new MacOSFileSystem(); CredentialStore = MacOSKeychain.Open(); } else if (PlatformUtils.IsLinux()) { throw new NotImplementedException(); } Environment = new PosixEnvironment(FileSystem); Terminal = new PosixTerminal(Trace); } string repoPath = Git.GetRepositoryPath(FileSystem.GetCurrentDirectory()); Settings = new Settings(Environment, Git, repoPath); HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams); }
public CommandContext() { Streams = new StandardStreams(); Trace = new Trace(); if (PlatformUtils.IsWindows()) { FileSystem = new WindowsFileSystem(); SessionManager = new WindowsSessionManager(); SystemPrompts = new WindowsSystemPrompts(); Environment = new WindowsEnvironment(FileSystem); Terminal = new WindowsTerminal(Trace); string gitPath = GetGitPath(Environment, FileSystem); Git = new GitProcess( Trace, gitPath, FileSystem.GetCurrentDirectory() ); Settings = new Settings(Environment, Git); CredentialStore = new WindowsCredentialManager(Settings.CredentialNamespace); } else if (PlatformUtils.IsMacOS()) { FileSystem = new MacOSFileSystem(); SessionManager = new MacOSSessionManager(); SystemPrompts = new MacOSSystemPrompts(); Environment = new PosixEnvironment(FileSystem); Terminal = new PosixTerminal(Trace); string gitPath = GetGitPath(Environment, FileSystem); Git = new GitProcess( Trace, gitPath, FileSystem.GetCurrentDirectory() ); Settings = new Settings(Environment, Git); CredentialStore = new MacOSKeychain(Settings.CredentialNamespace); } else if (PlatformUtils.IsLinux()) { FileSystem = new LinuxFileSystem(); // TODO: support more than just 'Posix' or X11 SessionManager = new PosixSessionManager(); SystemPrompts = new LinuxSystemPrompts(); Environment = new PosixEnvironment(FileSystem); Terminal = new PosixTerminal(Trace); string gitPath = GetGitPath(Environment, FileSystem); Git = new GitProcess( Trace, gitPath, FileSystem.GetCurrentDirectory() ); Settings = new Settings(Environment, Git); IGpg gpg = new Gpg( Environment.LocateExecutable("gpg"), SessionManager ); CredentialStore = new LinuxCredentialStore(FileSystem, Settings, SessionManager, gpg, Environment); } else { throw new PlatformNotSupportedException(); } HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams); // Set the parent window handle/ID SystemPrompts.ParentWindowId = Settings.ParentWindowId; }
public CommandContext(string appPath) { EnsureArgument.NotNullOrWhiteSpace(appPath, nameof(appPath)); ApplicationPath = appPath; Streams = new StandardStreams(); Trace = new Trace(); if (PlatformUtils.IsWindows()) { FileSystem = new WindowsFileSystem(); SessionManager = new WindowsSessionManager(); SystemPrompts = new WindowsSystemPrompts(); Environment = new WindowsEnvironment(FileSystem); Terminal = new WindowsTerminal(Trace); string gitPath = GetGitPath(Environment, FileSystem, Trace); Git = new GitProcess( Trace, Environment, gitPath, FileSystem.GetCurrentDirectory() ); Settings = new WindowsSettings(Environment, Git, Trace); } else if (PlatformUtils.IsMacOS()) { FileSystem = new MacOSFileSystem(); SessionManager = new MacOSSessionManager(); SystemPrompts = new MacOSSystemPrompts(); Environment = new PosixEnvironment(FileSystem); Terminal = new MacOSTerminal(Trace); string gitPath = GetGitPath(Environment, FileSystem, Trace); Git = new GitProcess( Trace, Environment, gitPath, FileSystem.GetCurrentDirectory() ); Settings = new Settings(Environment, Git); } else if (PlatformUtils.IsLinux()) { FileSystem = new LinuxFileSystem(); // TODO: support more than just 'Posix' or X11 SessionManager = new PosixSessionManager(); SystemPrompts = new LinuxSystemPrompts(); Environment = new PosixEnvironment(FileSystem); Terminal = new LinuxTerminal(Trace); string gitPath = GetGitPath(Environment, FileSystem, Trace); Git = new GitProcess( Trace, Environment, gitPath, FileSystem.GetCurrentDirectory() ); Settings = new Settings(Environment, Git); } else { throw new PlatformNotSupportedException(); } HttpClientFactory = new HttpClientFactory(FileSystem, Trace, Settings, Streams); CredentialStore = new CredentialStore(this); // Set the parent window handle/ID SystemPrompts.ParentWindowId = Settings.ParentWindowId; }