MichaelvdV@Atos

AFPlugin configuration as CLR object

Discussion created by MichaelvdV@Atos on May 10, 2010
Latest reply on Nov 10, 2011 by MvanderVeeken

I'm (still) fairly new to AF development, but something came to mind which I would like to share.

 

It seems that the only way to store configuration information is trough the configString property. You can save the information as a string, and you have to parse and construct the string to extract the 'property' information.

 

For my own convienance I have came up with a simple routine that serializes a CLR configuration object (which has properties) to a string, and stores that into the ConfigString property. This object is then used in my custom DataReference configuration form.

 

I find this very handy, and better to use then then the option used in the examples, where you have to parse and construct the string.

 

What do you guys think? It seems something like this could save some development time. Could something like this be implemented in AF itself?

#region Configuration
private string ConfigString_backing;
public override string ConfigString
{
    get
    {
        return ConfigString_backing;
    }
    set
    {
       ConfigString_backing = value;
       SaveConfigChanges();
    }
}

public TSDMDataReferenceConfiguration GetConfiguration()
{
    DataContractSerializer serializer = new DataContractSerializer(typeof(TSDMDataReferenceConfiguration));
    using (MemoryStream s = new MemoryStream(Encoding.ASCII.GetBytes(ConfigString)))
    {
        TSDMDataReferenceConfiguration config = serializer.ReadObject(s) as TSDMDataReferenceConfiguration;
        return config;
    }
}

public void SetConfiguration(TSDMDataReferenceConfiguration configuration)
{
    DataContractSerializer serializer = new DataContractSerializer(typeof(TSDMDataReferenceConfiguration));
    using (MemoryStream s = new MemoryStream())
    {
        serializer.WriteObject(s, configuration);
        using (StreamReader reader = new StreamReader(s))
        {
            s.Seek(0, SeekOrigin.Begin);
            string serialized = reader.ReadToEnd();
            ConfigString = serialized;
        }
    }
}
#endregion

Outcomes