Esempio n. 1
0
        public async Task <IEnumerable <string> > GetAllowedImageVersionsAsync()
        {
            string buildLocation = await m_projectInformationProvider.GetProjectBuildDirectoryAsync().ConfigureAwait(false);

            string settingsFile = GetCombinedFilePath(buildLocation);

            string json;

            try
            {
                json = await m_fileReaderProvider.ReadFileAsStringAsync(settingsFile).ConfigureAwait(false);
            }
            catch (IOException)
            {
                throw m_exceptionThrowerProvider.ThrowException($"Failed to read settings file at {settingsFile}");
            }

            try
            {
                return(ParseStringToJson(json));
            }
            catch (JsonSerializationException)
            {
                throw m_exceptionThrowerProvider.ThrowException("Failed to parse image settings file");
            }
            catch (JsonReaderException)
            {
                throw m_exceptionThrowerProvider.ThrowException("Failed to parse image settings file");
            }
        }
Esempio n. 2
0
        public async Task <FrcSettings?> GetFrcSettingsAsync()
        {
            bool verbose = m_buildSettingsProvider.Verbose;

            if (verbose)
            {
                await m_outputWriter.WriteLineAsync("Getting FRC Settings File").ConfigureAwait(false);
            }
            string projectDirectory = await m_projectInformationProvider.GetProjectRootDirectoryAsync().ConfigureAwait(false);

            string settingsFile = Path.Combine(projectDirectory, SettingsJsonFileName);
            string?json         = null;

            try
            {
                json = await m_fileReaderProvider.ReadFileAsStringAsync(settingsFile).ConfigureAwait(false);
            }
            catch (IOException)
            {
                // Locked or missing file, failed to read
                if (verbose)
                {
                    await m_outputWriter.WriteLineAsync("Could not read from settings file").ConfigureAwait(false);
                }
                return(null);
            }
            var deserializeSettings = new JsonSerializerSettings
            {
                MissingMemberHandling = MissingMemberHandling.Error
            };

            try
            {
                var settingsStore = await Task.Run(() => JsonConvert.DeserializeObject <FrcSettings>(json,
                                                                                                     deserializeSettings)).ConfigureAwait(false);

                if (verbose)
                {
                    await m_outputWriter.WriteLineAsync("Successfully read settings file").ConfigureAwait(false);
                }
                return(settingsStore);
            }
            catch (JsonSerializationException)
            {
                if (verbose)
                {
                    await m_outputWriter.WriteLineAsync("Could not parse settings file").ConfigureAwait(false);
                }
                return(null);
            }
        }