/// <summary> /// Pre-creates a SafeBox on the SendSecure system and initializes the Safebox object accordingly. /// </summary> /// <param name="safebox">A SafeBox object to be finalized by the SendSecure system</param> /// <param name="cancellationToken"></param> /// <returns>The updated SafeBox object with the necessary system parameters (GUID, public encryption key, upload URL) filled out</returns> public async Task <Helpers.Safebox> InitializeSafeboxAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { string jsonResponse = await JsonClient.NewSafeboxAsync(safebox.UserEmail, cancellationToken); safebox.Update(jsonResponse); return(safebox); }
public async Task <Helpers.Attachment> UploadAttachmentAsync(Helpers.Safebox safebox, Helpers.Attachment attachment, CancellationToken cancellationToken = default(CancellationToken)) { string jsonResponse = await JsonClient.UploadFileAsync(new Uri(safebox.UploadUrl), attachment.Stream, attachment.ContentType, attachment.FileName, attachment.Size, cancellationToken); var response = JsonConvert.DeserializeObject <JsonObjects.UploadFileResponseSuccess>(jsonResponse); attachment.Guid = response.temporary_document.document_guid; return(attachment); }
/// <summary> /// Mark all messages as unread of a specific safebox associated to the current user's account. /// </summary> /// <param name="safebox">A Safebox object</param> /// <param name="cancellationToken"></param> /// <returns>RequestResponse object containing the request result</returns> public async Task <JsonObjects.RequestResponse> MarkAsUnreadAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } string jsonResponse = await JsonClient.MarkAsUnreadAsync(safebox.Guid, cancellationToken); return(JsonObjects.RequestResponse.FromJson(jsonResponse)); }
public async Task <Helpers.Safebox> InitializeSafeboxAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { string jsonResponse = await JsonClient.NewSafeboxAsync(safebox.UserEmail, cancellationToken); var response = JsonConvert.DeserializeObject <JsonObjects.NewSafeboxResponseSuccess>(jsonResponse); safebox.Guid = response.guid; safebox.PublicEncryptionKey = response.public_encryption_key; safebox.UploadUrl = response.upload_url; return(safebox); }
/// <summary> /// Retrieve all download activity info of an existing safebox for the current user account. /// </summary> /// <param name="safebox">A Safebox object</param> /// <param name="cancellationToken"></param> /// <returns>The Download Activity</returns> public async Task <Helpers.DownloadActivity> DownloadActivityAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } string jsonResponse = await JsonClient.GetSafeboxDownloadActivityAsync(safebox.Guid, cancellationToken); safebox.Update(jsonResponse); return(safebox.DownloadActivity); }
/// <summary> /// Retrieve all messages info of an existing safebox for the current user account. /// </summary> /// <param name="safebox">A Safebox object</param> /// <param name="cancellationToken"></param> /// <returns>The list of messages</returns> public async Task <List <Helpers.Message> > MessagesAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } string jsonResponse = await JsonClient.GetSafeboxMessagesAsync(safebox.Guid, cancellationToken); safebox.Update(jsonResponse); return(safebox.Messages); }
/// <summary> /// Retrieve the audit record url of a specific safebox associated to the current user's account. /// </summary> /// <param name="safebox">A Safebox object</param> /// <param name="cancellationToken"></param> /// <returns>The Audit Record Url</returns> public async Task <string> AuditRecordUrlAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } string jsonResponse = await JsonClient.GetAuditRecordUrlAsync(safebox.Guid, cancellationToken); var response = JObject.Parse(jsonResponse); return(response["url"].Value <string>()); }
/// <summary> /// Add time to the expiration date of a specific safebox associated to the current user's account. /// </summary> /// <param name="safebox">A Safebox object</param> /// <param name="timeValue">Time value to be added to the expiration date</param> /// <param name="timeUnit">Time unit to be added to the expiration date</param> /// <param name="cancellationToken"></param> /// <returns>AddTimeResponseSuccess object containing the request result</returns> public async Task <JsonObjects.AddTimeResponseSuccess> AddTimeAsync(Helpers.Safebox safebox, int timeValue, Helpers.SecurityEnums.TimeUnit timeUnit, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } var json = "{\"safebox\":{\"add_time_value\":" + timeValue + ",\"add_time_unit\":\"" + Helpers.SecurityEnums.TimeUnitToString(timeUnit) + "\"}}"; string jsonResponse = await JsonClient.AddTimeAsync(json, safebox.Guid, cancellationToken); var response = JsonConvert.DeserializeObject <JsonObjects.AddTimeResponseSuccess>(jsonResponse); safebox.Expiration = response.NewExpiration; return(response); }
/// <summary> /// Retrieve all info of an existing safebox for the current user account. /// </summary> /// <param name="safebox">A Safebox object</param> /// <param name="sections">The list of sections to be retrieved</param> /// <param name="cancellationToken"></param> /// <returns>The updated safebox containing all the informations on the specified sections. /// If no sections are specified, it will return all safebox infos.</returns> public async Task <Helpers.Safebox> SafeboxInfoAsync(Helpers.Safebox safebox, string[] sections, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } string parameters = sections != null?String.Join(",", sections) : ""; string jsonResponse = await JsonClient.GetSafeboxInfoAsync(safebox.Guid, parameters, cancellationToken); var response = JObject.Parse(jsonResponse); safebox.Update(response["safebox"].ToString()); return(safebox); }
/// <summary> /// This actually "Sends" the SafeBox with all content and contact info previously specified. /// </summary> /// <param name="safebox">A Safebox object already finalized, with security profile, recipient(s), /// subject and message already defined, and attachments already uploaded.</param> /// <param name="cancellationToken"></param> /// <returns>The updated safebox</returns> public async Task <Helpers.Safebox> CommitSafeboxAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } if (safebox.Participants.Count == 0) { throw new Exceptions.SendSecureException("Participants cannot be empty"); } string jsonResponse = await JsonClient.CommitSafeboxAsync(safebox.ToJson(), cancellationToken); safebox.Update(jsonResponse); return(safebox); }
/// <summary> /// Retrieve a specific file url of a specific safebox associated to the current user's account. /// </summary> /// <param name="safebox">A Safebox object</param> /// <param name="attachment">An Attachment object</param> /// <param name="cancellationToken"></param> /// <returns>The file url</returns> public async Task <string> FileUrlAsync(Helpers.Safebox safebox, Helpers.Attachment attachment, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } if (attachment.Guid == null) { throw new Exceptions.SendSecureException("Document Guid cannot be null"); } string jsonResponse = await JsonClient.GetFileUrlAsync(safebox.Guid, attachment.Guid, safebox.UserEmail, cancellationToken); var response = JObject.Parse(jsonResponse); return(response["url"].Value <string>()); }
public async Task <Helpers.SafeboxResponse> SubmitSafeboxAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { await InitializeSafeboxAsync(safebox, cancellationToken); foreach (Helpers.Attachment attachment in safebox.Attachments) { await UploadAttachmentAsync(safebox, attachment, cancellationToken); } if (safebox.SecurityProfile == null) { safebox.SecurityProfile = await DefaultSecurityProfileAsync(safebox.UserEmail, cancellationToken); if (safebox.SecurityProfile == null) { throw new Exceptions.SendSecureException(); } } return(await CommitSafeboxAsync(safebox, cancellationToken)); }
public async Task <Helpers.SafeboxResponse> CommitSafeboxAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { var request = new JsonObjects.CommitSafeboxRequest { safebox = new JsonObjects.CommitSafeboxRequest.SafeBox { guid = safebox.Guid, subject = safebox.Subject, message = safebox.Message, security_profile_id = safebox.SecurityProfile.Id, public_encryption_key = safebox.PublicEncryptionKey, notification_language = Locale, reply_enabled = safebox.SecurityProfile.ReplyEnabled.Value, group_replies = safebox.SecurityProfile.GroupReplies.Value, expiration_value = safebox.SecurityProfile.ExpirationValue.Value, expiration_unit = safebox.SecurityProfile.ExpirationUnit.Value, retention_period_type = safebox.SecurityProfile.RetentionPeriodType.Value, retention_period_value = safebox.SecurityProfile.RetentionPeriodValue.Value, retention_period_unit = safebox.SecurityProfile.RetentionPeriodUnit.Value, encrypt_message = safebox.SecurityProfile.ReplyEnabled.Value, double_encryption = safebox.SecurityProfile.ReplyEnabled.Value, document_ids = new List <string>(), recipients = safebox.Recipients } }; foreach (var attachment in safebox.Attachments) { request.safebox.document_ids.Add(attachment.Guid); } string json = JsonConvert.SerializeObject(request); string jsonResponse = await JsonClient.CommitSafeboxAsync(json, cancellationToken); return(JsonConvert.DeserializeObject <Helpers.SafeboxResponse>(jsonResponse)); }
/// <summary> /// Reply to a specific safebox associated to the current user's account. /// </summary> /// <param name="safebox">A Safebox object</param> /// <param name="reply">A Reply object</param> /// <param name="cancellationToken"></param> /// <returns>RequestResponse object containing the request result</returns> public async Task <JsonObjects.RequestResponse> ReplyAsync(Helpers.Safebox safebox, Helpers.Reply reply, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } foreach (Helpers.Attachment attachment in reply.Attachments) { var fileParamsJson = safebox.TemporaryDocument(attachment.Size); var newFileResponseJson = await JsonClient.NewFileAsync(safebox.Guid, fileParamsJson, cancellationToken); var newFileResponse = JsonObjects.NewFileResponseSuccess.FromJson(newFileResponseJson); var uploadResponseJson = await JsonClient.UploadFileAsync(new Uri(newFileResponse.UploadUrl), attachment.Stream, attachment.ContentType, attachment.FileName, attachment.Size, cancellationToken); var uploadResponse = JsonConvert.DeserializeObject <JsonObjects.UploadFileResponseSuccess>(uploadResponseJson); reply.DocumentIds.Add(uploadResponse.TemporaryDocument.DocumentGuid); } ; var response = await JsonClient.ReplyAsync(safebox.Guid, reply.ToJson(), cancellationToken); return(JsonObjects.RequestResponse.FromJson(response)); }
/// <summary> /// Retrieve the audit record pdf of a specific safebox associated to the current user's account. /// </summary> /// <param name="safebox">A Safebox object</param> /// <param name="cancellationToken"></param> /// <returns>The audit record pdf stream</returns> public async Task <string> AuditRecordPdfAsync(Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { string url = await AuditRecordUrlAsync(safebox, cancellationToken); return(await JsonClient.GetAuditRecordPdfAsync(url, cancellationToken)); }
/// <summary> /// Update an existing participant of a specific safebox associated to the current user's account. /// </summary> /// <param name="participant">A Participant object</param> /// <param name="safebox">A Safebox object</param> /// <param name="cancellationToken"></param> /// <returns>The updated Participant</returns> public async Task <Helpers.Participant> UpdateParticipantAsync(Helpers.Participant participant, Helpers.Safebox safebox, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } if (participant.Id == null) { throw new Exceptions.SendSecureException("Participant Id cannot be null"); } string jsonResponse = await JsonClient.UpdateParticipantAsync(participant.UpdateFor <Helpers.Participant.Edition>().ToJson(), safebox.Guid, participant.Id, cancellationToken); participant.Update(jsonResponse); return(participant); }
/// <summary> /// Delete contact methods of an existing participant of a specific safebox associated to the current user's account. /// </summary> /// <param name="participant">A Participant object</param> /// <param name="safebox">A Safebox object</param> /// <param name="contactMethodsIds">A list of contact method id</param> /// <param name="cancellationToken"></param> /// <returns>The updated Participant</returns> public async Task <Helpers.Participant> DeleteParticipantContactMethods(Helpers.Participant participant, Helpers.Safebox safebox, List <int?> contactMethodsIds, CancellationToken cancellationToken = default(CancellationToken)) { if (safebox.Guid == null) { throw new Exceptions.SendSecureException("Safebox Guid cannot be null"); } if (participant.Id == null) { throw new Exceptions.SendSecureException("Participant id cannot be null"); } string jsonResponse = await JsonClient.UpdateParticipantAsync(participant.UpdateFor <Helpers.Participant.Destruction>().OfFollowingContacts(contactMethodsIds).ToJson(), safebox.Guid, participant.Id, cancellationToken); participant.Update(jsonResponse); return(participant); }