public override async Task Run() { if (string.IsNullOrEmpty(ActivityUI.FilePicker.Value)) { RaiseError("Excel file is not selected", ActivityErrorCode.DESIGN_TIME_DATA_MISSING); return; } var byteArray = await _excelUtils.GetExcelFileAsByteArray(ActivityUI.FilePicker.Value); var tableCrates = GetExcelFileDescriptionCrates(byteArray, ActivityUI.FilePicker.Value, null, true); var fileDescription = new StandardFileDescriptionCM { TextRepresentation = Convert.ToBase64String(byteArray), Filetype = Path.GetExtension(ActivityUI.FilePicker.Value), Filename = Path.GetFileName(ActivityUI.FilePicker.Value) }; foreach (var crate in tableCrates) { Payload.Add(crate); } Payload.Add(Crate.FromContent(FileCrateLabel, fileDescription)); }
private async Task ProcessFilePickers(IEnumerable <ControlDefinitionDTO> filepickers) { int labeless_pickers = 0; foreach (FilePicker filepicker in filepickers) { var uploadFilePath = filepicker.Value; byte[] file = null; switch (GetUriFileExtension(uploadFilePath)) { case ".xlsx": file = await ProcessExcelFile(uploadFilePath); break; } if (file == null) { continue; } string crate_label = GetFileDescriptionLabel(filepicker, labeless_pickers); var fileDescription = new StandardFileDescriptionCM { Filename = Path.GetFileName(uploadFilePath), TextRepresentation = Convert.ToBase64String(file), Filetype = Path.GetExtension(uploadFilePath) }; Payload.Add(Crate.FromContent(crate_label, fileDescription)); } }
public async Task <StandardFileDescriptionCM> GetFile(AuthorizationToken authorizationToken, string path) { var client = new DropboxClient(authorizationToken.Token, CreateDropboxClientConfig(UserAgent)); var result = await client.Files.DownloadAsync(path); var byteArray = await result.GetContentAsByteArrayAsync(); var fileDescription = new StandardFileDescriptionCM { TextRepresentation = Convert.ToBase64String(byteArray), Filetype = System.IO.Path.GetExtension(result.Response.PathDisplay), Filename = System.IO.Path.GetFileName(result.Response.Name) }; return(fileDescription); }
public override async Task Run() { var fileSelector = GetControl <DropDownList>("FileSelector"); if (string.IsNullOrEmpty(fileSelector.Value)) { RaiseError("No File was selected on design time", ActivityErrorCode.DESIGN_TIME_DATA_MISSING); return; } //let's download this file var file = await HubCommunicator.DownloadFile(int.Parse(fileSelector.Value)); if (file == null || file.Length < 1) { RaiseError("Unable to download file from Hub"); return; } string textRepresentation; using (var reader = new StreamReader(file, Encoding.UTF8)) { textRepresentation = reader.ReadToEnd(); } //let's convert this file to a string and store it in a file crate var fileDescription = new StandardFileDescriptionCM { Filename = fileSelector.selectedKey, TextRepresentation = textRepresentation }; var fileCrate = Crate.FromContent("DownloadFile", fileDescription); Payload.Add(fileCrate); Success(); }
private Crate <StandardFileListCM> PackDropboxFileListCrate(IEnumerable <string> fileList) { var descriptionList = new List <StandardFileDescriptionCM>(); foreach (var filePath in fileList) { var fileDesc = new StandardFileDescriptionCM() { Filename = Path.GetFileName(filePath), Filetype = Path.GetExtension(filePath) }; var fileSharedUrl = _dropboxService.GetFileSharedUrl(AuthorizationToken, filePath); fileDesc.DirectUrl = fileSharedUrl; descriptionList.Add(fileDesc); } return(Crate <StandardFileListCM> .FromContent( RuntimeCrateLabel, new StandardFileListCM { FileList = descriptionList })); }
private void AssertEnvelopeParameters(DocuSignApiConfiguration loginInfo, List <KeyValueDTO> rolesList, List <KeyValueDTO> fieldList, string curTemplateId, StandardFileDescriptionCM file) { Assert.AreEqual("*****@*****.**", rolesList[0].Value, "Incorrect value for role email field"); Assert.AreEqual("Value", fieldList.First(x => x.Key == "DropDownListName").Value, "Incorrect value for list field"); Assert.AreEqual("Value", fieldList.First(x => x.Key == "RadioName").Value, "Incorrect value for radio field"); Assert.AreEqual("value", fieldList.First(x => x.Key == DocuSignConstants.DocuSignRoleName).Value, "Incorrect value for text field"); Assert.AreEqual("true", fieldList.First(x => x.Key == "CheckBoxName").Value, "Incorrect value for checkbox field"); }
public void SendAnEnvelopeFromTemplate(DocuSignApiConfiguration loginInfo, List <KeyValueDTO> rolesList, List <KeyValueDTO> fieldList, string curTemplateId, StandardFileDescriptionCM fileHandler = null) { EnvelopesApi envelopesApi = new EnvelopesApi(loginInfo.Configuration); TemplatesApi templatesApi = new TemplatesApi(loginInfo.Configuration); bool override_document = fileHandler != null; Recipients recipients = null; EnvelopeSummary envelopeSummary = null; //creatig an envelope definiton EnvelopeDefinition envDef = new EnvelopeDefinition(); envDef.EmailSubject = "Test message from Fr8"; envDef.Status = "created"; Debug.WriteLine($"sending an envelope from template {curTemplateId} to {loginInfo}"); var templateRecepients = templatesApi.ListRecipients(loginInfo.AccountId, curTemplateId); //adding file or applying template if (override_document) { //if we override document - we don't create an envelope yet //we create it with recipients once we've processed recipient values and tabs envDef.Documents = new List <Document>() { new Document() { DocumentBase64 = fileHandler.TextRepresentation, FileExtension = fileHandler.Filetype, DocumentId = "1", Name = fileHandler.Filename ?? Path.GetFileName(fileHandler.DirectUrl) ?? "document" } }; recipients = templateRecepients; } else { //creating envelope envDef.TemplateId = curTemplateId; envelopeSummary = envelopesApi.CreateEnvelope(loginInfo.AccountId, envDef); //requesting list of recipients since their Ids might be different from the one we got from tempates recipients = envelopesApi.ListRecipients(loginInfo.AccountId, envelopeSummary.EnvelopeId); } //updating recipients foreach (var recepient in recipients.Signers) { var correspondingTemplateRecipient = templateRecepients.Signers.FirstOrDefault(a => a.RoutingOrder == recepient.RoutingOrder); var relatedFields = rolesList.Where(a => a.Tags.Contains("recipientId:" + correspondingTemplateRecipient?.RecipientId)).ToArray(); var newEmail = relatedFields.FirstOrDefault(a => a.Key.Contains(DocuSignConstants.DocuSignRoleEmail))?.Value; var newName = relatedFields.FirstOrDefault(a => a.Key.Contains(DocuSignConstants.DocuSignRoleName))?.Value; recepient.Name = string.IsNullOrEmpty(newName) ? recepient.Name : newName; recepient.Email = string.IsNullOrEmpty(newEmail) ? recepient.Email : newEmail; if (!recepient.Email.IsValidEmailAddress()) { throw new ApplicationException($"'{recepient.Email}' is not a valid email address"); } //updating tabs var tabs = override_document ? templatesApi.ListTabs(loginInfo.AccountId, curTemplateId, correspondingTemplateRecipient.RecipientId, new Tabs()) : envelopesApi.ListTabs(loginInfo.AccountId, envelopeSummary.EnvelopeId, recepient.RecipientId); JObject jobj = DocuSignTab.ApplyValuesToTabs(fieldList, correspondingTemplateRecipient, tabs); recepient.Tabs = jobj.ToObject <Tabs>(); } if (override_document) { //deep copy to exclude tabs var recps_deep_copy = JsonConvert.DeserializeObject <Recipients>(JsonConvert.SerializeObject(recipients)); recps_deep_copy.Signers.ForEach(a => a.Tabs = null); envDef.Recipients = recps_deep_copy; //creating envlope envelopeSummary = envelopesApi.CreateEnvelope(loginInfo.AccountId, envDef); } else { envelopesApi.UpdateRecipients(loginInfo.AccountId, envelopeSummary.EnvelopeId, recipients); } foreach (var recepient in recipients.Signers) { if (override_document) { JObject jobj = JObject.Parse(recepient.Tabs.ToJson()); foreach (var item in jobj.Properties()) { foreach (var tab in (JToken)item.Value) { tab["documentId"] = "1"; } } var tabs = jobj.ToObject <Tabs>(); envelopesApi.CreateTabs(loginInfo.AccountId, envelopeSummary.EnvelopeId, recepient.RecipientId, tabs); } else if (typeof(Tabs).GetProperties() .Select(prop => prop.GetValue(recepient.Tabs, null)) .Any(val => val != null)) { envelopesApi.UpdateTabs(loginInfo.AccountId, envelopeSummary.EnvelopeId, recepient.RecipientId, recepient.Tabs); } } // sending an envelope envelopesApi.Update(loginInfo.AccountId, envelopeSummary.EnvelopeId, new Envelope() { Status = "sent" }); }