Пример #1
0
        public byte[] GetBinaryStateSnapshot(OpenMetaverse.UUID itemID, StopScriptReason stopScriptReason)
        {
            if (!_masterScheduler.IsRunning)
            {
                _log.ErrorFormat("[Phlox]: Unable to retrieve state data for {0} master scheduler has died", itemID);
                return(null);
            }

            StateDataRequest req = new StateDataRequest(itemID, true);

            req.DisableScriptReason = stopScriptReason;

            _exeScheduler.RequestStateData(req);
            bool success = req.WaitForData(STATE_REQUEST_TIMEOUT);

            if (req.SerializedStateData != null)
            {
                return(req.SerializedStateData);
            }
            else
            {
                _log.ErrorFormat("[Phlox]: Unable to retrieve state data for {0}, timeout: {1}", itemID,
                                 !success);

                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Serialize a scene object to the original xml format
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>
        public static void ToXmlFormat(IEnumerable <SceneObjectGroup> sceneObjects, IEnumerable <ItemPermissionBlock> permissions,
                                       XmlTextWriter writer, StopScriptReason stopScriptReason)
        {
            writer.WriteStartElement(String.Empty, "CoalescedSceneObject", String.Empty);

            //permissions
            writer.WriteStartElement(String.Empty, "CSOPermissions", String.Empty);
            foreach (ItemPermissionBlock perm in permissions)
            {
                writer.WriteStartElement(String.Empty, "CSOPermission", String.Empty);
                perm.ToXml(writer);
                writer.WriteEndElement(); // ColObjectMember
            }
            writer.WriteEndElement();

            //scene objects
            writer.WriteStartElement(String.Empty, "ColObjects", String.Empty);
            foreach (SceneObjectGroup group in sceneObjects)
            {
                writer.WriteStartElement(String.Empty, "ColObjectMember", String.Empty);
                SceneObjectSerializer.ToOriginalXmlFormat(group, writer, stopScriptReason);
                writer.WriteEndElement(); // ColObjectMember
            }
            writer.WriteEndElement();     //ColObjects


            writer.WriteEndElement(); // CoalescedSceneObject
        }
        public static string ToXml2Format(SceneObjectGroup sceneObject, StopScriptReason stopScriptReason, bool saveScriptState)
        {
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(sw))
                {
                    ToXml2Format(sceneObject, writer, stopScriptReason);
                }

                return(sw.ToString());
            }
        }
        /// <summary>
        /// Serialize a scene object to the original xml format
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>
        public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, StopScriptReason stopScriptReason)
        {
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(sw))
                {
                    ToOriginalXmlFormat(sceneObject, writer, stopScriptReason);
                }

                return(sw.ToString());
            }
        }
Пример #5
0
        public string GetStateSnapshot(bool fromCrossing)
        {
            //m_log.Debug(" >>> GetStateSnapshot <<<");

            Dictionary <UUID, string> states           = new Dictionary <UUID, string>();
            StopScriptReason          stopScriptReason = fromCrossing ? StopScriptReason.Crossing : StopScriptReason.Derez;

            foreach (SceneObjectPart part in m_parts.Values)
            {
                foreach (KeyValuePair <UUID, string> s in part.Inventory.GetScriptStates(stopScriptReason))
                {
                    states[s.Key] = s.Value;
                }
            }

            if (states.Count < 1)
            {
                return("");
            }

            XmlDocument xmldoc = new XmlDocument();

            XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
                                                "", "");

            xmldoc.AppendChild(xmlnode);
            XmlElement rootElement = xmldoc.CreateElement("", "PhloxScriptData", "");

            xmldoc.AppendChild(rootElement);

            XmlElement wrapper = xmldoc.CreateElement("", "PhloxSS",
                                                      "");

            rootElement.AppendChild(wrapper);

            foreach (KeyValuePair <UUID, string> state in states)
            {
                XmlElement stateData = xmldoc.CreateElement("", "State", "");

                XmlAttribute stateID = xmldoc.CreateAttribute("", "UUID", "");
                stateID.Value = state.Key.ToString();
                stateData.Attributes.Append(stateID);

                stateData.InnerText = state.Value;
                wrapper.AppendChild(stateData);
            }

            return(xmldoc.InnerXml);
        }
        /// <summary>
        /// Serialize a scene object to the 'xml2' format.
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>
        public static string ToXml2Format(SceneObjectGroup sceneObject, bool stopScripts)
        {
            StopScriptReason reason = stopScripts ? StopScriptReason.Derez : StopScriptReason.None;

            return(ToXml2Format(sceneObject, reason, true));
        }
        /// <summary>
        /// Serialize a scene object to the original xml format
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>
        public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, StopScriptReason stopScriptReason)
        {
            //m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", Name);
            //int time = System.Environment.TickCount;

            writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
            writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
            sceneObject.RootPart.ToXml(writer);
            writer.WriteEndElement();
            writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);

            lock (sceneObject.Children)
            {
                foreach (SceneObjectPart part in sceneObject.Children.Values)
                {
                    if (part.UUID != sceneObject.RootPart.UUID)
                    {
                        writer.WriteStartElement(String.Empty, "Part", String.Empty);
                        part.ToXml(writer);
                        writer.WriteEndElement();
                    }
                }
            }

            writer.WriteEndElement(); // OtherParts
            sceneObject.SaveScriptedState(writer, stopScriptReason);
            writer.WriteEndElement(); // SceneObjectGroup

            //m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
        }
Пример #8
0
        public void SaveScriptedState(XmlTextWriter writer, StopScriptReason stopScriptReason)
        {
            Dictionary<UUID, string> states = new Dictionary<UUID, string>();

            // Dont capture script state while holding the lock, the phlox engine thread
            // will access the m_parts lock when disabling the script
            SceneObjectPart[] parts = GetParts();

            foreach (SceneObjectPart part in parts)
            {
                Dictionary<UUID, string> pstates = part.Inventory.GetScriptStates(stopScriptReason);
                foreach (UUID itemid in pstates.Keys)
                {
                    states.Add(itemid, pstates[itemid]);
                }
            }


            if (states.Count > 0)
            {
                // Now generate the necessary XML wrappings
                writer.WriteStartElement(String.Empty, "PhloxGroupScriptStates", String.Empty);
                foreach (UUID itemid in states.Keys)
                {
                    writer.WriteStartElement(String.Empty, "PhloxSavedSS", String.Empty);
                    writer.WriteAttributeString(String.Empty, "UUID", String.Empty, itemid.ToString());
                    writer.WriteRaw(states[itemid]); // Writes ScriptState element
                    writer.WriteEndElement(); // End of SavedScriptState
                }
                writer.WriteEndElement(); // End of GroupScriptStates
            }
        }
Пример #9
0
        /// <summary>
        /// Serialize a scene object to the original xml format
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>        
        public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, StopScriptReason stopScriptReason)
        {
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(sw))
                {
                    ToOriginalXmlFormat(sceneObject, writer, stopScriptReason);
                }

                return sw.ToString();
            }
        }                
Пример #10
0
        public byte[] GetBinaryStateSnapshot(OpenMetaverse.UUID itemID, StopScriptReason stopScriptReason)
        {
            if (!_masterScheduler.IsRunning)
            {
                _log.ErrorFormat("[Phlox]: Unable to retrieve state data for {0} master scheduler has died", itemID);
                return null;
            }

            StateDataRequest req = new StateDataRequest(itemID, true);
            req.DisableScriptReason = stopScriptReason;

            _exeScheduler.RequestStateData(req);
            bool success = req.WaitForData(STATE_REQUEST_TIMEOUT);

            if (req.SerializedStateData != null)
            {
                return req.SerializedStateData;
            }
            else
            {
                _log.ErrorFormat("[Phlox]: Unable to retrieve state data for {0}, timeout: {1}", itemID,
                    !success);

                return null;
            }
        }
Пример #11
0
 public static void ToXml2Format(SceneObjectGroup sceneObject, XmlTextWriter writer, StopScriptReason stopScriptReason)
 {
     ToXml2Format(sceneObject, writer, stopScriptReason, true);
 }
        public Dictionary<UUID, byte[]> GetBinaryScriptStates(StopScriptReason stopScriptReason)
        {
            Dictionary<UUID, byte[]> ret = new Dictionary<UUID, byte[]>();

            // Make sure we have a scene before we make this call.  GetScriptStates gets called
            // from ToXml in SOG which is static and therefore a scene may not exist.
            if (m_part.ParentGroup == null || m_part.ParentGroup.Scene == null)
                return ret;

            IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
            if (engines.Length == 0)
                return ret;

            IScriptModule engine = engines[0];
            if (engine == null)     // happens under Phlox if disabled
                return ret;

            List<TaskInventoryItem> items;
            lock (m_items)
            {
                //we dont want to hold a lock here, as the script engine will be
                //holding locks and making us wait for the states during these requests
                //so we make a copy here
                items = new List<TaskInventoryItem>(m_items.Values);
            }

            foreach (TaskInventoryItem item in items)
            {
                if (item.InvType == (int)InventoryType.LSL)
                {
                    byte[] n = engine.GetBinaryStateSnapshot(item.ItemID, stopScriptReason);
                    if (n != null)
                    {
                        ret[item.ItemID] = n;
                    }
                }
            }

            return ret;
        }
