Profile Picture

New methods added to IService Interface

Posted By dplaisted 10 Years Ago
Message
Posted Monday February 26 2007
We have added three new methods to the IService interface.  These methods allow a service to define various custom settings, and to display a dialog to modify them.  They were added in response to feedback that services may need more settings than a server address, port, username, and password.  They were also added to allow commission settings to be specified for the paper trade broker.

Here are the three methods:

bool HasCustomSettings();
bool ShowCustomSettingsForm(ref SerializableDictionary<string, string> settings);
bool Initialize(SerializableDictionary<string, string> settings);

If you have written a service plugin, you will need to add these three methods.  If you do not need to use custom settings in your service, return false from HasCustomSettings() and ShowCustomSettingsForm(), and return true from Initialize().

If you would like to use custom settings, then return true from HasCustomSettings().  This will enable the "Other Settings..." button in the service setup dialog for your plugin.  When this button is pressed, ShowCustomSettingsForm() will be called.  You should then show a dialog allowing the settings to be changed.  If the user accepts the changes made in your dialog box, you should return true, and the settings dictionary that was passed in should reflect the updated settings.  If the user cancels, return false.  The Initialize() method will be called just after your plugin is created, giving you access to the current custom settings.

The settings dictionary that is passed to you will be empty the if the service has been created and the user hasn't set up the custom settings yet.  Also, if you want to store some type of data besides a string, you will have to convert it back and forth.  Here is some sample code from the Paper trader which shows how you can handle these issues.

private double _flatCommission = 0.0;

private double _perShareCommission = 0.0;

private double _minCommission = 0.0;

private double _maxCommission = 0.0;

 

public virtual bool HasCustomSettings()

{

return true;

}

public virtual bool ShowCustomSettingsForm(ref SerializableDictionary<string, string> settings)

{

PaperTraderSettings dlg = new PaperTraderSettings();

string val;

if (settings.TryGetValue("FlatCommission", out val))

{

dlg.FlatCommission = double.Parse(val);

}

if (settings.TryGetValue("PerShareCommission", out val))

{

dlg.PerShareCommission = double.Parse(val);

}

if (settings.TryGetValue("MinCommission", out val))

{

dlg.MinCommission = double.Parse(val);

}

if (settings.TryGetValue("MaxCommission", out val))

{

dlg.MaxCommission = double.Parse(val);

}

if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)

{

settings["FlatCommission"] = dlg.FlatCommission.ToString();

settings["PerShareCommission"] = dlg.PerShareCommission.ToString();

settings["MinCommission"] = dlg.MinCommission.ToString();

settings["MaxCommission"] = dlg.MaxCommission.ToString();

return true;

}

return false;

}

public virtual bool Initialize(SerializableDictionary<string, string> settings)

{

_flatCommission = 0.0;

_perShareCommission = 0.0;

_minCommission = 0.0;

_maxCommission = 0.0;

string val;

if (settings.TryGetValue("FlatCommission", out val))

{

if (!double.TryParse(val, out _flatCommission))

{

lastError = "FlatCommission was not a number.";

return false;

}

}

if (settings.TryGetValue("PerShareCommission", out val))

{

if (!double.TryParse(val, out _perShareCommission))

{

lastError = "PerShareCommission was not a number.";

return false;

}

}

if (settings.TryGetValue("MinCommission", out val))

{

if (!double.TryParse(val, out _minCommission))

{

lastError = "MinCommission was not a number.";

return false;

}

}

if (settings.TryGetValue("MaxCommission", out val))

{

if (!double.TryParse(val, out _maxCommission))

{

lastError = "MaxCommission was not a number.";

return false;

}

}

return true;

}

Thanks,
Daniel



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems