public static void Copy(IEnumerable <IUntypedField> fields, IFieldMap from, IFieldMap to)
 {
     foreach (var field in fields)
     {
         Copy(field, from, to);
     }
 }
Example #2
0
        public virtual void Populate(IFieldMap fieldMap, Entity entity)
        {
            var fieldsWithNoValueOnEntity = new List<string>();

            foreach (var fieldInfo in GetType().GetFields())
            {
                var uiItem = fieldInfo.GetValue(this) as UIItem;
                if (uiItem == null || !ControlDictionary.Instance.IsEditable(uiItem)) return;

                string fieldName = fieldMap.GetFieldNameFor(fieldInfo.Name, fieldInfo.FieldType);
                if (string.IsNullOrEmpty(fieldName)) return;

                try
                {
                    EntityField entityField = entity.Field(fieldName);
                    if (entityField == null)
                        fieldsWithNoValueOnEntity.Add(fieldName);
                    else
                        entityField.SetValueOn(uiItem);
                }
                catch (TargetInvocationException e)
                {
                    throw new AppScreenException(
                        string.Format("Error assigning {0}.{1} to {2}.{3} ", entity.GetType(), fieldName, GetType(), fieldInfo.Name),
                        e.InnerException);
                }
            }

            if (fieldsWithNoValueOnEntity.Count == 0) return;
            
            string message = string.Join(",", fieldsWithNoValueOnEntity.ToArray());
            logger.WarnFormat("Mapping to screen: {0} with {1}, No value specified for fields {2}", this, entity.GetType(), message);
        }
 public void AddFieldMap(string workItemTypeName, IFieldMap fieldToTagFieldMap)
 {
     if (!fieldMapps.ContainsKey(workItemTypeName))
     {
         fieldMapps.Add(workItemTypeName, new List <IFieldMap>());
     }
     fieldMapps[workItemTypeName].Add(fieldToTagFieldMap);
 }
Example #4
0
 void Copy(IEnumerable <IUntypedField> fields, IFieldMap from, IFieldMap to)
 {
     foreach (var field in fields)
     {
         Copy(field, from, to);     // <-- now compiles because
     }
     // it calls non-generic overload
 }
Example #5
0
    public void Copy(IEnumerable <IUntypedField> fields, IFieldMap from, IFieldMap to)
    {
        var genericMethod = typeof(MapCopier).GetMethod("GenericCopy");

        foreach (var field in fields)
        {
            var method = genericMethod.MakeGenericMethod(field.Type);
            method.Invoke(null, new object[] { field, from, to });
        }
    }
Example #6
0
 void Copy(IEnumerable <IUntypedField> fields, IFieldMap from, IFieldMap to)
 {
     foreach (var field in fields)
     {
         Field f = field as Field;
         if (f != null)
         {
             Copy(f, from, to);
         }
     }
 }
Example #7
0
        public virtual void Populate(IFieldMap fieldMap, Entity entity)
        {
            var fieldsWithNoValueOnEntity = new List <string>();

            foreach (var fieldInfo in GetType().GetFields())
            {
                var uiItem = fieldInfo.GetValue(this) as UIItem;
                if (uiItem == null || !ControlDictionary.Instance.IsEditable(uiItem))
                {
                    return;
                }

                string fieldName = fieldMap.GetFieldNameFor(fieldInfo.Name, fieldInfo.FieldType);
                if (string.IsNullOrEmpty(fieldName))
                {
                    return;
                }

                try
                {
                    EntityField entityField = entity.Field(fieldName);
                    if (entityField == null)
                    {
                        fieldsWithNoValueOnEntity.Add(fieldName);
                    }
                    else
                    {
                        entityField.SetValueOn(uiItem);
                    }
                }
                catch (TargetInvocationException e)
                {
                    throw new AppScreenException(
                              string.Format("Error assigning {0}.{1} to {2}.{3} ", entity.GetType(), fieldName, GetType(), fieldInfo.Name),
                              e.InnerException);
                }
            }

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

            string message = string.Join(",", fieldsWithNoValueOnEntity.ToArray());

            logger.WarnFormat("Mapping to screen: {0} with {1}, No value specified for fields {2}", this, entity.GetType(), message);
        }
    // generate Copy lambda based on passed-in type
    static void Copy(IUntypedField field, IFieldMap from, IFieldMap to)
    {
        // figure out what type we need to look up;
        // we know we have a Field<TValue>, so find TValue
        Type type = field.GetType().GetGenericArguments()[0];
        Action <IUntypedField, IFieldMap, IFieldMap> copier;

        if (!copiers.TryGetValue(type, out copier))
        {
            // copier not found; create a lambda and compile it
            Type tFieldMap = typeof(IFieldMap);
            // create parameters to lambda
            ParameterExpression
                fieldParam = Expression.Parameter(typeof(IUntypedField)),
                fromParam  = Expression.Parameter(tFieldMap),
                toParam    = Expression.Parameter(tFieldMap);
            // create expression for "(Field<TValue>)field"
            var converter = Expression.Convert(fieldParam, field.GetType());
            // create expression for "to.Put(field, from.Get(field))"
            var copierExp =
                Expression.Call(
                    toParam,
                    tFieldMap.GetMethod("Put").MakeGenericMethod(type),
                    converter,
                    Expression.Call(
                        fromParam,
                        tFieldMap.GetMethod("Get").MakeGenericMethod(type),
                        converter));
            // create our lambda and compile it
            copier =
                Expression.Lambda <Action <IUntypedField, IFieldMap, IFieldMap> >(
                    copierExp,
                    fieldParam,
                    fromParam,
                    toParam)
                .Compile();
            // add the compiled lambda to the cache
            copiers[type] = copier;
        }
        // invoke the actual copy lambda
        copier(field, from, to);
    }
