コード例 #1
0
        public string CreateLayout(Package layoutPackage, String packageId)
        {
            string path = template.UrlFor(UrlTemplate.LAYOUT_PATH)
                .Build();

            string packageJson = JsonConvert.SerializeObject(layoutPackage, settings);
            Template apiTemplate = JsonConvert.DeserializeObject<Silanis.ESL.API.Template>(packageJson, settings);
            apiTemplate.Id = packageId;
            String templateJson = JsonConvert.SerializeObject(apiTemplate, settings);

            try
            {
                string response = restClient.Post(path, templateJson);
                Package aPackage = JsonConvert.DeserializeObject<Silanis.ESL.API.Package>(response, settings);
                return aPackage.Id;
            }
            catch (EslServerException e)
            {
                throw new EslServerException("Could not create layout." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new EslException("Could not create layout." + " Exception: " + e.Message, e);
            }
        }
コード例 #2
0
        public void Trash(PackageId id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            string path = template.UrlFor(UrlTemplate.PACKAGE_ID_PATH).Replace("{packageId}", id.Id).Build();

            Silanis.ESL.API.Package package = new Silanis.ESL.API.Package();

            package.Id      = id.Id;
            package.Trashed = true;

            try
            {
                restClient.Post(path, JsonConvert.SerializeObject(package, settings));
            }
            catch (EslServerException e)
            {
                throw new EslServerException("Unable to trash package." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new EslException("Unable to trash package." + " Exception: " + e.Message, e);
            }
        }
コード例 #3
0
        private Silanis.ESL.API.Package CreateTypicalAPIPackage()
        {
            Silanis.ESL.API.Package apiPackage = new Silanis.ESL.API.Package();
            apiPackage.Id           = "1";
            apiPackage.Language     = "en";
            apiPackage.Autocomplete = true;
            apiPackage.Consent      = "Consent";
            apiPackage.Completed    = new DateTime?();
            apiPackage.Description  = "API document package description";
            apiPackage.Due          = new DateTime?();
            apiPackage.Name         = "API package name";
            apiPackage.Status       = Silanis.ESL.API.PackageStatus.DRAFT;

            Silanis.ESL.API.Message apiMessage = new Silanis.ESL.API.Message();
            apiMessage.Content = "opt-out reason";
            apiMessage.Status  = Silanis.ESL.API.MessageStatus.NEW;
            apiMessage.Created = DateTime.Now;
            User fromUser = new User();

            fromUser.FirstName = "John";
            fromUser.LastName  = "Smith";
            fromUser.Email     = "*****@*****.**";
            apiMessage.From    = fromUser;
            apiPackage.AddMessage(apiMessage);
            User toUser = new User();

            toUser.FirstName = "Patty";
            toUser.LastName  = "Galant";
            toUser.Email     = "*****@*****.**";
            apiMessage.AddTo(toUser);

            return(apiPackage);
        }
コード例 #4
0
        public DocumentPackage GetPackage(PackageId id)
        {
            Silanis.ESL.API.Package package = packageService.GetPackage(id);

            DocumentPackage documentPackage = new DocumentPackageConverter(package).ToSDKPackage();

            return(documentPackage);
        }
コード例 #5
0
        public void ConvertAPIToAPI()
        {
            apiPackage1 = CreateTypicalAPIPackage();
            converter   = new DocumentPackageConverter(apiPackage1);
            apiPackage2 = converter.ToAPIPackage();

            Assert.IsNotNull(apiPackage2);
            Assert.AreEqual(apiPackage2, apiPackage1);
        }
コード例 #6
0
		public void ConvertAPIToAPI()
		{
			apiPackage1 = CreateTypicalAPIPackage();
			converter = new DocumentPackageConverter(apiPackage1);
			apiPackage2 = converter.ToAPIPackage();

			Assert.IsNotNull(apiPackage2);
			Assert.AreEqual(apiPackage2, apiPackage1);
		}
コード例 #7
0
ファイル: EslClient.cs プロジェクト: jutrec/esl.sdk.net
 public void SignDocument(PackageId packageId, string documentName)
 {
     Silanis.ESL.API.Package package = packageService.GetPackage(packageId);
     foreach (Silanis.ESL.API.Document document in package.Documents)
     {
         if (document.Name.Equals(documentName))
         {
             document.Approvals.Clear();
             signingService.SignDocument(packageId, document);
         }
     }
 }
コード例 #8
0
        /// <summary>
        /// Updates the package's fields and roles.
        /// </summary>
        /// <param name="packageId">The package id.</param>
        /// <param name="package">The updated package.</param>
        internal void UpdatePackage(PackageId packageId, Silanis.ESL.API.Package package)
        {
            string path = template.UrlFor(UrlTemplate.PACKAGE_ID_PATH)
                          .Replace("{packageId}", packageId.Id)
                          .Build();

            try {
                string json     = JsonConvert.SerializeObject(package, settings);
                string response = restClient.Put(path, json);
            } catch (Exception e) {
                throw new EslException("Could not update the package." + " Exception: " + e.Message);
            }
        }
コード例 #9
0
		public void ConvertSDKToAPI()
		{
			sdkPackage1 = CreateTypicalSDKDocumentPackage();
			apiPackage1 = new DocumentPackageConverter(sdkPackage1).ToAPIPackage();

			Assert.IsNotNull(apiPackage1);
			Assert.AreEqual(apiPackage1.Name, sdkPackage1.Name);
			Assert.AreEqual(apiPackage1.Description, sdkPackage1.Description);
			Assert.AreEqual(apiPackage1.Id, sdkPackage1.Id);
			Assert.AreEqual(apiPackage1.EmailMessage, sdkPackage1.EmailMessage);
			Assert.AreEqual(apiPackage1.Language, sdkPackage1.Language.ToString());
			Assert.AreEqual(apiPackage1.Due, sdkPackage1.ExpiryDate);
			Assert.AreEqual(apiPackage1.Status.ToString(), sdkPackage1.Status.ToString());
		}
コード例 #10
0
        public void ConvertSDKToAPI()
        {
            sdkPackage1 = CreateTypicalSDKDocumentPackage();
            apiPackage1 = new DocumentPackageConverter(sdkPackage1).ToAPIPackage();

            Assert.IsNotNull(apiPackage1);
            Assert.AreEqual(apiPackage1.Id, sdkPackage1.Id.ToString());
            Assert.AreEqual(apiPackage1.Name, sdkPackage1.Name);
            Assert.AreEqual(apiPackage1.Description, sdkPackage1.Description);
            Assert.AreEqual(apiPackage1.EmailMessage, sdkPackage1.EmailMessage);
            Assert.AreEqual(apiPackage1.Language, sdkPackage1.Language.ToString());
            Assert.AreEqual(apiPackage1.Due, sdkPackage1.ExpiryDate);
            Assert.AreEqual(apiPackage1.Status, sdkPackage1.Status.getApiValue());
        }
コード例 #11
0
 public void SignDocument(PackageId packageId, string documentName, CapturedSignature capturedSignature)
 {
     Silanis.ESL.API.Package package = packageService.GetPackage(packageId);
     foreach (Silanis.ESL.API.Document document in package.Documents)
     {
         if (document.Name.Equals(documentName))
         {
             document.Approvals.Clear();
             SignedDocument signedDocument = signingService.ConvertToSignedDocument(document);
             signedDocument.Handdrawn = capturedSignature.Handdrawn;
             signingService.SignDocument(packageId, signedDocument);
         }
     }
 }
コード例 #12
0
        private string FindRoleIdForSigner(string signerEmail, Silanis.ESL.API.Package createdPackage)
        {
            foreach (Silanis.ESL.API.Role role in createdPackage.Roles)
            {
                if (role.Signers.Count > 0 && role.Signers[0].Email != null)
                {
                    if (signerEmail.Equals(role.Signers[0].Email))
                    {
                        return(role.Id);
                    }
                }
            }

            throw new EslException(String.Format("No Role found for signer email {0}", signerEmail), null);
        }
コード例 #13
0
        private string FindRoleIdForGroup(GroupId groupId, Silanis.ESL.API.Package createdPackage)
        {
            foreach (Silanis.ESL.API.Role role in createdPackage.Roles)
            {
                if (role.Signers.Count > 0 && role.Signers[0].Group != null)
                {
                    if (groupId.Id.Equals(role.Signers[0].Group.Id))
                    {
                        return(role.Id);
                    }
                }
            }

            throw new EslException(String.Format("No Role found for group with id {0}", groupId.Id), null);
        }
コード例 #14
0
        /// <summary>
        /// Creates a package based on the settings of the pacakge parameter.
        /// </summary>
        /// <returns>The package id.</returns>
        /// <param name="package">The package to create.</param>
        internal PackageId CreatePackage(Silanis.ESL.API.Package package)
        {
            Support.LogMethodEntry(package);
            string path = template.UrlFor(UrlTemplate.PACKAGE_PATH)
                          .Build();

            try {
                string    json     = JsonConvert.SerializeObject(package, settings);
                string    response = restClient.Post(path, json);
                PackageId result   = JsonConvert.DeserializeObject <PackageId> (response);
                Support.LogMethodExit(result);
                return(result);
            } catch (Exception e) {
                throw new EslException("Could not create a new package." + " Exception: " + e.Message);
            }
        }
コード例 #15
0
        internal string CreatePackageFromTemplate(string templateId, Silanis.ESL.API.Package delta)
        {
            string path = urls.UrlFor(UrlTemplate.CLONE_PACKAGE_PATH).Replace("{packageId}", templateId)
                          .Build();

            try {
                string deltaJson = JsonConvert.SerializeObject(delta, settings);
                string response  = restClient.Post(path, deltaJson);
                Silanis.ESL.API.Package apiResult = JsonConvert.DeserializeObject <Silanis.ESL.API.Package> (response);
                return(apiResult.Id);
            }
            catch (EslServerException e) {
                throw new EslServerException("Could not create a package from template." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e) {
                throw new EslException("Could not create a package from template." + " Exception: " + e.Message, e);
            }
        }
コード例 #16
0
        public void Update(Silanis.ESL.API.Package apiTemplate)
        {
            string path = urls.UrlFor(UrlTemplate.PACKAGE_ID_PATH)
                          .Replace("{packageId}", apiTemplate.Id)
                          .Build();

            try
            {
                string json = JsonConvert.SerializeObject(apiTemplate, settings);
                restClient.Post(path, json);
            }
            catch (EslServerException e)
            {
                throw new EslServerException("Could not update template." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new EslException("Could not update template." + " Exception: " + e.Message, e);
            }
        }
コード例 #17
0
        internal string CreateTemplate(Silanis.ESL.API.Package template)
        {
            string path = urls.UrlFor(UrlTemplate.PACKAGE_PATH).Build();

            try
            {
                string json     = JsonConvert.SerializeObject(template, settings);
                string response = restClient.Post(path, json);
                Silanis.ESL.API.Package apiPackage = JsonConvert.DeserializeObject <Silanis.ESL.API.Package>(response);
                return(apiPackage.Id);
            }
            catch (EslServerException e)
            {
                throw new EslServerException("Could not create template." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new EslException("Could not create template." + " Exception: " + e.Message, e);
            }
        }
コード例 #18
0
        internal Silanis.ESL.API.Document ToAPIDocument(Silanis.ESL.API.Package apiPackage)
        {
            if (sdkDocument == null)
            {
                return(apiDocument);
            }

            Silanis.ESL.API.Document doc = ToAPIDocument();

            foreach (Signature signature in sdkDocument.Signatures)
            {
                Silanis.ESL.API.Approval approval = new SignatureConverter(signature).ToAPIApproval();

                if (signature.IsPlaceholderSignature())
                {
                    approval.Role = signature.RoleId.Id;
                }
                else if (signature.IsGroupSignature())
                {
                    approval.Role = FindRoleIdForGroup(signature.GroupId, apiPackage);
                }
                else
                {
                    approval.Role = FindRoleIdForSigner(signature.SignerEmail, apiPackage);
                }
                doc.AddApproval(approval);
            }

            foreach (Field field in sdkDocument.Fields)
            {
                doc.AddField(new FieldConverter(field).ToAPIField());
            }

            foreach (Field field in sdkDocument.QRCodes)
            {
                doc.AddField(new FieldConverter(field).ToAPIField());
            }

            return(doc);
        }
コード例 #19
0
        public void ConvertAPIToSDK()
        {
            apiPackage1 = CreateTypicalAPIPackage();
            sdkPackage1 = new DocumentPackageConverter(apiPackage1).ToSDKPackage();

            Assert.IsNotNull(sdkPackage1);
            Assert.AreEqual(apiPackage1.Id, sdkPackage1.Id.Id);
            Assert.AreEqual(apiPackage1.Autocomplete, sdkPackage1.Autocomplete);
            Assert.AreEqual(apiPackage1.Description, sdkPackage1.Description);
            Assert.AreEqual(apiPackage1.Due, sdkPackage1.ExpiryDate);
            Assert.AreEqual(apiPackage1.Status.ToString(), sdkPackage1.Status.ToString());
            Assert.AreEqual(apiPackage1.Name, sdkPackage1.Name);
            Assert.AreEqual(apiPackage1.Messages[0].Content, sdkPackage1.Messages[0].Content);
            Assert.AreEqual(apiPackage1.Messages[0].Created, sdkPackage1.Messages[0].Created);
            Assert.AreEqual(apiPackage1.Messages[0].Status.ToString(), sdkPackage1.Messages[0].Status.ToString());
            Assert.AreEqual(apiPackage1.Messages[0].From.FirstName, sdkPackage1.Messages[0].From.FirstName);
            Assert.AreEqual(apiPackage1.Messages[0].From.LastName, sdkPackage1.Messages[0].From.LastName);
            Assert.AreEqual(apiPackage1.Messages[0].From.Email, sdkPackage1.Messages[0].From.Email);
            Assert.AreEqual(apiPackage1.Messages[0].To[0].FirstName, sdkPackage1.Messages[0].To["*****@*****.**"].FirstName);
            Assert.AreEqual(apiPackage1.Messages[0].To[0].LastName, sdkPackage1.Messages[0].To["*****@*****.**"].LastName);
            Assert.AreEqual(apiPackage1.Messages[0].To[0].Email, sdkPackage1.Messages[0].To["*****@*****.**"].Email);
        }
コード例 #20
0
        public void ConvertAPIToSDK()
        {
            apiPackage1 = CreateTypicalAPIPackage();
            sdkPackage1 = new DocumentPackageConverter(apiPackage1).ToSDKPackage();

            Assert.IsNotNull(sdkPackage1);
            Assert.AreEqual(apiPackage1.Id, sdkPackage1.Id.Id);
            Assert.AreEqual(apiPackage1.Autocomplete, sdkPackage1.Autocomplete);
            Assert.AreEqual(apiPackage1.Description, sdkPackage1.Description);
            Assert.AreEqual(apiPackage1.Due, sdkPackage1.ExpiryDate);
            Assert.AreEqual(apiPackage1.Status.ToString(), sdkPackage1.Status.ToString());
            Assert.AreEqual(apiPackage1.Name, sdkPackage1.Name);
            Assert.AreEqual(apiPackage1.Messages[0].Content, sdkPackage1.Messages[0].Content);
            Assert.AreEqual(apiPackage1.Messages[0].Created, sdkPackage1.Messages[0].Created);
            Assert.AreEqual(apiPackage1.Messages[0].Status.ToString(), sdkPackage1.Messages[0].Status.ToString());
            Assert.AreEqual(apiPackage1.Messages[0].From.FirstName, sdkPackage1.Messages[0].From.FirstName);
            Assert.AreEqual(apiPackage1.Messages[0].From.LastName, sdkPackage1.Messages[0].From.LastName);
            Assert.AreEqual(apiPackage1.Messages[0].From.Email, sdkPackage1.Messages[0].From.Email);
            Assert.AreEqual(apiPackage1.Messages[0].To[0].FirstName, sdkPackage1.Messages[0].To["*****@*****.**"].FirstName);
            Assert.AreEqual(apiPackage1.Messages[0].To[0].LastName, sdkPackage1.Messages[0].To["*****@*****.**"].LastName);
            Assert.AreEqual(apiPackage1.Messages[0].To[0].Email, sdkPackage1.Messages[0].To["*****@*****.**"].Email);
        }
コード例 #21
0
        /// <summary>
        /// Creates a package based on the settings of the package parameter.
        ///
        /// WARNING: This method does not work if the sender has a signature
        ///
        /// </summary>
        /// <returns>The package id.</returns>
        /// <param name="package">The package to create.</param>
        internal PackageId CreatePackageOneStep(Silanis.ESL.API.Package package, ICollection <Silanis.ESL.SDK.Document> documents)
        {
            string path = template.UrlFor(UrlTemplate.PACKAGE_PATH)
                          .Build();

            try {
                string json         = JsonConvert.SerializeObject(package, settings);
                byte[] payloadBytes = Converter.ToBytes(json);

                string boundary = GenerateBoundary();
                byte[] content  = CreateMultipartPackage(documents, payloadBytes, boundary);

                string    response = restClient.PostMultipartPackage(path, content, boundary, json);
                PackageId result   = JsonConvert.DeserializeObject <PackageId> (response);

                return(result);
            } catch (EslServerException e) {
                throw new EslServerException("Could not create a new package." + " Exception: " + e.Message, e.ServerError, e);
            } catch (Exception e) {
                throw new EslException("Could not create a new package." + " Exception: " + e.Message, e);
            }
        }
コード例 #22
0
 /*
  * Construct with API objects
  */
 public DocumentConverter(Silanis.ESL.API.Document apiDocument, Silanis.ESL.API.Package apiPackage)
 {
     this.apiDocument = apiDocument;
     this.apiPackage = apiPackage;
 }
コード例 #23
0
 internal void UpdatePackage(PackageId packageId, Package package)
 {
     string path = template.UrlFor (UrlTemplate.PACKAGE_ID_PATH)
         .Replace ("{packageId}", packageId.Id)
         .Build();
         
     try {
         restClient.Post(path, JsonConvert.SerializeObject (package, settings));
         restClient.GetBytes(path);
     }
     catch (EslServerException e) {
         throw new EslServerException ("Unable to update package settings." + " Exception: " + e.Message, e.ServerError, e);
     }
     catch (Exception e) {
         throw new EslException ("Unable to update package settings." + " Exception: " + e.Message, e);
     }
 }
コード例 #24
0
		public void Trash(PackageId id)
		{
			if (id == null)
			{
				throw new ArgumentNullException("id");
			}

			string path = template.UrlFor(UrlTemplate.PACKAGE_ID_PATH).Replace("{packageId}", id.Id).Build ();
			Silanis.ESL.API.Package package = new Silanis.ESL.API.Package();

			package.Id = id.Id;
			package.Trashed = true;

			try 
			{
				restClient.Post(path, JsonConvert.SerializeObject (package, settings));
			}
            catch (EslServerException e) 
            {
                throw new EslServerException ("Unable to trash package." + " Exception: " + e.Message, e.ServerError, e);
            }
			catch (Exception e) 
			{
				throw new EslException ("Unable to trash package." + " Exception: " + e.Message, e);
			}
		}
コード例 #25
0
 public void ConvertNullAPIToAPI()
 {
     apiPackage1 = null;
     converter   = new DocumentPackageConverter(apiPackage1);
     Assert.IsNull(converter.ToAPIPackage());
 }
コード例 #26
0
		private Silanis.ESL.API.Package CreateTypicalAPIPackage()
		{
			Silanis.ESL.API.Package apiPackage = new Silanis.ESL.API.Package();
			apiPackage.Id = "1";
			apiPackage.Language = "en";
			apiPackage.Autocomplete = true;
			apiPackage.Consent = "Consent";
			apiPackage.Completed = new DateTime?();
			apiPackage.Description = "API document package description";
			apiPackage.Due = new DateTime?();
			apiPackage.Name = "API package name";
			apiPackage.Status = Silanis.ESL.API.PackageStatus.DRAFT;

            Silanis.ESL.API.Message apiMessage = new Silanis.ESL.API.Message();
            apiMessage.Content = "opt-out reason";
            apiMessage.Status = Silanis.ESL.API.MessageStatus.NEW;
            apiMessage.Created = DateTime.Now;
            User fromUser = new User();
            fromUser.FirstName = "John";
            fromUser.LastName = "Smith";
            fromUser.Email = "*****@*****.**";
            apiMessage.From = fromUser;
            apiPackage.AddMessage(apiMessage);
            User toUser = new User();
            toUser.FirstName = "Patty";
            toUser.LastName = "Galant";
            toUser.Email = "*****@*****.**";
            apiMessage.AddTo(toUser);

			return apiPackage;
		}
コード例 #27
0
		public void ConvertNullAPIToAPI()
		{
			apiPackage1 = null;
			converter = new DocumentPackageConverter(apiPackage1);
			Assert.IsNull(converter.ToAPIPackage());
		}
コード例 #28
0
		internal PackageId CreateTemplate(Package template)
		{
            template.Type = BasePackageType.TEMPLATE;
            string packageId = apiClient.CreateTemplate(template);
            return new PackageId(packageId);
		}
コード例 #29
0
 internal PackageId CreatePackageFromTemplate(PackageId templateId, Package delta)
 {
     string packageId = apiClient.CreatePackageFromTemplate(templateId.Id, delta);
     return new PackageId(packageId);
 }
コード例 #30
0
        internal static SignatureBuilder NewSignatureFromAPIApproval(Silanis.ESL.API.Approval apiApproval, Silanis.ESL.API.Package package)
        {
            SignatureBuilder signatureBuilder = null;

            Silanis.ESL.API.Signer apiSigner = null;
            foreach (Silanis.ESL.API.Role role in package.Roles)
            {
                if (role.Id.Equals(apiApproval.Role))
                {
                    if (!isPlaceHolder(role))
                    {
                        apiSigner = role.Signers [0];
                    }
                }
            }
            if (apiSigner != null)
            {
                if (apiSigner.Group == null)
                {
                    signatureBuilder = new SignatureBuilder(apiSigner.Email);
                }
                else
                {
                    signatureBuilder = new SignatureBuilder(new GroupId(apiSigner.Group.Id));
                }
            }
            else
            {
                signatureBuilder = new SignatureBuilder("");
            }
            signatureBuilder.WithName(apiApproval.Name);

            Silanis.ESL.API.Field apiSignatureField = null;
            foreach (Silanis.ESL.API.Field apiField in apiApproval.Fields)
            {
                if (apiField.Type == Silanis.ESL.API.FieldType.SIGNATURE)
                {
                    apiSignatureField = apiField;
                }
                else
                {
                    FieldBuilder fieldBuilder = FieldBuilder.NewFieldFromAPIField(apiField);
                    signatureBuilder.WithField(fieldBuilder);
                }
            }

            if (apiSignatureField == null)
            {
                signatureBuilder.WithStyle(SignatureStyle.ACCEPTANCE);
                signatureBuilder.WithSize(0, 0);
            }
            else
            {
                signatureBuilder.WithStyle(FromAPIFieldSubType(apiSignatureField.Subtype))
                .OnPage(apiSignatureField.Page)
                .AtPosition(apiSignatureField.Left, apiSignatureField.Top)
                .WithSize(apiSignatureField.Width, apiSignatureField.Height);

                if (apiSignatureField.Extract)
                {
                    signatureBuilder.EnableExtraction();
                }
            }

            return(signatureBuilder);
        }
コード例 #31
0
        internal PackageId CreateTemplateFromPackage(PackageId originalPackageId, Silanis.ESL.API.Package delta)
        {
            string templateId = apiClient.CreateTemplateFromPackage(originalPackageId.Id, delta);

            return(new PackageId(templateId));
        }
コード例 #32
0
 /*
  * Construct with API objects
  */
 public DocumentConverter(Silanis.ESL.API.Document apiDocument, Silanis.ESL.API.Package apiPackage)
 {
     this.apiDocument = apiDocument;
     this.apiPackage  = apiPackage;
 }