Example #1
0
        private Ingestion DeserializeMetadatasets(System.Xml.XmlReader reader)
        {
            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (reader.Name == "metadata-set")
                    {
                        string        strGuid = reader.GetAttribute("guid");
                        CFMetadataSet set     = new CFMetadataSet();
                        set.Content    = reader.ReadOuterXml();
                        set.Guid       = strGuid;
                        set.MappedGuid = strGuid;
                        MetadataSets.Add(set);
                    }
                    else
                    {
                        throw new FormatException("Invalid XML element: " + reader.Name);
                    }
                }

                if (reader.NodeType == System.Xml.XmlNodeType.EndElement)
                {
                    if (reader.Name == "metadata-sets")
                    {
                        return(this);
                    }
                }
            }

            return(this);
        }
Example #2
0
        protected FormField GetMetadataSetField(string metadatasetGuid, string fieldName)
        {
            CFMetadataSet metadataSet = MetadataSets.Where(ms => ms.Guid == metadatasetGuid).FirstOrDefault();

            if (metadataSet == null)
            {
                return(null);
            }

            FormField field = metadataSet.Fields.Where(f => f.Name == fieldName).FirstOrDefault();

            return(field);
        }
Example #3
0
        public EntityViewModel(CFEntity entity, string[] languageCodes, IDictionary <string, EntityViewModel> previousEntities = null) : this()
        {
            this.Id             = entity.Id;
            this.Guid           = entity.Guid;
            this.LanguageCodes  = languageCodes;
            this.EntityTypeName = entity.EntityType.Name;

            this.Created = entity.Created;

            Type entityType = entity.GetType();

            // Added to prevent circular child members.
            if (previousEntities == null)
            {
                previousEntities = new Dictionary <string, EntityViewModel>();
            }
            previousEntities.Add(this.Guid, this);

            foreach (CFMetadataSet metadataset in entity.MetadataSets)
            {
                MetadataSets.Add(new MetadataSetViewModel(metadataset, languageCodes));
            }

            if (typeof(CFItem).IsAssignableFrom(entityType))
            {
                foreach (CFDataObject dataObject in ((CFItem)entity).DataObjects)
                {
                    if (typeof(CFDataFile).IsAssignableFrom(dataObject.GetType()))
                    {
                        Files.Add(new DataFileViewModel((CFDataFile)dataObject, entity.Id));
                    }
                }
            }

            if (typeof(CFAggregation).IsAssignableFrom(entityType))
            {
                foreach (CFEntity member in ((CFAggregation)entity).ChildMembers)
                {
                    if (previousEntities.ContainsKey(member.Guid))
                    {
                        Children.Add(previousEntities[member.Guid]);
                    }
                    else
                    {
                        EntityViewModel child = new EntityViewModel(member, languageCodes, previousEntities);
                        Children.Add(child);
                    }
                }
            }
        }
Example #4
0
        private Ingestion DeserializeMetadatasets(XElement element)
        {
            foreach (XElement setElement in element.Elements())
            {
                string name    = setElement.Name.LocalName;
                string strGuid = setElement.Attribute("guid").Value;
                if (name == "metadata-set")
                {
                    CFMetadataSet set = new CFMetadataSet();
                    set.Content    = setElement.ToString();
                    set.Guid       = strGuid;
                    set.MappedGuid = strGuid;
                    MetadataSets.Add(set);
                }
            }

            return(this);
        }
Example #5
0
        protected void SetAttributeMappingValue(string name, string val, string lang = null, bool removePrevious = false)
        {
            CFEntityTypeAttributeMapping mapping = EntityType.AttributeMappings.Where(m => m.Name == name).FirstOrDefault();

            if (mapping == null)
            {
                throw new Exception(string.Format("{0} mapping metadata set is not specified for this entity type", name));
            }

            if (string.IsNullOrEmpty(mapping.FieldName))
            {
                throw new Exception(string.Format("Field is not specified in the {0} Mapping of this entity type", name));
            }

            CFMetadataSet metadataSet = MetadataSets.Where(ms => ms.Guid == mapping.MetadataSet.Guid).FirstOrDefault();

            metadataSet.SetFieldValue(mapping.FieldName, val, lang, removePrevious);
        }
Example #6
0
 public IEnumerable <FormFieldViewModel> GetAllFormFields()
 {
     return(MetadataSets.SelectMany(m => m.Fields));
 }