AddIn System
Overview
Network actions are implemented as AddIns, based on the Microsoft Managed Extensibility Framework.
Therefore, creating a new action is very easy. Follow these steps to create your first action AddIn.
If you think it could be interested for others as well, drop me a line, or post it on the Forum. I will add it then to the catalog of available actions.
Getting Started
First of all, create a new Class Library project within Visual Studio
2010 (Express Version works fine).
Add a reference to “ProxySwitcher.Common.dll”. You can find this DLL in
the ProxySwitcher program folder. You will also need references to
System.ComponentModel.Composition (the component of the Microsoft
Extensible Framework).
Now rename the newly created Class1.cs to a more meaningful name, in my
example “TestAction.cs”. Now you need to add an attribute to the class
to mark it as an AddIn:
using
ProxySwitcher.Common;
namespace MyAction
{
[SwitcherActionAddIn]
public class
MyNewAction :
SwitcherActionBase
As you can see, you also need to inherit from SwitcherActionBase. Here
you can see a basic implementation with comments:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Runtime.InteropServices;
using
ProxySwitcher.Common;
using
System.Windows.Controls;
namespace
MyAction
{
public class
MyNewAction : SwitcherActionBase
{
// Name shown to the user. Best
practice is to use resources for multi language support.
public
override string Name
{
get {
return "My Action Name"; }
}
// Currently not used, so return
string.Empty
public
override string Description
{
get {
return string.Empty; }
}
// If you want an icon to be displayed,
return the Stream.
// For the default icon return null.
public
override Stream IconResourceStream
{
// Set the Build Action to "Embedded
Resource" on an image and use
// the full name including the
namespace to load it here
get {
return Assembly.GetExecutingAssembly().GetManifestResourceStream("MyAction.wallpaper.png");
}
}
// Unique ID for this action. Use
GuidGenerator to create a new GUID.
public
override Guid Id
{
get {
return new
Guid("53538D11-0DA7-4EAF-A5C8-F49672EC6293");
}
}
// With this property, you can group
more addins with the same intense.
// All Action AddIns will be sorted in
the Action Menu by this property.
public
override string Group
{
get {
return "MyGroup"; }
}
// The important method which will be
executed on activating this AddIn
public
override void Activate(Guid
networkId, string networkName)
{
// All networks configured by the user
are identified by an ID (networkId).
// All actions can be associated to
more than one network configuration and
// can also be configured differently.
// You may also use the network name.
// To use the settings differently for
each network where this action is added,
// use the following approach:
string sett1 = Settings[networkId
+ "_Setting1"];
string sett2 = Settings[networkId
+ "_Setting2"];
// To save settings, use the same keys:
Settings[networkId + "_Setting1"]
= "bla";
// The settings will be loaded
automatically.
// After changing the settings, call
this
this.OnSettingsChanged();
// to make sure the settings are saved
and probably updated.
// Now you can set the proxy or do
whatever this AddIn should do.
}
// Here is the optional method you may
implement, if you want the user to configure your AddIn
// This will be called when the user
has added the AddIn to a network and select the Action AddIn.
public
override UserControl GetWindowControl(Guid
networkId, string networkName)
{
// Create a WPF UserControl with the
Height 300 and Width 400 to fit in the main window.
// Use the networkId to assign settings
to this network.
// For Example:
// return new MyUserControl(networkId);
return null;
}
}
}
Download
For a more advanced sample, download the “ChangeWallpaperAction”
here.
Proxy Action
If you want to create an Action AddIn for default proxy settings, you
can also inherit from “ProxySwitcher.Actions.ProxyBase.ProxySwitcherAction”.
This enables you to re-use the existing configuration control.
Deployment
To make it available to Proxy Switcher, copy the DLL to the
ProxySwitcher\AddIns directoy. If you have created multi language
resource files, copy the satellite assemblies to ProxySwitcher\de for
german. English must be used as the default language.