public SignedDocumentDelivery AddExcludedDocument(Document value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("Argument cannot be null");
     }
     
     _excludedDocuments.Add(value);
     return this;
 }
Exemple #2
0
     public Message AddDocument(Document value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("Argument cannot be null");
     }
     
     _documents.Add(value);
     return this;
 }
        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);
        }
Exemple #4
0
        internal SignedDocument ConvertToSignedDocument(Silanis.ESL.API.Document document)
        {
            SignedDocument signedDocument = new SignedDocument();

            signedDocument.Id                      = document.Id;
            signedDocument.Name                    = document.Name;
            signedDocument.Description             = document.Description;
            signedDocument.Approvals               = document.Approvals;
            signedDocument.External                = document.External;
            signedDocument.Index                   = document.Index;
            signedDocument.Extract                 = document.Extract;
            signedDocument.ExtractionTypes         = document.ExtractionTypes;
            signedDocument.Fields                  = document.Fields;
            signedDocument.Data                    = document.Data;
            signedDocument.SignedHash              = document.SignedHash;
            signedDocument.Pages                   = document.Pages;
            signedDocument.Size                    = document.Size;
            signedDocument.Status                  = document.Status;
            signedDocument.SignerVerificationToken = document.SignerVerificationToken;
            signedDocument.Tagged                  = document.Tagged;

            return(signedDocument);
        }
		public void UpdateDocumentMetadata(DocumentPackage template, Document document)
		{
			packageService.UpdateDocumentMetadata(template, document);
		}
		/// <summary>
		/// Deletes the document from the template.
		/// </summary>
		/// <param name="templateId">The template id.</param>
		/// <param name="document">The document to delete.</param>
		public void DeleteDocument (PackageId templateId, Document document)
		{
			DeleteDocument(templateId, document.Id);
		}
		/// <summary>
		/// Deletes the document from the package.
		/// </summary>
		/// <param name="packageId">The package id.</param>
		/// <param name="document">The document to delete.</param>
		public void DeleteDocument (PackageId packageId, Document document)
		{
			string path = template.UrlFor (UrlTemplate.DOCUMENT_ID_PATH)
                .Replace ("{packageId}", packageId.Id)
                .Replace ("{documentId}", "document.Id")
                .Build ();

			try {
                restClient.Delete(path);
			} catch (Exception e) {
				throw new EslException ("Could not delete document from package." + " Exception: " + e.Message);
			}
		}
Exemple #8
0
 /*
  * Construct with API objects
  */
 public DocumentConverter(Silanis.ESL.API.Document apiDocument, Silanis.ESL.API.Package apiPackage)
 {
     this.apiDocument = apiDocument;
     this.apiPackage  = apiPackage;
 }
