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 FeatureDeactivating(SPFeatureReceiverProperties properties) { // Retrieve a reference to the parent web application for the feature. SPWebApplication parent = (SPWebApplication)properties.Feature.Parent; foreach (var file in GetAllNwaFilesNWADefinition()) { XmlDocument nwaXml = GetNWADefinition(file); ActivityReference action = ActivityReference.ReadFromNWA(nwaXml); if (action != null) { // If the feature is not activated in any other web application, remove the action // definition from the configuration database. if (!IsFeatureActivatedInAnyWebApp(parent, properties.Definition.Id)) { ActivityReferenceCollection.RemoveAction(action.ActivityId); } // Remove the modification from the web.config file for the web application, to uninstall the // custom workflow activity from 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); // Identify and remove the modification from the web.config file. Collection <SPWebConfigModification> modifications = parent.WebConfigModifications; foreach (SPWebConfigModification modification in modifications) { // If the modification was added by Nintex Workflow, compare the assembly, namespace, and type of the workflow activity to the collection of // authorized activity types in the modification. If they match, remove the modification. // NOTE: AuthorizedTypes.OWNER_TOKEN is the owner token for any modification added by // Nintex Workflow. if (modification.Owner == AuthorisedTypes.OWNER_TOKEN) { if (IsAuthorizedTypeMatch(modification.Value, action.ActivityAssembly, activityTypeName, activityNamespace)) { // Remove the modification. modifications.Remove(modification); // Apply the updated modifications to the SharePoint farm containing the web application. parent.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications(); break; } } } } } }
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(); } }