示例#1
0
        public DocumentPackage GetPackage(PackageId id)
        {
            OneSpanSign.API.Package package = packageService.GetPackage(id);

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

            return(documentPackage);
        }
        public void ConvertAPIToAPI()
        {
            apiPackage1 = CreateTypicalAPIPackage();
            converter   = new DocumentPackageConverter(apiPackage1);
            apiPackage2 = converter.ToAPIPackage();

            Assert.IsNotNull(apiPackage2);
            Assert.AreEqual(apiPackage2, apiPackage1);
        }
        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());
        }
示例#4
0
 public void SignDocument(PackageId packageId, string documentName, CapturedSignature capturedSignature)
 {
     OneSpanSign.API.Package package = packageService.GetPackage(packageId);
     foreach (OneSpanSign.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);
         }
     }
 }
示例#5
0
        private string FindRoleIdForSigner(string signerEmail, OneSpanSign.API.Package createdPackage)
        {
            foreach (OneSpanSign.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 OssException(String.Format("No Role found for signer email {0}", signerEmail), null);
        }
示例#6
0
        private string FindRoleIdForGroup(GroupId groupId, OneSpanSign.API.Package createdPackage)
        {
            foreach (OneSpanSign.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 OssException(String.Format("No Role found for group with id {0}", groupId.Id), null);
        }
示例#7
0
        internal string CreatePackageFromTemplate(string templateId, OneSpanSign.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);
                OneSpanSign.API.Package apiResult = JsonConvert.DeserializeObject <OneSpanSign.API.Package> (response);
                return(apiResult.Id);
            }
            catch (OssServerException e) {
                throw new OssServerException("Could not create a package from template." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e) {
                throw new OssException("Could not create a package from template." + " Exception: " + e.Message, e);
            }
        }
示例#8
0
        internal string CreateTemplate(OneSpanSign.API.Package template)
        {
            string path = urls.UrlFor(UrlTemplate.PACKAGE_PATH).Build();

            try
            {
                string json     = JsonConvert.SerializeObject(template, settings);
                string response = restClient.Post(path, json);
                OneSpanSign.API.Package apiPackage = JsonConvert.DeserializeObject <OneSpanSign.API.Package>(response);
                return(apiPackage.Id);
            }
            catch (OssServerException e)
            {
                throw new OssServerException("Could not create template." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new OssException("Could not create template." + " Exception: " + e.Message, e);
            }
        }
示例#9
0
        public void Update(OneSpanSign.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 (OssServerException e)
            {
                throw new OssServerException("Could not update template." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new OssException("Could not update template." + " Exception: " + e.Message, e);
            }
        }
示例#10
0
        internal OneSpanSign.API.Document ToAPIDocument(OneSpanSign.API.Package apiPackage)
        {
            if (sdkDocument == null)
            {
                return(apiDocument);
            }

            OneSpanSign.API.Document doc = ToAPIDocument();

            foreach (Signature signature in sdkDocument.Signatures)
            {
                OneSpanSign.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 OneSpanSign.API.Package CreateTypicalAPIPackage()
        {
            OneSpanSign.API.Package apiPackage = new OneSpanSign.API.Package();
            apiPackage.Id           = "1";
            apiPackage.Language     = "zh-CN";
            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       = DocumentPackageStatus.DRAFT.getApiValue();
            apiPackage.Created      = DateTime.Now;

            OneSpanSign.API.Message apiMessage = new OneSpanSign.API.Message();
            apiMessage.Content = "opt-out reason";
            apiMessage.Status  = OneSpanSign.Sdk.MessageStatus.NEW.getApiValue();
            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);

            OneSpanSign.API.Sender sender = new OneSpanSign.API.Sender();
            sender.Email      = "*****@*****.**";
            apiPackage.Sender = sender;

            return(apiPackage);
        }
        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);
            Assert.AreEqual(apiPackage1.Sender.Email, sdkPackage1.SenderInfo.Email);
            Assert.AreEqual(apiPackage1.Created, sdkPackage1.CreatedDate);
        }
 public void ConvertNullAPIToAPI()
 {
     apiPackage1 = null;
     converter   = new DocumentPackageConverter(apiPackage1);
     Assert.IsNull(converter.ToAPIPackage());
 }
示例#14
0
        internal PackageId CreateTemplateFromPackage(PackageId originalPackageId, OneSpanSign.API.Package delta)
        {
            string templateId = apiClient.CreateTemplateFromPackage(originalPackageId.Id, delta);

            return(new PackageId(templateId));
        }
示例#15
0
 /*
  * Construct with API objects
  */
 public DocumentConverter(OneSpanSign.API.Document apiDocument, OneSpanSign.API.Package apiPackage)
 {
     this.apiDocument = apiDocument;
     this.apiPackage  = apiPackage;
 }