Beispiel #1
0
        public static TemplateLink CreateInstance(XmlTemplateLink xmlTemplateLink)
        {
            if (xmlTemplateLink == null)
            {
                return(null);
            }

            TemplateLink templateLink = new TemplateLink();

            templateLink.Name        = xmlTemplateLink.Name;
            templateLink.Description = xmlTemplateLink.Description;

            templateLink.To                  = xmlTemplateLink.To.EmptyIfNull().Trim();
            templateLink.With                = xmlTemplateLink.With.EmptyIfNull().Trim();
            templateLink.Positioning         = xmlTemplateLink.Position;
            templateLink.MinOccurencesMethod = xmlTemplateLink.MinOccurences;

            if (string.IsNullOrEmpty(templateLink.To))
            {
                throw new EtkException("Attribut 'To' cannot be null or empty", false);
            }

            return(templateLink);
        }
        /// <summary>Analyze a cell of the template part</summary>
        private IDefinitionPart AnalyzeCell(ExcelTemplateDefinitionPart templateDefinitionPart, ExcelInterop.Range cell)
        {
            IDefinitionPart part = null;

            if (cell.Value2 != null)
            {
                string value = cell.Value2.ToString();
                if (!string.IsNullOrEmpty(value))
                {
                    string trimmedValue = value.Trim();
                    if (trimmedValue.StartsWith(LINKED_TEMPLATE_PREFIX))
                    {
                        try
                        {
                            XmlTemplateLink xmlTemplateLink = trimmedValue.Deserialize <XmlTemplateLink>();
                            TemplateLink    templateLink    = TemplateLink.CreateInstance(xmlTemplateLink);

                            ExcelTemplateDefinition  templateDefinition       = (ETKExcel.TemplateManager as ExcelTemplateManager).GetTemplateDefinitionFromLink(templateDefinitionPart, templateLink);
                            LinkedTemplateDefinition linkedTemplateDefinition = new LinkedTemplateDefinition(templateDefinitionPart.Parent, templateDefinition, templateLink);
                            templateDefinitionPart.AddLinkedTemplate(linkedTemplateDefinition);
                            part = linkedTemplateDefinition;
                        }
                        catch (Exception ex)
                        {
                            string message = $"Cannot create the linked template dataAccessor '{trimmedValue}'. {ex.Message}";
                            throw new EtkException(message, false);
                        }
                    }
                    else
                    {
                        if (trimmedValue.StartsWith(ExcelBindingFilterDefinition.Filter_PREFIX))
                        {
                            ExcelBindingFilterDefinition filterdefinition = ExcelBindingFilterDefinition.CreateInstance(templateDefinitionPart, trimmedValue);
                            templateDefinitionPart.AddFilterDefinition(filterdefinition);
                            part = filterdefinition;
                        }
                        else if (trimmedValue.StartsWith(ExcelBindingSearchDefinition.Search_PREFIX))
                        {
                            ExcelBindingSearchDefinition searchdefinition = ExcelBindingSearchDefinition.CreateInstance(trimmedValue);
                            templateDefinitionPart.AddSearchDefinition(searchdefinition);
                            part = searchdefinition;
                        }
                        else
                        {
                            try
                            {
                                IBindingDefinition bindingDefinition = CreateBindingDefinition(templateDefinitionPart, value, trimmedValue);
                                templateDefinitionPart.AddBindingDefinition(bindingDefinition);
                                part = bindingDefinition;
                            }
                            catch (Exception ex)
                            {
                                string message = $"Cannot create the binding definition for '{trimmedValue}'. {ex.Message}";
                                throw new EtkException(message, false);
                            }
                        }
                    }
                }
            }
            return(part);
        }