Exemple #1
0
        public ApplicationDataSettings <T> Settings <T>(
            string key, bool isProtected, string[] subFolders = null, DataScope scope = DataScope.CurrentUser)
        {
            var applicationData = new ApplicationData(this, scope, subFolders);

            key = DataSettingsKey.KeyOrTypeName <T>(key);

            var fullKey = DataSettingsKey.GetFullPath(applicationData, key);

            ApplicationDataSettings <T> applicationDataSettings;

            if (settingsDictionary.ContainsKey(fullKey))
            {
                applicationDataSettings = (ApplicationDataSettings <T>)settingsDictionary[fullKey];

                var fullKeyWithExtension = DataSettingsKey.GetFullPathWithExtension(applicationData, key, isProtected);

                if (!applicationDataSettings.Configuration.Path.Equals(fullKeyWithExtension))
                {
                    var message = string.Format("Cannot change the ApplicationDataSettings with key {0} if already exists.", key);

                    throw new InvalidOperationException(message);
                }

                return(applicationDataSettings);
            }

            applicationDataSettings = applicationData.Settings <T>(isProtected, key);

            return(applicationDataSettings);
        }
Exemple #2
0
        public ApplicationDataSettings <T> Settings <T>(bool isProtected, string key = null)
        {
            key = DataSettingsKey.KeyOrTypeName <T>(key);

            var configuration = new DataSettingsConfiguration(this, isProtected, key);

            var applicationDataSettings = new ApplicationDataSettings <T>(configuration);

            return(applicationDataSettings);
        }
Exemple #3
0
        internal ApplicationData(ApplicationInfo applicationInfo, DataScope scope, IEnumerable <string> subFolders)
        {
            ApplicationInfo = applicationInfo;
            Scope           = scope;

            var subFoldersArray = subFolders == null ? null : subFolders.ToArray();

            if (subFoldersArray != null)
            {
                if (subFoldersArray.Any(string.IsNullOrWhiteSpace))
                {
                    throw new ArgumentException("The sub folders must not be empty.");
                }

                SubFolders = new ReadOnlyCollection <string>(subFoldersArray.ToList());
            }

            Path = DataSettingsKey.GetPartialPath(this);

            Children = new ReadOnlyCollection <ApplicationData>(childrenList);
        }
Exemple #4
0
        internal void RegisterSettings <T>(ApplicationDataSettings <T> applicationDataSettings)
        {
            var key = DataSettingsKey.GetFullPath(applicationDataSettings.Configuration.Data, applicationDataSettings.Configuration.Key);

            settingsDictionary.Add(key, applicationDataSettings);
        }