public override void Clone(SaveableData Data)
        {
            SaveAbleMapping otherMapping = Data as SaveAbleMapping;

            _mappings = new KeyValuePreset();
            otherMapping.Mappings.SyncDic();

            foreach (string key in otherMapping.Mappings.Keys)
            {
                _mappings.PushItem(key, otherMapping.Mappings.GetValue(key));
            }
        }
Exemplo n.º 2
0
        public void SaveMappings(string inPath)
        {
            SaveAbleMapping mappping = new SaveAbleMapping();

            foreach (DataEntity entity in _comparisons.Keys)
            {
                List <DataEntity> entities = GetConfirmedAssociations(entity);
                if (entities.Count > 0)
                {
                    string items = "";
                    foreach (DataEntity assocEntity in entities)
                    {
                        items += (items == "" ? "" : ";") + assocEntity.Comparable.Name + "|" + assocEntity.Id;
                    }
                    mappping.Mappings.PushItem(entity.Comparable.Name + "|" + entity.Id, items);
                }
                else if (entity.AssociatedEntity != null)
                {
                    mappping.Mappings.PushItem(entity.Comparable.Name + "|" + entity.Id, entity.AssociatedEntity.Comparable.Name + "|" + entity.AssociatedEntity.Id);
                }
            }

            mappping.Save(inPath, true);
        }
Exemplo n.º 3
0
        public void LoadMappings(string inPath)
        {
            SaveAbleMapping mappping = new SaveAbleMapping();

            mappping.Load(inPath);
            mappping.Mappings.SyncDic();

            Dictionary <DataEntity, List <DataEntity> > assocs = new Dictionary <DataEntity, List <DataEntity> >();

            foreach (string key in mappping.Mappings.Keys)
            {
                string[] nameSplit  = key.Split('|');
                string   entityName = nameSplit[1];

                DataEntity entity = GetEntity(entityName, true);
                if (entity != null)
                {
                    string[] mappings = ((string)mappping.Mappings.GetValue(key)).Split(';');
                    foreach (string mapping in mappings)
                    {
                        string[]   nameSplit2  = mapping.Split('|');
                        string     entityName2 = nameSplit2[1];
                        DataEntity otherEntity = GetEntity(entityName2, false);
                        if (otherEntity != null)
                        {
                            if (assocs.ContainsKey(entity))
                            {
                                assocs[entity].Add(otherEntity);
                            }
                            else
                            {
                                List <DataEntity> entities = new List <DataEntity>();
                                entities.Add(otherEntity);
                                assocs.Add(entity, entities);
                            }
                        }
                    }
                }
            }

            foreach (DataEntity key in assocs.Keys)
            {
                List <DataEntity> newAssocs = assocs[key];
                List <DataEntity> oldAssocs = GetConfirmedAssociations(key);
                if (oldAssocs.Count > 0)
                {
                    foreach (DataEntity assocEntity in oldAssocs)
                    {
                        if (!newAssocs.Contains(assocEntity))
                        {
                            DeAssociate(key, assocEntity);
                        }
                    }
                }
                else
                {
                    if (newAssocs.Count == 1)
                    {
                        if (key.AssociatedEntity != newAssocs[0])
                        {
                            Associate(key, newAssocs[0]);
                        }
                    }
                    else
                    {
                        if (newAssocs.Count == 0)
                        {
                            if (key.AssociatedEntity != null)
                            {
                                key.DontAssociate = true;
                            }
                        }
                        else
                        {
                            foreach (DataEntity assocEntity in newAssocs)
                            {
                                if (!oldAssocs.Contains(assocEntity))
                                {
                                    Associate(key, assocEntity);
                                }
                            }
                        }
                    }
                }
            }

            AssociateEntities();
        }