コード例 #1
0
        protected internal virtual void AddDefinitionInfoToCache(IProcessDefinitionEntity processDefinition, ProcessEngineConfigurationImpl processEngineConfiguration, ICommandContext commandContext)
        {
            if (!processEngineConfiguration.EnableProcessDefinitionInfoCache)
            {
                return;
            }

            DeploymentManager deploymentManager = processEngineConfiguration.DeploymentManager;
            IProcessDefinitionInfoEntityManager definitionInfoEntityManager = commandContext.ProcessDefinitionInfoEntityManager;
            ObjectMapper objectMapper = commandContext.ProcessEngineConfiguration.ObjectMapper;
            IProcessDefinitionInfoEntity definitionInfoEntity = definitionInfoEntityManager.FindProcessDefinitionInfoByProcessDefinitionId(processDefinition.Id);

            JToken infoNode = null;

            if (definitionInfoEntity is object && definitionInfoEntity.InfoJsonId is object)
            {
                byte[] infoBytes = definitionInfoEntityManager.FindInfoJsonById(definitionInfoEntity.InfoJsonId);
                if (infoBytes != null)
                {
                    try
                    {
                        infoNode = objectMapper.ReadTree(infoBytes);
                    }
                    catch (Exception)
                    {
                        throw new ActivitiException("Error deserializing json info for process definition " + processDefinition.Id);
                    }
                }
            }

            ProcessDefinitionInfoCacheObject definitionCacheObject = new ProcessDefinitionInfoCacheObject();

            if (definitionInfoEntity == null)
            {
                definitionCacheObject.Revision = 0;
            }
            else
            {
                definitionCacheObject.Id       = definitionInfoEntity.Id;
                definitionCacheObject.Revision = definitionInfoEntity.Revision;
            }

            if (infoNode == null)
            {
                infoNode = objectMapper.CreateObjectNode();
            }
            definitionCacheObject.InfoNode = infoNode;

            deploymentManager.ProcessDefinitionInfoCache.Add(processDefinition.Id, definitionCacheObject);
        }
コード例 #2
0
        protected internal virtual ProcessDefinitionInfoCacheObject RetrieveProcessDefinitionInfoCacheObject(string processDefinitionId, ICommandContext commandContext)
        {
            IProcessDefinitionInfoEntityManager infoEntityManager = commandContext.ProcessDefinitionInfoEntityManager;
            ObjectMapper objectMapper = commandContext.ProcessEngineConfiguration.ObjectMapper;

            ProcessDefinitionInfoCacheObject cacheObject = cache.GetOrCreate(processDefinitionId, (key) => new ProcessDefinitionInfoCacheObject()
            {
                Revision = 0,
                InfoNode = objectMapper.CreateObjectNode()
            });

            IProcessDefinitionInfoEntity infoEntity = infoEntityManager.FindProcessDefinitionInfoByProcessDefinitionId(processDefinitionId);

            if (infoEntity != null && infoEntity.Revision != cacheObject.Revision)
            {
                cacheObject.Revision = infoEntity.Revision;
                if (infoEntity.InfoJsonId is object)
                {
                    byte[] infoBytes = infoEntityManager.FindInfoJsonById(infoEntity.InfoJsonId);
                    try
                    {
                        JToken infoNode = objectMapper.ReadTree(infoBytes);
                        cacheObject.InfoNode = infoNode;
                    }
                    catch (Exception e)
                    {
                        throw new ActivitiException("Error reading json info node for process definition " + processDefinitionId, e);
                    }
                }
            }
            else if (infoEntity == null)
            {
                cacheObject.Revision = 0;
                cacheObject.InfoNode = objectMapper.CreateObjectNode();
            }

            return(cacheObject);
        }
コード例 #3
0
        public virtual object  Execute(ICommandContext commandContext)
        {
            if (string.IsNullOrWhiteSpace(processDefinitionId))
            {
                throw new ActivitiIllegalArgumentException("process definition id is null");
            }

            if (infoNode == null)
            {
                throw new ActivitiIllegalArgumentException("process definition info node is null");
            }

            IProcessDefinitionInfoEntityManager definitionInfoEntityManager = commandContext.ProcessDefinitionInfoEntityManager;
            IProcessDefinitionInfoEntity        definitionInfoEntity        = definitionInfoEntityManager.FindProcessDefinitionInfoByProcessDefinitionId(processDefinitionId);

            if (definitionInfoEntity == null)
            {
                definitionInfoEntity = definitionInfoEntityManager.Create();
                definitionInfoEntity.ProcessDefinitionId = processDefinitionId;
                commandContext.ProcessDefinitionInfoEntityManager.InsertProcessDefinitionInfo(definitionInfoEntity);
            }

            if (infoNode != null)
            {
                try
                {
                    ObjectMapper writer = commandContext.ProcessEngineConfiguration.ObjectMapper;
                    commandContext.ProcessDefinitionInfoEntityManager.UpdateInfoJson(definitionInfoEntity.Id, writer.WriteValueAsBytes(infoNode));
                }
                catch (Exception)
                {
                    throw new ActivitiException("Unable to serialize info node " + infoNode);
                }
            }

            return(null);
        }