Home » Microsoft TechnologiesRSS

How to Add custom WF4 Activities to ToolBox using Code?

Hi

I have a number of custom activities in my dll. My requirement is to add the custom activities to ToolBox using Code/installer.

I written the following code

System.Reflection.Assembly asm;
asm = Assembly.LoadFrom(Path.Combine(assemblyPath, @"MyProject.dll"));

var types = from t in asm.GetExportedTypes()
wheretypeof(Activity).IsAssignableFrom(t)
select t.FullName;

if (types != null && types.Count() > 0)
{
string activityName;
foreach (var item in types)
{
activityName = item.Substring(item.LastIndexOf(".") + 1);
myTab.ToolBoxItems.Add(activityName, item); 
} 
}

Above code is adding the activities to the Toolbox as HTML Controls. How can I add the same as WF4 Activities in Toolbox ?

Thanks
Ambily

 

2 Answers Found

 

Answer 1

Hi, Ambily

I notice your mail in the discussion list also, So far, I think SGuy Ge's anwser is helpful. here quote his reply:

"

You’ll need to write a VS package for that purpose. Please take a look at the State Machine release on CodePlex as an example, it includes such a VS package.

 

Be noted that it works a bit differently than you might have expected, i.e. the toolbox  items are not installed during installation time, rather, it’s installed when the package is being loaded. But it’s closest to what you want.

"
Hope it would be helpful to others

Thanks
 

Answer 2

Hi Andrew

Thanks for the Reply.

We resolved the issue using the following code  snippet. Only issue left is, it taking the default toolbox  icon.

 

if (File.Exists(Path.Combine(libPath, @"Myproject.dll")))
   {    
    string myTab = "MyTab";
    EnvDTE.Window window = dte.Windows.Item(EnvDTEConstants.vsWindowKindToolbox);
    EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)window.Object;
    ToolBoxTab initialTab = toolbox.ActiveTab;
    EnvDTE.ToolBoxTab myTab = null;
    foreach (ToolBoxTab tab in toolbox.ToolBoxTabs)
    {
     if (tab.Name.ToUpper() == myTab.ToUpper())
     {
      myTab = tab;
      break;
     }
    }

    if (myTab != null)
    {
     myTab.Delete();
    }

    myTab = toolbox.ToolBoxTabs.Add(myTab);
    myTab.Activate();

    var asm  = Assembly.LoadFrom(Path.Combine(libPath, @"Myproject.dll"));

    var types  = from t in asm.GetExportedTypes()
       wheretypeof(Activity).IsAssignableFrom(t)
       select t;

    if (types != null && types.Count() > 0)
    {
     foreach (var item  in types)
     {
      var dataObject = new OleDataObject();
      dataObject.SetData("AssemblyName", asm.GetName());
      dataObject.SetData("CF_WORKFLOW_4", item.Name);
      dataObject.SetData("WorkflowItemTypeNameFormat", item.AssemblyQualifiedName);
      myTab.ToolBoxItems.Add(item.Name, dataObject, vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
     }
    }
   }

 

Thanks

Ambily


Associate Consultant
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter