コード例 #1
0
        public ActionResult Sample44()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                string message = null;
                //Get post data
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String firstEmail = Request.Form["firstEmail"];
                String firstName = Request.Form["firstName"];
                String lastName = Request.Form["lastName"];
                String secondEmail = Request.Form["secondEmail"];
                String basePath = Request.Form["basePath"];
                //Set second signer name. Can be obtained in the same manner as first signer name.
                String secondName = firstName + "2";
                String gender = Request.Form["gender"];
                var file = Request.Files["file"];
                String uploadedGuid = "";
                String iframe = "";
                String secondIframe = "";
                // Check is all requered fields are entered
                if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey) || String.IsNullOrEmpty(firstEmail) || String.IsNullOrEmpty(secondEmail) ||
                    String.IsNullOrEmpty(firstName) || String.IsNullOrEmpty(secondName))
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample44", null, result);
                }
                else
                {
                    if (basePath.Equals(""))
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //Upload local file
                    Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                    if (upload.Guid != null)
                    {
                        //If file uploaded return it's guid
                        uploadedGuid = upload.Guid;
                        //Check is file uploaded
                        if (!uploadedGuid.Equals(""))
                        {
                            //Created array with data for merging
                            System.Collections.Hashtable enteredData = new System.Collections.Hashtable();
                            enteredData.Add("gender", gender);
                            enteredData.Add("name", firstName);
                            //Set fields counter
                            Int32 count = enteredData.Count;
                            //Create Datasource object
                            Groupdocs.Assembly.Data.Datasource dataSource = new Groupdocs.Assembly.Data.Datasource();
                            //Create array of DatasourceField objects
                            Groupdocs.Assembly.Data.DatasourceField[] fieldArray = new Groupdocs.Assembly.Data.DatasourceField[count];
                            //Set DatasourceFiled data
                            Int32 counter = 0;
                            foreach (System.Collections.DictionaryEntry fields in enteredData)
                            {
                                //Set object array content
                                string[] values = new string[1];
                                values.SetValue(System.Convert.ToString(fields.Value), 0);
                                Groupdocs.Assembly.Data.DatasourceField field = new Groupdocs.Assembly.Data.DatasourceField();
                                Groupdocs.Assembly.Data.DatasourceFieldType type = new Groupdocs.Assembly.Data.DatasourceFieldType();
                                type = 0;
                                field.Name = System.Convert.ToString(fields.Key);
                                field.Type = type;
                                field.Values = values;
                                //Push DatasourceField to array of DatasourceField objects
                                fieldArray.SetValue(field, counter);
                                counter++;
                            }
                            //Set fields array to the Datasource
                            dataSource.Fields = fieldArray;
                            //Add new Datasource to GroupDocs
                            decimal addDataSource = service.AddDataSource(dataSource);
                            //Check is not empty addDataSource
                            if (!addDataSource.Equals(""))
                            {
                                //If status ok merge Datasource to new pdf file
                                decimal job = service.MergeTemplate(uploadedGuid, addDataSource, "pdf", false);
                                if (!job.Equals(""))
                                {
                                    //Delay necessary that the inquiry would manage to be processed
                                    System.Threading.Thread.Sleep(5000);
                                    //Create Job info object
                                    Groupdocs.Api.Contract.GetJobDocumentsResult jobInfo = new Groupdocs.Api.Contract.GetJobDocumentsResult();
                                    //Make request to api for get document info by job id
                                    jobInfo = service.GetJobDocuments(job);
                                    //Get guid
                                    String guid = jobInfo.Inputs[0].Outputs[0].Guid;
                                    //Get name
                                    String fileName = jobInfo.Inputs[0].Outputs[0].Name;
                                    //Create envelope
                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeResponse envelop = service.CreateEnvelope("", "", fileName, guid, false);
                                    if (envelop.Status.Equals("Ok"))
                                    {
                                        decimal dec = new decimal();
                                        //Get role list for curent user
                                        Groupdocs.Api.Contract.Signature.SignatureRolesResponse roles = service.GetSignatureRoles("");
                                        String roleId = "";
                                        //Get id of role which can sign
                                        for (int i = 0; i < roles.Result.Roles.Length; i++)
                                        {
                                            if (roles.Result.Roles[i].Name.Equals("Signer"))
                                            {
                                                roleId = roles.Result.Roles[i].Id;
                                                break;
                                            }
                                        }
                                        if (String.IsNullOrEmpty(lastName))
                                        {
                                            lastName = "Empty Last Name";
                                        }
                                        //Add recipient to envelope
                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addFirstRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, firstEmail, firstName, lastName, roleId, dec);
                                        if (addFirstRecipient.Status.Equals("Ok"))
                                        {
                                            //Add second recipient to envelope
                                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addSecondRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, secondEmail, secondName, lastName + "2", roleId, dec);
                                            if (addSecondRecipient.Status.Equals("Ok"))
                                            {
                                                //Get document from envelop
                                                Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentsResponse getDocuments = service.GetEnvelopeDocuments(envelop.Result.Envelope.Id);
                                                if (getDocuments.Status.Equals("Ok"))
                                                {
                                                    System.Random rand = new System.Random();
                                                    String fieldName = "singlIndex1" + rand.Next(0, 1000);
                                                    //Create envelop field settings object (LocationsX,Y max value can bee 1.0)
                                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo envelopFieldSettings = new Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo();
                                                    envelopFieldSettings.LocationX = new decimal(0.15);
                                                    envelopFieldSettings.LocationY = new decimal(0.23);
                                                    envelopFieldSettings.LocationWidth = 150;
                                                    envelopFieldSettings.LocationHeight = 50;
                                                    envelopFieldSettings.Name = fieldName;
                                                    envelopFieldSettings.ForceNewField = true;
                                                    envelopFieldSettings.Page = 1;
                                                    //Add envelop field to the document
                                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addFirstField = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, addFirstRecipient.Result.Recipient.Id, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings);
                                                    //Updated field settings for the second signer
                                                    fieldName = "singlIndex2" + rand.Next(0, 1000);
                                                    envelopFieldSettings.LocationX = new decimal(0.35);
                                                    envelopFieldSettings.LocationY = new decimal(0.23);
                                                    envelopFieldSettings.LocationWidth = 150;
                                                    envelopFieldSettings.LocationHeight = 50;
                                                    envelopFieldSettings.Name = fieldName;
                                                    envelopFieldSettings.ForceNewField = true;
                                                    envelopFieldSettings.Page = 1;
                                                    //Add envelop field for the second signer
                                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addSecondField = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, addSecondRecipient.Result.Recipient.Id, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings);
                                                    //Send envelop
                                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeSendResponse send = service.SendEnvelope(envelop.Result.Envelope.Id, String.Empty);
                                                    //Check envelope send status
                                                    if (send.Status.Equals("Ok"))
                                                    {
                                                        // Generate Embed viewer url with entered file id
                                                        iframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addFirstRecipient.Result.Recipient.Id;
                                                        iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                                        // Generate Embed viewer url for second signer
                                                        secondIframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addSecondRecipient.Result.Recipient.Id;
                                                        secondIframe = Groupdocs.Security.UrlSignature.Sign(secondIframe, privateKey);
                                                        result.Add("iframe1", iframe);
                                                        result.Add("iframe2", secondIframe);
                                                        return View("Sample44", null, result);
                                                    }
                                                    //If status failed set error for template
                                                    else
                                                    {
                                                        message = send.ErrorMessage;
                                                        result.Add("error", message);
                                                        return View("Sample44", null, result);
                                                    }
                                                }
                                                //If get document from envelop is failed return error
                                                else
                                                {
                                                    message = getDocuments.ErrorMessage;
                                                    result.Add("error", message);
                                                    return View("Sample44", null, result);
                                                }
                                            }
                                            //If add recipient is failed return error
                                            else
                                            {
                                                message = addSecondRecipient.ErrorMessage;
                                                result.Add("error", message);
                                                return View("Sample44", null, result);
                                            }
                                        }
                                        //If add recipient is failed return error
                                        else
                                        {
                                            message = addFirstRecipient.ErrorMessage;
                                            result.Add("error", message);
                                            return View("Sample44", null, result);
                                        }

                                    }
                                    //If envelope wasn't created send error
                                    else
                                    {
                                        message = envelop.ErrorMessage;
                                        result.Add("error", message);
                                        return View("Sample44", null, result);
                                    }
                                }
                                else
                                {
                                    result.Add("error", "MargeTemplate is fail");
                                    return View("Sample44", null, result);
                                }
                            }
                            else
                            {
                                result.Add("error", "AddDataSource returned empty job id");
                                return View("Sample44", null, result);
                            }
                        }
                        // If request return's null return error to the template
                        else
                        {
                            message = "Upload is failed";
                            result.Add("error", message);
                            return View("Sample44", null, result);
                        }
                    }
                    else
                    {
                        //If file wasn't uploaded return error
                        message = "Something wrong with upload";
                        result.Add("error", message);
                        return View("Sample44", null, result);
                    }
                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample44");
            }
        }
