Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            // Get the workflow context for the workflow activity.
            NWWorkflowContext ctx = NWWorkflowContext.GetContext(
                this.__Context,
                new Guid(this.__ListId),
                this.__ListItem.Id,
                this.WorkflowInstanceId,
                this);

            string resolvedFieldValue = ctx.AddContextDataToString(this.TaxFieldValue);
            string resolvedListID     = ctx.AddContextDataToString(this.lookupList);
            int    resolvedItemID     = int.Parse(ctx.AddContextDataToString(this.itemID));

            base.LogProgressStart(ctx);

            Nintex.Workflow.Diagnostics.EventLogger.Log(
                "Updating '" + TaxonomyFieldName + "' Value '" + TaxFieldValue + "' ",
                Microsoft.SharePoint.Administration.TraceSeverity.Verbose,
                _ErrorSource);

            try
            {
                SPList             list               = ctx.Web.Lists.GetList(new Guid(resolvedListID), false);
                SPListItem         item               = list.GetItemById(resolvedItemID);
                TaxonomyField      taxonomyField      = list.Fields[TaxonomyFieldName] as TaxonomyField;
                TaxonomyFieldValue taxonomyFieldValue = new TaxonomyFieldValue(taxonomyField);

                String[] TermValues = resolvedFieldValue.Split('|');
                if (TermValues[0].Length > 0)
                {
                    // value|GUID
                    if (TermValues.Length == 2)
                    {
                        taxonomyFieldValue.Label    = TermValues[0];
                        taxonomyFieldValue.TermGuid = TermValues[1];
                    }
                    taxonomyField.SetFieldValue(item, taxonomyFieldValue);
                    item.SystemUpdate(false);
                }
            }
            catch (Exception ex)
            {
                Nintex.Workflow.Diagnostics.EventLogger.Log(
                    "Error occured while updating '" + TaxonomyFieldName + "' Value '" + resolvedFieldValue + "' " + ex.Message,
                    Microsoft.SharePoint.Administration.TraceSeverity.Unexpected,
                    _ErrorSource);
            }

            base.LogProgressEnd(ctx, executionContext);
            return(ActivityExecutionStatus.Closed);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
 internal string GetLastApproverCommentsAsXml(NWWorkflowContext ctx)
 {
     return new NintexTaskCollection(ctx.InstanceID, ctx.Web).GetAllApprovalTaskCommentsAsXml();
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ctx"></param>
 /// <returns></returns>
 public override object GetValueObject(NWWorkflowContext ctx)
 {
     return GetLastApproverCommentsAsXml(ctx);
 }
Exemplo n.º 9
0
 internal string GetLastApproverCommentsAsXml(NWWorkflowContext ctx)
 {
     return(new NintexTaskCollection(ctx.InstanceID, ctx.Web).GetAllApprovalTaskCommentsAsXml());
 }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ctx"></param>
 /// <returns></returns>
 public override object GetValueObject(NWWorkflowContext ctx)
 {
     return(GetLastApproverCommentsAsXml(ctx));
 }