public static Dynamic.Publication BuildPublication(TCM.Repository tcmPublication)
 {
     Dynamic.Publication pub = new Dynamic.Publication();
     pub.Title = tcmPublication.Title;
     pub.Id = tcmPublication.Id.ToString();
     return pub;
 }
        public static List<Dynamic.Category> BuildCategories(TCM.Component component, BuildManager manager)
        {
            // note that there might be multiple fields based on the same category, so we need to combine them
            // for that purpose we use a dictionary
            Dictionary<string, Dynamic.Category> categories = new Dictionary<string, Dynamic.Category>();

            // first, add categories from the content (note that mm components have no content!)
            if (component.Content != null)
            {
                ItemFields tcmFields = new TCM.Fields.ItemFields(component.Content, component.Schema);
                addFromItemFields(tcmFields, categories, manager);
            }

            // next, add categories from the metadata
            if (component.Metadata != null)
            {
                ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(component.Metadata, component.MetadataSchema);
                addFromItemFields(tcmMetadataFields, categories, manager);
            }

            // finally, create a List from the Dictionary and return it
            List<Dynamic.Category> categoryList = new List<Dynamic.Category>();
            foreach (Dynamic.Category cat in categories.Values)
            {
                categoryList.Add(cat);
            }
            return categoryList;
        }
        public static Dynamic.Schema BuildSchema(TCM.Schema tcmSchema, BuildManager manager)
        {
			if (tcmSchema == null) {
				return null;
			}
			Dynamic.Schema s = new Dynamic.Schema();
			s.Title = tcmSchema.Title;
			s.Id = tcmSchema.Id.ToString();

            if (!manager.BuildProperties.OmitContextPublications)
                s.Publication = manager.BuildPublication(tcmSchema.ContextRepository);
            if (!manager.BuildProperties.OmitFolders)
                s.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmSchema.OrganizationalItem);

            if (!String.IsNullOrEmpty(tcmSchema.RootElementName))
            {
                s.RootElementName = tcmSchema.RootElementName;
            }
            // note that non-webschemas and multimedia schema's lack a root element. In order not
            // to break deserialization, setting it to undefined will do
            else
            {
                s.RootElementName = "undefined";
            }

			return s;
		}
 public static Dynamic.OrganizationalItem BuildOrganizationalItem(TCM.Folder tcmFolder)
 {
     Dynamic.OrganizationalItem oi = new Dynamic.OrganizationalItem();
     oi.Title = tcmFolder.Title;
     oi.Id = tcmFolder.Id.ToString();
     oi.PublicationId = tcmFolder.ContextRepository.Id.ToString();
     return oi;
 }
 public static Dynamic.OrganizationalItem BuildOrganizationalItem(TCM.Folder tcmFolder)
 {
    GeneralUtils.TimedLog("start BuildOrganizationalItem");
    Dynamic.OrganizationalItem oi = new Dynamic.OrganizationalItem();
    oi.Title = tcmFolder.Title;
    oi.Id = tcmFolder.Id.ToString();
    oi.PublicationId = tcmFolder.ContextRepository.Id.ToString();
    GeneralUtils.TimedLog("finished BuildOrganizationalItem");
    return oi;
 }
		public static Dynamic.Publication BuildPublication(TCM.Repository tcmPublication) {
         GeneralUtils.TimedLog("start BuildPublication");
			Dynamic.Publication pub = new Dynamic.Publication();
         GeneralUtils.TimedLog("get title from pub");
         pub.Title = tcmPublication.Title;
         GeneralUtils.TimedLog("found title");
         GeneralUtils.TimedLog("title=" + pub.Title);
         pub.Id = tcmPublication.Id.ToString();
         GeneralUtils.TimedLog("finished BuildPublication");
         return pub;
		}
        public static Dynamic.Schema BuildSchema(TCM.Schema tcmSchema, BuildManager manager)
        {
            if (tcmSchema == null) {
                return null;
            }
            Dynamic.Schema s = new Dynamic.Schema();
            s.Title = tcmSchema.Title;
            s.Id = tcmSchema.Id.ToString();
            s.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmSchema.OrganizationalItem);
            s.Publication = manager.BuildPublication(tcmSchema.ContextRepository);

            return s;
        }
 public virtual Dynamic.Component BuildComponent(TCM.Component tcmComponent, int linkLevels, bool resolveWidthAndHeight,bool publishEmptyFields)
 {
     return ComponentBuilder.BuildComponent(tcmComponent, linkLevels, resolveWidthAndHeight,publishEmptyFields, this);
 }
        public virtual Dynamic.Component BuildComponent(TCM.Component tcmComponent)
        {
            return ComponentBuilder.BuildComponent(tcmComponent, this);
		}
 public Dynamic.Keyword BuildKeyword(TCM.Keyword keyword, int linkLevels)
 {
     return KeywordBuilder.BuildKeyword(keyword, linkLevels, this);
 }
 public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, BuildManager manager)
 {
     return BuildComponent(tcmComponent, 1, false, manager);
 }
 public virtual Dynamic.Schema BuildSchema(TCM.Schema tcmSchema)
 {
     return SchemaBuilder.BuildSchema(tcmSchema, this);
 }
 public virtual Dynamic.OrganizationalItem BuildOrganizationalItem(TCM.Folder tcmFolder)
 {
     return OrganizationalItemBuilder.BuildOrganizationalItem(tcmFolder);
 }
        public static void AddFields(Dynamic.SerializableDictionary<string, Field> fields, TCM.Fields.ItemFields tcmItemFields, int linkLevels, bool resolveWidthAndHeight, Dynamic.MergeAction mergeAction, BuildManager manager)
        {
            foreach (TCM.Fields.ItemField tcmItemField in tcmItemFields)
             {
            try
            {
               if (fields.ContainsKey(tcmItemField.Name))
               {
                  if (mergeAction.Equals(Dynamic.MergeAction.Skip))
                  {
                     continue;
                  }
                  Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight);
                  if (mergeAction.Equals(Dynamic.MergeAction.Replace))
                  {
                     fields.Remove(f.Name);
                     fields.Add(f.Name, f);
                  }
                  else
                  {
                     Field existingField = fields[f.Name];
                     switch (existingField.FieldType)
                     {

                        case FieldType.ComponentLink:
                        case FieldType.MultiMediaLink:
                           foreach (Component linkedComponent in f.LinkedComponentValues)
                           {
                              bool valueExists = false;
                              foreach (Component existingLinkedComponent in existingField.LinkedComponentValues)
                              {
                                 if (linkedComponent.Id.Equals(existingLinkedComponent.Id))
                                 {
                                    // this value already exists
                                    valueExists = true;
                                    break;
                                 }
                              }
                              if (!valueExists)
                              {
                                 existingField.LinkedComponentValues.Add(linkedComponent);
                              }
                           }
                           break;
                        case FieldType.Date:
                           foreach (DateTime dateTime in f.DateTimeValues)
                           {
                              bool valueExists = false;
                              foreach (DateTime existingDateTime in existingField.DateTimeValues)
                              {
                                 if (dateTime.Equals(existingDateTime))
                                 {
                                    // this value already exists
                                    valueExists = true;
                                    break;
                                 }
                              }
                              if (!valueExists)
                              {
                                 existingField.DateTimeValues.Add(dateTime);
                              }
                           }
                           break;
                        case FieldType.Number:
                           foreach (int nr in f.NumericValues)
                           {
                              bool valueExists = false;
                              foreach (int existingNr in existingField.NumericValues)
                              {
                                 if (nr == existingNr)
                                 {
                                    // this value already exists
                                    valueExists = true;
                                    break;
                                 }
                              }
                              if (!valueExists)
                              {
                                 existingField.NumericValues.Add(nr);
                              }
                           }
                           break;
                        default:
                           foreach (string val in f.Values)
                           {
                              bool valueExists = false;
                              foreach (string existingVal in existingField.Values)
                              {
                                 if (val.Equals(existingVal))
                                 {
                                    // this value already exists
                                    valueExists = true;
                                    break;
                                 }
                              }
                              if (!valueExists)
                              {
                                 existingField.Values.Add(val);
                              }
                           }
                           break;
                     }
                  }
               }
               else
               {
                   Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight);
                  fields.Add(f.Name, f);
               }
            }
            catch (FieldHasNoValueException)
            {
               // fail silently, field is not added to the list
            }
            catch (FieldTypeNotDefinedException)
            {
               // fail silently, field is not added to the list
            }
             }
        }
 public static Dynamic.Fields BuildFields(TCM.Fields.ItemFields tcmItemFields, int linkLevels, bool resolveWidthAndHeight, BuildManager manager)
 {
     var fields = new Fields();
      AddFields(fields, tcmItemFields, linkLevels, resolveWidthAndHeight, Dynamic.MergeAction.Replace, manager);
      return fields;
 }
      public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int currentLinkLevel, BuildManager manager)
      {
          log.Debug(string.Format("start BuildComponent with component {0} ({1}) and link level {2}", tcmComponent.Title, tcmComponent.Id, currentLinkLevel));
          Dynamic.Component c = new Dynamic.Component();
          c.Title = tcmComponent.Title;
          c.Id = tcmComponent.Id.ToString();
          c.RevisionDate = tcmComponent.RevisionDate;

          c.Version = tcmComponent.Version;
          c.Schema = manager.BuildSchema(tcmComponent.Schema);
          
          c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString());

          if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia))
          {
              Multimedia multimedia = new Multimedia();
              multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType;

              // PLEASE NOTE: this weird way to set the size of the multimedia is needed because of a difference between Tridion 2011 and 2013
              // The property in Tridion's BinaryContent class changed its name AND its type (int FileSize became long Size)
              // This way, we can use preprocessing to choose the right property
              // Thijs Borst and Quirijn Slings, 9 April 2015
#if Legacy
              PropertyInfo prop = tcmComponent.BinaryContent.GetType().GetProperty("FileSize", BindingFlags.Public | BindingFlags.Instance);
              multimedia.Size = Convert.ToInt64(prop.GetValue(tcmComponent.BinaryContent,null));
#else
              PropertyInfo prop = tcmComponent.BinaryContent.GetType().GetProperty("Size", BindingFlags.Public | BindingFlags.Instance);
              multimedia.Size = (long) prop.GetValue(tcmComponent.BinaryContent,null);
#endif
              multimedia.FileName = tcmComponent.BinaryContent.Filename;

              string extension = System.IO.Path.GetExtension(multimedia.FileName);
              if (string.IsNullOrEmpty(extension))
              {
                  multimedia.FileExtension = "";
              }
              else
              {
                  // remove leading dot from extension because microsoft returns this as ".gif"
                  multimedia.FileExtension = extension.Substring(1);
              }

              if (manager.BuildProperties.ResolveWidthAndHeight)
              {
                  try
                  {
                      MemoryStream memstream = new MemoryStream();
                      tcmComponent.BinaryContent.WriteToStream(memstream);
                      Image image = Image.FromStream(memstream);
                      memstream.Close();

                      multimedia.Width = image.Size.Width;
                      multimedia.Height = image.Size.Height;
                  }
                  catch (Exception e)
                  {
                      log.Warning(string.Format("error retrieving width and height of image: is component with ID {0} really an image? Error message: {1}", c.Id, e.Message));
                      multimedia.Width = 0;
                      multimedia.Height = 0;
                  }
              }
              else
              {
                  multimedia.Width = 0;
                  multimedia.Height = 0;
              }
              c.Multimedia = multimedia;
              c.Multimedia.Url = manager.PublishMultimediaComponent(c);
          }
          else
          {
              c.Multimedia = null;
          }
          c.Fields = new Dynamic.FieldSet();
          c.MetadataFields = new Dynamic.FieldSet();
          if (currentLinkLevel > 0)
          {
              if (tcmComponent.Content != null)
              {
                  TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema);
                  c.Fields = manager.BuildFields(tcmFields, currentLinkLevel);
              }
              
              if (tcmComponent.Metadata != null)
              {
                  TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema);
                  c.MetadataFields = manager.BuildFields(tcmMetadataFields, currentLinkLevel);
              }
          }
          if (!manager.BuildProperties.OmitContextPublications)
          {
              c.Publication = manager.BuildPublication(tcmComponent.ContextRepository);
          }
          if (!manager.BuildProperties.OmitOwningPublications)
          {
              c.OwningPublication = manager.BuildPublication(tcmComponent.OwningRepository);
          }
          if (!manager.BuildProperties.OmitFolders)
          {
              TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem;
              c.Folder = manager.BuildOrganizationalItem(folder);
          }
          if (!manager.BuildProperties.OmitCategories)
          {
              c.Categories = manager.BuildCategories(tcmComponent);
          }
          manager.AddXpathToFields(c.Fields, "tcm:Content/custom:" + tcmComponent.Schema.RootElementName); 
          manager.AddXpathToFields(c.MetadataFields, "tcm:Metadata/custom:Metadata");
          return c;
      }
 public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, BuildManager manager)
 {
     return BuildComponent(tcmComponent, manager.BuildProperties.LinkLevels, manager);
 }
      public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int currentLinkLevel, BuildManager manager)
      {
          log.Debug(string.Format("start BuildComponent with component {0} ({1}) and link level {2}", tcmComponent.Title, tcmComponent.Id, currentLinkLevel));
          Dynamic.Component c = new Dynamic.Component();
          c.Title = tcmComponent.Title;
          c.Id = tcmComponent.Id.ToString();
          c.RevisionDate = tcmComponent.RevisionDate;

          c.Version = tcmComponent.Version;
          c.Schema = manager.BuildSchema(tcmComponent.Schema);
          
          c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString());

          if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia))
          {
              Multimedia multimedia = new Multimedia();
              multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType;
              multimedia.Size = tcmComponent.BinaryContent.Size;
              multimedia.FileName = tcmComponent.BinaryContent.Filename;

              string extension = System.IO.Path.GetExtension(multimedia.FileName);
              if (string.IsNullOrEmpty(extension))
              {
                  multimedia.FileExtension = "";
              }
              else
              {
                  // remove leading dot from extension because microsoft returns this as ".gif"
                  multimedia.FileExtension = extension.Substring(1);
              }

              if (manager.BuildProperties.ResolveWidthAndHeight)
              {
                  try
                  {
                      MemoryStream memstream = new MemoryStream();
                      tcmComponent.BinaryContent.WriteToStream(memstream);
                      Image image = Image.FromStream(memstream);
                      memstream.Close();

                      multimedia.Width = image.Size.Width;
                      multimedia.Height = image.Size.Height;
                  }
                  catch (Exception e)
                  {
                      log.Warning(string.Format("error retrieving width and height of image: is component with ID {0} really an image? Error message: {1}", c.Id, e.Message));
                      multimedia.Width = 0;
                      multimedia.Height = 0;
                  }
              }
              else
              {
                  multimedia.Width = 0;
                  multimedia.Height = 0;
              }
              c.Multimedia = multimedia;
              c.Multimedia.Url = manager.PublishMultimediaComponent(c);
          }
          else
          {
              c.Multimedia = null;
          }
          c.Fields = new Dynamic.FieldSet();
          c.MetadataFields = new Dynamic.FieldSet();
          if (currentLinkLevel > 0)
          {
              if (tcmComponent.Content != null)
              {
                  TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema);
                  c.Fields = manager.BuildFields(tcmFields, currentLinkLevel);
              }
              
              if (tcmComponent.Metadata != null)
              {
                  TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema);
                  c.MetadataFields = manager.BuildFields(tcmMetadataFields, currentLinkLevel);
              }
          }
          if (!manager.BuildProperties.OmitContextPublications)
          {
              c.Publication = manager.BuildPublication(tcmComponent.ContextRepository);
          }
          if (!manager.BuildProperties.OmitOwningPublications)
          {
              c.OwningPublication = manager.BuildPublication(tcmComponent.OwningRepository);
          }
          if (!manager.BuildProperties.OmitFolders)
          {
              TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem;
              c.Folder = manager.BuildOrganizationalItem(folder);
          }
          if (!manager.BuildProperties.OmitCategories)
          {
              c.Categories = manager.BuildCategories(tcmComponent);
          }
          manager.AddXpathToFields(c.Fields, "tcm:Content/custom:" + tcmComponent.Schema.RootElementName); 
          manager.AddXpathToFields(c.MetadataFields, "tcm:Metadata/custom:Metadata");
          return c;
      }
      public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, BuildManager manager)
      {
          GeneralUtils.TimedLog("start BuildComponent");
          Dynamic.Component c = new Dynamic.Component();
          c.Title = tcmComponent.Title;
          c.Id = tcmComponent.Id.ToString();
          c.RevisionDate = tcmComponent.RevisionDate;
          GeneralUtils.TimedLog("component title = " + c.Title);

          c.Version = tcmComponent.Version;
          GeneralUtils.TimedLog("start building schema");
          c.Schema = manager.BuildSchema(tcmComponent.Schema);
          GeneralUtils.TimedLog("finished building schema");
          
          c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString());

          if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia))
          {
              GeneralUtils.TimedLog("start building multimedia");
              Multimedia multimedia = new Multimedia();
              multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType;
              multimedia.Size = tcmComponent.BinaryContent.FileSize;
              multimedia.FileName = tcmComponent.BinaryContent.Filename;
              // remove leading dot from extension because microsoft returns this as ".gif"
              string extension = System.IO.Path.GetExtension(multimedia.FileName);
              if (string.IsNullOrEmpty(extension))
                  multimedia.FileExtension = "";
              else
                  multimedia.FileExtension = extension.Substring(1);

              if (resolveWidthAndHeight)
              {
                  try
                  {
                      MemoryStream memstream = new MemoryStream();
                      tcmComponent.BinaryContent.WriteToStream(memstream);
                      Image image = Image.FromStream(memstream);
                      memstream.Close();

                      multimedia.Width = image.Size.Width;
                      multimedia.Height = image.Size.Height;
                  }
                  catch (Exception e)
                  {
                      log.Warning("error retrieving width and height of image: " + e.Message);
                      multimedia.Width = 0;
                      multimedia.Height = 0;
                  }
              }
              else
              {
                  multimedia.Width = 0;
                  multimedia.Height = 0;
              }
              c.Multimedia = multimedia;
              GeneralUtils.TimedLog("finished building multimedia");
          }
          else
          {
              c.Multimedia = null;
          }
          c.Fields = new Dynamic.FieldSet();
          c.MetadataFields = new Dynamic.FieldSet();
          if (linkLevels > 0)
          {
              if (tcmComponent.Content != null)
              {
                  GeneralUtils.TimedLog("start retrieving tcm fields");
                  TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema);
                  log.Debug("TCM fields" +tcmFields.ToXml());
                  GeneralUtils.TimedLog("finished retrieving tcm fields");
                  GeneralUtils.TimedLog("start building fields");
                  c.Fields = manager.BuildFields(tcmFields, linkLevels, resolveWidthAndHeight,publishEmptyFields);
                  GeneralUtils.TimedLog("finished building fields");
              }
              
              if (tcmComponent.Metadata != null)
              {
                  GeneralUtils.TimedLog("start retrieving tcm metadata fields");
                  TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema);
                  GeneralUtils.TimedLog("finished retrieving tcm metadata fields");
                  GeneralUtils.TimedLog("start building metadata fields");
                  c.MetadataFields = manager.BuildFields(tcmMetadataFields, linkLevels, resolveWidthAndHeight,publishEmptyFields);
                  GeneralUtils.TimedLog("finished building metadata fields");
              }
          }
          c.Publication = manager.BuildPublication(tcmComponent.ContextRepository);
          c.OwningPublication = manager.BuildPublication(tcmComponent.OwningRepository);
          TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem;
          c.Folder = manager.BuildOrganizationalItem(folder);
          c.Categories = manager.BuildCategories(tcmComponent);

          manager.AddXpathToFields(c.Fields, "tcm:Content/custom:" + tcmComponent.Schema.RootElementName); // TODO: check if the first part of the XPath is really the root element name, or simply always 'Content'
          manager.AddXpathToFields(c.MetadataFields, "tcm:Metadata/custom:Metadata");
          return c;
      }
 public virtual Dynamic.FieldSet BuildFields(TCM.Fields.ItemFields tcmItemFields, int linkLevels, bool resolveWidthAndHeight,bool publishEmptyFields)
 {
     return FieldsBuilder.BuildFields(tcmItemFields, linkLevels, resolveWidthAndHeight,publishEmptyFields, this);
 }
 public Dynamic.Keyword BuildKeyword(TCM.Keyword keyword)
 {
     return KeywordBuilder.BuildKeyword(keyword);
 }
 public virtual Dynamic.FieldSet BuildFields(TCM.Fields.ItemFields tcmItemFields, int currentLinkLevel)
 {
     return FieldsBuilder.BuildFields(tcmItemFields, currentLinkLevel, this);
 }
 public virtual Dynamic.Publication BuildPublication(TCM.Repository tcmPublication)
 {
     return PublicationBuilder.BuildPublication(tcmPublication);
 }
