private OneSpanSign.Sdk.DocumentPackage CreateTypicalSDKDocumentPackage()
        {
            OneSpanSign.Sdk.DocumentPackage sdkDocumentPackage = PackageBuilder.NewPackageNamed("SDK Package Name")
                                                                 .WithID(new PackageId("packageId"))
                                                                 .WithStatus(DocumentPackageStatus.DRAFT)
                                                                 .DescribedAs("typical description")
                                                                 .WithEmailMessage("typical email message")
                                                                 .WithLanguage(CultureInfo.GetCultureInfo("zh-CN"))
                                                                 .Build();

            return(sdkDocumentPackage);
        }
        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());
        }
Exemplo n.º 3
0
        public PackageId CreatePackage(DocumentPackage package)
        {
            ValidateSignatures(package);
            if (!IsSdkVersionSetInPackageData(package))
            {
                SetSdkVersionInPackageData(package);
            }

            OneSpanSign.API.Package packageToCreate = new DocumentPackageConverter(package).ToAPIPackage();
            PackageId id = packageService.CreatePackage(packageToCreate);

            try
            {
                UploadDocuments(id, package.Documents);
            }
            catch (Exception e)
            {
                packageService.DeletePackage(id);
                throw new OssException("Could not create a new package." + " Exception: " + e.Message, e);
            }
            return(id);
        }
Exemplo n.º 4
0
        private void SetNewSignersIndexIfRoleWorkflowEnabled(PackageId templateId, DocumentPackage documentPackage)
        {
            DocumentPackage template = new DocumentPackageConverter(packageService.GetPackage(templateId)).ToSDKPackage();

            if (CheckSignerOrdering(template))
            {
                int firstSignerIndex = GetMaxSigningOrder(template, documentPackage) + 1;
                foreach (Signer signer in documentPackage.Signers)
                {
                    Signer templatePlaceholder = template.GetPlaceholder(signer.Id);
                    if (templatePlaceholder != null)
                    {
                        signer.SigningOrder = templatePlaceholder.SigningOrder;
                    }

                    if (signer.SigningOrder <= 0)
                    {
                        signer.SigningOrder = firstSignerIndex;
                        firstSignerIndex++;
                    }
                }
            }
        }
        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 ConvertNullSDKToAPI()
 {
     sdkPackage1 = null;
     converter   = new DocumentPackageConverter(sdkPackage1);
     Assert.IsNull(converter.ToAPIPackage());
 }
 public byte[] DownloadAllAttachmentsForSignerInPackage(DocumentPackage sdkPackage, Signer signer)
 {
     return(DownloadAllAttachmentFilesForSignerInPackage(sdkPackage, signer).Contents);
 }
 /// <summary>
 /// Sender downloads all attachment files for the signer in the package.
 /// </summary>
 /// <returns>The attachment files with file name.</returns>
 /// <param name="packageId">Package identifier.</param>
 /// <param name="signer">Signer.</param>
 public DownloadedFile DownloadAllAttachmentFilesForSignerInPackage(DocumentPackage sdkPackage, Signer signer)
 {
     return(apiClient.DownloadAllAttachmentFilesForSignerInPackage(sdkPackage, signer));
 }
Exemplo n.º 9
0
 public Document UploadDocument(string fileName, byte[] fileContent, Document document,
                                DocumentPackage documentPackage)
 {
     return(UploadDocument(fileName, fileContent, document, documentPackage.Id));
 }
Exemplo n.º 10
0
 public Document UploadDocument(Document document, DocumentPackage documentPackage)
 {
     return(UploadDocument(document.FileName, document.Content, document, documentPackage.Id));
 }
Exemplo n.º 11
0
 public void UpdatePackage(OneSpanSign.Sdk.PackageId packageId, DocumentPackage documentPackage)
 {
     packageService.UpdatePackage(packageId, new DocumentPackageConverter(documentPackage).ToAPIPackage());
 }
Exemplo n.º 12
0
        public PackageId CreatePackageFromTemplate(PackageId templateId, string packageName)
        {
            DocumentPackage sdkPackage = PackageBuilder.NewPackageNamed(packageName).Build();

            return(CreatePackageFromTemplate(templateId, sdkPackage));
        }
Exemplo n.º 13
0
        public PackageId CreateTemplateFromPackage(PackageId originalPackageId, string templateName)
        {
            DocumentPackage sdkPackage = PackageBuilder.NewPackageNamed(templateName).Build();

            return(CreateTemplateFromPackage(originalPackageId, sdkPackage));
        }
Exemplo n.º 14
0
 public PackageId CreateTemplateFromPackage(PackageId originalPackageId, DocumentPackage delta)
 {
     return(templateService.CreateTemplateFromPackage(originalPackageId,
                                                      new DocumentPackageConverter(delta).ToAPIPackage()));
 }
