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(); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { //Check if activity is allowed to run ActivityActivationReference.IsAllowed(this, __Context.Web); //Resolve tags in string (variables, etc) NWWorkflowContext ctx = NWWorkflowContext.GetContext(__Context, new Guid(__ListId), __ListItem.Id, WorkflowInstanceId, this); //Activity has begun executing base.LogProgressStart(ctx); LogHelper.LogInfo(Cat, "NTX PowerShell running at: " + this.__Context.CurrentItemUrl); //Determine if a Workflow Constant is being used for authentication string runtimeUsername = null; string runtimePassword = null; if (LoginUserName.Contains("WFConstant") & LoginPassword == "") { CredentialValue.DetermineRuntimeCredentials(LoginUserName, LoginPassword, out runtimeUsername, out runtimePassword, ctx.Context.Web.ID, ctx.Context.Site.ID); } else { runtimeUsername = LoginUserName; runtimePassword = LoginPassword; } String script = ctx.AddContextDataToString(PSScript); try { var ps = new PSHelper(); LogHelper.LogInfo(Cat, "Executing script as " + runtimeUsername + " on " + ComputerName + AppName + ":" + PortNumber + " SSL Enabled: " + SSLEnabled); ps.CreatePowerShellRunspace(SSLEnabled, ComputerName, PortNumber, AppName, ShellUri, runtimeUsername, runtimePassword); ps.SetRunSpaceVariable("NTXWorkflowContext", __Context); ps.SetRunSpaceVariable("NTXListID", new Guid(__ListId)); ps.SetRunSpaceVariable("NTXWorkflowInstanceID", new Guid(__ListId)); LogHelper.LogInfo(Cat, "NTX PowerShell RunSpaceVariables loaded"); ps.AddScriptToPipeLine(script); LogHelper.LogInfo(Cat, "NTX PowerShell Script loaded: " + script); ps.ConvertPipeContentsToString(); ResultOutput = ps.ProcessResultsToString(ps.InvokePipeline()); //Added to ensure runspaces are closed after execution completes. https://msdn.microsoft.com/en-us/library/system.management.automation.runspaces.runspacefactory(v=vs.85).aspx ps.DisposePowerShellRunspace(); } catch (Exception e) { ResultOutput = e.ToString(); LogHelper.LogException(Cat, e); } //activity has stopped executing base.LogProgressEnd(ctx, executionContext); LogHelper.LogInfo(Cat, "NTX PowerShell completed at: " + __Context.CurrentItemUrl); return(ActivityExecutionStatus.Closed); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { ActivityActivationReference.IsAllowed(this, __Context.Web); // Get the workflow context for the workflow activity. NWWorkflowContext ctx = NWWorkflowContext.GetContext(__Context, new Guid(__ListId), __ListItem.Id, WorkflowInstanceId, this); base.LogProgressStart(ctx); string approverNames = ctx.AddContextDataToString(this.Approvers); string qryUrl = ctx.AddContextDataToString(this.UrlMiscInfo); string[] approvers = Akki.AdobeSign.Common.Utilities.GetUserEmails(approverNames, ctx.Web.Url).ToArray(); try { SPList spList = this.__Context.Web.Lists[new Guid(this.__ListId)]; SPListItem spItm = spList.GetItemById(this.__ListItem.Id); var agreeementName = string.Format(Constants.MsgListItemAgreementName, spItm.ID, spList.Title); SPView listView = spList.Views[Constants.AkkiItemViewTypeAdobe]; if (listView == null) { throw new ApplicationException(Constants.ErrNoViewFound); } SPViewFieldCollection viewfieldCollection = listView.ViewFields; StringBuilder buff = new StringBuilder(16); buff.Append(Constants.HeaderTextInfo); foreach (string viewFieldName in viewfieldCollection) { buff.Append(Environment.NewLine); buff.Append(Environment.NewLine); var val = spItm[viewFieldName]; buff.Append(string.Format("{0}:{1}", viewFieldName, val)); buff.Append(Environment.NewLine); buff.Append(Environment.NewLine); } var agreementId = AdobeOperations.SendDocumentByBytesForSigninig(Encoding.ASCII.GetBytes(buff.ToString()), null, agreeementName, approvers, null, qryUrl).agreementId; this.OutAdobeAgreementID = agreementId; // if no problem try { Utilities.SetDefaultColValues(spItm, agreementId, AgreementStatus.OUT_FOR_SIGNATURE); } catch { } } catch (Exception ex) { //log.Error("[Execute]", ex); throw; } base.LogProgressEnd(ctx, executionContext); return(ActivityExecutionStatus.Closed); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { ActivityActivationReference.IsAllowed(this, __Context.Web); // Get the workflow context for the workflow activity. NWWorkflowContext ctx = NWWorkflowContext.GetContext(__Context, new Guid(__ListId), __ListItem.Id, WorkflowInstanceId, this); base.LogProgressStart(ctx); //BLOG. this function // get all the properties you need here string aggreementName = ctx.AddContextDataToString(this.AgreementName); string approversProp = ctx.AddContextDataToString(this.Approvers); string qryUrl = ctx.AddContextDataToString(this.UrlMiscInfo); string compDocsIds = ctx.AddContextDataToString(this.CompendiumDocsID); try { SPList spList = this.__Context.Web.Lists[new Guid(this.__ListId)]; SPListItem spItm = spList.GetItemById(this.__ListItem.Id); aggreementName = string.IsNullOrEmpty(aggreementName) ? spList.Title + "-" + spItm.ID + "-" + spItm.File.Name : aggreementName; List <string> lstApprovers = Akki.AdobeSign.Common.Utilities.GetUserEmails(approversProp, ctx.Web.Url); this.HistoryListMessage = "Initiator Email " + ctx.WorkflowInitiator.Email; // get the bytes for all the compendium documents List <byte[]> comDocBytes = null; if (!string.IsNullOrEmpty(compDocsIds)) { comDocBytes = new List <byte[]>(); var docsID = compDocsIds.Split(Constants.Delimiter); foreach (var doc in docsID) { int docId = int.Parse(doc); var spItmCompDoc = spList.GetItemById(docId); comDocBytes.Add(spItmCompDoc.File.OpenBinary()); } } var response = AdobeOperations.SendDocumentByBytesForAuthoring(spItm.File.OpenBinary(), comDocBytes, aggreementName, lstApprovers.ToArray(), ctx.WorkflowInitiator.Email, qryUrl); this.HistoryListMessage = string.Format(Constants.MsgAgreemntID, response.agreementId); this.OutAdobeAgreementID = response.agreementId; this.OutAuthoringUrl = response.url; } catch (Exception e) { //log.Error("[Execute]:", e); throw; } base.LogProgressEnd(ctx, executionContext); return(ActivityExecutionStatus.Closed); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { try { ActivityActivationReference.IsAllowed(this, __Context.Web); // Get the workflow context for the workflow activity. NWWorkflowContext ctx = NWWorkflowContext.GetContext(__Context, new Guid(__ListId), __ListItem.Id, WorkflowInstanceId, this); base.LogProgressStart(ctx); //BLOG. this function ttps://community.nintex.com/docs/DOC-1673-list-of-nintex-workflowonpremise-custom-actions // get all the properties you need here string agreementID = ctx.AddContextDataToString(this.AgreementID); var destsiteUrl = ctx.AddContextDataToString(this.DestSiteUrl); var destDocLib = ctx.AddContextDataToString(this.DestDocLib); var destDocName = ctx.AddContextDataToString(this.DestDocName); var spWeb = string.IsNullOrEmpty(destsiteUrl) ? this.__Context.Web : new SPSite(destsiteUrl).OpenWeb(); var docLib = string.IsNullOrEmpty(destDocLib) ? spWeb.Lists[new Guid(this.__ListId)] : spWeb.Lists[destDocLib]; destDocName = (string.IsNullOrEmpty(destDocName) ? this.__Context.ItemName : Path.GetFileNameWithoutExtension(destDocName)) + Constants.PdfExtension; string destFileUrl = (docLib.RootFolder.ServerRelativeUrl.EndsWith("/") ? docLib.RootFolder.ServerRelativeUrl : docLib.RootFolder.ServerRelativeUrl + "/") + destDocName; if (string.IsNullOrEmpty(agreementID)) { this.HistoryListMessage = Constants.ErrNoAgreememtID; } else { var fileBytes = AdobeOperations.GetSignedDocument(agreementID); //TODO...use the input parameter for overriding SPFile spFile = spWeb.Files.Add(destFileUrl, fileBytes, true); spFile.Update(); // Utilities.SetDefaultColValues(spFile.Item, agreementID, AgreementStatus.SIGNED); this.OutDocumentID = spFile.Item.ID; this.HistoryListMessage = Constants.MsgDocmuentUploadedSuccessfully; } base.LogProgressEnd(ctx, executionContext); return(ActivityExecutionStatus.Closed); } catch (Exception e) { ///log.Error("[Execute]", e); throw; } }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { ActivityActivationReference.IsAllowed(this, __Context.Web); // Get the workflow context for the workflow activity. NWWorkflowContext ctx = NWWorkflowContext.GetContext(__Context, new Guid(__ListId), __ListItem.Id, WorkflowInstanceId, this); base.LogProgressStart(ctx); string agreementId = ctx.AddContextDataToString(this.AgreementID); if (string.IsNullOrEmpty(agreementId)) { //log.Error("[Execute]:" + Constants.ErrNoAgreementID); throw new ApplicationException(Constants.ErrNoAgreementID); } try { AgreementInfo agreementInfo = AdobeOperations.GetAgreementStatus(agreementId); if (agreementInfo == null) { // TODO: log4Net, debug // log in history this.LogHistoryListMessage = true; this.HistoryListMessage = string.Format(Constants.ErrNoAgreementFound, agreementId); } else { // LOG events and status this.Status = agreementInfo.status.ToString(); this.Events = Utilities.SerializeXml <List <DocumentHistoryEvent> >(agreementInfo.events); if (agreementInfo.nextParticipantSetInfos != null) { this.PendingApprovers = string.Join(";", agreementInfo.nextParticipantSetInfos.SelectMany(npSInfo => npSInfo.nextParticipantSetMemberInfos).ToList().Select(e => e.email).ToArray()); } } } catch (Exception e) { //log.Error("[Execute]", e); throw; } base.LogProgressEnd(ctx, executionContext); return(ActivityExecutionStatus.Closed); }
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(); } }