Amazon.Runtime.Internal.Settings.PersistenceManager.saveSettingsType C# (CSharp) Метод

saveSettingsType() приватный Метод

private saveSettingsType ( string type, SettingsCollection settings ) : void
type string
settings SettingsCollection
Результат void
        void saveSettingsType(string type, SettingsCollection settings)
        {
            this.disableWatcher(type);
            try
            {
                var filePath = getFileFromType(type);

                if (settings == null || settings.Count == 0)
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    return;
                }

                // Cover the case where the file still has a lock on it from a previous IO access and needs time to let go.
                var retryAttempt = 0;
                while(true)
                {
                    try
                    {
                        using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
                        using (var writer = new StreamWriter(stream))
                        {
                            settings.Persist(writer);
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        if (retryAttempt < 5)
                        {
                            Thread.Sleep(1000);
                            retryAttempt++;
                        }
                        else
                            throw;
                    }
                }
            }
            finally
            {
                this.enableWatcher(type);
            }
        }