public SenderConverter(Silanis.ESL.API.Sender sender) { if (sender == null) throw new ArgumentNullException("sender"); this.apiSender = sender; this.sdkSenderInfo = null; }
public SenderConverter(Silanis.ESL.SDK.SenderInfo senderInfo) { if (senderInfo == null) throw new ArgumentNullException("senderInfo"); this.apiSender = null; this.sdkSenderInfo = senderInfo; }
internal static SignerBuilder NewSignerFromAPISigner (Silanis.ESL.API.Role role) { Silanis.ESL.API.Signer eslSigner = role.Signers [0]; SignerBuilder builder = SignerBuilder.NewSignerWithEmail( eslSigner.Email ) .WithCustomId ( eslSigner.Id ) .WithFirstName( eslSigner.FirstName ) .WithLastName( eslSigner.LastName ) .WithCompany( eslSigner.Company ) .WithTitle( eslSigner.Title ) .SigningOrder( role.Index ); if ( role.Reassign ) { builder.CanChangeSigner (); } if ( role.EmailMessage != null ) { builder.WithEmailMessage( role.EmailMessage.Content ); } if ( role.Locked ) { builder.Lock(); } if (eslSigner.Delivery != null && eslSigner.Delivery.Email) { builder.DeliverSignedDocumentsByEmail(); } return builder; }
public Silanis.ESL.API.CustomField CreateCustomField( Silanis.ESL.API.CustomField apiField ) { string path = template.UrlFor(UrlTemplate.ACCOUNT_CUSTOMFIELD_PATH).Build(); try { string stringResponse; if (DoesCustomFieldExist(apiField.Id)) { stringResponse = client.Put(path, JsonConvert.SerializeObject(apiField, settings)); } else { stringResponse = client.Post(path, JsonConvert.SerializeObject(apiField, settings)); } return JsonConvert.DeserializeObject<Silanis.ESL.API.CustomField>(stringResponse); } catch (EslServerException e) { throw new EslServerException("Could not add/update the custom field to account." + " Exception: " + e.Message, e.ServerError, e); } catch (Exception e) { throw new EslException("Could not add/update the custom field to account." + " Exception: " + e.Message, e); } }
// Convert from API to SDK SenderCompletionReport private Silanis.ESL.SDK.SenderCompletionReport ToSDKSenderCompletionReport(Silanis.ESL.API.SenderCompletionReport apiSenderCompletionReport) { Silanis.ESL.SDK.SenderCompletionReport sdkSenderCompletionReport = new Silanis.ESL.SDK.SenderCompletionReport(); sdkSenderCompletionReport.Sender = new SenderConverter(apiSenderCompletionReport.Sender).ToSDKSender(); return sdkSenderCompletionReport; }
public SignerConverter (Silanis.ESL.API.Role apiRole) { this.apiRole = apiRole; if (apiRole != null) { this.apiSigner = apiRole.Signers[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; }
internal static CustomFieldBuilder CustomField( Silanis.ESL.API.CustomField apiCustomField ) { CustomFieldBuilder result = new CustomFieldBuilder(); result.WithId( apiCustomField.Id ) .WithDefaultValue( apiCustomField.Value ); foreach ( Silanis.ESL.API.Translation tran in apiCustomField.Translations ) { result.WithTranslation( TranslationBuilder.NewTranslation( tran ) ); } return result; }
/// <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); } }
public Silanis.ESL.API.Sender InviteUser( Silanis.ESL.API.Sender invitee ) { string path = template.UrlFor(UrlTemplate.ACCOUNT_MEMBER_PATH).Build (); try { string json = JsonConvert.SerializeObject (invitee, jsonSettings); string response = restClient.Post(path, json); Silanis.ESL.API.Sender apiResponse = JsonConvert.DeserializeObject<Silanis.ESL.API.Sender> (response, jsonSettings ); return apiResponse; } catch (EslServerException e) { throw new EslServerException ("Failed to invite new account member.\t" + " Exception: " + e.Message, e.ServerError, e); } catch (Exception e) { throw new EslException ("Failed to invite new account member.\t" + " Exception: " + e.Message, e); } }
// Convert from API to SDK SenderUsageReport. private Silanis.ESL.SDK.SenderUsageReport ToSDKSenderUsageReport(Silanis.ESL.API.SenderUsageReport apiSenderUsageReport) { Silanis.ESL.SDK.SenderUsageReport sdkSenderUsageReport = new Silanis.ESL.SDK.SenderUsageReport(); sdkSenderUsageReport.Sender = new SenderConverter(apiSenderUsageReport.Sender).ToSDKSender(); IDictionary<UsageReportCategory, int> categoryCount = new Dictionary<UsageReportCategory, int>(); foreach (KeyValuePair<string, object> entry in apiSenderUsageReport.Packages) { UsageReportCategory usageReportCategory = (UsageReportCategory)Enum.Parse(typeof(UsageReportCategory), entry.Key.ToUpper()); categoryCount.Add(usageReportCategory, Convert.ToInt32(entry.Value)); } sdkSenderUsageReport.CountByUsageReportCategory = categoryCount; return sdkSenderUsageReport; }
/// <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); } }
public Silanis.ESL.API.Group CreateGroup( Silanis.ESL.API.Group apiGroup ) { string path = template.UrlFor (UrlTemplate.GROUPS_PATH).Build (); try { string json = JsonConvert.SerializeObject (apiGroup, settings); string response = restClient.Post(path, json); Silanis.ESL.API.Group apiResponse = JsonConvert.DeserializeObject<Silanis.ESL.API.Group> (response); return apiResponse; } catch (EslServerException e) { throw new EslServerException ("Failed to create new group." + " Exception: " + e.Message, e.ServerError, e); } catch (Exception e) { throw new EslException ("Failed to create new group." + " Exception: " + e.Message, e); } }
public void UpdateSender(Silanis.ESL.API.Sender apiSender, string senderId){ string path = template.UrlFor(UrlTemplate.ACCOUNT_MEMBER_ID_PATH) .Replace("{senderUid}", senderId) .Build(); try { string json = JsonConvert.SerializeObject (apiSender, jsonSettings); apiSender.Id = senderId; restClient.Post(path, json); } catch (EslServerException e) { throw new EslServerException("Could not update sender.\t" + " Exception: " + e.Message, e.ServerError, e); } catch (Exception e) { throw new EslException("Could not update sender.\t" + " Exception: " + e.Message, e); } }
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); } }
internal PackageBuilder (Silanis.ESL.API.Package package) { this.id = new PackageId( package.Id ); this.packageName = package.Name; this.autocomplete = package.Autocomplete; this.description = package.Description; this.expiryDate = package.Due; this.status = ConvertPackageStatus(package.Status); this.emailMessage = package.EmailMessage; this.settings = new DocumentPackageSettingsBuilder(package.Settings).build(); this.senderInfo = new SenderConverter(package.Sender).ToSDKSenderInfo(); this.attributes = new DocumentPackageAttributes(package.Data); foreach ( Silanis.ESL.API.Role role in package.Roles ) { if ( role.Signers.Count == 0 ) { continue; } if (role.Signers[0].Group != null) { WithSigner(SignerBuilder.NewSignerFromGroup(new GroupId(role.Signers[0].Group.Id))); } else { WithSigner(SignerBuilder.NewSignerFromAPISigner(role).Build()); if (role.Type == Silanis.ESL.API.RoleType.SENDER) { Silanis.ESL.API.Signer senderSigner = role.Signers[0]; WithSenderInfo( SenderInfoBuilder.NewSenderInfo(senderSigner.Email) .WithName(senderSigner.FirstName, senderSigner.LastName) .WithCompany(senderSigner.Company) .WithTitle(senderSigner.Title)); } } } foreach ( Silanis.ESL.API.Document apiDocument in package.Documents ) { Document document = DocumentBuilder.NewDocumentFromAPIDocument( apiDocument, package ).Build(); WithDocument( document ); } }
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); } }
internal static FieldBuilder NewFieldFromAPIField (Silanis.ESL.API.Field apiField) { FieldBuilder fieldBuilder = new FieldBuilder() .OnPage( apiField.Page ) .AtPosition( apiField.Left, apiField.Top ) .WithSize( apiField.Width, apiField.Height ) .WithStyle( GetFieldStyleFromAPIField( apiField ) ) .WithName( apiField.Name ); if ( apiField.Id != null ) { fieldBuilder.WithId( apiField.Id ); } if ( apiField.Extract ) { fieldBuilder.WithPositionExtracted(); } fieldBuilder.WithValue( apiField.Value ); return fieldBuilder; }
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); } }
internal Silanis.ESL.API.Document ToAPIDocument (Silanis.ESL.API.Package createdPackage) { Silanis.ESL.API.Document doc = new Silanis.ESL.API.Document (); doc.Name = Name; doc.Index = Index; doc.Extract = Extract; if ( Id != null ) { doc.Id = Id; } if (Description != null) { doc.Description = Description; } Converter converter = new Converter (); foreach (Signature signature in signatures) { Silanis.ESL.API.Approval approval = converter.ConvertToApproval (signature); if (signature.IsGroupSignature() ) { approval.Role = FindRoleIdForGroup (signature.GroupId, createdPackage); } else { approval.Role = FindRoleIdForSigner (signature.SignerEmail, createdPackage); } doc.AddApproval (approval); } foreach (Field field in fields) { doc.AddField (converter.ToAPIField(field)); } return doc; }
/// <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); } }
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; }
private DocumentPackageStatus ConvertPackageStatus (Silanis.ESL.API.PackageStatus status) { switch (status) { case Silanis.ESL.API.PackageStatus.DRAFT: return DocumentPackageStatus.DRAFT; case Silanis.ESL.API.PackageStatus.SENT: return DocumentPackageStatus.SENT; case Silanis.ESL.API.PackageStatus.COMPLETED: return DocumentPackageStatus.COMPLETED; case Silanis.ESL.API.PackageStatus.ARCHIVED: return DocumentPackageStatus.ARCHIVED; case Silanis.ESL.API.PackageStatus.DECLINED: return DocumentPackageStatus.DECLINED; case Silanis.ESL.API.PackageStatus.OPTED_OUT: return DocumentPackageStatus.OPTED_OUT; case Silanis.ESL.API.PackageStatus.EXPIRED: return DocumentPackageStatus.EXPIRED; default: throw new EslException("Unknown Silanis.ESL.API.PackageStatus value: " + status); } }
public void ModifyQRCode(string packageId, string documentId, Silanis.ESL.API.Field apiField) { string path = template.UrlFor(UrlTemplate.QRCODE_ID_PATH) .Replace("{packageId}", packageId) .Replace("{documentId}", documentId) .Replace("{fieldId}", apiField.Id) .Build(); string json = JsonConvert.SerializeObject(apiField, settings); try { restClient.Put(path, json); } catch (EslServerException e) { throw new EslServerException("Could not modify QR code in document." + " Exception: " + e.Message, e.ServerError, e); } catch (Exception e) { throw new EslException("Could not modify QR code in document." + " Exception: " + e.Message, e); } }
internal static DocumentBuilder NewDocumentFromAPIDocument (Silanis.ESL.API.Document apiDocument, Silanis.ESL.API.Package package) { DocumentBuilder documentBuilder = DocumentBuilder.NewDocumentNamed(apiDocument.Name) .WithId(apiDocument.Id) .AtIndex(apiDocument.Index) .WithDescription(apiDocument.Description); foreach ( Silanis.ESL.API.Approval apiApproval in apiDocument.Approvals ) { Signature signature = SignatureBuilder.NewSignatureFromAPIApproval( apiApproval, package ).Build (); documentBuilder.WithSignature( signature ); } foreach ( Silanis.ESL.API.Field apiField in apiDocument.Fields ) { FieldBuilder fieldBuilder = FieldBuilder.NewFieldFromAPIField( apiField ); documentBuilder.WithInjectedField( fieldBuilder ); } return documentBuilder; }
public string AddQRCode(string packageId, string documentId, Silanis.ESL.API.Field apiField) { string path = template.UrlFor(UrlTemplate.QRCODE_PATH) .Replace("{packageId}", packageId) .Replace("{documentId}", documentId) .Build(); string json = JsonConvert.SerializeObject(apiField, settings); try { string response = restClient.Post(path, json); Silanis.ESL.API.Field result = JsonConvert.DeserializeObject<Silanis.ESL.API.Field>(response, settings); return result.Id; } catch (EslServerException e) { throw new EslServerException("Could not add QR code to document." + " Exception: " + e.Message, e.ServerError, e); } catch (Exception e) { throw new EslException("Could not add QR code to document." + " Exception: " + e.Message, e); } }
/// <summary> /// Initializes a new instance of the <see cref="Silanis.ESL.SDK.ChallengeConverter"/> class. /// </summary> /// <param name="sdkChallenge">Sdk challenge.</param> public ChallengeConverter(Silanis.ESL.SDK.Challenge sdkChallenge) { this.sdkChallenge = sdkChallenge; }
/// <summary> /// Construct with API object involved in conversion. /// </summary> /// <param name="apiChallenge">API challenge.</param> public ChallengeConverter(Silanis.ESL.API.AuthChallenge apiChallenge) { this.apiChallenge = apiChallenge; }
internal static TranslationBuilder NewTranslation( Silanis.ESL.API.Translation apiTranslation ) { TranslationBuilder builder = new TranslationBuilder( apiTranslation.Language ); builder.WithName( apiTranslation.Name ) .WithDescription( apiTranslation.Description ); return builder; }
public CeremonyLayoutSettingsConverter(Silanis.ESL.API.LayoutOptions apiLayoutOptions) { this.apiLayoutOptions = apiLayoutOptions; }