Nevron Open Vision Documentation
Framework / System / Application Settings
In This Topic
    Application Settings
    In This Topic

    NOV provides a cross-platform way for NOV applications to store application settings - key/byte array pairs. This is done via the following methods of the static NApplication class:

    Under the hood, NOV saves the application settings to the following location depending on the platform the NOV code is running on:

    The following example demonstrates a sample NOV DOM node that can be used for application settings:

    Sample Application Settings Class
    Copy Code
    public class MyAppSettings : NNode
    {
        public MyAppSettings()
        {
        }
        static MyAppSettings()
        {
            MyAppSettingsSchema = NSchema.Create(typeof(MyAppSettings), NNodeSchema);
            ThemeProperty = MyAppSettingsSchema.AddSlot("Theme", typeof(ENUITheme), ENUITheme.Windows10);
            DeveloperModeProperty = MyAppSettingsSchema.AddSlot("DeveloperMode", NDomType.Boolean, false);
        }
    
        public ENUITheme Theme
        {
            get
            {
                return (ENUITheme)GetValue(ThemeProperty);
            }
            set
            {
                SetValue(ThemeProperty, value);
            }
        }
        public bool DeveloperMode
        {
            get
            {
                return (bool)GetValue(DeveloperModeProperty);
            }
            set
            {
                SetValue(DeveloperModeProperty, value);
            }
        }
    
        public static readonly NSchema MyAppSettingsSchema;
        public static readonly NProperty ThemeProperty;
        public static readonly NProperty DeveloperModeProperty;
    }
    

    You can use the following code to save and load the application settings:

    Saving and Loading Application Settings
    Copy Code
    private void SaveSettingsButton_Click(NEventArgs arg)
    {
        using (MemoryStream stream = new MemoryStream())
        {
            // Use a DOM node serializer to save the app settings to a memory stream
            NDomNodeSerializer serializer = new NDomNodeSerializer();
            serializer.SaveToStream(m_AppSettings, stream, SettingsFormat);
            // Save the settings data
            byte[] settingsData = stream.ToArray();
            NApplication.SetSettingAsync(AppSettingsKey, settingsData).Then(
                delegate (NUndefined ud)
                {
                    // Settings saved successfully
                }
            );
        }
    }
    
    private void LoadSettingsButton_Click(NEventArgs arg)
    {
        // Load the settings data
        NApplication.GetSettingAsync(AppSettingsKey).Then(
            delegate (byte[] settingsData)
            {
                using (MemoryStream stream = new MemoryStream(settingsData))
                {
                    // Use a DOM node deserializer to load the app settings from the memory stream
                    NDomNodeDeserializer deserializer = new NDomNodeDeserializer();
                    MyAppSettings loadedSettings = (MyAppSettings)deserializer.LoadFromStream(stream, SettingsFormat)[0];
                }
            },
            delegate (Exception ex)
            {
                NMessageBox.ShowError("Failed to load the app settings. Exception was: " + ex.Message, "Error");
            }
        );
    }
    

    You can always store your application's settings in any other way, but if you plan to release your NOV application to other platforms, too, then we strongly recommend you use the NOV application settings mechanism. This will save you a lot of work in the future.

    See Also

    Serialization