示例#24
0
        public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int currentLinkLevel, BuildManager manager)
        {
            Dynamic.Field f = new Dynamic.Field();

            if (tcmItemField == null && manager.BuildProperties.PublishEmptyFields)
            {
                f.Values.Add("");
                return f;
            }
            else if (tcmItemField == null && !manager.BuildProperties.PublishEmptyFields)
            {
                throw new FieldHasNoValueException();
            }
            f.Name = tcmItemField.Name;
            if (tcmItemField is TCM.Fields.XhtmlField)
            {
                TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField;
                if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields)
                {
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    foreach (string v in sField.Values)
                    {
                        f.Values.Add(manager.PublishBinariesInRichTextField(v));
                    }
                }
                f.FieldType = FieldType.Xhtml;
                return f;
            }
            if (tcmItemField is TCM.Fields.MultiLineTextField)
            {
                TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField;
                if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields)
                {
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    foreach (string v in sField.Values)
                    {
                        f.Values.Add(v);
                    }
                }
                f.FieldType = FieldType.MultiLineText;
                return f;
            }
            if (tcmItemField is TCM.Fields.TextField)
            {
                TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField;
                if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields)
                {
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    foreach (string v in sField.Values)
                    {
                        f.Values.Add(v);
                    }
                }
                f.FieldType = FieldType.Text;
                return f;
            }
            if (tcmItemField is TCM.Fields.KeywordField)
            {
                TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField;
                if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields)
                {
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    // add keyword values
                    f.Keywords = new List<Keyword>();
                    // we will wrap each linked component in a ContentModel component
                    foreach (TCM.Keyword kw in sField.Values)
                    {
                        f.Keywords.Add(manager.BuildKeyword(kw));
                    }
                    if (!manager.BuildProperties.OmitValueLists)
                    {
                        f.Values = new List<string>();
                        foreach (TCM.Keyword kw in sField.Values)
                        {
                            f.Values.Add(kw.Title);
                        }
                    }

                    KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition;
                    f.CategoryId = fieldDef.Category.Id;
                    f.CategoryName = fieldDef.Category.Title;
                }
                f.FieldType = FieldType.Keyword;
                return f;
            }
            if (tcmItemField is TCM.Fields.NumberField)
            {
                TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField;
                if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields)
                {
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    f.NumericValues = (List<double>)sField.Values;
                    if (!manager.BuildProperties.OmitValueLists)
                    {
                        f.Values = new List<string>();
                        foreach (double d in f.NumericValues)
                        {
                            f.Values.Add(Convert.ToString(d));
                        }
                    }
                }
                f.FieldType = FieldType.Number;
                return f;
            }
            if (tcmItemField is TCM.Fields.DateField)
            {
                TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField;

                if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields)
                {
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    f.DateTimeValues = (List<DateTime>)sField.Values;
                    if (!manager.BuildProperties.OmitValueLists)
                    {
                        f.Values = new List<string>();
                        foreach (DateTime dt in f.DateTimeValues)
                        {
                            f.Values.Add(Convert.ToString(dt));
                        }
                    }
                }
                f.FieldType = FieldType.Date;
                return f;
            }
            if (tcmItemField is TCM.Fields.MultimediaLinkField)
            {
                TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField;
                if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields)
                {
                    f.Values.Add(tcmItemField.Name);
                }
                else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    // we will wrap each linked component in a ContentModel component
                    f.LinkedComponentValues = new List<Dynamic.Component>();
                    int nextLinkLevel = currentLinkLevel - 1;
                    if (MustFollowField(sField, manager))
                    {
                        log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name));
                    }
                    else
                    {
                        log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name));
                        nextLinkLevel = 0;
                    }
                    foreach (TCM.Component comp in sField.Values)
                    {
                        f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel));
                    }
                    if (!manager.BuildProperties.OmitValueLists)
                    {
                        f.Values = new List<string>();
                        foreach (Dynamic.Component c in f.LinkedComponentValues)
                        {
                            f.Values.Add(c.Id);
                        }
                    }
                }
                f.FieldType = FieldType.MultiMediaLink;
                return f;
            }
            if (tcmItemField is TCM.Fields.ComponentLinkField)
            {
                TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField;
                if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields)
                {
                    f.Values.Add(tcmItemField.Name);
                }
                else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    // we will wrap each linked component in a ContentModel component
                    f.LinkedComponentValues = new List<Dynamic.Component>();
                    int nextLinkLevel = currentLinkLevel - 1;
                    if (MustFollowField(sField, manager))
                    {
                        log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name));
                    }
                    else
                    {
                        log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name));
                        nextLinkLevel = 0;
                    }

                    foreach (TCM.Component comp in sField.Values)
                    {
                        f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel));
                    }


                    if (!manager.BuildProperties.OmitValueLists)
                    {
                        f.Values = new List<string>();
                        foreach (Dynamic.Component c in f.LinkedComponentValues)
                        {
                            f.Values.Add(c.Id);
                        }
                    }
                }
                f.FieldType = FieldType.ComponentLink;
                return f;
            }

            if (tcmItemField is TCM.Fields.EmbeddedSchemaField)
            {

                TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField;
                f.FieldType = FieldType.Embedded;
                f.EmbeddedValues = new List<Dynamic.FieldSet>();
                bool hasValues = CheckIfEmbeddedFieldHasValues(sField);
                if (!hasValues && manager.BuildProperties.PublishEmptyFields)
                {
                    Dynamic.FieldSet fields = new FieldSet();
                    Dynamic.Field fe = new Dynamic.Field();
                    f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema);
                    EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition;
                    ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema);

                    for (int i = 0; i < newItemField.Count; i++)
                    {

                        if (newItemField[i] is TCM.Fields.EmbeddedSchemaField)
                        {
                            TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i];
                            if (innerField.Values.Count == 0)
                            {
                                Dynamic.FieldSet fieldsinner = new FieldSet();
                                Dynamic.Field fin = new Dynamic.Field();
                                fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema);
                                EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition;
                                ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema);
                                for (int n = 0; n < newinItemField.Count; n++)
                                {
                                    fin.Name = newItemField[n].Name;
                                    fieldsinner.Add(newinItemField[n].Name, fin);
                                }
                                fe.EmbeddedValues.Add(fieldsinner);
                                fe.Values.Add("");
                            }
                            fe.Name = newItemField[i].Name;
                            fields.Add(newItemField[i].Name, fe);

                        }
                        else
                        {
                            Dynamic.Field fein = manager.BuildField(newItemField[i], currentLinkLevel);
                            fein.Values.Clear();
                            fields.Add(newItemField[i].Name, fein);
                        }
                    }
                    f.EmbeddedValues.Add(fields);
                    f.Values.Add("");
                }
                else if (!hasValues && !manager.BuildProperties.PublishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {

                    // we will wrap each linked component in a ContentModel component
                    f.EmbeddedValues = new List<Dynamic.FieldSet>();
                    f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema);

                    foreach (TCM.Fields.ItemFields embeddedFields in sField.Values)
                    {
                        f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, currentLinkLevel));
                    }
                }

                return f;
            }

            throw new FieldTypeNotDefinedException();
        }
 public virtual Dynamic.FieldSet BuildFields(TCM.Fields.ItemFields tcmItemFields)
 {
     return FieldsBuilder.BuildFields(tcmItemFields, this.BuildProperties.LinkLevels, this);
 }
 public virtual Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int linkLevels, bool resolveWidthAndHeight)
 {
     return FieldBuilder.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight, this);
 }
        public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int linkLevels, bool resolveWidthAndHeight, BuildManager manager)
        {
            GeneralUtils.TimedLog("start BuildComponent");
            Dynamic.Component c = new Dynamic.Component();
            c.Title = tcmComponent.Title;
            c.Id = tcmComponent.Id.ToString();
             GeneralUtils.TimedLog("component title = " + c.Title);

             GeneralUtils.TimedLog("start building schema");
             c.Schema = manager.BuildSchema(tcmComponent.Schema);
             GeneralUtils.TimedLog("finished building schema");
             c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString());

             if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia))
             {
            GeneralUtils.TimedLog("start building multimedia");
            Multimedia multimedia = new Multimedia();
            multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType;
            multimedia.Size = tcmComponent.BinaryContent.FileSize;
            multimedia.FileName = tcmComponent.BinaryContent.Filename;
            // remove leading dot from extension because microsoft returns this as ".gif"
            multimedia.FileExtension = System.IO.Path.GetExtension(multimedia.FileName).Substring(1);

            if (resolveWidthAndHeight)
            {
               MemoryStream memstream = new MemoryStream();
               tcmComponent.BinaryContent.WriteToStream(memstream);
               Image image = Image.FromStream(memstream);
               memstream.Close();

               multimedia.Width = image.Size.Width;
               multimedia.Height = image.Size.Height;
            }
            else
            {
               multimedia.Width = 0;
               multimedia.Height = 0;
            }
            c.Multimedia = multimedia;
            GeneralUtils.TimedLog("finished building multimedia");
             }
             else
             {
            c.Multimedia = null;
             }
             c.Fields = new Dynamic.SerializableDictionary<string,Field>();
            c.MetadataFields = new Dynamic.SerializableDictionary<string, Field>();
            if (linkLevels > 0) {
            if (tcmComponent.Content != null)
            {
               GeneralUtils.TimedLog("start retrieving tcm fields");
               TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema);
               GeneralUtils.TimedLog("finished retrieving tcm fields");
               GeneralUtils.TimedLog("start building fields");
               c.Fields = manager.BuildFields(tcmFields, linkLevels, resolveWidthAndHeight);
               GeneralUtils.TimedLog("finished building fields");
            }
                if (tcmComponent.Metadata != null) {
               GeneralUtils.TimedLog("start retrieving tcm metadata fields");
               TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema);
               GeneralUtils.TimedLog("finished retrieving tcm metadata fields");
               GeneralUtils.TimedLog("start building metadata fields");
               c.MetadataFields = manager.BuildFields(tcmMetadataFields, linkLevels, resolveWidthAndHeight);
               GeneralUtils.TimedLog("finished building metadata fields");
            }
            }

             GeneralUtils.TimedLog("start retrieving tcm publication");
             TCM.Repository pub = tcmComponent.ContextRepository;
             GeneralUtils.TimedLog("finished retrieving tcm publication");
             GeneralUtils.TimedLog("start building publication");
             c.Publication = manager.BuildPublication(pub);
             GeneralUtils.TimedLog("finished building publication");

             GeneralUtils.TimedLog("start retrieving tcm folder");
             TCM.Folder folder = (TCM.Folder) tcmComponent.OrganizationalItem;
             GeneralUtils.TimedLog("finished retrieving tcm folder");
             GeneralUtils.TimedLog("start building folder");
             c.Folder = manager.BuildOrganizationalItem(folder);
             GeneralUtils.TimedLog("finished building folder");
             GeneralUtils.TimedLog("start building categories");
             c.Categories = manager.BuildCategories(tcmComponent);
             GeneralUtils.TimedLog("finished building categories");

             GeneralUtils.TimedLog("finished BuildComponent " + c.Title);

             return c;
        }
 public virtual List<Dynamic.Category> BuildCategories(TCM.Component component)
 {
     return CategoriesBuilder.BuildCategories(component, this);
 }
