/// <summary>
 /// Builds a list of references in actions
 /// </summary>
 /// <param name="referencedObjectId">Id of the object that is referenced and for which the references are built</param>
 /// <param name="actions">Actions to analyze</param>
 /// <returns>References for the object</returns>
 private IEnumerable <ObjectReference> BuildActionReferences(string referencedObjectId, List <ActionNode> actions)
 {
     return(actions.Where(a => a.ActionRelatedToObjectId == referencedObjectId || (a.ActionRelatedToAdditionalObjects != null && a.ActionRelatedToAdditionalObjects.Any(a => a.ObjectId == referencedObjectId))).Select(a => new ObjectReference {
         ObjectId = a.Id,
         ObjectName = _actionTranslator.TranslateActionType((ActionType)a.ActionType)
     }));
 }
Exemple #2
0
        /// <summary>
        /// Renders a dialog step
        /// </summary>
        /// <param name="data">Dialog Step Data</param>
        /// <param name="flexFieldObject">Flex Field to which the dialog belongs</param>
        /// <returns>Dialog Step Render Result</returns>
        public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportDialogData data, FlexFieldObject flexFieldObject)
        {
            ActionNode actionNode = data.Action;

            if (actionNode == null)
            {
                return(null);
            }

            ActionRendererDispatcher actionRenderer = GetActionRenderForNode(actionNode);

            ExportDialogDataChild nextStep = null;

            if (data.Children != null)
            {
                if (actionRenderer != null)
                {
                    nextStep = actionRenderer.GetNextStep(data.Children);
                }
                else
                {
                    nextStep = data.Children.FirstOrDefault();
                }
            }

            ExportTemplate template = await _defaultTemplateProvider.GetDefaultTemplateByType(_project.Id, TemplateType.TaleAction);

            if (!_renderers.ContainsKey(template.RenderingEngine))
            {
                throw new KeyNotFoundException(string.Format("Unknown rendering engine {0} for ActionNode", template.RenderingEngine.ToString()));
            }

            IActionStepRenderer stepRenderer = _renderers[template.RenderingEngine];

            stepRenderer.ResetStepRenderingValues();

            string oldContext = _errorCollection.CurrentErrorContext;

            _errorCollection.CurrentErrorContext = _localizer["ErrorContextAction", _actionTranslator.TranslateActionType((ActionType)actionNode.ActionType)];
            try
            {
                string actionContent = await BuildActionContent(actionRenderer, actionNode, data, flexFieldObject, stepRenderer);

                return(await stepRenderer.RenderDialogStep(template, data, nextStep, flexFieldObject, actionContent));
            }
            catch (Exception ex)
            {
                _errorCollection.AddException(ex);
                return(new ExportDialogStepRenderResult {
                    StepCode = "<<ERROR_RENDERING_ACTION>>"
                });
            }
            finally
            {
                _errorCollection.CurrentErrorContext = oldContext;
            }
        }