Example #1
0
        private void SetInputField(Dictionary <string, object> row, TransformationField fld)
        {
            try
            {
                object rowVal = null;

                if (fld.IsGlobalVar)
                {
                    rowVal = fld.GlobalVal;
                }
                else
                {
                    rowVal = row[fld.Map];
                }

                if (rowVal != null && fld.PropertySet != null)
                {
                    fld.PropertySet(this, rowVal);
                }
                else if (fld.Required)
                {
                    throw new TransformationException(string.Format("{1} ({0}) is Empty and Required", fld.Name, fld.Map));
                }
                else
                {
                    fld.PropertySet(this, fld.PropertyDefault);
                }
            }
            catch (Exception ex)
            {
                throw new TransformationException(string.Format("{0} - {2} ({1})", ex.Message, fld.Name, fld.Map));
            }
        }
Example #2
0
        private void SetupInputOutputFields(XElement mappingConfigXML, PropertyInfo property, TransformationFieldAttrib attr, string PropName)
        {
            if ((attr.FieldType == TransformationFieldTypeEnum.Input || attr.FieldType == TransformationFieldTypeEnum.InOut) && !property.CanWrite)
            {
                throw new ConfigException(string.Format("{0} Input Transformation Properties Must be Writtable", PropName));
            }

            var mappedName = mappingConfigXML == null || mappingConfigXML.Element(PropName) == null ? "" : mappingConfigXML.Element(PropName).ToString();
            var tranFld    = new TransformationField()
            {
                Name     = PropName,
                Map      = !string.IsNullOrEmpty(mappedName) ? mappedName : PropName,
                Required = attr.Required,
                FldType  = attr.FieldType,
            };

            if (tranFld.Map.StartsWith("@"))
            {
                tranFld.IsGlobalVar = true;
                object globalObject = null;
                GlobalData.Data.TryGetValue(tranFld.Map, out globalObject);

                tranFld.GlobalVal = globalObject;
            }

            tranFld.PropertyDefault = property.PropertyType.IsValueType ? Activator.CreateInstance(property.PropertyType) : null;
            tranFld.PropertyGet     = LinqAccessors.BuildGetAccessor(property.GetGetMethod());
            tranFld.PropertySet     = LinqAccessors.BuildSetAccessor(property.GetSetMethod());

            if (attr.FieldType == TransformationFieldTypeEnum.Input || attr.FieldType == TransformationFieldTypeEnum.InOut)
            {
                _inputfields.Add(tranFld);
            }

            if (attr.FieldType == TransformationFieldTypeEnum.Output || attr.FieldType == TransformationFieldTypeEnum.InOut)
            {
                _outputfields.Add(tranFld);
            }
        }