fixing XmlWriter problem
parent
7a8a481f88
commit
2ad8710e19
|
@ -65,29 +65,33 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
|
|||
|
||||
public string GetHandlerRegions(OSHttpResponse httpResponse)
|
||||
{
|
||||
XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty);
|
||||
RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
|
||||
|
||||
rxw.WriteStartElement(String.Empty, "regions", String.Empty);
|
||||
foreach (Scene s in App.SceneManager.Scenes)
|
||||
{
|
||||
XmlWriter.WriteStartElement(String.Empty, "uuid", String.Empty);
|
||||
XmlWriter.WriteString(s.RegionInfo.RegionID.ToString());
|
||||
XmlWriter.WriteEndElement();
|
||||
rxw.WriteStartElement(String.Empty, "uuid", String.Empty);
|
||||
rxw.WriteString(s.RegionInfo.RegionID.ToString());
|
||||
rxw.WriteEndElement();
|
||||
}
|
||||
XmlWriter.WriteEndElement();
|
||||
rxw.WriteEndElement();
|
||||
|
||||
return XmlWriterResult;
|
||||
return rxw.ToString();
|
||||
}
|
||||
|
||||
protected string ShortRegionInfo(string key, string value)
|
||||
{
|
||||
RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
|
||||
|
||||
if (String.IsNullOrEmpty(value) ||
|
||||
String.IsNullOrEmpty(key)) return null;
|
||||
|
||||
XmlWriter.WriteStartElement(String.Empty, "region", String.Empty);
|
||||
XmlWriter.WriteStartElement(String.Empty, key, String.Empty);
|
||||
XmlWriter.WriteString(value);
|
||||
XmlWriter.WriteEndDocument();
|
||||
rxw.WriteStartElement(String.Empty, "region", String.Empty);
|
||||
rxw.WriteStartElement(String.Empty, key, String.Empty);
|
||||
rxw.WriteString(value);
|
||||
rxw.WriteEndDocument();
|
||||
|
||||
return XmlWriterResult;
|
||||
return rxw.ToString();
|
||||
}
|
||||
|
||||
public string GetHandlerRegion(OSHttpResponse httpResponse, string param)
|
||||
|
@ -114,9 +118,10 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
|
|||
if (1 == comps.Length)
|
||||
{
|
||||
// complete region details requested
|
||||
RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
|
||||
XmlSerializer xs = new XmlSerializer(typeof(RegionDetails));
|
||||
xs.Serialize(XmlWriter, details, _xmlNs);
|
||||
return XmlWriterResult;
|
||||
xs.Serialize(rxw, details, _xmlNs);
|
||||
return rxw.ToString();
|
||||
}
|
||||
|
||||
if (2 == comps.Length)
|
||||
|
@ -185,20 +190,22 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
|
|||
int users = scene.GetAvatars().Count;
|
||||
int objects = scene.Entities.Count - users;
|
||||
|
||||
XmlWriter.WriteStartElement(String.Empty, "region", String.Empty);
|
||||
XmlWriter.WriteStartElement(String.Empty, "stats", String.Empty);
|
||||
RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
|
||||
|
||||
XmlWriter.WriteStartElement(String.Empty, "users", String.Empty);
|
||||
XmlWriter.WriteString(users.ToString());
|
||||
XmlWriter.WriteEndElement();
|
||||
rxw.WriteStartElement(String.Empty, "region", String.Empty);
|
||||
rxw.WriteStartElement(String.Empty, "stats", String.Empty);
|
||||
|
||||
XmlWriter.WriteStartElement(String.Empty, "objects", String.Empty);
|
||||
XmlWriter.WriteString(objects.ToString());
|
||||
XmlWriter.WriteEndElement();
|
||||
rxw.WriteStartElement(String.Empty, "users", String.Empty);
|
||||
rxw.WriteString(users.ToString());
|
||||
rxw.WriteEndElement();
|
||||
|
||||
XmlWriter.WriteEndDocument();
|
||||
rxw.WriteStartElement(String.Empty, "objects", String.Empty);
|
||||
rxw.WriteString(objects.ToString());
|
||||
rxw.WriteEndElement();
|
||||
|
||||
return XmlWriterResult;
|
||||
rxw.WriteEndDocument();
|
||||
|
||||
return rxw.ToString();
|
||||
}
|
||||
|
||||
protected string RegionPrims(OSHttpResponse httpResponse, Scene scene, Vector3 min, Vector3 max)
|
||||
|
|
|
@ -66,78 +66,78 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
|
|||
|
||||
public string GetRegionInfoHandlerRegions(OSHttpResponse httpResponse)
|
||||
{
|
||||
RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
|
||||
|
||||
// regions info
|
||||
XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty);
|
||||
rxw.WriteStartElement(String.Empty, "regions", String.Empty);
|
||||
{
|
||||
// regions info: number of regions
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "number", String.Empty);
|
||||
XmlWriter.WriteValue(App.SceneManager.Scenes.Count);
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "number", String.Empty);
|
||||
rxw.WriteValue(App.SceneManager.Scenes.Count);
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
// regions info: max number of regions
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "max", String.Empty);
|
||||
rxw.WriteStartAttribute(String.Empty, "max", String.Empty);
|
||||
if (App.ConfigSource.Source.Configs["RemoteAdmin"] != null)
|
||||
{
|
||||
XmlWriter.WriteValue(App.ConfigSource.Source.Configs["RemoteAdmin"].GetInt("region_limit", -1));
|
||||
rxw.WriteValue(App.ConfigSource.Source.Configs["RemoteAdmin"].GetInt("region_limit", -1));
|
||||
}
|
||||
else
|
||||
{
|
||||
XmlWriter.WriteValue(-1);
|
||||
rxw.WriteValue(-1);
|
||||
}
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
// regions info: region
|
||||
foreach (Scene s in App.SceneManager.Scenes)
|
||||
{
|
||||
XmlWriter.WriteStartElement(String.Empty, "region", String.Empty);
|
||||
rxw.WriteStartElement(String.Empty, "region", String.Empty);
|
||||
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "uuid", String.Empty);
|
||||
XmlWriter.WriteString(s.RegionInfo.RegionID.ToString());
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "uuid", String.Empty);
|
||||
rxw.WriteString(s.RegionInfo.RegionID.ToString());
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "name", String.Empty);
|
||||
XmlWriter.WriteString(s.RegionInfo.RegionName);
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "name", String.Empty);
|
||||
rxw.WriteString(s.RegionInfo.RegionName);
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "x", String.Empty);
|
||||
XmlWriter.WriteValue(s.RegionInfo.RegionLocX);
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "x", String.Empty);
|
||||
rxw.WriteValue(s.RegionInfo.RegionLocX);
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "y", String.Empty);
|
||||
XmlWriter.WriteValue(s.RegionInfo.RegionLocY);
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "y", String.Empty);
|
||||
rxw.WriteValue(s.RegionInfo.RegionLocY);
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "external_hostname", String.Empty);
|
||||
XmlWriter.WriteString(s.RegionInfo.ExternalHostName);
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "external_hostname", String.Empty);
|
||||
rxw.WriteString(s.RegionInfo.ExternalHostName);
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "master_name", String.Empty);
|
||||
XmlWriter.WriteString(String.Format("{0} {1}", s.RegionInfo.MasterAvatarFirstName, s.RegionInfo.MasterAvatarLastName));
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "master_name", String.Empty);
|
||||
rxw.WriteString(String.Format("{0} {1}", s.RegionInfo.MasterAvatarFirstName, s.RegionInfo.MasterAvatarLastName));
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "master_uuid", String.Empty);
|
||||
XmlWriter.WriteString(s.RegionInfo.MasterAvatarAssignedUUID.ToString());
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "master_uuid", String.Empty);
|
||||
rxw.WriteString(s.RegionInfo.MasterAvatarAssignedUUID.ToString());
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "ip", String.Empty);
|
||||
XmlWriter.WriteString(s.RegionInfo.InternalEndPoint.ToString());
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "ip", String.Empty);
|
||||
rxw.WriteString(s.RegionInfo.InternalEndPoint.ToString());
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
int users = s.GetAvatars().Count;
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "avatars", String.Empty);
|
||||
XmlWriter.WriteValue(users);
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "avatars", String.Empty);
|
||||
rxw.WriteValue(users);
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
XmlWriter.WriteStartAttribute(String.Empty, "objects", String.Empty);
|
||||
XmlWriter.WriteValue(s.Entities.Count - users);
|
||||
XmlWriter.WriteEndAttribute();
|
||||
rxw.WriteStartAttribute(String.Empty, "objects", String.Empty);
|
||||
rxw.WriteValue(s.Entities.Count - users);
|
||||
rxw.WriteEndAttribute();
|
||||
|
||||
XmlWriter.WriteEndElement();
|
||||
rxw.WriteEndElement();
|
||||
}
|
||||
}
|
||||
XmlWriter.WriteEndElement();
|
||||
|
||||
return XmlWriterResult;
|
||||
return rxw.ToString();
|
||||
}
|
||||
#endregion GET methods
|
||||
}
|
||||
|
|
|
@ -94,16 +94,18 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
|
|||
|
||||
public string CreateRegion(OSHttpRequest request, OSHttpResponse response)
|
||||
{
|
||||
XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty);
|
||||
RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
|
||||
|
||||
rxw.WriteStartElement(String.Empty, "regions", String.Empty);
|
||||
foreach (Scene s in App.SceneManager.Scenes)
|
||||
{
|
||||
XmlWriter.WriteStartElement(String.Empty, "uuid", String.Empty);
|
||||
XmlWriter.WriteString(s.RegionInfo.RegionID.ToString());
|
||||
XmlWriter.WriteEndElement();
|
||||
rxw.WriteStartElement(String.Empty, "uuid", String.Empty);
|
||||
rxw.WriteString(s.RegionInfo.RegionID.ToString());
|
||||
rxw.WriteEndElement();
|
||||
}
|
||||
XmlWriter.WriteEndElement();
|
||||
rxw.WriteEndElement();
|
||||
|
||||
return XmlWriterResult;
|
||||
return rxw.ToString();
|
||||
}
|
||||
|
||||
public string LoadPrims(string requestBody, OSHttpRequest request, OSHttpResponse response, Scene scene)
|
||||
|
|
|
@ -53,8 +53,8 @@ namespace OpenSim.ApplicationPlugins.Rest
|
|||
private string _prefix; // URL prefix below
|
||||
// which all REST URLs
|
||||
// are living
|
||||
private StringWriter _sw = null;
|
||||
private RestXmlWriter _xw = null;
|
||||
// private StringWriter _sw = null;
|
||||
// private RestXmlWriter _xw = null;
|
||||
|
||||
private string _godkey;
|
||||
private int _reqk;
|
||||
|
@ -149,31 +149,31 @@ namespace OpenSim.ApplicationPlugins.Rest
|
|||
/// </summary>
|
||||
public abstract string ConfigName { get; }
|
||||
|
||||
public XmlTextWriter XmlWriter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _xw)
|
||||
{
|
||||
_sw = new StringWriter();
|
||||
_xw = new RestXmlWriter(_sw);
|
||||
_xw.Formatting = Formatting.Indented;
|
||||
}
|
||||
return _xw;
|
||||
}
|
||||
}
|
||||
// public XmlTextWriter XmlWriter
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if (null == _xw)
|
||||
// {
|
||||
// _sw = new StringWriter();
|
||||
// _xw = new RestXmlWriter(_sw);
|
||||
// _xw.Formatting = Formatting.Indented;
|
||||
// }
|
||||
// return _xw;
|
||||
// }
|
||||
// }
|
||||
|
||||
public string XmlWriterResult
|
||||
{
|
||||
get
|
||||
{
|
||||
_xw.Flush();
|
||||
_xw.Close();
|
||||
_xw = null;
|
||||
// public string XmlWriterResult
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// _xw.Flush();
|
||||
// _xw.Close();
|
||||
// _xw = null;
|
||||
|
||||
return _sw.ToString();
|
||||
}
|
||||
}
|
||||
// return _sw.ToString();
|
||||
// }
|
||||
// }
|
||||
|
||||
#endregion properties
|
||||
|
||||
|
|
|
@ -33,6 +33,14 @@ namespace OpenSim.ApplicationPlugins.Rest
|
|||
{
|
||||
public class RestXmlWriter: XmlTextWriter
|
||||
{
|
||||
private StringWriter m_sw = null;
|
||||
|
||||
public RestXmlWriter(StringWriter sw) : base(sw)
|
||||
{
|
||||
m_sw = sw;
|
||||
Formatting = Formatting.Indented;
|
||||
}
|
||||
|
||||
public RestXmlWriter(TextWriter textWriter) : base(textWriter)
|
||||
{
|
||||
}
|
||||
|
@ -52,5 +60,13 @@ namespace OpenSim.ApplicationPlugins.Rest
|
|||
public override void WriteStartDocument(bool standalone)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
WriteEndElement();
|
||||
Flush();
|
||||
Close();
|
||||
return m_sw.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue