Exemplo n.º 1
0
        public FakeTemplate WithBaseIDs(ID[] baseIDs)
        {
            if (baseIDs == null || baseIDs.Length == 0)
            {
                return(this);
            }

            StringBuilder ids = new StringBuilder();

            for (int i = 0; i < baseIDs.Length; i++)
            {
                if (i > 0)
                {
                    ids.Append("|");
                }

                ids.Append(baseIDs[i].ToString());
                string name     = "Template_" + baseIDs[i];
                var    template = new FakeTemplate(name, baseIDs[i], this.Database);
                templateEngine.GetTemplate(baseIDs[i]).Returns(template);
                templateEngine.GetTemplate(name).Returns(template);
            }

            templateBuilder.SetBaseIDs(ids.ToString());
            return(this);
        }
        public override TemplateCollection GetTemplates(CallContext context)
        {
            var owner = new TemplateCollection();

            var database      = GetDatabase(context);
            var templatesRoot = database.GetItems(ItemIDs.TemplateRoot.ToString());

            var templates = new List <Template>(templatesRoot.Count());

            foreach (var syncItem in templatesRoot)
            {
                if (ID.IsNullOrEmpty(ID.Parse(syncItem.ID)) || syncItem.ID.Equals(TemplateIDs.TemplateFolder.ToString()))
                {
                    continue;
                }

                var templateBuilder = new Template.Builder(syncItem.Name, ID.Parse(syncItem.ID), owner);

                templateBuilder.SetFullName(syncItem.ItemPath);

                var dataSection = templateBuilder.AddSection("Data", ID.NewID);

                foreach (var syncField in syncItem.SharedFields)
                {
                    if (string.IsNullOrEmpty(syncField.FieldID) || string.IsNullOrEmpty(syncField.FieldName))
                    {
                        continue;
                    }

                    if (syncField.FieldID.Equals(FieldIDs.BaseTemplate.ToString()))
                    {
                        templateBuilder.SetBaseIDs(syncField.FieldValue);
                    }
                    else
                    {
                        dataSection.AddField(syncField.FieldName, ID.Parse(syncField.FieldID));
                    }
                }

                var version = syncItem.GetLatestVersions().FirstOrDefault();

                foreach (var syncField in version.Fields)
                {
                    if (string.IsNullOrEmpty(syncField.FieldID) || string.IsNullOrEmpty(syncField.FieldName))
                    {
                        continue;
                    }

                    dataSection.AddField(syncField.FieldName, ID.Parse(syncField.FieldID));
                }

                templates.Add(templateBuilder.Template);
            }

            owner.Reset(templates.ToArray());

            return(owner);
        }
        public Template.Builder BuildTemplate(TemplateCollection owner)
        {
            var builder = new Template.Builder(TemplateName, Id, owner);

            builder.SetFullName(TemplateName);
            builder.SetBaseIDs(BaseIdsValue);

            return(builder);
        }
Exemplo n.º 4
0
        public static Template CreateTemplate(ID templateId, ID baseTemplateId, TemplateCollection templateCollection)
        {
            var builder = new Template.Builder($"test-{templateId}", templateId, templateCollection);

            if (baseTemplateId != (ID)null)
            {
                builder.SetBaseIDs(baseTemplateId.ToString());
            }

            var template = builder.Template;

            templateCollection.Add(template);
            return(template);
        }
Exemplo n.º 5
0
        protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates)
        {
            var builder = new Template.Builder(ft.Name, ft.ID, templates);
            var section = builder.AddSection("Data", ID.NewID);

            foreach (var field in ft.Fields)
            {
                var newField = section.AddField(field.Name, field.ID);
                newField.SetShared(field.Shared);
                newField.SetType(field.Type);
            }

            builder.SetBaseIDs(string.Join("|", ft.BaseIDs ?? new ID[] { } as IEnumerable <ID>));

            return(builder.Template);
        }
 public void AddTemplate(Item item, IEnumerable<Item> baseTeamplates)
 {
     Template.Builder builder = new Template.Builder(item.Name, item.ID, new TemplateCollection());
     StringBuilder strnBuilder = new StringBuilder();
     foreach (Item baseTemplate in baseTeamplates)
     {
         strnBuilder.Append(string.Format("{0}|", baseTemplate.ID));
     }
     if (baseTeamplates.Any())
     {
         string idsString = strnBuilder.ToString().TrimEnd('|');
         builder.SetBaseIDs(idsString);
     }
     _templateCollection.Add(builder.Template);
     _idCollection.Add(item.ID);
 }
