Click or drag to resize
How To use application settings

PACKflow provides a per-application, database-persisted settings API, along with an auto-generated web interface for convenient edition.

This topic contains the following sections:

Introduction
Application codes often need to access settings shaping their behavior.

A contact email address, quotas on content-types, or a custom screen's welcome message are good examples.

Developers usually address this issue using the standard System.Configuration namespace. This allows defining settings in the .config files of the executable hosting the assembly.

This approach is convenient by its simple use and genericity, but shows architectural limitations within PACKflow, where an application is hosted in several processes :

  • Editing an application setting would require editing a .config file for every execution context and would be quite error-prone. Moreover, changing a value would need a downtime to ensure behavior consistency.

  • Developpers don't know in advance every possible execution context for their codes. Custom execution environments may add to PACKflow's default processes, making the task to know every .config file location impossible.

  • .config files are expected to hold system, process-specific settings, because these may vary along processes. As an exemple, a connection string to the same database may differ by process for security reasons.

  • Many applications run concurrently on PACKflow processes. A file per app would lead to a demultiplication of .config files, with possible performance and deployment issues.

Overview

PACKflow provides an easy-to-use, process-independant application settings systems.

Generated applications embed a strongly typed settings class. Developers can extend it with simple properties.

The settings class instance is persisted in database when saving the application.

App Settings 1
Walktrough

This section summarizes how to use applications settings. There are 3 steps:

  1. Extend custom settings class in application project.

  2. Reference custom settings in application code.

  3. After deployment, adjust settings runtime.

1. Extend settings class

In your application's generated project, open this file: [YourProjectDirectory]\Objects\Application\Application_[YourAppName]_Settings.cs

Code should look like this:

C#
namespace Packflow.YourApplication
{
    /* Add serializable properties (using the DataMember attribute) in this class 
    will make them available in the web administration and on your PFApplication instances.
    The following types are currently accepted: String, decimal, Boolean and DateTimeOffset. */
    [DataContract]
    public class Application_YourApplication_Settings : PFApplicationSettings
    {

    }
}

Extend the class with the necessary settings, as public properties. Add a 'DataMember' attribute on them.

String, Decimal, Boolean and DateTimeOffset are the accepted types.

C#
namespace Packflow.YourApplication
{
    [DataContract]
    public class Application_YourApplication_Settings : PFApplicationSettings
    {
            [DataMember]
            public string WelcomeMessage {get;set;}

            [DataMember]
            public decimal ItemsQuota {get;set;}

            [DataMember]
            public DateTimeOffset CountdownReference {get;set;}

            [DataMember]
            public Boolean SendConfirmationsToAdmins {get;set;}
    }
}

2. Use settings in code

Here is an exemple on how to access strongly typed settings from an item's class. In this case, this would be usefull to customize a modeled notification message.

C#
namespace Packflow.MyApplication
{
    public partial class Concept : ItemOfApplication_MyApplication
    {
        public override string GetMessagePlaceHolderContent(string placeHolderName, string language)
        {
            string message = ParentApplication.Settings.WelcomeMessage;
            DateTimeOffset countDown = ParentApplication.Settings.CountdownReference;

            //Use settings to customize notification message.

            return base.GetMessagePlaceHolderContent(placeHolderName, language);
        }
    }
}

3. Adjust settings runtime

After deployment, browse to the applications settings page, under : [YourSiteUrl]/Administration/AppSettings

You will find the editable settings under your application's node, in an auto-generated interface. Site administrators can edit and save settings from here.

Note how CamelCasing in property name is converted to display names.

App Settings 2
See Also