예제 #1
0
        protected internal virtual bool LocalizeDataObjectElements(IList <ValuedDataObject> dataObjects, JToken infoNode)
        {
            bool                localizationValuesChanged = false;
            ICommandContext     commandContext            = Context.CommandContext;
            IDynamicBpmnService dynamicBpmnService        = commandContext.ProcessEngineConfiguration.DynamicBpmnService;

            foreach (ValuedDataObject dataObject in dataObjects)
            {
                dataObject.ExtensionElements.TryGetValue("localization", out IList <ExtensionElement> localizationElements);
                if (localizationElements != null)
                {
                    foreach (ExtensionElement localizationElement in localizationElements)
                    {
                        if (BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX.Equals(localizationElement.NamespacePrefix))
                        {
                            string locale        = localizationElement.GetAttributeValue(null, "locale");
                            string name          = localizationElement.GetAttributeValue(null, "name");
                            string documentation = null;

                            localizationElement.ChildElements.TryGetValue("documentation", out IList <ExtensionElement> documentationElements);
                            if (documentationElements != null)
                            {
                                foreach (ExtensionElement documentationElement in documentationElements)
                                {
                                    documentation = documentationElement.ElementText.Trim();
                                    break;
                                }
                            }

                            if (name is object && IsEqualToCurrentLocalizationValue(locale, dataObject.Id, DynamicBpmnConstants.LOCALIZATION_NAME, name, infoNode) == false)
                            {
                                dynamicBpmnService.ChangeLocalizationName(locale, dataObject.Id, name, infoNode);
                                localizationValuesChanged = true;
                            }

                            if (documentation is object && IsEqualToCurrentLocalizationValue(locale, dataObject.Id, DynamicBpmnConstants.LOCALIZATION_DESCRIPTION, documentation, infoNode) == false)
                            {
                                dynamicBpmnService.ChangeLocalizationDescription(locale, dataObject.Id, documentation, infoNode);
                                localizationValuesChanged = true;
                            }
                        }
                    }
                }
            }

            return(localizationValuesChanged);
        }
예제 #2
0
        protected internal virtual bool LocalizeFlowElements(ICollection <FlowElement> flowElements, JToken infoNode)
        {
            bool localizationValuesChanged = false;

            if (flowElements == null)
            {
                return(localizationValuesChanged);
            }

            ICommandContext     commandContext     = Context.CommandContext;
            IDynamicBpmnService dynamicBpmnService = commandContext.ProcessEngineConfiguration.DynamicBpmnService;

            foreach (FlowElement flowElement in flowElements)
            {
                if (flowElement is UserTask || flowElement is SubProcess)
                {
                    flowElement.ExtensionElements.TryGetValue("localization", out IList <ExtensionElement> localizationElements);
                    if (localizationElements != null)
                    {
                        foreach (ExtensionElement localizationElement in localizationElements)
                        {
                            if (BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX.Equals(localizationElement.NamespacePrefix))
                            {
                                string locale        = localizationElement.GetAttributeValue(null, "locale");
                                string name          = localizationElement.GetAttributeValue(null, "name");
                                string documentation = null;
                                localizationElement.ChildElements.TryGetValue("documentation", out IList <ExtensionElement> documentationElements);
                                if (documentationElements != null)
                                {
                                    foreach (ExtensionElement documentationElement in documentationElements)
                                    {
                                        documentation = documentationElement.ElementText.Trim();
                                        break;
                                    }
                                }

                                string flowElementId = flowElement.Id;
                                if (IsEqualToCurrentLocalizationValue(locale, flowElementId, "name", name, infoNode) == false)
                                {
                                    dynamicBpmnService.ChangeLocalizationName(locale, flowElementId, name, infoNode);
                                    localizationValuesChanged = true;
                                }

                                if (documentation is object && IsEqualToCurrentLocalizationValue(locale, flowElementId, "description", documentation, infoNode) == false)
                                {
                                    dynamicBpmnService.ChangeLocalizationDescription(locale, flowElementId, documentation, infoNode);
                                    localizationValuesChanged = true;
                                }

                                break;
                            }
                        }
                    }

                    if (flowElement is SubProcess subprocess)
                    {
                        bool isFlowElementLocalizationChanged = LocalizeFlowElements(subprocess.FlowElements, infoNode);
                        bool isDataObjectLocalizationChanged  = LocalizeDataObjectElements(subprocess.DataObjects, infoNode);
                        if (isFlowElementLocalizationChanged || isDataObjectLocalizationChanged)
                        {
                            localizationValuesChanged = true;
                        }
                    }
                }
            }

            return(localizationValuesChanged);
        }
예제 #3
0
        protected internal virtual void CreateLocalizationValues(string processDefinitionId, Process process)
        {
            if (process == null)
            {
                return;
            }

            ICommandContext     commandContext     = Context.CommandContext;
            IDynamicBpmnService dynamicBpmnService = commandContext.ProcessEngineConfiguration.DynamicBpmnService;
            JToken infoNode = dynamicBpmnService.GetProcessDefinitionInfo(processDefinitionId);

            bool localizationValuesChanged = false;

            process.ExtensionElements.TryGetValue("localization", out IList <ExtensionElement> localizationElements);
            if (localizationElements != null)
            {
                foreach (ExtensionElement localizationElement in localizationElements)
                {
                    if (BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX.Equals(localizationElement.NamespacePrefix))
                    {
                        string locale        = localizationElement.GetAttributeValue(null, "locale");
                        string name          = localizationElement.GetAttributeValue(null, "name");
                        string documentation = null;
                        localizationElement.ChildElements.TryGetValue("documentation", out IList <ExtensionElement> documentationElements);
                        if (documentationElements != null)
                        {
                            foreach (ExtensionElement documentationElement in documentationElements)
                            {
                                documentation = documentationElement.ElementText.Trim();
                                break;
                            }
                        }

                        string processId = process.Id;
                        if (!IsEqualToCurrentLocalizationValue(locale, processId, "name", name, infoNode))
                        {
                            dynamicBpmnService.ChangeLocalizationName(locale, processId, name, infoNode);
                            localizationValuesChanged = true;
                        }

                        if (documentation is object && !IsEqualToCurrentLocalizationValue(locale, processId, "description", documentation, infoNode))
                        {
                            dynamicBpmnService.ChangeLocalizationDescription(locale, processId, documentation, infoNode);
                            localizationValuesChanged = true;
                        }

                        break;
                    }
                }
            }

            bool isFlowElementLocalizationChanged = LocalizeFlowElements(process.FlowElements, infoNode);
            bool isDataObjectLocalizationChanged  = LocalizeDataObjectElements(process.DataObjects, infoNode);

            if (isFlowElementLocalizationChanged || isDataObjectLocalizationChanged)
            {
                localizationValuesChanged = true;
            }

            if (localizationValuesChanged)
            {
                dynamicBpmnService.SaveProcessDefinitionInfo(processDefinitionId, infoNode);
            }
        }