Exemplo n.º 15
0
 public PackageId CreatePackageFromTemplate(PackageId templateId, DocumentPackage delta)
 {
     ValidateSignatures(delta);
     SetNewSignersIndexIfRoleWorkflowEnabled(templateId, delta);
     return(templateService.CreatePackageFromTemplate(templateId, new DocumentPackageConverter(delta).ToAPIPackage()));
 }
Exemplo n.º 16
0
        internal OneSpanSign.Sdk.DocumentPackage ToSDKPackage()
        {
            if (apiPackage == null)
            {
                return(sdkPackage);
            }

            PackageBuilder packageBuilder = PackageBuilder.NewPackageNamed(apiPackage.Name);

            packageBuilder.WithID(new PackageId(apiPackage.Id));

            if (apiPackage.Autocomplete.Value)
            {
                packageBuilder.WithAutomaticCompletion();
            }
            else
            {
                packageBuilder.WithoutAutomaticCompletion();
            }

            packageBuilder.ExpiresOn(apiPackage.Due);
            packageBuilder.WithStatus(new PackageStatusConverter(apiPackage.Status).ToSDKPackageStatus());


            if (apiPackage.Description != null)
            {
                packageBuilder.DescribedAs(apiPackage.Description);
            }

            if (apiPackage.EmailMessage != null)
            {
                packageBuilder.WithEmailMessage(apiPackage.EmailMessage);
            }

            if (apiPackage.Language != null)
            {
                packageBuilder.WithLanguage(new CultureInfo(apiPackage.Language));
            }

            if (apiPackage.Settings != null)
            {
                packageBuilder.WithSettings(new DocumentPackageSettingsConverter(apiPackage.Settings).toSDKDocumentPackageSettings());
            }

            if (apiPackage.Sender != null)
            {
                packageBuilder.WithSenderInfo(new SenderConverter(apiPackage.Sender).ToSDKSenderInfo());
            }

            if (apiPackage.Notarized != null)
            {
                packageBuilder.WithNotarized(apiPackage.Notarized);
            }

            if (apiPackage.Trashed != null)
            {
                packageBuilder.WithTrashed(apiPackage.Trashed.Value);
            }

            if (apiPackage.Visibility != null)
            {
                packageBuilder.WithVisibility(new VisibilityConverter(apiPackage.Visibility).ToSDKVisibility());
            }

            if (apiPackage.TimezoneId != null)
            {
                packageBuilder.WithTimezoneId(apiPackage.TimezoneId);
            }

            packageBuilder.WithAttributes(new DocumentPackageAttributesBuilder(apiPackage.Data).Build());

            foreach (OneSpanSign.API.Role role in apiPackage.Roles)
            {
                if (role.Signers.Count == 0)
                {
                    packageBuilder.WithSigner(SignerBuilder.NewSignerPlaceholder(new Placeholder(role.Id, role.Name, role.Index)));
                }
                else if (role.Signers[0].Group != null)
                {
                    packageBuilder.WithSigner(SignerBuilder.NewSignerFromGroup(new GroupId(role.Signers[0].Group.Id)));
                }
                else
                {
                    packageBuilder.WithSigner(new SignerConverter(role).ToSDKSigner());

                    // The custom sender information is stored in the role.signer object.
                    if ("SENDER".Equals(role.Type))
                    {
                        // Override sender info with the customized ones.
                        OneSpanSign.Sdk.SenderInfo senderInfo = new OneSpanSign.Sdk.SenderInfo();

                        OneSpanSign.API.Signer signer = role.Signers[0];
                        senderInfo.FirstName = signer.FirstName;
                        senderInfo.LastName  = signer.LastName;
                        senderInfo.Title     = signer.Title;
                        senderInfo.Company   = signer.Company;
                        senderInfo.Email     = signer.Email;

                        packageBuilder.WithSenderInfo(senderInfo);
                    }
                }
            }

            foreach (OneSpanSign.API.Document apiDocument in apiPackage.Documents)
            {
                Document document = new DocumentConverter(apiDocument, apiPackage).ToSDKDocument();
                packageBuilder.WithDocument(document);
            }

            DocumentPackage documentPackage = packageBuilder.Build();

            IList <Message> messages = new List <Message>();

            foreach (OneSpanSign.API.Message apiMessage in apiPackage.Messages)
            {
                messages.Add(new MessageConverter(apiMessage).ToSDKMessage());
            }
            documentPackage.Messages = messages;
            if (apiPackage.Updated != null)
            {
                documentPackage.UpdatedDate = apiPackage.Updated;
            }

            if (apiPackage.Created != null)
            {
                documentPackage.CreatedDate = apiPackage.Created;
            }

            IList <FieldCondition> conditions = new List <FieldCondition>();

            foreach (OneSpanSign.API.FieldCondition apiFieldCondition in apiPackage.Conditions)
            {
                conditions.Add(new FieldConditionConverter(apiFieldCondition).ToSDKFieldCondition());
            }
            documentPackage.Conditions = conditions;

            return(documentPackage);
        }