Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            OldToNewIdMapping o = obj as OldToNewIdMapping;

            if (o != null)
            {
                return(o.Uuid == this.Uuid);
            }
            else
            {
                return(base.Equals(obj));
            }
        }
Ejemplo n.º 2
0
        private HashSet <OldToNewIdMapping> RestoreData(Database restoreTo, ILogger logger)
        {
            HashSet <OldToNewIdMapping> result = new HashSet <OldToNewIdMapping>();

            DatabaseToRestoreTo = restoreTo;
            DatabaseToRestoreTo.TryEnsureSchema(DaoTypes.First(), logger);

            Dictionary <string, Dao> tempForeignKeyTargets = InsertTempForeignKeyTargets();

            // for all the poco types load them all from the repo
            foreach (Type pocoType in BackupRepository.StorableTypes)
            {
                // copy the poco as a dao and save it into the restoreTo
                IEnumerable <object> all = BackupRepository.RetrieveAll(pocoType);
                Type daoType             = DaoTypes.FirstOrDefault(t => t.Name.Equals(pocoType.Name));
                Args.ThrowIf <InvalidOperationException>(daoType == null, "The Dto of type {0} didn't have a corresponding Dao type", pocoType.Name);

                foreach (object poco in all)
                {
                    string uuid = Meta.GetUuid(poco, true);
                    Dao    dao  = (Dao)poco.CopyAs(daoType);
                    dao.IdValue              = null;
                    dao.DataRow              = null;
                    dao.ForceInsert          = true;
                    dao.UniqueFilterProvider = () =>
                    {
                        return(Query.Where("Uuid") == uuid);
                    };
                    ForceUpdateIfExistsInTarget(uuid, dao);
                    SetTemporaryForeignKeys(dao, tempForeignKeyTargets);

                    dao.Save(DatabaseToRestoreTo);
                    OldToNewIdMapping idMapping = new OldToNewIdMapping
                    {
                        PocoType = pocoType,
                        DaoType  = daoType,
                        OldId    = (long)poco.Property("Id"),
                        NewId    = (long)dao.IdValue,
                        Uuid     = uuid
                    };

                    result.Add(idMapping);
                }
            }
            return(result);
        }