public void Remove()
 {
     if (ActEntryTemplatesByCode.ContainsKey(_currentActEntryTemplate.Code))
     {
         ActEntryTemplatesByCode.Remove(_currentActEntryTemplate.Code);
     }
     _currentActEntryTemplate = null;
 }
        /// <summary>
        /// Start the definition of act entry template for a given act_code. Each act_code cooresponds to a
        /// type of event in the clarify system.
        /// </summary>
        /// <param name="code">The act_code of the activity entry you wish to include. </param>
        public IAfterActEntryCode ActEntry(int code)
        {
            addCurrentActEntryTemplate();

            _currentActEntryTemplate = new ActEntryTemplate {
                Code = code
            };

            return(this);
        }
        public void RenderTemplate(WorkflowObject workflowObject, IDictionary <int, ActEntryTemplate> actEntryTemplates)
        {
            ActEntryTemplatesByCode = actEntryTemplates;

            _currentActEntryTemplate = null;

            DefineTemplate(workflowObject);

            addCurrentActEntryTemplate();
        }
        /// <summary>
        /// Start the definition of act entry template for a given act_code. If a template for this act_code is already present it will replace it.
        /// Each act_code cooresponds to a type of event in the clarify system.
        /// </summary>
        /// <param name="code">The act_code of the activity entry you wish to include. </param>
        /// <param name="isVerbose">When this is true the history item will not be returned unless ShowAllActivities is true.</param>
        public IAfterActEntryCode ActEntry(int code)
        {
            addCurrentActEntryTemplate();

            _currentActEntryTemplate = new ActEntryTemplate(_historyOutputParser)
            {
                Code = code
            };

            return(this);
        }
        public ActEntryTemplate(ActEntryTemplate input)
        {
            Code               = input.Code;
            DisplayName        = input.DisplayName;
            ActivityDTOUpdater = input.ActivityDTOUpdater;
            ActivityDTOEditor  = input.ActivityDTOEditor;

            RelatedGenericRelationName = input.RelatedGenericRelationName;
            RelatedGenericAction       = input.RelatedGenericAction;
            RelatedGenericFields       = input.RelatedGenericFields;
            HTMLizer = input.HTMLizer;
        }
        private void addCurrentActEntryTemplate()
        {
            if (_currentActEntryTemplate == null)
            {
                return;
            }

            //replace existing template
            if (ActEntryTemplatesByCode.ContainsKey(_currentActEntryTemplate.Code))
            {
                ActEntryTemplatesByCode.Remove(_currentActEntryTemplate.Code);
            }

            ActEntryTemplatesByCode.Add(_currentActEntryTemplate.Code, _currentActEntryTemplate);

            _currentActEntryTemplate = null;
        }
        /// <summary>
        /// Edit the existing act entry template for the given act_code. If one does not already exist a new one is created.
        /// </summary>
        /// <param name="code">The act_code of the activity entry whose template you wish to edit.</param>
        public IAfterActEntryCode EditActEntry(int code)
        {
            addCurrentActEntryTemplate();

            //find existing template if it exists.
            if (ActEntryTemplatesByCode.ContainsKey(code))
            {
                _currentActEntryTemplate = ActEntryTemplatesByCode[code];
            }
            else
            {
                _currentActEntryTemplate = new ActEntryTemplate(_historyOutputParser)
                {
                    Code = code
                };
            }

            return(this);
        }
        private HistoryItem createActivityDTOFromMapper(ActEntry actEntry, IDictionary<ActEntryTemplate, ClarifyGeneric> templateRelatedGenerics)
        {
            var dto = defaultActivityDTOAssembler(actEntry);

            var template = new ActEntryTemplate(actEntry.Template);

            updateActivityDto(actEntry, dto, template, templateRelatedGenerics);

            if (isActivityDTOEditorPresent(template))
            {
                template.ActivityDTOEditor(dto);
            }

            template.HTMLizer(dto);

            return dto;
        }
 private static bool isActivityDTOUpdaterPresent(ActEntryTemplate template)
 {
     return template.ActivityDTOUpdater != null;
 }
        private void addCurrentActEntryTemplate()
        {
            if (_currentActEntryTemplate == null)
                return;

            //replace existing template
            if (ActEntryTemplatesByCode.ContainsKey(_currentActEntryTemplate.Code))
            {
                ActEntryTemplatesByCode.Remove(_currentActEntryTemplate.Code);
            }

            ActEntryTemplatesByCode.Add(_currentActEntryTemplate.Code, _currentActEntryTemplate);

            _currentActEntryTemplate = null;
        }
        public void RenderTemplate(WorkflowObject workflowObject, IDictionary<int, ActEntryTemplate> actEntryTemplates)
        {
            ActEntryTemplatesByCode = actEntryTemplates;

            _currentActEntryTemplate = null;

            DefineTemplate(workflowObject);

            addCurrentActEntryTemplate();
        }
 public void Remove()
 {
     if (ActEntryTemplatesByCode.ContainsKey(_currentActEntryTemplate.Code))
     {
         ActEntryTemplatesByCode.Remove(_currentActEntryTemplate.Code);
     }
     _currentActEntryTemplate = null;
 }
        /// <summary>
        /// Start the definition of act entry template for a given act_code. Each act_code cooresponds to a
        /// type of event in the clarify system.
        /// </summary>
        /// <param name="code">The act_code of the activity entry you wish to include. </param>
        public IAfterActEntryCode ActEntry(int code)
        {
            addCurrentActEntryTemplate();

            _currentActEntryTemplate = new ActEntryTemplate {Code = code};

            return this;
        }
        /// <summary>
        /// Start the definition of act entry template for a given act_code. If a template for this act_code is already present it will replace it. 
        /// Each act_code cooresponds to a type of event in the clarify system.
        /// </summary>
        /// <param name="code">The act_code of the activity entry you wish to include. </param>
        /// <param name="isVerbose">When this is true the history item will not be returned unless ShowAllActivities is true.</param>
        public IAfterActEntryCode ActEntry(int code)
        {
            addCurrentActEntryTemplate();

            _currentActEntryTemplate = new ActEntryTemplate(_historyOutputParser) {Code = code};

            return this;
        }
        /// <summary>
        /// Edit the existing act entry template for the given act_code. If one does not already exist a new one is created.
        /// </summary>
        /// <param name="code">The act_code of the activity entry whose template you wish to edit.</param>
        public IAfterActEntryCode EditActEntry(int code)
        {
            addCurrentActEntryTemplate();

            //find existing template if it exists.
            if (ActEntryTemplatesByCode.ContainsKey(code))
            {
                _currentActEntryTemplate = ActEntryTemplatesByCode[code];
            }
            else
            {
                _currentActEntryTemplate = new ActEntryTemplate(_historyOutputParser) { Code = code };
            }

            return this;
        }
        private ActEntryTemplate findTemplateByActCode(int code, IDictionary<int, ActEntryTemplate> templatesByCode)
        {
            if (templatesByCode.ContainsKey(code))
            {
                return templatesByCode[code];
            }

            _logger.LogDebug("No template found for act_code {0}. Using default act entry template.", code);

            //create a copy of the default template with the code and display name set correctly.
            var template = new ActEntryTemplate(templatesByCode[ActEntryTemplatePolicyConfiguration.DefaultActEntryTemplateMagicCode])
            {
                Code = code,
            };
            return template;
        }
        private bool updateActivityDto(ActEntry actEntry, HistoryItem dto, ActEntryTemplate template, IDictionary<ActEntryTemplate, ClarifyGeneric> templateRelatedGenerics)
        {
            if (!isActivityDTOUpdaterPresent(template)) return false;

            var relatedRow = actEntry.ActEntryRecord;
            var relatedGenericKey = actEntry.Template;

            if (templateRelatedGenerics.ContainsKey(relatedGenericKey))
            {
                var relatedRows = actEntry.ActEntryRecord.RelatedRows(templateRelatedGenerics[relatedGenericKey]);

                //when a row related to the act entry was retrieved give that row to the updater.
                relatedRow = relatedRows.Length > 0 ? relatedRows[0] : null;

                if (relatedRow == null)
                {
                    _logger.LogDebug("Activity updater for code {0} against object {1}-{2} did not work because no related row for relation {3} was found."
                            .ToFormat(template.Code, dto.Type, dto.Id, template.RelatedGenericRelationName));
                    return false;
                }
            }

            if (relatedRow != null)
            {
                template.ActivityDTOUpdater(relatedRow, dto, template);
                return true;
            }

            return false;
        }
        public ActEntryTemplate(ActEntryTemplate input)
        {
            Code = input.Code;
            DisplayName = input.DisplayName;
            ActivityDTOUpdater = input.ActivityDTOUpdater;
            ActivityDTOEditor = input.ActivityDTOEditor;

            RelatedGenericRelationName = input.RelatedGenericRelationName;
            RelatedGenericAction = input.RelatedGenericAction;
            RelatedGenericFields = input.RelatedGenericFields;
            HTMLizer = input.HTMLizer;
        }