public void ScriptStateToXml(XmlTextWriter writer) { List <ObjectPart> parts = Values; writer.WriteStartElement("ScriptData"); bool haveScriptState = false; foreach (ObjectPart p in parts) { foreach (ObjectPartInventoryItem i in p.Inventory.Values) { IScriptState scriptState = i.ScriptState; if (scriptState != null) { if (!haveScriptState) { writer.WriteStartElement("ScriptStates"); haveScriptState = true; } writer.WriteStartElement("State"); writer.WriteAttributeString("UUID", i.ID.ToString()); scriptState.ToXml(writer); writer.WriteEndElement(); } } } if (haveScriptState) { writer.WriteEndElement(); } writer.WriteEndElement(); }
public string Evaluate(ITask task, IScriptState scriptState, string scriptBody) { var options = ScriptOptions.Default; options = AddSystemImports(options); options = AddCakeApiImports(options); options = AddCakeModuleImports(options, task, scriptState); object result = null; var currentTaskName = scriptState.CurrentTask == null ? "<none>" : scriptState.CurrentTask.Name; var currentTaskType = scriptState.CurrentTask == null ? "" : scriptState.CurrentTask.GetType().Name; try { CSharpScript.EvaluateAsync(scriptBody, options, scriptState) .ContinueWith(s => result = s.Result) .Wait(); } catch (CompilationErrorException e) { Log.Error("Failed to compile script {Type} '{Name}': {Diag}", currentTaskType, currentTaskName, string.Join(Environment.NewLine, e.Diagnostics)); throw; } catch (Exception e) { Log.Error("Failed to execute script {Type} '{Name}'", currentTaskType, currentTaskName, e); throw; } return((result as string)?.TrimEnd()); }
public string GenerateAllParts(ITask scriptTask, IScriptState scriptState) { return(string.Concat( GeneratePart(scriptTask, TaskPart.Header, scriptState), GeneratePart(scriptTask, TaskPart.Body, scriptState), GeneratePart(scriptTask, TaskPart.Footer, scriptState) )); }
public void SetLoadedScriptState(string engineName, IScriptState state) { if (m_ScriptStates == null) { Interlocked.CompareExchange(ref m_ScriptStates, new Dictionary <string, IScriptState>(), null); } m_ScriptStates[engineName] = state; }
public bool TryGetScriptState(string enginename, out IScriptState state) { state = ScriptState; if (state != null) { /* if set, ScriptState variable takes precedence */ return(true); } state = default(IScriptState); if (m_ScriptStates?.TryGetValue(enginename, out state) ?? false) { m_ScriptStates = null; } return(false); }
public string GeneratePart(ITask scriptTask, TaskPart TaskPart, IScriptState scriptState) { var scriptPath = scriptPathProvider.GetPath(scriptTask, TaskPart); var isTemplateOptional = TaskPart != TaskPart.Body; var scriptBody = templateFileProvider.GetFileContents(scriptPath, isTemplateOptional); if (scriptBody == null) { return(null); } try { scriptState.CurrentTask = scriptTask; Log.Info("Generating {TaskPart} of {Type} '{ScriptTaskName}'.", TaskPart, scriptTask.GetType().Name, scriptTask.Name); Log.IncreaseIndent(); return(scriptEvaluator.Evaluate(scriptTask, scriptState, scriptBody)); } finally { scriptState.CurrentTask = null; Log.DecreaseIndent(); } }
protected void RemoveScene(SceneInterface s) { ScriptThreadPool.Shutdown(); m_ParcelAccessManager.Stop(); Environment.OnEnvironmentControllerChangeParams -= StoreEnvironmentControllerData; Environment.Stop(); PathfindingService?.Stop(); int serializedcount = 0; foreach (ObjectPart part in Primitives) { foreach (ObjectPartInventoryItem item in part.Inventory.Values) { IScriptState state = item.ScriptState; if (state != null) { try { m_SimulationDataStorage.ScriptStates[ID, part.ID, item.ID] = state.ToDbSerializedState(); if (++serializedcount % 50 == 0) { m_Log.InfoFormat("Serialized {0} script states", serializedcount); } } catch (Exception e) { m_Log.ErrorFormat("Script state serialization failed for {0} ({1}): prim {2} ({3}): item {4} ({5}): {6}: {7}\n{8}", Name, ID, part.Name, part.ID, item.Name, item.ID, e.GetType().FullName, e.Message, e.StackTrace); } } } } if (serializedcount == 1) { m_Log.InfoFormat("Serialized {0} script state", serializedcount); } else if (serializedcount % 50 != 0) { m_Log.InfoFormat("Serialized {0} script states", serializedcount); } m_RestartObject = null; if (m_NeighborService != null) { RegionInfo rInfo = s.GetRegionInfo(); rInfo.Flags &= ~RegionFlags.RegionOnline; m_NeighborService.NotifyNeighborStatus(rInfo); } if (m_SceneListener != null) { m_SceneListener.StopStorageThread(); SceneListeners.Remove(m_SceneListener); } if (m_TerrainListener != null) { m_TerrainListener.StopStorageThread(); Terrain.TerrainListeners.Remove(m_TerrainListener); } if (m_IMRouter != null) { m_IMRouter.SceneIM.Remove(IMSend); } UDPCircuitsManager udpServer = m_UDPServer; udpServer?.Shutdown(); m_UDPServer = null; }
private ScriptOptions AddCakeModuleImports(ScriptOptions scriptOptions, ITask task, IScriptState scriptState) { return(scriptOptions .AddReferences(task.GetType().GetTypeInfo().Assembly) .AddImports(scriptState.GetType().Namespace) .AddImports(task.GetType().Namespace)); }
public void ToXml(XmlTextWriter writer, UGUI nextOwner, Vector3 offsetpos, XmlSerializationOptions options = XmlSerializationOptions.None, bool writeOffsetPos = true) { List <ObjectPart> parts = Values; writer.WriteStartElement("SceneObjectGroup"); if (writeOffsetPos) { Vector3 opos = Position - offsetpos; writer.WriteAttributeString("x", opos.X.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("y", opos.Y.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("z", opos.Z.ToString(System.Globalization.CultureInfo.InvariantCulture)); } if ((options & XmlSerializationOptions.WriteXml2) == 0) { writer.WriteStartElement("RootPart"); } RootPart.ToXml(writer, options); if ((options & XmlSerializationOptions.WriteXml2) == 0) { writer.WriteEndElement(); } writer.WriteStartElement("OtherParts"); foreach (ObjectPart p in parts) { if (p.ID != RootPart.ID) { if ((options & XmlSerializationOptions.WriteXml2) == 0) { writer.WriteStartElement("Part"); } p.ToXml(writer, nextOwner, options); if ((options & XmlSerializationOptions.WriteXml2) == 0) { writer.WriteEndElement(); } } } writer.WriteEndElement(); bool haveScriptState = false; foreach (ObjectPart p in parts) { foreach (ObjectPartInventoryItem i in p.Inventory.Values) { IScriptState scriptState = i.ScriptState; if (scriptState != null) { if (!haveScriptState) { writer.WriteStartElement("GroupScriptStates"); haveScriptState = true; } writer.WriteStartElement("SavedScriptState"); writer.WriteAttributeString("UUID", i.ID.ToString()); scriptState.ToXml(writer); writer.WriteEndElement(); } } } if (haveScriptState) { writer.WriteEndElement(); } writer.WriteEndElement(); }