Пример #1
0
        public virtual IAttachment Execute(ICommandContext commandContext)
        {
            if (!(processInstanceId is null))
            {
                VerifyExecutionParameters(commandContext);
            }

            IAttachmentEntity attachment = commandContext.AttachmentEntityManager.Create();

            attachment.Name = attachmentName;
            attachment.ProcessInstanceId = processInstanceId;
            attachment.TaskId            = taskId;
            attachment.Description       = attachmentDescription;
            attachment.Type   = attachmentType;
            attachment.Url    = url;
            attachment.UserId = Authentication.AuthenticatedUser.Id;
            attachment.Time   = commandContext.ProcessEngineConfiguration.Clock.CurrentTime;

            commandContext.AttachmentEntityManager.Insert(attachment, false);

            if (content != null)
            {
                byte[]           bytes     = IoUtil.ReadInputStream(content, attachmentName);
                IByteArrayEntity byteArray = commandContext.ByteArrayEntityManager.Create();
                byteArray.Bytes = bytes;
                commandContext.ByteArrayEntityManager.Insert(byteArray);
                attachment.ContentId = byteArray.Id;
                attachment.Content   = byteArray;
            }

            commandContext.HistoryManager.CreateAttachmentComment(taskId, processInstanceId, attachmentName, true);

            if (commandContext.ProcessEngineConfiguration.EventDispatcher.Enabled)
            {
                // Forced to fetch the process-instance to associate the right
                // process definition
                string processDefinitionId = null;
                if (!(attachment.ProcessInstanceId is null))
                {
                    IExecutionEntity process = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(processInstanceId);
                    if (process != null)
                    {
                        processDefinitionId = process.ProcessDefinitionId;
                    }
                }

                commandContext.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
                commandContext.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, attachment, processInstanceId, processInstanceId, processDefinitionId));
            }

            return(attachment);
        }
        public virtual Stream  Execute(ICommandContext commandContext)
        {
            IAttachmentEntity attachment = commandContext.AttachmentEntityManager.FindById <IAttachmentEntity>(new KeyValuePair <string, object>("id", attachmentId));

            string contentId = attachment.ContentId;

            if (contentId is null)
            {
                return(null);
            }

            IByteArrayEntity byteArray = commandContext.ByteArrayEntityManager.FindById <IByteArrayEntity>(new KeyValuePair <string, object>("id", contentId));

            byte[] bytes = byteArray.Bytes;

            return(new System.IO.MemoryStream(bytes));
        }
Пример #3
0
 public virtual void Delete()
 {
     if (!deleted && !(id is null))
     {
         if (entity != null)
         {
             // if the entity has been loaded already,
             // we might as well use the safer optimistic locking delete.
             Context.CommandContext.ByteArrayEntityManager.Delete(entity);
         }
         else
         {
             Context.CommandContext.ByteArrayEntityManager.DeleteByteArrayById(id);
         }
         entity  = null;
         id      = null;
         deleted = true;
     }
 }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        public void EnsureInitialized()
        {
            var ctx = Context.CommandContext;

            if (id != null && entity == null)
            {
                if (ctx == null)
                {
                    if (!(ProcessEngineServiceProvider.Resolve <IProcessEngine>().ProcessEngineConfiguration is ProcessEngineConfigurationImpl pi))
                    {
                        return;
                    }

                    ctx = pi.CommandContextFactory.CreateCommandContext(new ByteArrayRefCmd(id));
                    Context.CommandContext = ctx;
                }

                entity = ctx.ByteArrayEntityManager.FindById <IByteArrayEntity>(new KeyValuePair <string, object>("id", id));
                name   = entity.Name;
            }
        }