Exemplo n.º 7
0
        public void AddTemplate(Item item, IEnumerable <Item> baseTeamplates)
        {
            Template.Builder builder     = new Template.Builder(item.Name, item.ID, new TemplateCollection());
            StringBuilder    strnBuilder = new StringBuilder();

            foreach (Item baseTemplate in baseTeamplates)
            {
                strnBuilder.Append(string.Format("{0}|", baseTemplate.ID));
            }
            if (baseTeamplates.Any())
            {
                string idsString = strnBuilder.ToString().TrimEnd('|');
                builder.SetBaseIDs(idsString);
            }
            _templateCollection.Add(builder.Template);
            _idCollection.Add(item.ID);
        }
Exemplo n.º 8
0
        protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates)
        {
            var builder = new Template.Builder(ft.Name, ft.ID, templates);
            var section = builder.AddSection("Data", ID.NewID);

            foreach (var field in ft.Fields)
            {
                if (ft.ID != TemplateIDs.StandardTemplate && field.IsStandard())
                {
                    continue;
                }

                var newField = section.AddField(field.Name, field.ID);
                newField.SetShared(field.Shared);
                newField.SetType(field.Type);
            }

            builder.SetBaseIDs(ft.BaseIDs.Any() ? string.Join("|", ft.BaseIDs as IEnumerable <ID>) : TemplateIDs.StandardTemplate.ToString());

            return(builder.Template);
        }
Exemplo n.º 9
0
        public void IsDerived_ItemInheritsBaseTemplate_ReturnsTrue()
        {
            // setup
            #region Setup

            var itemTemplateId = ID.NewID;
            var baseTemplateId = ID.NewID;
            var itemId         = ID.NewID;

            var item = Substitute.For <Item>(
                itemId,
                new ItemData(
                    new ItemDefinition(itemId, "Item Of Base Template", itemTemplateId, ID.Null),
                    this.Language,
                    Version.Parse(1),
                    new FieldList()
                    ),
                this.Database);

            var baseTemplate     = new Template.Builder("Base Template", baseTemplateId, this.TemplateEngine).Template;
            var itemTemplateItem = new Template.Builder("Item Template", itemTemplateId, this.TemplateEngine);
            itemTemplateItem.SetBaseIDs(baseTemplateId.ToString());
            var itemTemplate = itemTemplateItem.Template;

            this.TemplateEngine.GetTemplate(itemTemplateId).Returns(itemTemplate);
            this.TemplateEngine.GetTemplate(baseTemplateId).Returns(baseTemplate);

            this.TemplateManager.GetTemplate(itemTemplateId, this.Database).Returns(itemTemplate);
            this.TemplateManager.GetTemplate(baseTemplateId, this.Database).Returns(baseTemplate);
            this.TemplateManager.GetTemplate(item).Returns(itemTemplate);

            #endregion

            // act
            var isDerived = this.ItemExtensions.IsDerived(item, baseTemplateId);

            // assert
            isDerived.Should().BeTrue();
        }
