コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: lpperras/sendsecure-csharp
        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);
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
ファイル: Client.cs プロジェクト: lpperras/sendsecure-csharp
        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);
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        /// <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>());
        }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
        /// <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>());
        }
コード例 #12
0
ファイル: Client.cs プロジェクト: lpperras/sendsecure-csharp
        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));
        }
コード例 #13
0
ファイル: Client.cs プロジェクト: lpperras/sendsecure-csharp
        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));
        }
コード例 #14
0
        /// <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));
        }
コード例 #15
0
        /// <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));
        }
コード例 #16
0
        /// <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);
        }
コード例 #17
0
        /// <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);
        }