public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication parent = (SPWebApplication)properties.Feature.Parent; // First step is register the action to the Nintex Workflow database XmlDocument nwaXml = GetNWADefinition(properties); ActivityReference newActivityReference = ActivityReference.ReadFromNWA(nwaXml); ActivityReference action = ActivityReferenceCollection.FindByAdapter(newActivityReference.AdapterType, newActivityReference.AdapterAssembly); if (action != null) { // update the details if the adapter already exists ActivityReferenceCollection.UpdateActivity(action.ActivityId, newActivityReference.Name, newActivityReference.Description, newActivityReference.Category, newActivityReference.ActivityAssembly, newActivityReference.ActivityType, newActivityReference.AdapterAssembly, newActivityReference.AdapterType, newActivityReference.HandlerUrl, newActivityReference.ConfigPage, newActivityReference.RenderBehaviour, newActivityReference.Icon, newActivityReference.ToolboxIcon, newActivityReference.WarningIcon, newActivityReference.QuickAccess, newActivityReference.ListTypeFilter); } else { ActivityReferenceCollection.AddActivity(newActivityReference.Name, newActivityReference.Description, newActivityReference.Category, newActivityReference.ActivityAssembly, newActivityReference.ActivityType, newActivityReference.AdapterAssembly, newActivityReference.AdapterType, newActivityReference.HandlerUrl, newActivityReference.ConfigPage, newActivityReference.RenderBehaviour, newActivityReference.Icon, newActivityReference.ToolboxIcon, newActivityReference.WarningIcon, newActivityReference.QuickAccess, newActivityReference.ListTypeFilter); action = ActivityReferenceCollection.FindByAdapter(newActivityReference.AdapterType, newActivityReference.AdapterAssembly); } // Second step is to modify the web.config file to allow use of the activity in declarative workflows string activityTypeName = string.Empty; string activityNamespace = string.Empty; Utility.ExtractNamespaceAndClassName(action.ActivityType, out activityTypeName, out activityNamespace); AuthorisedTypes.InstallAuthorizedWorkflowTypes(parent, action.ActivityAssembly, activityNamespace, activityTypeName); // Third step is to activate the action for the farm ActivityActivationReference reference = new ActivityActivationReference(action.ActivityId, Guid.Empty, Guid.Empty); reference.AddOrUpdateActivationReference(); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { // Retrieve a reference to the parent web application for the feature. SPWebApplication parent = (SPWebApplication)properties.Feature.Parent; foreach (var file in GetAllNwaFilesNWADefinition()) { // Retrieve the contents of the action definition file. XmlDocument nwaXml = GetNWADefinition(file); // Instantiate an ActivityReference object from the action definition file. ActivityReference newActivityReference = ActivityReference.ReadFromNWA(nwaXml); // Attempt to instantiate an ActivityReference object from the the workflow action adapter // identified by the AdapterType and AdapterAssembly elements from the action definition file. // For new deployments, action is set to null; otherwise, the existing ActivityReference // for the custom workflow action is retrieved. ActivityReference action = ActivityReferenceCollection.FindByAdapter( newActivityReference.AdapterType, newActivityReference.AdapterAssembly); // If the custom workflow action has been previously deployed, // update the ActivityReference for the custom action; otherwise, // add a new Activityreference for the custom action and then // instantiate it. if (action != null) { // Update the ActivityReference for the custom workflow action. ActivityReferenceCollection.UpdateActivity( action.ActivityId, newActivityReference.Name, newActivityReference.Description, newActivityReference.Category, newActivityReference.ActivityAssembly, newActivityReference.ActivityType, newActivityReference.AdapterAssembly, newActivityReference.AdapterType, newActivityReference.HandlerUrl, newActivityReference.ConfigPage, newActivityReference.RenderBehaviour, newActivityReference.Icon, newActivityReference.ToolboxIcon, newActivityReference.WarningIcon, newActivityReference.QuickAccess, newActivityReference.ListTypeFilter); } else { // Add a new ActivityReference for the custom workflow action. ActivityReferenceCollection.AddActivity( newActivityReference.Name, newActivityReference.Description, newActivityReference.Category, newActivityReference.ActivityAssembly, newActivityReference.ActivityType, newActivityReference.AdapterAssembly, newActivityReference.AdapterType, newActivityReference.HandlerUrl, newActivityReference.ConfigPage, newActivityReference.RenderBehaviour, newActivityReference.Icon, newActivityReference.ToolboxIcon, newActivityReference.WarningIcon, newActivityReference.QuickAccess, newActivityReference.ListTypeFilter); // Instantiate the newly-added ActivityReference. action = ActivityReferenceCollection.FindByAdapter( newActivityReference.AdapterType, newActivityReference.AdapterAssembly); } // Add a modification to the web.config file for the web application, to install the // custom workflow activity to the collection of authorized activity types for the // web application. string activityTypeName = string.Empty; string activityNamespace = string.Empty; // Extract the type name and namespace name from the value of the ActivityType property. Utility.ExtractNamespaceAndClassName(action.ActivityType, out activityTypeName, out activityNamespace); // Add the assembly, namespace, and type of the workflow activity to the collection of // authorized activity types for the web application. // Activate the custom workflow action. ActivityActivationReference reference = new ActivityActivationReference( action.ActivityId, Guid.Empty, Guid.Empty); reference.AddOrUpdateActivationReference(); } }