Esempio n. 1
0
        private void CleanMaps()
        {
            foreach (MappedProperty mp in RequestMap.MappedProperties.ToArray())
            {
                var existing = (from p in MappableProperties.Cast <DbProperty>()
                                where p.Id == mp.Source.Id &&
                                p.Name == mp.Source.Name &&
                                (p.PropertyType == DbPropertyType.In ||
                                 p.PropertyType == DbPropertyType.InOut)
                                select p).LastOrDefault();

                if (existing == null)
                {
                    if (mp.Id != Guid.Empty)
                    {
                        if (!mappedPropertiesToDelete.ContainsKey(RequestMap))
                        {
                            mappedPropertiesToDelete.Add(RequestMap, new List <MappedProperty>());
                        }

                        mappedPropertiesToDelete[RequestMap].Add(mp);
                    }

                    RequestMap.MappedProperties.Remove(mp);
                }
            }

            foreach (MappedProperty mp in ResponseMap.MappedProperties.ToArray())
            {
                var existing = (from p in MappableProperties.Cast <DbProperty>()
                                where p.Id == mp.Source.Id &&
                                p.Name == mp.Source.Name &&
                                (p.PropertyType == DbPropertyType.Out ||
                                 p.PropertyType == DbPropertyType.InOut)
                                select p).LastOrDefault();

                if (existing == null)
                {
                    if (mp.Id != Guid.Empty)
                    {
                        if (!mappedPropertiesToDelete.ContainsKey(ResponseMap))
                        {
                            mappedPropertiesToDelete.Add(ResponseMap, new List <MappedProperty>());
                        }

                        mappedPropertiesToDelete[ResponseMap].Add(mp);
                    }

                    ResponseMap.MappedProperties.Remove(mp);
                }
            }
        }
Esempio n. 2
0
        public void Map()
        {
            propertyListView.Items.Clear();
            detailGrid.SelectedObject = null;

            if (RequestMap == null)
            {
                RequestMap = new PropertyMap();
            }

            if (ResponseMap == null)
            {
                ResponseMap = new PropertyMap();
            }

            CleanMaps();

            foreach (DbProperty dbProperty in MappableProperties.Cast <DbProperty>())
            {
                MappedProperty mappedProperty = null;

                if (dbProperty.PropertyType == DbPropertyType.In || dbProperty.PropertyType == DbPropertyType.InOut)
                {
                    var temp = (from mp in RequestMap.MappedProperties
                                where mp.Source.Name == dbProperty.Name
                                select mp).LastOrDefault();

                    if (temp == null)
                    {
                        temp             = new MappedProperty();
                        temp.PropertyMap = RequestMap;
                        temp.IsEnabled   = true;
                        temp.IsMandatory = dbProperty.IsMandatory.GetValueOrDefault();
                        temp.Sequence    = dbProperty.Sequence;
                        temp.Target      = FindTargetProperty(dbProperty);
                        RequestMap.MappedProperties.Add(temp);
                    }

                    temp.Source = dbProperty;

                    if (FindTargetProperty(dbProperty) != null)
                    {
                        existingProperties.Add(temp);
                    }

                    mappedProperty = temp;
                }

                if (dbProperty.PropertyType == DbPropertyType.Out || dbProperty.PropertyType == DbPropertyType.InOut)
                {
                    var temp = (from mp in ResponseMap.MappedProperties
                                where mp.Source.Name == dbProperty.Name
                                select mp).LastOrDefault();

                    if (temp == null)
                    {
                        temp             = new MappedProperty();
                        temp.PropertyMap = ResponseMap;
                        temp.IsEnabled   = true;
                        temp.IsMandatory = dbProperty.IsMandatory.GetValueOrDefault();
                        temp.Sequence    = dbProperty.Sequence;
                        temp.Target      = FindTargetProperty(dbProperty);
                        ResponseMap.MappedProperties.Add(temp);
                    }

                    temp.Source = dbProperty;

                    if (mappedProperty == null)
                    {
                        if (FindTargetProperty(dbProperty) != null)
                        {
                            existingProperties.Add(temp);
                        }

                        mappedProperty = temp;
                    }
                }

                ListViewItem item = propertyListView.Items.Add(dbProperty.PropertyType.ToString());
                item.SubItems.Add(mappedProperty.Source.Name);
                item.SubItems.Add(GetDataTypeName(mappedProperty));

                if (string.IsNullOrEmpty(mappedProperty.Name))
                {
                    if (mappedProperty.Target != null)
                    {
                        item.SubItems.Add(mappedProperty.Target.Name);
                    }
                    else
                    {
                        item.SubItems.Add("");
                    }
                }
                else
                {
                    item.SubItems.Add(mappedProperty.Name);
                }

                if ((mappedProperty.Target != null) && (mappedProperty.Target.Type != null))
                {
                    item.SubItems.Add(mappedProperty.Target.Type.ToString());
                }
                else
                {
                    item.SubItems.Add("");
                }

                item.Tag = mappedProperty;
            }

            UpdateListViewColors();
            EnableDisableButtons();
        }