Exemple #9
0
        /// <summary>
        /// Uploads the Document and file in byte[] to the package.
        /// </summary>
        /// <param name="packageId">The package id.</param>
        /// <param name="fileName">The name of the document.</param>
        /// <param name="fileBytes">The file to upload in bytes.</param>
        /// <param name="document">The document object that has field settings.</param>
        internal void UploadDocument(PackageId packageId, string fileName, byte[] fileBytes, Silanis.ESL.API.Document document)
        {
            Support.LogMethodEntry(packageId, fileName, document);
            string path = template.UrlFor(UrlTemplate.DOCUMENT_PATH)
                          .Replace("{packageId}", packageId.Id)
                          .Build();

            try {
                string json = JsonConvert.SerializeObject(document, settings);
                Support.LogDebug("document json = " + json);
                byte[] payloadBytes = Converter.ToBytes(json);

                string boundary = GenerateBoundary();
                byte[] content  = CreateMultipartContent(fileName, fileBytes, payloadBytes, boundary);

                restClient.PostMultipartFile(path, content, boundary);
                Support.LogMethodExit("Document uploaded without issue");
//				Converter.ToString (HttpMethods.MultipartPostHttp (apiToken, path, content, boundary));
            } catch (Exception e) {
                throw new EslException("Could not upload document to package." + " Exception: " + e.Message);
            }
        }
		/// <summary>
		/// Uploads the Document and file in byte[] to the package.
		/// </summary>
		/// <param name="packageId">The package id.</param>
		/// <param name="fileName">The name of the document.</param>
		/// <param name="fileBytes">The file to upload in bytes.</param>
		/// <param name="document">The document object that has field settings.</param>
		internal Document UploadDocument (DocumentPackage package, string fileName, byte[] fileBytes, Document document)
		{
			string path = template.UrlFor (UrlTemplate.DOCUMENT_PATH)
				.Replace ("{packageId}", package.Id.Id)
					.Build ();

			Silanis.ESL.API.Package internalPackage = new DocumentPackageConverter(package).ToAPIPackage();
			Silanis.ESL.API.Document internalDoc = new DocumentConverter(document).ToAPIDocument(internalPackage);

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

				string boundary = GenerateBoundary ();
				byte[] content = CreateMultipartContent (fileName, fileBytes, payloadBytes, boundary);

				string response = restClient.PostMultipartFile(path, content, boundary, json);

				Silanis.ESL.API.Document uploadedDoc = JsonConvert.DeserializeObject<Silanis.ESL.API.Document>(response);
				return new DocumentConverter(uploadedDoc, internalPackage).ToSDKDocument();
			} 
            catch (EslServerException e) 
            {
                throw new EslServerException ("Could not upload document to package." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e) 
			{
				throw new EslException ("Could not upload document to package." + " Exception: " + e.Message, e);
			}
		}
        /// <summary>
        /// Updates the document's data, but not the actually document binary..
        /// </summary>
        /// <param name="package">The DocumentPackage to update.</param>
        /// <param name="document">The Document to update.</param>
		public void UpdateDocumentMetadata(DocumentPackage package, Document document)
        {
            string path = template.UrlFor(UrlTemplate.DOCUMENT_ID_PATH)
				.Replace("{packageId}", package.Id.Id)
				.Replace("{documentId}", document.Id)
				.Build();

            Silanis.ESL.API.Package apiPackage = new DocumentPackageConverter(package).ToAPIPackage();
            Silanis.ESL.API.Document apiDocument = new DocumentConverter(document).ToAPIDocument(apiPackage);

            foreach (Silanis.ESL.API.Document apiDoc in apiPackage.Documents)
            {
                if (apiDoc.Id.Equals(document.Id))
                {
                    apiDocument = apiDoc;
                    break;
                }
            }
            if (apiDocument == null)
            {
                throw new EslException("Document is not part of the package.", null);
            }
            
			try 
			{
				string json = JsonConvert.SerializeObject (apiDocument, settings);
				restClient.Post(path, json);
			} 
            catch (EslServerException e) 
            {
                throw new EslServerException ("Could not update the document's metadata." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e) 
			{
                throw new EslException ("Could not update the document's metadata." + " Exception: " + e.Message, e);
			}

            IContractResolver prevContractResolver = settings.ContractResolver;
            settings.ContractResolver = DocumentMetadataContractResolver.Instance;            
            
            try
            {
                string json = JsonConvert.SerializeObject(apiDocument, settings);
                restClient.Post(path, json);
            }
            catch (EslServerException e) 
            {
                throw new EslServerException ("Could not upload document to package." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new EslException("Could not upload document to package." + " Exception: " + e.Message, e);
            }
            finally
            {
                settings.ContractResolver = prevContractResolver;
            }
		}
		/// <summary>
		/// Deletes the document from the package.
		/// </summary>
		/// <param name="packageId">The package id.</param>
		/// <param name="document">The document to delete.</param>
		public void DeleteDocument (PackageId packageId, Document document)
		{
			DeleteDocument(packageId, document.Id);
		}
		public PackageBuilder WithDocument (Document document)
		{
			documents [document.Name] = document;
			return this;
		}
 /*
  * Construct with API objects
  */
 public DocumentConverter(Silanis.ESL.API.Document apiDocument, Silanis.ESL.API.Package apiPackage)
 {
     this.apiDocument = apiDocument;
     this.apiPackage = apiPackage;
 }
        internal Silanis.ESL.API.Document ToAPIDocument()
        {
            if (sdkDocument == null)
            {
                return apiDocument;
            }

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

            doc.Name = sdkDocument.Name;
            doc.Index = sdkDocument.Index;
            doc.Extract = sdkDocument.Extract;
            doc.External = new ExternalConverter(sdkDocument.External).ToAPIExternal();

            if (sdkDocument.Id != null)
            {
                doc.Id = sdkDocument.Id;
            }

            if (sdkDocument.Description != null)
            {
                doc.Description = sdkDocument.Description;
            }

            return doc;
        }