Пример #13
0
        /// <summary>
        /// Serialize a scene object to the original xml format
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>
        public static string ToXmlFormat(IEnumerable <SceneObjectGroup> sceneObject, IEnumerable <ItemPermissionBlock> permissions, StopScriptReason stopScriptReason)
        {
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(sw))
                {
                    ToXmlFormat(sceneObject, permissions, writer, stopScriptReason);
                }

                return(sw.ToString());
            }
        }
Пример #14
0
        public void SaveScriptedState(XmlTextWriter writer, StopScriptReason stopScriptReason)
        {
            Dictionary<UUID, string> states = new Dictionary<UUID, string>();
            
            m_childParts.ForEachPart((SceneObjectPart part) => {
                Dictionary<UUID, string> pstates = part.Inventory.GetScriptStates(stopScriptReason);
                foreach (UUID itemid in pstates.Keys)
                {
                    states.Add(itemid, pstates[itemid]);
                }
            });

            if (states.Count > 0)
            {
                // Now generate the necessary XML wrappings
                writer.WriteStartElement(String.Empty, "PhloxGroupScriptStates", String.Empty);
                foreach (UUID itemid in states.Keys)
                {
                    writer.WriteStartElement(String.Empty, "PhloxSavedSS", String.Empty);
                    writer.WriteAttributeString(String.Empty, "UUID", String.Empty, itemid.ToString());
                    writer.WriteRaw(states[itemid]); // Writes ScriptState element
                    writer.WriteEndElement(); // End of SavedScriptState
                }
                writer.WriteEndElement(); // End of GroupScriptStates
            }
        }
Пример #15
0
        public static string ToXml2Format(SceneObjectGroup sceneObject, StopScriptReason stopScriptReason, bool saveScriptState)
        {
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(sw))
                {
                    ToXml2Format(sceneObject, writer, stopScriptReason);
                }

                return sw.ToString();
            }
        }
Пример #16
0
        /// <summary>
        /// Serialize a scene object to the 'xml2' format.
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>          
        public static void ToXml2Format(SceneObjectGroup sceneObject, XmlTextWriter writer, StopScriptReason stopScriptReason, bool saveScriptState)
        {
            //m_log.DebugFormat("[SERIALIZER]: Starting serialization of SOG {0} to XML2", Name);
            //int time = System.Environment.TickCount;

            writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
            sceneObject.RootPart.ToXml(writer);
            writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
            
            foreach (SceneObjectPart part in sceneObject.GetParts())
            {
                if (part.UUID != sceneObject.RootPart.UUID)
                {
                    part.ToXml(writer);
                }
            }

            writer.WriteEndElement(); // End of OtherParts
            if (saveScriptState)
            {
                sceneObject.SaveScriptedState(writer, stopScriptReason);
            }
            writer.WriteEndElement(); // End of SceneObjectGroup

            //m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0} to XML2, {1}ms", Name, System.Environment.TickCount - time);
        }   
Пример #17
0
 public static void ToXml2Format(SceneObjectGroup sceneObject, XmlTextWriter writer, StopScriptReason stopScriptReason)
 {
     ToXml2Format(sceneObject, writer, stopScriptReason, true);
 }