示例#29
0
 private static bool MustFollowField(TCM.Fields.ComponentLinkField field, BuildManager manager)
 {
     // TODO: check for setting 'followLinksPerField'
     if (!manager.BuildProperties.FollowLinksPerField)
         return true;
     XmlNamespaceManager nsMan = new XmlNamespaceManager(new NameTable());
     nsMan.AddNamespace("dd4t", "http://www.sdltridion.com/2011/DD4TField");
     XmlElement followLink = (XmlElement)field.Definition.ExtensionXml.SelectSingleNode("//dd4t:configuration/dd4t:followlink", nsMan);
     return (followLink != null && followLink.InnerText == "true");
 }
        public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, BuildManager manager)
        {
            Dynamic.Field f = new Dynamic.Field();

            if (tcmItemField == null&&publishEmptyFields)
            {
                GeneralUtils.TimedLog("item field is null");
                //throw new FieldHasNoValueException();
                f.Values.Add("");
                return f;                
            }
            else if (tcmItemField == null && !publishEmptyFields)
            {
                throw new FieldHasNoValueException();
            }
            f.Name = tcmItemField.Name;
            if (tcmItemField is TCM.Fields.XhtmlField)
            {
                TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField;
                GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count));
                if (sField.Values.Count == 0 && publishEmptyFields)
                {
                    //throw new FieldHasNoValueException();
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !publishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    foreach (string v in sField.Values)
                    {
                        f.Values.Add(v);
                    }                    
                }
                f.FieldType = FieldType.Xhtml;
                return f;
            }
            if (tcmItemField is TCM.Fields.MultiLineTextField)
            {
                TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField;
                GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count));
                //if (sField.Values.Count == 0)
                  //  throw new FieldHasNoValueException();
                if (sField.Values.Count == 0 && publishEmptyFields)
                {
                    //throw new FieldHasNoValueException();
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !publishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    foreach (string v in sField.Values)
                    {
                        f.Values.Add(v);
                    }
                }
                f.FieldType = FieldType.MultiLineText;
                return f;
            }
            if (tcmItemField is TCM.Fields.TextField)
            {
                TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField;
                GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count));
                //if (sField.Values.Count == 0)
                  //  throw new FieldHasNoValueException();
                if (sField.Values.Count == 0 && publishEmptyFields)
                {
                    //throw new FieldHasNoValueException();
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !publishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    foreach (string v in sField.Values)
                    {
                        f.Values.Add(v);
                    }
                }
                f.FieldType = FieldType.Text;
                return f;
            }
            if (tcmItemField is TCM.Fields.KeywordField)
            {
                TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField;
                GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count));
                //if (sField.Values.Count == 0)
                //    throw new FieldHasNoValueException();
                if (sField.Values.Count == 0 && publishEmptyFields)
                {
                    //throw new FieldHasNoValueException();
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !publishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    // add keyword values
                    f.Keywords = new List<Keyword>();
                    // we will wrap each linked component in a ContentModel component
                    f.Values = new List<string>();
                    foreach (TCM.Keyword kw in sField.Values)
                    {
                        // todo: add binary to package, and add BinaryUrl property to the component
                        f.Values.Add(kw.Title);
                        f.Keywords.Add(manager.BuildKeyword(kw));
                    }
                    
                    KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition;
                    f.CategoryId = fieldDef.Category.Id;
                    f.CategoryName = fieldDef.Category.Title;
                }
                f.FieldType = FieldType.Keyword;
                return f;
            }
            if (tcmItemField is TCM.Fields.NumberField)
            {
                TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField;
                GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count));

                //if (sField.Values.Count == 0)
                  //  throw new FieldHasNoValueException();
                if (sField.Values.Count == 0 && publishEmptyFields)
                {
                    //throw new FieldHasNoValueException();
                    f.Values.Add("");
                }
                 else if (sField.Values.Count == 0 && !publishEmptyFields)
                 {
                     throw new FieldHasNoValueException();
                 }
                 else
                 {
                     f.NumericValues = (List<double>)sField.Values;
                     f.Values = new List<string>();
                     foreach (double d in f.NumericValues)
                     {
                         f.Values.Add(Convert.ToString(d));
                     }
                 }
                f.FieldType = FieldType.Number;
                return f;
            }
            if (tcmItemField is TCM.Fields.DateField)
            {
                TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField;
                GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count));
                //if (sField.Values.Count == 0)
                //  throw new FieldHasNoValueException();

                if (sField.Values.Count == 0 && publishEmptyFields)
                {
                    //throw new FieldHasNoValueException();
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !publishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {

                    f.DateTimeValues = (List<DateTime>)sField.Values;
                    f.Values = new List<string>();
                    foreach (DateTime dt in f.DateTimeValues)
                    {
                        f.Values.Add(Convert.ToString(dt));
                    }
                }
                f.FieldType = FieldType.Date;
                return f;
            }
            if (tcmItemField is TCM.Fields.MultimediaLinkField)
            {
                TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField;
                GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count));
                if (sField.Values.Count == 0 && publishEmptyFields)
                {
                    f.Values.Add(tcmItemField.Name);
                }
                else if (sField.Values.Count == 0 && !publishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {

                    // we will wrap each linked component in a ContentModel component
                    f.LinkedComponentValues = new List<Dynamic.Component>();
                    foreach (TCM.Component comp in sField.Values)
                    {
                        // todo: add binary to package, and add BinaryUrl property to the component
                        f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields));
                    }
                    f.Values = new List<string>();
                    foreach (Dynamic.Component c in f.LinkedComponentValues)
                    {
                        f.Values.Add(c.Id);
                    }
                }
                f.FieldType = FieldType.MultiMediaLink;
                return f;
            }
            if (tcmItemField is TCM.Fields.ComponentLinkField)
            {
                TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField;
                GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count));
                //if (sField.Values.Count == 0)
                  //  throw new FieldHasNoValueException();
                if (sField.Values.Count == 0 && publishEmptyFields)
                {
                    f.Values.Add(tcmItemField.Name);
                }
                else if (sField.Values.Count == 0 && !publishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {
                    // we will wrap each linked component in a ContentModel component
                    f.LinkedComponentValues = new List<Dynamic.Component>();
                    foreach (TCM.Component comp in sField.Values)
                    {
                        f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields));
                    }
                    f.Values = new List<string>();
                    foreach (Dynamic.Component c in f.LinkedComponentValues)
                    {
                        f.Values.Add(c.Id);
                    }
                }
                f.FieldType = FieldType.ComponentLink;
                return f;
            }

            if (tcmItemField is TCM.Fields.EmbeddedSchemaField)
            {
                
                TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField;
                GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count));
                //if (sField.Values.Count == 0)
                  //throw new FieldHasNoValueException();
                f.FieldType = FieldType.Embedded;
                f.EmbeddedValues = new List<Dynamic.FieldSet>();
                
                if (sField.Values.Count == 0 && publishEmptyFields)
                {
                    Dynamic.FieldSet fields = new FieldSet();
                    Dynamic.Field fe = new Dynamic.Field();
                    f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema);
                    EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition;
                    ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema);
                    
                    for (int i = 0; i < newItemField.Count; i++)
                    {

                        if (newItemField[i] is TCM.Fields.EmbeddedSchemaField)
                        {
                            TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i];
                            if (innerField.Values.Count == 0)
                            {
                                Dynamic.FieldSet fieldsinner = new FieldSet();
                                Dynamic.Field fin = new Dynamic.Field();
                                fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema);
                                EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition;
                                ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema);
                                for (int n = 0; n < newinItemField.Count; n++)
                                {
                                    fin.Name = newItemField[n].Name;
                                    fieldsinner.Add(newinItemField[n].Name, fin);
                                }
                                fe.EmbeddedValues.Add(fieldsinner);
                                fe.Values.Add("");
                            }
                            fe.Name = newItemField[i].Name;
                            fields.Add(newItemField[i].Name, fe);

                        }
                        else
                        {
                            Dynamic.Field fein = manager.BuildField(newItemField[i], linkLevels, resolveWidthAndHeight, publishEmptyFields);
                            fein.Values.Clear();
                            fields.Add(newItemField[i].Name, fein);
                           
                        }                       
                                                
                    }
                    f.EmbeddedValues.Add(fields);                    
                    f.Values.Add("");
                }
                else if (sField.Values.Count == 0 && !publishEmptyFields)
                {
                    throw new FieldHasNoValueException();
                }
                else
                {

                    // we will wrap each linked component in a ContentModel component
                    f.EmbeddedValues = new List<Dynamic.FieldSet>();
                    f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema);
                    
                    foreach (TCM.Fields.ItemFields embeddedFields in sField.Values)
                    {
                        f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, linkLevels, resolveWidthAndHeight, publishEmptyFields));
                    }
                }
                
                return f;
            }

            throw new FieldTypeNotDefinedException();
        }