private void Execute(IProtectAttachment attachment, IContentEncryptionUi ui) { try { using (var applicationController = new ApplicationControllerWrapper()) { attachment.Status = PropertyNames.Processing; if (_marshaller.AttachmentEncryption.Decrypt(attachment, ui) == 0) { if (attachment.FileType == FileType.PDFDocument) { Pdf.Security.Remove(attachment.FileName, attachment.OpenPassword); } if (!attachment.IsCollection) attachment.Status = PropertyNames.Decrypted; var action = new DiscoveryAction(_marshaller, StatusUpdate, new List<IProtectAttachment> { attachment }, attachment.IsCollection); action.DiscoveryCompleted(); RaiseEvent(StatusUpdate, new ActionEventArgs(PropertyNames.Decrypted) { Attachment = attachment }); } else { attachment.Status = PropertyNames.DecryptionCancelled; } } attachment.Status = PropertyNames.IsProcessed; } catch (OperationCanceledException) { //ignore } catch (Exception e) { Logger.LogError(e); attachment.LastError = e; attachment.Status = PropertyNames.Exception; _encounteredException = true; RaiseEvent(StatusUpdate, new ActionEventArgs(PropertyNames.Exception) { Exception = e, Attachment = attachment }); } }
public void Discover(List<IProtectAttachment> attachments, bool isEncryptedCollection = false) { _tasks.Add(new NamedTask(() => { var actualAttachments=attachments.Where(p => p.Status != PropertyNames.UserRemovedAttachment).ToList(); if (actualAttachments.Any()) { var action = new DiscoveryAction(_marshaller, StatusUpdate, actualAttachments, isEncryptedCollection); if ((_tasks.Count == 0) || ((_tasks.FirstOrDefault(x => x.Name == TaskNames.AddAttachment) == null) && (_tasks.FirstOrDefault(x => x.Name == TaskNames.Discover) == null))) { // Only raise the discovery completed event if there are no more adds/discovers in the queue. action.DiscoveryCompleted(); } } }, TaskNames.Discover)); }
private void Execute(IEnumerable<IProtectAttachment> attachments) { var discoveryList = new List<IProtectAttachment>(); foreach (var attachment in attachments) { if (attachment.IsCollection || attachment.IsDiscoverable) { discoveryList.Add(attachment); } if (!FileTypeHelper.IsSupported(attachment.FileType)) { RaiseEvent(StatusUpdate, new ActionEventArgs(attachment, PropertyNames.UnsupportedFileFormat)); } } if (discoveryList.Count > 0) { var action = new DiscoveryAction(_marshaller, StatusUpdate, discoveryList); action.DiscoveryCompleted(); } }