Backup() public method

Backup the scene. This acts as the main method of the backup thread.
public Backup ( bool forced ) : void
forced bool
return void
示例#1
0
文件: CMModel.cs 项目: ChrisD/opensim
        /// <summary>
        /// Retrieves the latest revision of a region in xml form,
        /// converts it to scene object groups and scene presences,
        /// swaps the current scene's entity list with the revision's list.
        /// Note: Since deleted objects while
        /// </summary>
        public void RollbackRegion(Scene scene)
        {
            System.Collections.ArrayList xmllist = null;
            SceneObjectGroup temp = null;
            System.Collections.Hashtable deleteListUUIDs = new Hashtable();
//            Dictionary<LLUUID, EntityBase> SearchList = new Dictionary<LLUUID,EntityBase>();
            Dictionary<UUID, EntityBase> ReplacementList = new Dictionary<UUID,EntityBase>();
            int revision = m_database.GetMostRecentRevision(scene.RegionInfo.RegionID);
//            EntityBase[] searchArray;

            xmllist = m_database.GetRegionObjectXMLList(scene.RegionInfo.RegionID, revision);
            if (xmllist == null)
            {
                m_log.Info("[CMMODEL]: Region (" + scene.RegionInfo.RegionID + ") does not have given revision number (" + revision + ").");
                return;
            }

            m_log.Info("[CMMODEL]: Region (" + scene.RegionInfo.RegionID + ") revision number (" + revision + ").");
            m_log.Info("[CMMODEL]: Scene Objects = " + xmllist.Count);
            m_log.Info("[CMMODEL]: Converting scene entities list to specified revision.");

            m_log.ErrorFormat("[CMMODEL]: 1");

            foreach (string xml in xmllist)
            {
                try
                {
                    temp = SceneObjectSerializer.FromXml2Format(xml);
                    temp.SetScene(scene);
                    foreach (SceneObjectPart part in temp.Children.Values)
                        part.RegionHandle = scene.RegionInfo.RegionHandle;
                    ReplacementList.Add(temp.UUID, (EntityBase)temp);
                }
                catch (Exception e)
                {
                    m_log.Info("[CMMODEL]: Error while creating replacement list for rollback: " + e);
                }
            }

            //If in scene but not in revision and not a client, remove them
            while (true)
            {
                try
                {
                    foreach (EntityBase entity in scene.GetEntities())
                    {
                        if (entity == null)
                            continue;

                        if (entity is ScenePresence)
                        {
                            ReplacementList.Add(entity.UUID, entity);
                            continue;
                        }
                        else //if (!ReplacementList.ContainsKey(entity.UUID))
                            deleteListUUIDs.Add(entity.UUID, 0);
                    }
                }
                catch(Exception e)
                {
                    m_log.ErrorFormat("[CMMODEL]: " + e);
                    deleteListUUIDs.Clear();
                    ReplacementList.Clear();
                    continue;
                }
                break;
            }

            foreach (UUID uuid in deleteListUUIDs.Keys)
            {
                try
                {
                    // I thought that the DeleteGroup() function would handle all of this, but it doesn't. I'm not sure WHAT it handles.
                    ((SceneObjectGroup)scene.Entities[uuid]).DetachFromBackup();
                    scene.PhysicsScene.RemovePrim(((SceneObjectGroup)scene.Entities[uuid]).RootPart.PhysActor);
                    scene.SendKillObject(scene.Entities[uuid].LocalId);
                    scene.SceneGraph.DeleteSceneObject(uuid, false);
                    ((SceneObjectGroup)scene.Entities[uuid]).DeleteGroup(false);
                }
                catch(Exception e)
                {
                    m_log.ErrorFormat("[CMMODEL]: Error while removing objects from scene: " + e);
                }
            }

            lock (scene)
            {
                scene.Entities.Clear();

                foreach (KeyValuePair<UUID,EntityBase> kvp in ReplacementList)
                {
                    scene.Entities.Add(kvp.Value);
                }
            }

            foreach (EntityBase ent in ReplacementList.Values)
            {
                try
                {
                    if (!(ent is SceneObjectGroup))
                        continue;

                    if ((((SceneObjectGroup)ent).RootPart.GetEffectiveObjectFlags() & (uint) PrimFlags.Phantom) == 0)
                        ((SceneObjectGroup)ent).ApplyPhysics(true);
                    ((SceneObjectGroup)ent).AttachToBackup();
                    ((SceneObjectGroup)ent).HasGroupChanged = true; // If not true, then attaching to backup does nothing because no change is detected.
                    ((SceneObjectGroup)ent).ScheduleGroupForFullUpdate();
                }
                catch(Exception e)
                {
                    m_log.ErrorFormat("[CMMODEL]: Error while attaching new scene entities to backup and scheduling for a full update: " + e);
                }
            }
            m_log.Info("[CMMODEL]: Scheduling a backup of new scene object groups to backup.");
            scene.Backup();
        }