Пример #18
0
        /// <summary>
        /// Serialize a scene object to the 'xml2' format.
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>
        public static void ToXml2Format(SceneObjectGroup sceneObject, XmlTextWriter writer, StopScriptReason stopScriptReason, bool saveScriptState)
        {
            //m_log.DebugFormat("[SERIALIZER]: Starting serialization of SOG {0} to XML2", Name);
            //int time = System.Environment.TickCount;

            writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
            sceneObject.RootPart.ToXml(writer);
            writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);

            List <SceneObjectPart> parts = new List <SceneObjectPart>(sceneObject.Children.Values);

            foreach (SceneObjectPart part in parts)
            {
                if (part.UUID != sceneObject.RootPart.UUID)
                {
                    part.ToXml(writer);
                }
            }

            writer.WriteEndElement(); // End of OtherParts
            if (saveScriptState)
            {
                sceneObject.SaveScriptedState(writer, stopScriptReason);
            }
            writer.WriteEndElement(); // End of SceneObjectGroup

            //m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0} to XML2, {1}ms", Name, System.Environment.TickCount - time);
        }
        /// <summary>
        /// Serialize a scene object to the original xml format
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>        
        public static string ToXmlFormat(IEnumerable<SceneObjectGroup> sceneObject, IEnumerable<ItemPermissionBlock> permissions, StopScriptReason stopScriptReason)
        {
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(sw))
                {
                    ToXmlFormat(sceneObject, permissions, writer, stopScriptReason);
                }

                return sw.ToString();
            }
        }
        public Tuple<Dictionary<UUID, byte[]>, Dictionary<UUID, byte[]>> GetBinaryScriptStatesAndCompiledScripts(StopScriptReason stopScriptReason)
        {
            // Make sure we have a scene before we make this call.  GetScriptStates gets called
            // from ToXml in SOG which is static and therefore a scene may not exist.
            if (m_part.ParentGroup == null || m_part.ParentGroup.Scene == null)
                return new Tuple<Dictionary<UUID, byte[]>, Dictionary<UUID, byte[]>>(new Dictionary<UUID, byte[]>(), new Dictionary<UUID, byte[]>());

            IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
            if (engines.Length == 0)
                return new Tuple<Dictionary<UUID, byte[]>, Dictionary<UUID, byte[]>>(new Dictionary<UUID, byte[]>(), new Dictionary<UUID, byte[]>());

            IScriptModule engine = engines[0];
            if (engine == null)    // happens under Phlox if disabled
                return new Tuple<Dictionary<UUID, byte[]>, Dictionary<UUID, byte[]>>(new Dictionary<UUID, byte[]>(), new Dictionary<UUID, byte[]>());

            List<TaskInventoryItem> items;
            lock (m_items)
            {
                //we dont want to hold a lock here, as the script engine will be
                //holding locks and making us wait for the states during these requests
                //so we make a copy here
                items = new List<TaskInventoryItem>(m_items.Values);
            }

            var states = new Dictionary<UUID, byte[]>();
            List<UUID> scriptAssetIds = new List<UUID>();
            foreach (TaskInventoryItem item in items)
            {
                if (item.InvType == (int)InventoryType.LSL)
                {
                    scriptAssetIds.Add(item.AssetID);
                    byte[] n = engine.GetBinaryStateSnapshot(item.ItemID, stopScriptReason);
                    if (n != null)
                    {
                        states[item.ItemID] = n;
                    }
                }
            }

            Dictionary<UUID, byte[]> byteCode = engine.GetBytecodeForAssets(scriptAssetIds);

            return new Tuple<Dictionary<UUID, byte[]>, Dictionary<UUID, byte[]>>(states, byteCode);
        }
        /// <summary>
        /// Serialize a scene object to the original xml format
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <returns></returns>            
        public static void ToXmlFormat(IEnumerable<SceneObjectGroup> sceneObjects, IEnumerable<ItemPermissionBlock> permissions,
            XmlTextWriter writer, StopScriptReason stopScriptReason)
        {
            writer.WriteStartElement(String.Empty, "CoalescedSceneObject", String.Empty);

            //permissions
            writer.WriteStartElement(String.Empty, "CSOPermissions", String.Empty);
            foreach (ItemPermissionBlock perm in permissions)
            {
                writer.WriteStartElement(String.Empty, "CSOPermission", String.Empty);
                perm.ToXml(writer);
                writer.WriteEndElement(); // ColObjectMember
            }
            writer.WriteEndElement();

            //scene objects
            writer.WriteStartElement(String.Empty, "ColObjects", String.Empty);
            foreach (SceneObjectGroup group in sceneObjects)
            {
                writer.WriteStartElement(String.Empty, "ColObjectMember", String.Empty);
                SceneObjectSerializer.ToOriginalXmlFormat(group, writer, stopScriptReason);
                writer.WriteEndElement(); // ColObjectMember
            }
            writer.WriteEndElement(); //ColObjects


            writer.WriteEndElement(); // CoalescedSceneObject
        }