Exemplo n.º 10
0
        protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates)
        {
            var builder = new Template.Builder(ft.Name, ft.ID, templates);

            var sectionName = "Data";
            var sectionId   = ID.NewID;

            var sectionItem = ft.Children.FirstOrDefault(i => i.TemplateID == TemplateIDs.TemplateSection);

            if (sectionItem != null)
            {
                sectionName = sectionItem.Name;
                sectionId   = sectionItem.ID;
            }

            var section = builder.AddSection(sectionName, sectionId);

            foreach (var field in ft.Fields)
            {
                if (ft.ID != TemplateIDs.StandardTemplate && field.IsStandard())
                {
                    continue;
                }

                var newField = section.AddField(field.Name, field.ID);
                newField.SetShared(field.Shared);
                newField.SetType(field.Type);
                newField.SetSource(field.Source);
            }

            if (ft.ID != TemplateIDs.StandardTemplate)
            {
                builder.SetBaseIDs(ft.BaseIDs.Any() ? string.Join("|", ft.BaseIDs as IEnumerable <ID>) : TemplateIDs.StandardTemplate.ToString());
            }

            return(builder.Template);
        }
        public override TemplateCollection GetTemplates(CallContext context)
        {
            var owner = new TemplateCollection();

            var database = GetDatabase(context);
            var templatesRoot = database.GetItems(ItemIDs.TemplateRoot.ToString());

            var templates = new List<Template>(templatesRoot.Count());

            foreach (var syncItem in templatesRoot)
            {
                if (ID.IsNullOrEmpty(ID.Parse(syncItem.ID)) || syncItem.ID.Equals(TemplateIDs.TemplateFolder.ToString()))
                {
                    continue;
                }

                var templateBuilder = new Template.Builder(syncItem.Name, ID.Parse(syncItem.ID), owner);

                templateBuilder.SetFullName(syncItem.ItemPath);

                var dataSection = templateBuilder.AddSection("Data", ID.NewID);

                foreach (var syncField in syncItem.SharedFields)
                {
                    if (string.IsNullOrEmpty(syncField.FieldID) || string.IsNullOrEmpty(syncField.FieldName))
                    {
                        continue;
                    }

                    if (syncField.FieldID.Equals(FieldIDs.BaseTemplate.ToString()))
                    {
                        templateBuilder.SetBaseIDs(syncField.FieldValue);
                    }
                    else
                    {
                        dataSection.AddField(syncField.FieldName, ID.Parse(syncField.FieldID));
                    }
                }

                var version = syncItem.GetLatestVersions().FirstOrDefault();

                foreach (var syncField in version.Fields)
                {
                    if (string.IsNullOrEmpty(syncField.FieldID) || string.IsNullOrEmpty(syncField.FieldName))
                    {
                        continue;
                    }

                    dataSection.AddField(syncField.FieldName, ID.Parse(syncField.FieldID));
                }

                templates.Add(templateBuilder.Template);
            }

            owner.Reset(templates.ToArray());

            return owner;
        }
Exemplo n.º 12
0
    protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates)
    {
      var builder = new Template.Builder(ft.Name, ft.ID, templates);

      var sectionName = "Data";
      var sectionId = ID.NewID;

      var sectionItem = ft.Children.FirstOrDefault(i => i.TemplateID == TemplateIDs.TemplateSection);
      if (sectionItem != null)
      {
        sectionName = sectionItem.Name;
        sectionId = sectionItem.ID;
      }

      var section = builder.AddSection(sectionName, sectionId);

      foreach (var field in ft.Fields)
      {
        if (ft.ID != TemplateIDs.StandardTemplate && field.IsStandard())
        {
          continue;
        }

        var newField = section.AddField(field.Name, field.ID);
        newField.SetShared(field.Shared);
        newField.SetType(field.Type);
        newField.SetSource(field.Source);
      }

      if (ft.ID != TemplateIDs.StandardTemplate)
      {
        builder.SetBaseIDs(ft.BaseIDs.Any() ? string.Join("|", ft.BaseIDs as IEnumerable<ID>) : TemplateIDs.StandardTemplate.ToString());
      }

      return builder.Template;
    }
Exemplo n.º 13
0
    protected virtual Template BuildTemplate(DbTemplate ft, TemplateCollection templates)
    {
      var builder = new Template.Builder(ft.Name, ft.ID, templates);
      var section = builder.AddSection("Data", ID.NewID);

      foreach (var field in ft.Fields)
      {
        if (ft.ID != TemplateIDs.StandardTemplate && field.IsStandard())
        {
          continue;
        }

        var newField = section.AddField(field.Name, field.ID);
        newField.SetShared(field.Shared);
        newField.SetType(field.Type);
      }

      builder.SetBaseIDs(ft.BaseIDs.Any() ? string.Join("|", ft.BaseIDs as IEnumerable<ID>) : TemplateIDs.StandardTemplate.ToString());

      return builder.Template;
    }