コード例 #2
0
        public ActionResult Sample37()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String email = Request.Form["email"];
                String name = Request.Form["name"];
                String lastName = Request.Form["lastName"];
                String callbackUrl = Request.Form["callbackUrl"];
                String fileId = Request.Form["fileId"];
                String url = Request.Form["url"];
                var file = Request.Files["file"];
                String fileName = "";
                String guid = "";
                String basePath = Request.Form["basePath"];
                String iframe = "";
                // Set entered data to the results list
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("email", email);
                result.Add("firstName", name);
                result.Add("lastName", lastName);
                // Check if callbackUrl is not empty
                if (!String.IsNullOrEmpty(callbackUrl))
                {
                    result.Add("callbackUrl", callbackUrl);
                }
                String message = null;
                // Check is all needed fields are entered
                if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey) || String.IsNullOrEmpty(email)
                    || String.IsNullOrEmpty(lastName) || String.IsNullOrEmpty(name))
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample37", null, result);
                }
                else
                {
                    //path to settings file - temporary save clientId and apiKey like to property file
                    create_info_file(clientId, privateKey, "");
                    if (basePath.Equals(""))
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //if URL to web file was provided - upload the file from Web and get it's GUID
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String uploadWeb = service.UploadUrl(url);
                        if (uploadWeb != null)
                        {
                            //If file uploaded return his GuId
                            guid = uploadWeb;
                            //Get all files from GroupDocs account
                            Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true);
                            if (storageInfo.Files.Length > 0)
                            {
                                // Get file id by uploaded file GuId
                                for (int i = 0; i < storageInfo.Files.Length; i++)
                                {
                                    if (storageInfo.Files[i].Guid == guid)
                                    {
                                        fileName = storageInfo.Files[i].Name;
                                    }
                                }
                            }
                            else
                            {
                                message = "Get files list is failed";
                                result.Add("error", message);
                                return View("Sample37", null, result);
                            }
                        }
                        //If file wasn't uploaded return error
                        else
                        {
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample37", null, result);
                        }
                    }
                    //if file was uploaded locally - upload the file and get it's GUID
                    if (!file.FileName.Equals(""))
                    {
                        //Upload local file
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        if (upload.Guid != null)
                        {
                            //If file uploaded return his guid
                            guid = upload.Guid;
                            fileName = upload.AdjustedName;
                        }
                        else
                        {
                            //If file wasn't uploaded return error
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample37", null, result);
                        }
                    }
                    if (!fileId.Equals(""))
                    {
                        guid = fileId;
                        //Get all files from GroupDocs account
                        Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("", 0, -1, null, false, null, null, true);
                        if (storageInfo.Files.Length > 0)
                        {
                            // Get file id by uploaded file GuId
                            for (int i = 0; i < storageInfo.Files.Length; i++)
                            {
                                if (storageInfo.Files[i].Guid == guid)
                                {
                                    fileName = storageInfo.Files[i].Name;
                                }

                            }
                        }
                        else
                        {
                            message = "Get files list is failed";
                            result.Add("error", message);
                            return View("Sample37", null, result);
                        }

                    }
                    //Check is file uploaded
                    if (!guid.Equals("") && !fileName.Equals(""))
                    {
                        //Create envilope using user id and entered by user name
                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeResponse envelop = service.CreateEnvelope("", "", fileName, guid, false);
                        if (envelop.Status.Equals("Ok"))
                        {
                            decimal order = new decimal();
                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentResponse addDocument = service.AddEnvelopeDocument(envelop.Result.Envelope.Id, guid, order, true);
                            if (addDocument.Status.Equals("Ok"))
                            {
                                decimal dec = new decimal();
                                //Get role list for curent user
                                Groupdocs.Api.Contract.Signature.SignatureRolesResponse roles = service.GetSignatureRoles("");
                                String roleId = "";
                                //Get id of role which can sign
                                for (int i = 0; i < roles.Result.Roles.Length; i++)
                                {
                                    if (roles.Result.Roles[i].Name.Equals("Signer"))
                                    {
                                        roleId = roles.Result.Roles[i].Id;
                                        break;
                                    }
                                }
                                //Add recipient to envelope
                                Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, email, name, lastName, roleId, dec);
                                if (addRecipient.Status.Equals("Ok"))
                                {
                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentsResponse getDocuments = service.GetEnvelopeDocuments(envelop.Result.Envelope.Id);
                                    if (getDocuments.Status.Equals("Ok"))
                                    {
                                        System.Random rand = new System.Random();
                                        String fieldName = "singlSample" + rand.Next(0, 1000);
                                        //Create envelop field settings object (LocationsX,Y max value can bee 1.0)
                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo envelopFieldSettings = new Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo();
                                        envelopFieldSettings.LocationX = new decimal(0.15);
                                        envelopFieldSettings.LocationY = new decimal(0.73);
                                        envelopFieldSettings.LocationWidth = 150;
                                        envelopFieldSettings.LocationHeight = 50;
                                        envelopFieldSettings.Name = fieldName;
                                        envelopFieldSettings.ForceNewField = true;
                                        envelopFieldSettings.Page = 1;
                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addFields = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, addRecipient.Result.Recipient.Id, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings);
                                        //Send envelop with callbackUrl url
                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeSendResponse send = service.SendEnvelope(envelop.Result.Envelope.Id, callbackUrl);
                                        //Check is envelope send status
                                        if (send.Status.Equals("Ok"))
                                        {
                                            // Generate Embed viewer url with entered file id
                                            if (basePath.Equals("https://api.groupdocs.com/v2.0"))
                                            {
                                                iframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                            }
                                            if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0"))
                                            {
                                                iframe = "https://dev-apps-groupdocs.dynabic.com/signature/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                            }
                                            if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0"))
                                            {
                                                iframe = "https://stage-apps-groupdocs.dynabic.com/signature/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                            }
                                            if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0"))
                                            {
                                                iframe = "https://realtime-apps.groupdocs.com/signature/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                            }
                                            iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                            result.Add("iframe", iframe);
                                            //Set data for template
                                            result.Add("envelop", envelop.Result.Envelope.Id);
                                            result.Add("recipient", addRecipient.Result.Recipient.Id);
                                            return View("Sample37", null, result);
                                        }
                                        //If status failed set error for template
                                        else
                                        {
                                            result.Add("error", send.ErrorMessage);
                                            return View("Sample37", null, result);
                                        }
                                    }
                                    else
                                    {
                                        result.Add("error", getDocuments.ErrorMessage);
                                        return View("Sample37", null, result);
                                    }
                                }
                                else
                                {
                                    result.Add("error", addRecipient.ErrorMessage);
                                    return View("Sample37", null, result);
                                }
                            }
                            else
                            {
                                result.Add("error", addDocument.ErrorMessage);
                                return View("Sample37", null, result);
                            }
                        }
                        //If envelope wasn't created send error
                        else
                        {
                            result.Add("error", envelop.ErrorMessage);
                            return View("Sample37", null, result);
                        }
                    }
                    // If request return's null return error to the template
                    else
                    {
                        result.Add("error", "Upload is failed");
                        return View("Sample37", null, result);
                    }

                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample37");
            }
        }
