Beispiel #1
0
        private VisualStudioTokenProvider[] GetTokenProviders(string tokenProviderPath)
        {
            var content = GetTokenProviderContent(tokenProviderPath);

            try
            {
                using JsonDocument document = JsonDocument.Parse(content);

                JsonElement providersElement = document.RootElement.GetProperty("TokenProviders");

                var providers = new VisualStudioTokenProvider[providersElement.GetArrayLength()];
                for (int i = 0; i < providers.Length; i++)
                {
                    JsonElement providerElement = providersElement[i];

                    var path       = providerElement.GetProperty("Path").GetString();
                    var preference = providerElement.GetProperty("Preference").GetInt32();
                    var arguments  = GetStringArrayPropertyValue(providerElement, "Arguments");

                    providers[i] = new VisualStudioTokenProvider(path, arguments, preference);
                }

                Array.Sort(providers);
                return(providers);
            }
            catch (JsonException exception)
            {
                throw new CredentialUnavailableException($"File found at \"{tokenProviderPath}\" isn't a valid JSON file", exception);
            }
            catch (Exception exception)
            {
                throw new CredentialUnavailableException($"JSON file found at \"{tokenProviderPath}\" has invalid schema.", exception);
            }
        }
Beispiel #2
0
        private VisualStudioTokenProvider[] GetTokenProviders(string tokenProviderPath)
        {
            var content = GetTokenProviderContent(tokenProviderPath);

            JsonElement providersElement = JsonDocument.Parse(content).RootElement.GetProperty("TokenProviders");

            var providers = new VisualStudioTokenProvider[providersElement.GetArrayLength()];

            for (int i = 0; i < providers.Length; i++)
            {
                JsonElement providerElement = providersElement[i];

                var path       = providerElement.GetProperty("Path").GetString();
                var preference = providerElement.GetProperty("Preference").GetInt32();
                var arguments  = GetStringArrayPropertyValue(providerElement, "Arguments");

                providers[i] = new VisualStudioTokenProvider(path, arguments, preference);
            }

            Array.Sort(providers);
            return(providers);
        }