コード例 #1
0
        /// <summary>
        /// Implementation of <see cref="IWorkflowScript.OnWorkflowScriptExecute" />.
        /// <seealso cref="IWorkflowScript" />
        /// </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            bool result = true;

            try
            {
                Guid     Envelope_Id = Guid.Empty;
                string   propEnvId = "", title = "", notifySigner = "", overrideDeliveryMethod = "", singleEmail = "";
                string[] multipleEmails = new string[10], designers = new string[10];
                bool     notify = true, design = false, uploadStaples = false;

                //Initiate a new TrueSign object. The clint API creds must have been set
                //on Session Property bags before the script was called.
                //TrueSignClientID - holds the Guid for the API client ID
                //TrueSignClientSecret - holds a string for the API client secret
                TrueSignNext TrueSign = new TrueSignNext(app, args);

                //Check if the envelope was already created (in a batch situation)
                if (!args.SessionPropertyBag.TryGetValue("TrueSignEnvelopeId", out propEnvId))
                {
                    //You are here because this is a new envelope. Get the title set in a prop bag
                    args.SessionPropertyBag.TryGetValue("TrueSignEnvelopeTitle", out title);

                    args.SessionPropertyBag.TryGetValue("TrueSignOverrideDeliveryMethod", out overrideDeliveryMethod);

                    //If the title was empty, we will set a default one
                    if (string.IsNullOrEmpty(title))
                    {
                        title = "OnBase Envelope " + DateTime.Now.ToString("g");
                    }

                    //Create a contact object that will be on external envelopes.
                    //This info will appear on the email sent to the required signer. NOT REQUIRED
                    var contact = new Contact();
                    contact.First_Name = "";
                    contact.Last_Name  = "";
                    contact.Title      = "ImageSoft County Court";
                    contact.Email      = "*****@*****.**";
                    contact.Phone      = "(313) 555 - 5555";

                    //Create the actual envelope
                    var env = TrueSign.CreateEnvelope(title, null, null, contact, overrideDeliveryMethod);
                    if (env == null)
                    {
                        throw new Exception("Failed to create a new envelope");
                    }

                    //Set the envelope ID to a property bag.
                    Envelope_Id = env.Id;
                    args.SessionPropertyBag.Set("TrueSignEnvelopeId", Envelope_Id.ToString());
                }
                else
                {
                    //You are here because an envelope has already been created and this is the 1+ document in the batch.
                    //You could also be here because you forgot to clear the properties.
                    Envelope_Id = Guid.Parse(propEnvId);

                    app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Envelope had already been created, adding files...");
                }

                //Upload the current document to the envelope
                var doc = TrueSign.AddToEnvelope(Envelope_Id, args.Document);
                if (doc == null)
                {
                    throw new Exception(string.Format("Failed to add document to envelope. Doc ID: {0}", args.Document.ID));
                }

                args.SessionPropertyBag.TryGetValue("TrueSignUploadStaples", out uploadStaples);
                if (uploadStaples)
                {
                    List <Hyland.Unity.Document> staples = new List <Hyland.Unity.Document>();
                    foreach (var note in args.Document.Notes.FindAll(x => x.NoteType.Flavor == NoteFlavor.Staple))
                    {
                        staples.Add(note.StapledDocument);
                    }

                    if (staples.Count > 0)
                    {
                        TrueSign.AddToEnvelope(Envelope_Id, staples, true);
                    }
                }

                //Call the function to save all notes in a prop bag.
                //This only works when the envelope has one signer and a TrueSignNoteId prop has been set.
                SaveAnchorsToProp(app, args, doc.Id);

                //If this is the last document in the batch
                if (args.BatchDocumentsRemaining == 0)
                {
                    List <Signer> signers = new List <Signer>();

                    //Check if envelope has multiple or single signer
                    //if (args.SessionPropertyBag.TryGetValue("TrueSignSignerEmail", out singleEmail))
                    //    signers.Add(GetSigner(app, args));
                    if (args.SessionPropertyBag.TryGetValue("TrueSignSignerEmail", out multipleEmails))
                    {
                        signers.AddRange(GetSigners(app, args));
                    }
                    else
                    {
                        app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "No property bag for signer email found...");
                    }

                    foreach (Signer signer in signers)
                    {
                        //Check if this envelope is meant for an external signer
                        if (signer.Type == Signer_Type.External)
                        {
                            //Add the signer to the envelope.
                            TrueSign.AddExternalSigner(Envelope_Id, signer);
                        }
                        else
                        {
                            args.SessionPropertyBag.TryGetValue("TrueSignNotifySigner", out notifySigner);

                            if (!string.IsNullOrEmpty(notifySigner))
                            {
                                signer.Notify = bool.Parse(notifySigner);
                            }

                            //This is an internal signer so all we need is their email address
                            TrueSign.AddInternalSigner(Envelope_Id, signer);
                        }
                    }

                    args.SessionPropertyBag.TryGetValue("TrueSignDesign", out design);
                    if (!design)
                    {
                        //Close the envelope and mark it ready for the signer to sign.
                        TrueSign.SendEnvelope(Envelope_Id);
                    }
                    else
                    {
                        args.SessionPropertyBag.TryGetValue("TrueSignDesigners", out designers);
                        var designerList = new List <string>();
                        for (int i = 0; i < designers.Length; i++)
                        {
                            if (!string.IsNullOrEmpty(designers[i]))
                            {
                                designerList.Add(designers[i]);
                            }
                        }

                        TrueSign.SetDesigners(Envelope_Id, designerList);
                    }
                }
            }
            catch (Exception ex)
            {
                app.Diagnostics.Write(ex);
                result = false;
                args.PropertyBag.Set("error", ex.Message);
            }
            args.ScriptResult = result;
        }
