private ExcelTemplate RetreiveTemplate(string name, byte[] body)
        {
#warning Order and for each
            Entity entity = null;
            object entityID, attributeID, formatID;

            Teleform.Reporting.Attribute attribute = null;

            var placeholders = GetExcelPlaceHolders(body);

            if (placeholders.Count == 0)
            {
                throw new Exception("Указанный файл не содержит шаблон.");
            }

            var fields    = new List <TemplateField>();
            var creatorID = new Teleform.Reporting.UniqueIDCreator();

            creatorID.Split(placeholders.First().ID, out entityID, out attributeID, out formatID);

            entity = Global.Schema.Entities.FirstOrDefault(o => o.ID.ToString() == entityID.ToString());

            foreach (var holder in placeholders)
            {
                creatorID.Split(holder.ID, out entityID, out attributeID, out formatID);

                attribute = entity.Attributes.FirstOrDefault(o => o.ID.ToString() == attributeID.ToString());

                if (attribute == null)
                {
                    throw new InvalidOperationException(
                              string.Format("Сущность '{0}' не имеет атрибут с идентификатором {1}.",
                                            entity.Name, attributeID));
                }

                var field = new TemplateField(attribute);

                field.Format = attribute.Type.GetAdmissableFormats().FirstOrDefault(o => o.ID.ToString() == formatID.ToString());

                if (field.Format == null)
                {
                    throw new InvalidOperationException(
                              string.Format("Тип '{0}' атрибута {1} не имеет формат с идентификатором {2}.",
                                            attribute.Type.Name, attribute.Name, formatID));
                }

                field.Name = holder.Alias;

                fields.Add(field);
            }

#warning sheetName
            var template = new Teleform.Reporting.MicrosoftOffice.ExcelTemplate(name, entity, "ExcelBased", body, fields, "Лист1");
            return(template);
        }
Ejemplo n.º 2
0
 public Property(Attribute attribute, object value)
     : this(attribute)
 {
     Value = value;
 }