Exemplo n.º 1
0
        /// <summary>
        /// Creates a logical item given a data source item.
        /// </summary>
        /// <param name="sourceProperties">The source properties.</param>
        /// <param name="item">The data source item.</param>
        /// <returns></returns>
        protected virtual T GetLogicalItem(PropertyDescriptorCollection sourceProperties, object item)
        {
            T logicalItem = this.CreateInstance();

            PropertyDescriptorCollection targetProperties =
                GetListItemPropertiesByType(logicalItem.GetType());

            IEnumerator <PropertyMapping> enumerator = this.PropertyMappings.GetEnumerator();

            while (enumerator.MoveNext())
            {
                PropertyMapping mapping = enumerator.Current;
                if (!this.ShouldApplyMapping(mapping))
                {
                    continue;
                }

                PropertyDescriptor sourceProp = sourceProperties.Find(mapping.DataSourceItemProperty, true);
                if (sourceProp != null)
                {
                    object             value      = sourceProp.GetValue(item);
                    PropertyDescriptor targetProp = targetProperties.Find(mapping.LogicalItemProperty, true);
                    if (targetProp != null)
                    {
                        if (mapping.ConvertToLogicalValue != null)
                        {
                            value = mapping.ConvertToLogicalValue(value, sourceProp.Converter);
                        }
                        targetProp.SetValue(logicalItem, value);
                    }
                    else
                    {
                        this.ProcessDataSourceValue(logicalItem, mapping, value);
                    }
                }
                else
                {
                    PropertyDescriptor targetProp = targetProperties.Find(mapping.LogicalItemProperty, true);
                    if (targetProp != null)
                    {
                        this.OnSourcePropertyNotFound(item, mapping, targetProp, logicalItem);
                    }
                }
            }

            logicalItem.SetDataItem(item);
            return(logicalItem);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the data item properties.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="logicalItem">The logical item.</param>
        protected virtual void UpdateDataItemProperties(object item, T logicalItem)
        {
            //this.OnUpdateDataSourceItemBegin();

            IEnumerator <PropertyMapping> enumerator = this.PropertyMappings.GetEnumerator();

            while (enumerator.MoveNext())
            {
                PropertyMapping mapping = enumerator.Current;
                if (!this.UpdateDataItemProperty(item, logicalItem, mapping))
                {
                    continue;
                }
            }

            //this.OnUpdateDataSourceItemEnd();
        }
Exemplo n.º 3
0
        //protected virtual void OnUpdateDataSourceItemBegin()
        //{
        //}

        //protected virtual void OnUpdateDataSourceItemEnd()
        //{
        //}

        protected virtual void ProcessLogicalItem(T logicalItem, object dataSourceItem, PropertyMapping mapping, PropertyDescriptor dataItemProperty)
        {
        }
Exemplo n.º 4
0
 /// <summary>
 /// Called to process a value from the data source when the target sheduler item property
 /// as per the mapping cannot be found.
 /// </summary>
 /// <param name="logicalItem">The logical item.</param>
 /// <param name="mapping">The mapping.</param>
 /// <param name="value">The value.</param>
 protected virtual void ProcessDataSourceValue(T logicalItem, PropertyMapping mapping, object value)
 {
 }
Exemplo n.º 5
0
 protected virtual bool ShouldApplyMapping(PropertyMapping mapping)
 {
     return(true);
 }
Exemplo n.º 6
0
 protected virtual void OnSourcePropertyNotFound(object dataItem, PropertyMapping mapping, PropertyDescriptor targetProp, object logicalItem)
 {
     //called in inheritors
 }