Source

main / Source / WebClient / Web.BizLogic / Extensions / MetadataDetailListExtension.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataUp.Web.BizLogic
{
    public static class MetadataDetailListExtension
    {
        public static void UpdateFrom(this MetadataDetailList thisObject, MetadataDetailList actual)
        {
            if (thisObject != null && thisObject.Metadata != null && actual != null && actual.Metadata != null)
            {
                foreach (var item in thisObject.Metadata)
                {
                    var actualMetadata = actual.Metadata.Where(m => string.Compare(m.Name, item.Name, true) == 0).FirstOrDefault();
                    if (actualMetadata != null)
                    {
                        item.Value = actualMetadata.Value;
                    }
                }
            }

            if (thisObject != null && thisObject.ParamterMetadata != null && actual != null && actual.ParamterMetadata != null)
            {
                foreach (var item in actual.ParamterMetadata)
                {
                    var attributeList = item.AttributeList.Distinct(new ParameterAttributeComparer());
                    thisObject.ParamterMetadata.Add(new ParameterMetadataDetail
                        {
                            EntityName = item.EntityName,
                             EntityDescription = item.EntityDescription,
                              AttributeList = attributeList.ToList()
                        });
                    //ParameterMetadataDetail detail = null;
                    //var actualMetadata = actual.ParamterMetadata.
                    //    Where(m => (string.Compare(m.Name, item.Name, true) == 0 
                    //        && string.Compare(m.Type, item.Type, true) == 0 
                    //        && string.Compare(m.Units, item.Units, true) == 0 
                    //        && string.Compare(m.Description, item.Description, true) == 0)).FirstOrDefault();
                    //if (actualMetadata != null)
                    //{
                    //    detail = new ParameterMetadataDetail();
                    //    detail.Name = actualMetadata.Name;
                    //    detail.Description = actualMetadata.Description;
                    //    detail.Type = actualMetadata.Type;
                    //    detail.Units = actualMetadata.Units;
                    //    thisObject.ParamterMetadata.Add(detail);
                    //}
                }
            }
        }

    }


}