Esempio n. 1
0
        public void Initialize()
        {
            if (!File.Exists(EnvironmentVariables.SettingsFilePath))
            {
                CreateNewSettingsFile();
            }
            else
            {
                LoadCurrent();
            }

            var settingsModels     = IoC.GetAll <ISettingsDataModel>();
            var settingsCategories = IoC.GetAll <ISettingsCategory>();

            foreach (var settingsCategory in settingsCategories)
            {
                SettingsFile.AddCategoryElement(settingsCategory);
            }

            foreach (var settingsModel in settingsModels)
            {
                if (SettingsFile.GetSingleNode(settingsModel.SettingsFilePath) == null)
                {
                    //if (settingsModel.Category.IsToolsOptionsCategory)
                    SettingsFile.AddToolsOptionsModelElement(settingsModel.Name, settingsModel.Category.Name);
                    //else
                    //    throw new NotImplementedException();
                }
                settingsModel.LoadOrCreate();
            }
            Initialized?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 2
0
        protected GetValueResult GetOrCreatePropertyValueInternal <T>(string propertyPath, string propertyName,
                                                                      out T value, bool createNew, T defaultValue = default(T), bool navigateAttributeWise = true)
        {
            value = defaultValue;
            var data = SettingsFile.GetPropertyValueData(propertyPath, propertyName, navigateAttributeWise);

            //Could not find, but we can create a PropertyValue element
            if (data == null && createNew)
            {
                var node = SettingsFile.GetSingleNode(propertyPath);
                if (node == null)
                {
                    return(GetValueResult.Missing);
                }
                SettingsFile.AddPropertyValueElement(node, propertyName, value?.ToString());
                return(GetValueResult.Created);
            }
            //Don't create PropertyValue if data is null
            return(data == null ? GetValueResult.Missing : TryGetValue(data, out value, defaultValue));
        }
Esempio n. 3
0
 public XmlNode GetDataModelNode(string settingsFilePath)
 {
     return(SettingsFile.GetSingleNode(settingsFilePath));
 }