Example #1
0
        public override void UpdateValues(CFXmlModel src)
        {
            //Unlike multi-select option fields such as check boxes, single select option fields such as radio buttons sends
            //the selected option as a value. Therefore, we need to find the corresponding value from the option set in the
            //destination and set it's selected property to true (and deselect all other properties).

            var dstWrapper = Data.Element("options");

            if (dstWrapper == null)
            {
                Data.Add(dstWrapper = new XElement("options"));
            }

            string srcValue = ((SingleSelectOptionsField)src).Value;
            string lang     = Lang(null);

            //Iterating through all options in the destinatopn
            foreach (XElement opt in dstWrapper.Elements("option"))
            {
                bool selected = false;
                if (!string.IsNullOrEmpty(srcValue))
                {
                    IEnumerable <TextValue> dstValues = XmlHelper.GetTextValues(opt, false);
                    selected = dstValues.Where(d => d.LanguageCode == lang && d.Value == srcValue).Any();
                }
                opt.SetAttributeValue("selected", selected);
            }
        }
        public override void UpdateValues(CFXmlModel src)
        {
            base.UpdateValues(src);

            var src_item = src as AbstractForm;

            UpdateValueFields(src_item.Fields.ToList());
        }
Example #3
0
        public T CreateAggregation <T>(CFXmlModel aggregation) where T : CFAggregation, new()
        {
            T            agg            = new T();
            string       entityTypeName = aggregation.Data.Attribute("entity-type").Value;
            CFEntityType entType        = Db.EntityTypes.Where(e => e.Name == entityTypeName).FirstOrDefault();

            agg            = (T)aggregation;
            agg.EntityType = entType;

            return(agg);
        }
Example #4
0
        public T CreateAggregation <T>(CFXmlModel aggregation) where T : CFAggregation, new()
        {
            //T agg = new T();
            Regex entityTypeRegex = new Regex(@"(entity-type)=[""']?((?:.(?![""']?\s + (?:\S +)=|[>""']))+.)[""']?");

            string entityTypeName = entityTypeRegex.Match(aggregation.Content).Groups[2].Value;
            int?   entType        = Db.EntityTypes.Where(e => e.Name == entityTypeName).Select(e => e.Id).FirstOrDefault();
            T      agg            = (T)aggregation;

            agg.EntityTypeId = entType;

            return(agg);
        }
Example #5
0
        private Ingestion DeserializeAggregations(XmlReader reader)
        {
            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    string     name    = reader.LocalName;
                    CFXmlModel model   = null;
                    string     strGuid = reader.GetAttribute("guid");
                    switch (name)
                    {
                    case "collection":
                        model = new CFCollection();
                        break;

                    case "item":
                        model = new CFItem();
                        break;

                    case "form":
                        model = new Form();
                        break;

                    case "file":
                        model = new CFDataFile();
                        break;

                    default:
                        throw new FormatException("Invalid XML element: " + reader.Name);
                    }

                    if (model != null)
                    {
                        model.Guid       = strGuid;
                        model.MappedGuid = strGuid;
                        model.Content    = reader.ReadOuterXml();
                        Aggregations.Add(model);
                    }
                }

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

            return(this);
        }
Example #6
0
        public void ItemTest()
        {
            string path = GetSampleDataFilePathName("Item.xml");

            Assert.IsTrue(File.Exists(path));

            CFItem model = CFXmlModel.Load(path) as CFItem;

            Assert.IsNotNull(model);

            List <CFMetadataSet> metadatasets = model.MetadataSets.ToList();

            Assert.AreEqual(2, metadatasets.Count());
        }
Example #7
0
        public override void UpdateValues(CFXmlModel src)
        {
            base.UpdateValues(src);

            var src_item = src as AbstractForm;

            foreach (FormField field in this.Fields)
            { // checkhere type of
                var src_field = src_item.Fields.Where(x => x.Guid == field.Guid).FirstOrDefault();
                if (src_field != null)
                {
                    field.UpdateValues(src_field);
                }
            }
        }
Example #8
0
        public override void UpdateValues(CFXmlModel src)
        {
            XElement srcValueWrapper = src.Data.Element("value");

            if (srcValueWrapper == null)
            {
                return;
            }

            XElement dstValueWrapper = Data.Element("value");

            if (dstValueWrapper == null)
            {
                Data.Add(dstValueWrapper = new XElement("value"));
            }

            dstValueWrapper.Value = srcValueWrapper.Value;
        }
        /// <summary>
        /// Recursively through all fields in a form to find fields of type ExternalMediaField and
        /// checks whether the media sources referred by them exist. Returns the list of URLs of media
        /// sources that does not exist.
        /// </summary>
        /// <param name="model">The form or field.</param>
        /// <returns></returns>
        public List <string> CheckMedia(CFXmlModel model)
        {
            List <string> errorneousMedia = new List <string>();

            if (typeof(Form).IsAssignableFrom(model.GetType()))
            {
                Form form = model as Form;
                foreach (var child in form.Fields)
                {
                    errorneousMedia.AddRange(CheckMedia(child));
                }
            }
            else if (typeof(ExternalMediaField).IsAssignableFrom(model.GetType()))
            {
                if (!CheckMedia((model as ExternalMediaField).Source))
                {
                    errorneousMedia.Add((model as ExternalMediaField).Source);
                }
            }
            else if (typeof(CompositeFormField).IsAssignableFrom(model.GetType()))
            {
                CompositeFormField cfield = model as CompositeFormField;

                foreach (var child in cfield.Header)
                {
                    errorneousMedia.AddRange(CheckMedia(child));
                }

                foreach (var child in cfield.Fields)
                {
                    errorneousMedia.AddRange(CheckMedia(child));
                }

                foreach (var child in cfield.Footer)
                {
                    errorneousMedia.AddRange(CheckMedia(child));
                }
            }

            return(errorneousMedia);
        }
