OptionsPage and settings for our Shell Package

Discussions related to custom development with Select.
Post Reply
ddudley3
Posts: 55
Joined: Fri May 03, 2013 9:11 am

OptionsPage and settings for our Shell Package

Post by ddudley3 »

We need to be able to store certain configurable values for the Shell Package we've created.

I found the SDK reference and example for the OptionsPage and Settings objects.
I've implemented this and it shows in the Select Options.

However, no matter what I set there, its only shows in the TextBox as long as I'm in Select.exe
Once I exit and go back in, it's null again.

1) How do I save this option and have it show up again when I launch Select?
2) Once it's saved, how do I get to it from my Package to use it? Like I usually do with ConfigurationManager.AppSettings
3) IF this Options Page and IConfigurationManager is not what I need to use, How Can I store any configurable values for my Package ?

Thanks
ddudley3
Posts: 55
Joined: Fri May 03, 2013 9:11 am

Re: OptionsPage and settings for our Shell Package

Post by ddudley3 »

follow up

I can see when I originally created the settings class it created a .Settings section in the Select(Exp).exe.Config file.

There was no key or value like in others.

I therefore tried adding one like other sections has and made the key match my settings field name.
I expected the value to therefore populate in the UI after launching again. It didn;t
Also if I enter a value in the UI it doesn't save it (Even if I explicitly call SaveChanges() with a button in the control).

thanks
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: OptionsPage and settings for our Shell Package

Post by BobRichards »

Select will initialize the settings using the OptionsSetting attribute on the property when they are retrieved through the IConfigurationManager. The values are also persisted when Select closes.

When you change the persisted settings to a value different from their default value, they will be written to the config file. If the user changes the value back to the default state (or only reads but never changes the settings), no settings will be written to the config file (since they are not different than the default state).
Bob Richards, Senior Software Developer, SoftPro
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: OptionsPage and settings for our Shell Package

Post by BobRichards »

The typical usage of the Options page and Settings for Shell packages is as follows:

Create the collection of settings. You can persist strings, dates, and many other types. The OptionsSetting attribute allows you to provide the initial value. In this example, we will only use a single value. However, you can add as many as you wish.

Code: Select all

[Guid("321CEEA8-12D6-446F-858B-187FB4991E8F")]
internal class MySettings : OptionsSettings
{
	[OptionsSetting("Trial")]
	public string LicenseKey { get; set; }
}
Create the form that will be displayed in the Options box by customizing a WinForms UserControl. Modify the contructor to allow passing in the service provider so we can enable two-way binding between the persisted object (a string in this example) and the UI control (a simple TextBox).

Code: Select all

public partial class LicenseOptionsControl : UserControl
{
	public LicenseOptionsControl(IServiceProvider sp)
	{
		InitializeComponent();

		// Get settings and setup two-way binding between persisted object and UI text box.
		IConfigurationManager config = (IConfigurationManager)sp.GetService(typeof(IConfigurationManager));
		MySettings settings = config.GetSettings<MySettings>();
		txtLicenseKey.DataBindings.Add("Text", settings, "LicenseKey");
	}
}
Create a class to handle the control startup.

Code: Select all

internal class LicenseOptionsPage : OptionsPage, IServiceProvider
{
	protected override void OnInitialize()
	{ }

	public override Control CreateControl()
	{
		return new LicenseOptionsControl(this);
	}

	public new object GetService(Type serviceType)
	{
		return base.GetService(serviceType);
	}
}
Finally, add two attributes to the Shell package class to let Select know that your package has two features - an options page AND a settings collection. Your are not required to have both since you may just want to have persisted settings and not allow the user to manipulate them.

Code: Select all

[ProvideOptionsSettings(typeof(MySettings))]
[ProvideOptionsPage("License Options", typeof(LicenseOptionsPage))]
...
partial class MyPackage : Package
To retrieve the settings in your package, just get them from the IConfigurationManager.

Code: Select all

IConfigurationManager configMgr = this.GetService<IConfigurationManager>();
MySettings settings = configMgr.GetSettings<MySettings>();

string license = settings.LicenseKey;
Bob Richards, Senior Software Developer, SoftPro
ddudley3
Posts: 55
Joined: Fri May 03, 2013 9:11 am

Re: OptionsPage and settings for our Shell Package

Post by ddudley3 »

ok great... thanks

so if I choose to not have the

Code: Select all

[ProvideOptionsSettings(typeof(MySettings))]
so that users can't change it... I can still pull it out that's great.

If I initially set the default value to something and then I want to change it later since I don't know what that value is
How do I change it without have that options Page attribute?
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: OptionsPage and settings for our Shell Package

Post by BobRichards »

To be clear, you don't have to have an options page in order to have settings persisted by Select - they are entirely separate. It is the ProvideOptionsPage attribute that provides an options page to the user. You control what the user can access since you have to write the UI. If you don't want the user to be able to change a setting, just don't put it on the options page (or write the value to a UI component and don't provide a binding).

If you want to alter the settings in code, just get the collection and change it. It will be persisted automatically by Select when you exit.

Code: Select all

IConfigurationManager config = (IConfigurationManager)sp.GetService(typeof(IConfigurationManager));
MySettings settings = config.GetSettings<MySettings>();
settings.LicenseKey = "blah blah blah";
Bob Richards, Senior Software Developer, SoftPro
ddudley3
Posts: 55
Joined: Fri May 03, 2013 9:11 am

Re: OptionsPage and settings for our Shell Package

Post by ddudley3 »

I can not include the OptionsPage.
I can set a default value

so, when we go to deploy this package along with SPS Clients and want to change the value

What options do we have?

1) Is it possible to keep the OptionsPage included but "Permission it" based on user/role? so certain ones cannot change or see it?
2) Is it possible for us to know the location of the values storage once it's stored in select. I assume the values are stored in the Database somewhere. This way we can modify the value when we deploy this in a different environment and may need to change the value
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: OptionsPage and settings for our Shell Package

Post by BobRichards »

1) Is it possible to keep the OptionsPage included but "Permission it" based on user/role? so certain ones cannot change or see it?

You write the code for the options page. You can do as you wish. You can retrieve the current user in the UserControl and write the desired information. The easiest thing to do is if user is/is not (or preferably if user is/is not a member of a certain group/role) privileged, then either display the bound controls or else display a label that says "User not authorized to adjust settings for this feature".

2) Is it possible for us to know the location of the values storage once it's stored in select. I assume the values are stored in the Database somewhere. This way we can modify the value when we deploy this in a different environment and may need to change the value

Shell settings are kept on the client machine. They are easy enough to find in AppData, but be aware that accessing them in this manner is a *hack* and is not supported. SoftPro reserves the right to change the location/format/existance of this file at any point without notification. Instead, in your MyPackage initialization, do what you need to do for additional validation/synchronization.
Bob Richards, Senior Software Developer, SoftPro
Post Reply