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:
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.
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.This section summarizes how to use applications settings. There are 3 steps:
Extend custom settings class in application project.
Reference custom settings in application code.
After deployment, adjust settings runtime.
In your application's generated project, open this file: [YourProjectDirectory]\Objects\Application\Application_[YourAppName]_Settings.cs
Code should look like this:
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.
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;} } }
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.
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); } } }
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.