コード例 #2
0
        /// <summary>
        /// Implementation of <see cref="IWorkflowScript.OnWorkflowScriptExecute" />.
        /// <seealso cref="IWorkflowScript" />
        /// </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            var result = true;

            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, "Starting Download Envelope Script");

                //Check if this document is of type TrueSign Completed Envelope
                if (args.Document.DocumentType.Name.ToUpper() == "TRUESIGN COMPLETED ENVELOPE")
                {
                    //Initiate a new TrueSign object
                    TrueSignNext TrueSign = new TrueSignNext(app);

                    //Read the JSON of this document as a TrueSign envelope
                    var envelope = TrueSign.ReadEnvelope(args.Document);
                    if (envelope == null)
                    {
                        throw new Exception("Unable to read OnBase doc as a TrueSign Envelope");
                    }

                    //Add all doc ids to a property bag
                    AddDocsProperty(app, args, envelope);

                    //Check if the envelope was rejected
                    if (envelope.Status == Envelope_Status.Rejected)
                    {
                        AddRejectionProperty(app, args, envelope);
                    }
                    else
                    {
                        app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Downloading envelope with ID: {0}", envelope.Id));

                        //Download and create a new revision of the document
                        var success = TrueSign.DownloadEnvelopeDocs(envelope);
                        if (!success)
                        {
                            throw new Exception("Unable to download envelope docs from the TrueSign API");
                        }
                    }
                }
                else
                {
                    string Envelope_Id = "";
                    if (args.SessionPropertyBag.TryGetValue("TrueSignEnvelopeId", out Envelope_Id))
                    {
                        app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Downloading envelope with ID: {0}", Envelope_Id));

                        //Initialize a new TrueSign object. We will retrieve the API creds from the prop bags
                        //TrueSignClientId
                        //TrueSignClientSecret
                        TrueSignNext TrueSign = new TrueSignNext(app, args);

                        //Get the envelope from the API
                        var envelope = TrueSign.GetEnvelope(Guid.Parse(Envelope_Id));
                        if (envelope == null)
                        {
                            throw new Exception(string.Format("Unable to get envelope with ID {0} from TrueSign API", Envelope_Id));
                        }

                        //Add all doc ids to a property bag
                        AddDocsProperty(app, args, envelope);

                        //Check if the envelope was rejected
                        if (envelope.Status == Envelope_Status.Rejected)
                        {
                            AddRejectionProperty(app, args, envelope);
                        }
                        else
                        {
                            //Download and create a new revision of the document
                            var success = TrueSign.DownloadEnvelopeDocs(envelope);
                            if (!success)
                            {
                                throw new Exception("Unable to download envelope docs from the TrueSign API");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("TrueSignEnvelopeId property bag not found.");
                    }
                }
            }
            catch (Exception ex)
            {
                app.Diagnostics.Write(ex);
                result = false;
                args.PropertyBag.Set("error", ex.ToString());
            }

            args.ScriptResult = result;
        }