コード例 #3
0
        public ActionResult Sample39()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                string message = null;
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                //Chekck is email entered, if not sign document with widget
                if (String.IsNullOrEmpty(Request.Form["email"]))
                {
                    //Get data from ajax
                    System.IO.Stream inputStream = Request.InputStream;
                    System.Text.Encoding encoding = Request.ContentEncoding;
                    System.IO.StreamReader reader = new System.IO.StreamReader(inputStream, encoding);
                    string jsonString = reader.ReadToEnd();
                    //Parse json data from ajax
                    var postData = Newtonsoft.Json.Linq.JObject.Parse(jsonString);
                    //Get data from parsed object
                    String clientId = postData["userId"].ToString();
                    String privateKey = postData["privateKey"].ToString();
                    var document = postData["documents"];
                    var signers = postData["signers"];
                    string guid = null;
                    // Check is all needed fields are entered
                    if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey))
                    {
                        // If not all fields entered send error message
                        message = "Please enter all parameters";
                    }
                    else
                    {
                        //Create GroupDocs service
                        GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey);
                        //Create document for signing object
                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentDocumentSettingsInfo[] documentSettings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentDocumentSettingsInfo[1];
                        documentSettings[0] = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentDocumentSettingsInfo();
                        documentSettings[0].Name = document[0]["name"].ToString();
                        documentSettings[0].Data = document[0]["data"].ToString();
                        //Create signature object
                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo[] signatureSettings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo[1];
                        signatureSettings[0] = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo();
                        signatureSettings[0].Name = signers[0]["name"].ToString();
                        signatureSettings[0].Data = signers[0]["data"].ToString();
                        //Create sign settings info object
                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentSettingsInfo settings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSettingsInfo();
                        settings.Documents = documentSettings;
                        settings.Signers = signatureSettings;
                        //Make request to sign document
                        Groupdocs.Api.Contract.Signature.SignatureSignDocumentResponse sign = service.SignDocument(settings);
                        if (sign.Status.Equals("Ok"))
                        {
                            //Get job GUID
                            string jobGuid = sign.Result.JobId;
                            int counter = 5;
                            //Check signed document status and get signed document GUID
                            for (int i = 0; i < counter; i++)
                            {
                                System.Threading.Thread.Sleep(5000);
                                Groupdocs.Api.Contract.Signature.SignatureSignDocumentStatusResponse getSignDocumentStatus = service.GetSignDocumentStatus(jobGuid);
                                if (getSignDocumentStatus.Status.Equals("Ok"))
                                {
                                    if (getSignDocumentStatus.Result.Documents[0].Status.ToString() == "Completed")
                                    {
                                        guid = getSignDocumentStatus.Result.Documents[0].DocumentId;
                                        break;
                                    }
                                }
                                else
                                {
                                    message = getSignDocumentStatus.ErrorMessage;
                                }
                            }
                        }
                        else
                        {
                            message = sign.ErrorMessage;
                        }
                    }
                    //Add data to responce json
                    result.Add("error", message);
                    result.Add("guid", guid);
                    result.Add("clientId", clientId);
                    result.Add("privateKey", privateKey);
                    //Create json string and return it to ajax request
                    return Json(serializer.Serialize(result));
                }
                //Check if email entered if so sign document with out widget
                else if (!String.IsNullOrEmpty(Request.Form["email"]))
                {
                    //Get post data
                    String clientId = Request.Form["clientId"];
                    String privateKey = Request.Form["privateKey"];
                    String email = Request.Form["email"];
                    String name = Request.Form["name"];
                    String lastName = Request.Form["lastName"];
                    String callbackUrl = Request.Form["callbackUrl"];
                    var file = Request.Files["file"];
                    String fileName = "";
                    String guid = "";
                    String iframe = "";
                    // Set entered data to the results list
                    result.Add("clientId", clientId);
                    result.Add("privateKey", privateKey);
                    result.Add("email", email);
                    result.Add("firstName", name);
                    result.Add("lastName", lastName);
                    // Check if callbackUrl is not empty
                    if (!String.IsNullOrEmpty(callbackUrl))
                    {
                        result.Add("callbackUrl", callbackUrl);
                    }
                    // Check is all needed fields are entered
                    if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey) || String.IsNullOrEmpty(email)
                        || String.IsNullOrEmpty(lastName) || String.IsNullOrEmpty(name))
                    {
                        // If not all fields entered send error message
                        message = "Please enter all parameters";
                        result.Add("error", message);
                        return View("Sample39", null, result);
                    }
                    else
                    {
                        //path to settings file - temporary save clientId and apiKey like to property file
                        create_info_file(clientId, privateKey, "");
                        String callbackInfo = AppDomain.CurrentDomain.BaseDirectory + "callback_info.txt";
                        if (System.IO.File.Exists(callbackInfo))
                        {
                            System.IO.File.Delete(callbackInfo);
                        }
                        // Create service for Groupdocs account
                        GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey);
                        //Upload local file
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        if (upload.Guid != null)
                        {
                            //If file uploaded return his guid
                            guid = upload.Guid;
                            fileName = upload.AdjustedName;
                            //Check is file uploaded
                            if (!guid.Equals("") && !fileName.Equals(""))
                            {
                                //Create envelope using user id and entered by user name
                                Groupdocs.Api.Contract.Signature.SignatureEnvelopeResponse envelop = service.CreateEnvelope("", "", fileName, guid, false);
                                if (envelop.Status.Equals("Ok"))
                                {
                                    decimal order = new decimal();
                                    decimal dec = new decimal();
                                    //Get role list for curent user
                                    Groupdocs.Api.Contract.Signature.SignatureRolesResponse roles = service.GetSignatureRoles("");
                                    String roleId = "";
                                    //Get id of role which can sign
                                    for (int i = 0; i < roles.Result.Roles.Length; i++)
                                    {
                                        if (roles.Result.Roles[i].Name.Equals("Signer"))
                                        {
                                            roleId = roles.Result.Roles[i].Id;
                                            break;
                                        }
                                    }
                                    //Add recipient to envelope
                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, email, name, lastName, roleId, dec);
                                    if (addRecipient.Status.Equals("Ok"))
                                    {
                                        //Get document from envelop
                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentsResponse getDocuments = service.GetEnvelopeDocuments(envelop.Result.Envelope.Id);
                                        if (getDocuments.Status.Equals("Ok"))
                                        {
                                            System.Random rand = new System.Random();
                                            String fieldName = "singlSample" + rand.Next(0, 1000);
                                            //Create envelop field settings object (LocationsX,Y max value can bee 1.0)
                                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo envelopFieldSettings = new Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo();
                                            envelopFieldSettings.LocationX = new decimal(0.15);
                                            envelopFieldSettings.LocationY = new decimal(0.73);
                                            envelopFieldSettings.LocationWidth = 150;
                                            envelopFieldSettings.LocationHeight = 50;
                                            envelopFieldSettings.Name = fieldName;
                                            envelopFieldSettings.ForceNewField = true;
                                            envelopFieldSettings.Page = 1;
                                            //Add envelop field to the document
                                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addFields = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, addRecipient.Result.Recipient.Id, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings);
                                            //Send envelop with callbackUrl url
                                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeSendResponse send = service.SendEnvelope(envelop.Result.Envelope.Id, callbackUrl);
                                            //Check is envelope send status
                                            if (send.Status.Equals("Ok"))
                                            {
                                                // Generate Embed viewer url with entered file id
                                                iframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                                iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                                result.Add("iframe", iframe);
                                                return View("Sample39", null, result);
                                            }
                                            //If status failed set error for template
                                            else
                                            {
                                                message = send.ErrorMessage;
                                                result.Add("error", message);
                                                return View("Sample39", null, result);
                                            }
                                        }
                                        //If get document from envelop is failed return error
                                        else
                                        {
                                            message = getDocuments.ErrorMessage;
                                            result.Add("error", message);
                                            return View("Sample39", null, result);
                                        }
                                    }
                                    //If add recipient is failed return error
                                    else
                                    {
                                        message = addRecipient.ErrorMessage;
                                        result.Add("error", message);
                                        return View("Sample39", null, result);
                                    }
                                }
                                //If envelope wasn't created send error
                                else
                                {
                                    message = envelop.ErrorMessage;
                                    result.Add("error", message);
                                    return View("Sample39", null, result);
                                }
                            }
                            // If request return's null return error to the template
                            else
                            {
                                message = "Upload is failed";
                                result.Add("error", message);
                                return View("Sample39", null, result);
                            }
                        }
                        else
                        {
                            //If file wasn't uploaded return error
                            message = "Something wrong with upload";
                            result.Add("error", message);
                            return View("Sample39", null, result);
                        }
                    }

                }
                return View("Sample39");
            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample39");
            }
        }
