internal Application(ICommandContext context,
                             IHostProviderRegistry providerRegistry,
                             IConfigurationService configurationService,
                             string appPath)
            : base(context)
        {
            EnsureArgument.NotNull(providerRegistry, nameof(providerRegistry));
            EnsureArgument.NotNull(configurationService, nameof(configurationService));
            EnsureArgument.NotNullOrWhiteSpace(appPath, nameof(appPath));

            _appPath              = appPath;
            _providerRegistry     = providerRegistry;
            _configurationService = configurationService;

            _configurationService.AddComponent(this);
        }
Exemplo n.º 2
0
        private static string FormatText(string message, string filePath, int lineNumber, string memberName)
        {
            const int sourceColumnMaxWidth = 23;

            EnsureArgument.NotNull(message, nameof(message));
            EnsureArgument.NotNull(filePath, nameof(filePath));
            EnsureArgument.PositiveOrZero(lineNumber, nameof(lineNumber));
            EnsureArgument.NotNull(memberName, nameof(memberName));

            // Source column format is file:line
            string source = $"{filePath}:{lineNumber}";

            if (source.Length > sourceColumnMaxWidth)
            {
                int idx    = 0;
                int maxlen = sourceColumnMaxWidth - 3;
                int srclen = source.Length;

                while (idx >= 0 && (srclen - idx) > maxlen)
                {
                    idx = source.IndexOf('\\', idx + 1);
                }

                // If we cannot find a path separator which allows the path to be long enough, just truncate the file name
                if (idx < 0)
                {
                    idx = srclen - maxlen;
                }

                source = "..." + source.Substring(idx);
            }

            // Git's trace format is "{timestamp,-15} {source,-23} trace: {details}"
            string text = $"{DateTime.Now:HH:mm:ss.ffffff} {source,-23} trace: [{memberName}] {message}";

            return(text);
        }
        protected ApplicationBase(ICommandContext context)
        {
            EnsureArgument.NotNull(context, nameof(context));

            Context = context;
        }
        protected EnvironmentBase(IFileSystem fileSystem)
        {
            EnsureArgument.NotNull(fileSystem, nameof(fileSystem));

            FileSystem = fileSystem;
        }
        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);
                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, Git);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }

            HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams);

            // Set the parent window handle/ID
            SystemPrompts.ParentWindowId = Settings.ParentWindowId;
        }
Exemplo n.º 6
0
        public ConfigurationService(ICommandContext context)
        {
            EnsureArgument.NotNull(context, nameof(context));

            _context = context;
        }
        public CredentialStore(ICommandContext context)
        {
            EnsureArgument.NotNull(context, nameof(context));

            _context = context;
        }