OpenSim.Region.Framework.Scenes.Scene.Backup C# (CSharp) Method

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
        public void Backup(bool forced)
        {
            lock (m_returns)
            {
                EventManager.TriggerOnBackup(SimulationDataService, forced);
                m_backingup = false;

                foreach (KeyValuePair<UUID, ReturnInfo> ret in m_returns)
                {
                    UUID transaction = UUID.Random();

                    GridInstantMessage msg = new GridInstantMessage();
                    msg.fromAgentID = new Guid(UUID.Zero.ToString()); // From server
                    msg.toAgentID = new Guid(ret.Key.ToString());
                    msg.imSessionID = new Guid(transaction.ToString());
                    msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
                    msg.fromAgentName = "Server";
                    msg.dialog = (byte)19; // Object msg
                    msg.fromGroup = false;
                    msg.offline = (byte)1;
                    msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
                    msg.Position = Vector3.Zero;
                    msg.RegionID = RegionInfo.RegionID.Guid;
                    msg.binaryBucket = new byte[0];
                    if (ret.Value.count > 1)
                        msg.message = string.Format("Your {0} objects were returned from {1} in region {2} due to {3}", ret.Value.count, ret.Value.location.ToString(), RegionInfo.RegionName, ret.Value.reason);
                    else
                        msg.message = string.Format("Your object {0} was returned from {1} in region {2} due to {3}", ret.Value.objectName, ret.Value.location.ToString(), RegionInfo.RegionName, ret.Value.reason);

                    IMessageTransferModule tr = RequestModuleInterface<IMessageTransferModule>();
                    if (tr != null)
                        tr.SendInstantMessage(msg, delegate(bool success) {});
                }
                m_returns.Clear();
            }
        }

Usage Example

Ejemplo n.º 1
0
        /// <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();
        }
Scene