コード例 #4
0
        public ActionResult Sample31()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String email = Request.Form["email"];
                String name = Request.Form["name"];
                String country = Request.Form["country"];
                String callbackUrl = Request.Form["callbackUrl"];
                String templateGuid = Request.Form["templateGuid"];
                String city = Request.Form["city"];
                String street = Request.Form["street"];
                String guid = "";
                String iframe = "";
                String basePath = Request.Form["basePath"];
                // Set entered data to the results list
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("email", email);
                result.Add("name", name);
                result.Add("street", street);
                result.Add("country", country);
                result.Add("city", city);

                // Check if callbackUrl is not empty
                if (!String.IsNullOrEmpty(callbackUrl))
                {
                    result.Add("callbackUrl", callbackUrl);
                }

                String message = null;
                // Check is all needed fields are entered
                if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey))
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample31", null, result);
                }
                else
                {

                    //path to settings file - temporary save clientId and apiKey like to property file
                    create_info_file(clientId, privateKey, "");
                    if (basePath.Equals(""))
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    if (!templateGuid.Equals(""))
                    {
                        guid = templateGuid;

                    }
                    //Create Hashtable with entere data
                    if (!guid.Equals(""))
                    {
                        System.Collections.Hashtable enteredData = new System.Collections.Hashtable();
                        enteredData.Add("street", street);
                        enteredData.Add("city", city);
                        enteredData.Add("country", country);
                        enteredData.Add("name", name);
                        enteredData.Add("email", email);

                        //Create Datasource object
                        Groupdocs.Assembly.Data.Datasource dataSource = new Groupdocs.Assembly.Data.Datasource();
                        //Create array of DatasourceField objects
                        Groupdocs.Assembly.Data.DatasourceField[] fieldArray = new Groupdocs.Assembly.Data.DatasourceField[5];
                        //Filing DataSource object with user data
                        int index = 0;
                        foreach (System.Collections.DictionaryEntry value in enteredData)
                        {
                            //Create object with value
                            string[] values = new string[1];
                            values.SetValue(value.Value.ToString(), 0);
                            //Create DataSourceField object
                            Groupdocs.Assembly.Data.DatasourceField field = new Groupdocs.Assembly.Data.DatasourceField();
                            //Create DataSource Field type
                            Groupdocs.Assembly.Data.DatasourceFieldType type = new Groupdocs.Assembly.Data.DatasourceFieldType();
                            //Set field type to "text"
                            type = 0;
                            field.Name = value.Key.ToString();
                            field.Type = type;
                            field.Values = values;
                            //Push DatasourceField to array of DatasourceField objects
                            fieldArray.SetValue(field, index);
                            index = index + 1;

                        }
                        //Set feilds array to the Datasource
                        dataSource.Fields = fieldArray;
                        //Add new Datasource to GroupDocs
                        decimal addDataSource = service.AddDataSource(dataSource);
                        //Check is not empty addDataSource
                        if (!addDataSource.Equals(""))
                        {
                            //If status ok merge Datasource to new pdf file
                            decimal job = service.MergeTemplate(guid, addDataSource, "pdf", false);
                            if (!job.Equals(""))
                            {
                                Groupdocs.Api.Contract.GetJobDocumentsResult jobInfo = new Groupdocs.Api.Contract.GetJobDocumentsResult();
                                //### Check job status
                                for (int n = 0; n <= 5; n++)
                                {
                                    //Delay necessary that the inquiry would manage to be processed
                                    System.Threading.Thread.Sleep(5000);
                                    //Make request to api for get document info by job id
                                    jobInfo = service.GetJobDocuments(job);
                                    //Check job status, if status is Completed or Archived exit from cycle
                                    if (jobInfo.JobStatus.Equals("Completed") || jobInfo.JobStatus.Equals("Archived"))
                                    {
                                        break;
                                        //If job status Postponed throw exception with error
                                    }
                                    else if (jobInfo.JobStatus.Equals("Postponed"))
                                    {
                                        result.Add("error", "Job is fail");
                                        return View("Sample31", null, result);

                                    }
                                }
                                //Create envilope using entered by user name
                                Groupdocs.Api.Contract.Signature.SignatureEnvelopeResponse envelop = service.CreateEnvelope("", "", name, "", false);
                                if (envelop.Status.Equals("Ok"))
                                {
                                    //Add selected document to the envelop
                                    decimal order = new decimal();
                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentResponse addDocument = service.AddEnvelopeDocument(envelop.Result.Envelope.Id, guid, order, true);
                                    if (addDocument.Status.Equals("Ok"))
                                    {
                                        decimal dec = new decimal();
                                        //Get role list for curent user
                                        Groupdocs.Api.Contract.Signature.SignatureRolesResponse roles = service.GetSignatureRoles("");
                                        String roleId = "";
                                        //Get id of role which can sign
                                        for (int i = 0; i < roles.Result.Roles.Length; i++)
                                        {
                                            if (roles.Result.Roles[i].Name.Equals("Signer"))
                                            {
                                                roleId = roles.Result.Roles[i].Id;
                                                break;
                                            }
                                        }
                                        //Create Field settings object and set field name (which must be unique)
                                        Groupdocs.Api.Contract.Signature.SignatureFieldSettingsInfo fieldSettings = new Groupdocs.Api.Contract.Signature.SignatureFieldSettingsInfo();
                                        System.Random rand = new System.Random();
                                        String fieldName = "singlSample" + rand.Next(0, 1000);
                                        fieldSettings.Name = fieldName;
                                        //Add created field to the Gd account
                                        Groupdocs.Api.Contract.Signature.SignatureFieldResponse createField = service.AddSignatureField(fieldSettings);
                                        if (createField.Status.Equals("Ok"))
                                        {
                                            //Add recipient to envelope
                                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, email, name, "Last", roleId, dec);
                                            if (addRecipient.Status.Equals("Ok"))
                                            {
                                                //Get recipients from envelop
                                                Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientsResponse getRecipient = service.GetEnvelopeRecipients(envelop.Result.Envelope.Id);
                                                if (getRecipient.Status.Equals("Ok"))
                                                {
                                                    //Get recipient id
                                                    String recipientId = getRecipient.Result.Recipients[0].Id;
                                                    //Get documents from envelop
                                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentsResponse getDocuments = service.GetEnvelopeDocuments(envelop.Result.Envelope.Id);
                                                    if (getDocuments.Status.Equals("Ok"))
                                                    {
                                                        //Create envelop field settings object (LocationsX,Y max value can bee 1.0)
                                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo envelopFieldSettings = new Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo();
                                                        envelopFieldSettings.LocationX = new decimal(0.15);
                                                        envelopFieldSettings.LocationY = new decimal(0.73);
                                                        envelopFieldSettings.LocationWidth = 150;
                                                        envelopFieldSettings.LocationHeight = 50;
                                                        envelopFieldSettings.Name = fieldName;
                                                        envelopFieldSettings.ForceNewField = true;
                                                        envelopFieldSettings.Page = 1;
                                                        //Add created field to the envelop
                                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addField = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, recipientId, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings);
                                                        if (addField.Status.Equals("Ok"))
                                                        {
                                                            //Send envelop with callbackUrl url
                                                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeSendResponse send = service.SendEnvelope(envelop.Result.Envelope.Id, callbackUrl);
                                                            //Check is envelope send status
                                                            if (send.Status.Equals("Ok"))
                                                            {
                                                                // Generate Embed viewer url with entered file id
                                                                if (basePath.Equals("https://api.groupdocs.com/v2.0"))
                                                                {
                                                                    iframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                                                }
                                                                if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0"))
                                                                {
                                                                    iframe = "https://dev-apps-groupdocs.dynabic.com/signature/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                                                }
                                                                if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0"))
                                                                {
                                                                    iframe = "https://stage-api-groupdocs.dynabic.com/signature/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                                                }
                                                                if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0"))
                                                                {
                                                                    iframe = "https://realtime-apps.groupdocs.com/signature/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                                                }
                                                                iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                                                result.Add("iframe", iframe);
                                                                //Set data for template
                                                                result.Add("envelop", envelop.Result.Envelope.Id);
                                                                result.Add("recipient", addRecipient.Result.Recipient.Id);
                                                                return View("Sample31", null, result);
                                                            }
                                                            //If status failed set error for template
                                                            else
                                                            {
                                                                result.Add("error", send.ErrorMessage);
                                                                return View("Sample31", null, result);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            result.Add("error", addField.ErrorMessage);
                                                            return View("Sample31", null, result);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        result.Add("error", getDocuments.ErrorMessage);
                                                        return View("Sample31", null, result);
                                                    }
                                                }
                                                else
                                                {
                                                    result.Add("error", getRecipient.ErrorMessage);
                                                    return View("Sample31", null, result);
                                                }
                                            }
                                            else
                                            {
                                                result.Add("error", addRecipient.ErrorMessage);
                                                return View("Sample31", null, result);
                                            }
                                        }
                                        else
                                        {
                                            result.Add("error", createField.ErrorMessage);
                                            return View("Sample31", null, result);
                                        }
                                    }
                                    else
                                    {
                                        result.Add("error", addDocument.ErrorMessage);
                                        return View("Sample31", null, result);
                                    }
                                }
                                //If envelope wasn't created send error
                                else
                                {
                                    result.Add("error", envelop.ErrorMessage);
                                    return View("Sample31", null, result);
                                }
                            }
                            // If request return's null return error to the template
                            else
                            {
                                result.Add("error", "mergeTemplate is failed");
                                return View("Sample31", null, result);
                            }
                        }
                        // If request return's null return error to the template
                        else
                        {
                            result.Add("error", "addDataSource is failed");
                            return View("Sample31", null, result);
                        }
                    }
                    else
                    {
                        result.Add("error", "GUID is empty");
                        return View("Sample31", null, result);
                    }

                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample31");
            }
        }