Source

main / Source / WebClient / Web.BizLogic / Helper / MetadataHelper.cs

Naethra D 3ee1b94 


























































using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using DataUp.Web.Common;
using System.Collections.ObjectModel;

namespace DataUp.Web.BizLogic
{
    /// <summary>
    /// Helper to read Metadata tags from file.
    /// </summary>
    public static class MetadataHelper
    {
        public static Collection<MetadataDetail> GetDefaultMetadataList()
        {
            Collection<MetadataDetail> metadataDetailList = new Collection<MetadataDetail>();
            string metadataXmlPath = Common.Constants.MetadataXmlPath;
            string metadataValue = string.Empty;

            if (!string.IsNullOrWhiteSpace(metadataXmlPath) && File.Exists(metadataXmlPath))
            {
                metadataValue = File.ReadAllText(metadataXmlPath);
            }
            else
            {
                metadataXmlPath = HttpContext.Current.Server.MapPath("~") + "NewScientificMetadata.xml";
                if (File.Exists(metadataXmlPath))
                {
                    metadataValue = File.ReadAllText(HttpContext.Current.Server.MapPath("~") + "NewScientificMetadata.xml");
                }
            }

            if (!string.IsNullOrWhiteSpace(metadataValue))
            {
                var metadata = metadataValue.DeserializeXML<metadatalist>();

                if (metadata != null)
                {
                    foreach (var group in metadata.metadatagroup)
                    {
                        foreach (var item in group.metadata)
                        {
                            metadataDetailList.Add(new MetadataDetail()
                            {
                                Name = item.field.Trim(),
                                Description = item.description.Trim(),
                                IsRequired = item.isrequired,
                                Type = (item.type == null)? item.type: item.type.Trim()
                            });
                        }
                    }
                }
            }
            return metadataDetailList;
        }
    }
}