Example #10
0
        public void MetadataFieldsTest()
        {
            string path = GetSampleDataFilePathName("MetadataSet.xml");

            Assert.IsTrue(File.Exists(path));

            XElement root = XElement.Load(path);

            Assert.IsNotNull(root);

            CFMetadataSet model = CFXmlModel.Parse(root) as CFMetadataSet;

            Assert.IsNotNull(model);

            IReadOnlyList <FormField> fields = model.Fields;

            Assert.AreEqual(3, fields.Count);

            var field = fields.Where(f => f is TextField).FirstOrDefault();

            Assert.IsNotNull(field);
            Assert.AreEqual("Subject", field.GetName("en"));
            Assert.AreEqual("Sujet", field.GetName("fr"));
            Assert.AreEqual("Enter the subject here.", field.GetDescription("en"));

            field = fields.Where(f => f is TextArea).FirstOrDefault();
            Assert.IsNotNull(field);
            Assert.AreEqual("Description", field.GetName("en"));
            Assert.AreEqual("La description", field.GetName("fr"));
            Assert.AreEqual("Enter the description here.", field.GetDescription("en"));

            field = fields.Where(f => f is RadioButtonSet).FirstOrDefault();
            Assert.IsNotNull(field);
            Assert.AreEqual("Radio button set 1", field.GetName("en"));
            Assert.AreEqual("Réglage du bouton radio 1", field.GetName("fr"));
            Assert.AreEqual("This is a radio button set.", field.GetDescription("en"));

            ////var options = (field as RadioButtonSet).GetOptions("fr");
            ////Assert.AreEqual("Première option\nDeuxième option\nTroisième option", options);
            ////Assert.AreEqual("First option\nSecond option\nThird option", (field as RadioButtonSet).Options);
        }
Example #11
0
        public CFDataFile GetFile(int id, string guid, bool checkInItems = true)
        {
            CFXmlModel model = Db.XmlModels.Find(id);

            if (model is CFDataFile && model.Guid == guid)
            {
                return(model as CFDataFile);
            }

            if (checkInItems && model is CFItem)
            {
                return((model as CFItem).Files.Where(f => f.Guid == guid).FirstOrDefault());
            }

            if (typeof(AbstractForm).IsAssignableFrom(model.GetType()))
            {
                return((model as AbstractForm).Fields.SelectMany(m => m.Files).Where(m => m.DataFile.Guid == guid).FirstOrDefault().DataFile);
            }

            return(null);
        }
Example #12
0
        public override void UpdateValues(CFXmlModel src)
        {
            XElement srcValueWrapper = src.Data.Element("value");

            if (srcValueWrapper == null)
            {
                return;
            }

            IEnumerable <XElement> srcText = srcValueWrapper.Elements("text");

            if (srcText.Count() == 0)
            {
                return;
            }

            XElement dstValeWrapper = Data.Element("value");

            if (dstValeWrapper == null)
            {
                Data.Add(dstValeWrapper = new XElement("value"));
            }
            else
            {
                //deleting all existing text elements from the destination
                foreach (var txt in dstValeWrapper.Elements("text").ToList())
                {
                    txt.Remove();
                }
            }

            //inserting clones of text elements in the src value wrapper
            foreach (var txt in srcValueWrapper.Elements("text"))
            {
                dstValeWrapper.Add(new XElement(txt));
            }
        }
Example #13
0
        public override void UpdateValues(CFXmlModel src)
        {
            base.UpdateValues(src);

            CompositeFormField srcField = src as CompositeFormField;

            //Updating contents of all child fields
            foreach (FormField field in Fields)
            { // checkhere type of
                var src_field = srcField.Fields.Where(x => x.Guid == field.Guid).FirstOrDefault();
                if (src_field != null)
                {
                    field.UpdateValues(src_field);
                }
            }

            //Updating contents of the header fields
            foreach (FormField field in Header)
            { // checkhere type of
                var src_field = srcField.Header.Where(x => x.Guid == field.Guid).FirstOrDefault();
                if (src_field != null)
                {
                    field.UpdateValues(src_field);
                }
            }

            //Updating contents of the footer fields
            foreach (FormField field in Footer)
            { // checkhere type of
                var src_field = srcField.Footer.Where(x => x.Guid == field.Guid).FirstOrDefault();
                if (src_field != null)
                {
                    field.UpdateValues(src_field);
                }
            }
        }
Example #14
0
        private Ingestion DeserializeAggregations(XElement element)
        {
            foreach (XElement child in element.Elements())
            {
                string     name    = child.Name.LocalName;
                CFXmlModel model   = null;
                string     strGuid = child.Attribute("guid").Value;
                switch (name)
                {
                case "collection":
                    model = new CFCollection();
                    break;

                case "item":
                    model = new CFItem();
                    break;

                case "form":
                    model = new Form();
                    break;

                case "file":
                    model = new CFDataFile();
                    break;
                }

                if (model != null)
                {
                    model.Guid       = strGuid;
                    model.MappedGuid = strGuid;
                    model.Content    = child.ToString();
                    Aggregations.Add(model);
                }
            }
            return(this);
        }
Example #15
0
        public override void UpdateValues(CFXmlModel src)
        {
            CFOptionsField optionsField = src as CFOptionsField;

            this.Options = optionsField.Options;
        }
Example #16
0
 public MetadataDefinition(CFXmlModel data, int id)
 {
     Id   = id;
     Data = data;
 }