Beispiel #1
0
        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
                           });
            }
        }
Beispiel #2
0
        private void ExecuteTasks(IEnumerable<IWorkshareTask> tasks)
        {
            using (var applicationController = new ApplicationControllerWrapper())
            {
                foreach (IWorkshareTask task in tasks)
                {
                    try
                    {
                        _marshaller.WaitOne();

                        if (IsCancellationPending)
                            return;

                        var itemTask = task as IWorkshareItemTask;
                        if (itemTask != null)
                        {
                            itemTask.ApplicationController = applicationController;
                            itemTask.EncryptionManager = _marshaller.AttachmentEncryption;

                            if (itemTask.Attachment != null && itemTask.Attachment.LastError != null)
                                continue;
                        }

						

						if ((task is TaskZip || task is TaskSendLink) && (_encounteredException))
                            continue;

                        RaiseEvent(StatusUpdate, new ActionEventArgs(task, PropertyNames.Progress));

                        task.Execute(_marshaller.CancellationToken);

                        if ((itemTask != null) && (task is TaskReencrypt) && itemTask.Attachment.HasPassword)
                            _marshaller.AttachmentEncryption.UpdatePasswordCache(itemTask.Attachment);

						if ((itemTask != null) && (task is TaskZip) && itemTask.Attachment.HasPassword)
						{
							var zipTask = (TaskZip)task;
							_marshaller.AttachmentEncryption.SavePasswordToCache(zipTask.Attachment, zipTask.ZipOpenPassword);
						}
                        if ((itemTask != null) && (task is TaskPdf) && itemTask.Attachment.HasPassword)
                        {
                            var pdfTask = (TaskPdf)task ;
                            _marshaller.AttachmentEncryption.SavePasswordToCache(itemTask.Attachment, pdfTask.PdfOpenPassword);
                        }

                        var link = task as TaskSendLink;
                        if (link != null)
                        {
                            RaiseEvent(StatusUpdate,
                                       new ActionEventArgs(PropertyNames.PlatformFolderCreated)
                                       {
                                           PlatformFolderId =
                                               link.FolderId
                                       });
                        }
                    }
                    catch (Exception e)
                    {
                        _encounteredException = true;

                        IProtectAttachment attachment = null;
                        var itemTask = task as IWorkshareItemTask;
                        if (itemTask != null)
                        {
                            attachment = itemTask.Attachment;
                            attachment.LastError = e;
                            attachment.Status = PropertyNames.Exception;
                        }

                        Logger.LogError(e);
                        RaiseEvent(StatusUpdate,
                                   new ActionEventArgs(PropertyNames.Exception) { Exception = e, Attachment = attachment });
                    }
                }
            }
        }