Example #9
0
 void Copy(Field field, IFieldMap from, IFieldMap to)
 {
     to.Put(field, from.Get(field));
 }
        public static void LoadAttributeTransfer(IApplication app, List <AttributeTransferDetails> attTransferDetails)
        {
            IEditor                  editor        = null;
            UID                      pUID          = null;
            IAttributeTransfer       pAttTrans     = null;
            IAttributeTransferType   pAttTransType = null;
            IFieldMap                pFieldMap     = null;
            AttributeTransferDetails attConfig     = null;
            IFeatureLayer            pSfl          = null;
            IFeatureLayer            pTfl          = null;
            IField                   pSourceField  = null;
            IField                   pTargetField  = null;

            ICommandItem pCmdItem = null;
            IAttributeTransferDefaultSettings pATDS = null;

            try
            {
                editor = Globals.getEditor(app);

                if (editor.EditState == esriEditState.esriStateNotEditing)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg") + " " + A4LGSharedFunctions.Localizer.GetString("StrtEditing"));
                    return;
                }

                if (attTransferDetails == null)
                {
                    return;
                }
                if (attTransferDetails.Count == 0)
                {
                    return;
                }


                pAttTransType = (IAttributeTransferType)editor;
                pAttTrans     = pAttTransType.AttributeTransfer;



                for (int j = 0; j < attTransferDetails.Count; j++)
                {
                    attConfig = attTransferDetails[j];

                    string aSourceName     = attConfig.SourceLayerName;
                    string aTargetName     = attConfig.TargetLayerName;
                    bool   FCorLayerSource = true;
                    bool   FCorLayerTarget = true;
                    pSfl = Globals.FindLayer(app, aSourceName, ref FCorLayerSource) as IFeatureLayer;
                    pTfl = Globals.FindLayer(app, aTargetName, ref FCorLayerTarget) as IFeatureLayer;
                    if (pSfl == null || pTfl == null)
                    {
                        //MessageBox.Show("The source or target layer is not present");
                        //return;
                    }
                    else
                    {
                        pFieldMap = pAttTrans.FindFieldMap(pSfl.FeatureClass, pTfl.FeatureClass);
                        if (pFieldMap != null)
                        {
                            pAttTrans.DeleteFieldMap(pFieldMap);
                        }
                        pFieldMap = new FieldMapClass();

                        pFieldMap.SourceClass = pSfl.FeatureClass;
                        pFieldMap.TargetClass = pTfl.FeatureClass;



                        for (int i = 0; i < attConfig.FromToFields.Length; i++)
                        {
                            if (attConfig.FromToFields[i] == null)
                            {
                                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("AttrTrasftLoadRError_1"));
                                return;
                            }
                            if (attConfig.FromToFields[i].SourceField == null || attConfig.FromToFields[i].TargetField == null)
                            {
                                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("AttrTrasftLoadRError_1"));
                                return;
                            }
                            pSourceField = Globals.GetField(pSfl.FeatureClass.Fields, attConfig.FromToFields[i].SourceField);
                            pTargetField = Globals.GetField(pTfl.FeatureClass.Fields, attConfig.FromToFields[i].TargetField);
                            if (pSourceField != null && pTargetField != null)
                            {
                                pFieldMap.SetFieldMap(pSourceField, pTargetField);
                            }
                        }


                        pAttTrans.FieldMap = pFieldMap;

                        pATDS = (IAttributeTransferDefaultSettings)pAttTrans;

                        pATDS.SourceName = aSourceName;
                        pATDS.TargetName = aTargetName;
                    }
                }


                pUID       = new UIDClass();
                pUID.Value = "esriEditorExt.FieldMappingCommand";


                app.CurrentTool = null;


                pCmdItem = app.Document.CommandBars.Find(pUID);
                pCmdItem.Execute();
            }
            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + "LoadAttributeTransfer: " + ex.ToString());
            }
            finally
            {
                editor        = null;
                pUID          = null;
                pAttTrans     = null;
                pAttTransType = null;
                pFieldMap     = null;
                attConfig     = null;
                pSfl          = null;
                pTfl          = null;
                pSourceField  = null;
                pTargetField  = null;

                pCmdItem = null;
                pATDS    = null;
            }
        }
Example #11
0
 private static void GenericCopy <TValue>(Field <TValue> field, IFieldMap from, IFieldMap to)
 {
     to.Put(field, from.Get(field));
 }
Example #12
0
 void Copy <TValue>(Field <TValue> field, IFieldMap from, IFieldMap to)
 {
     to.Put(field, from.Get(field));
 }
Example #13
0
 // non-generic overload of Copy
 void Copy(IUntypedField field, IFieldMap from, IFieldMap to)
 {
     to.PutObject(field, from.GetObject(field));
 }
Example #14
0
 protected override string GetKeyForItem(IFieldMap <TRecord> item)
 {
     return(item.FieldName);
 }