add error handling

master
Christopher 2020-07-08 01:53:10 +02:00
parent a9f5e997ad
commit 462036f74b
3 changed files with 66 additions and 95 deletions

View File

@ -1,55 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenSim.Modules.DataValue
{
class Compress
{
public static void CopyTo(Stream src, Stream dest)
{
byte[] bytes = new byte[4096];
int cnt;
while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0)
{
dest.Write(bytes, 0, cnt);
}
}
public static byte[] Zip(string str)
{
var bytes = Encoding.UTF8.GetBytes(str);
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(mso, CompressionMode.Compress))
{
CopyTo(msi, gs);
}
return mso.ToArray();
}
}
public static string Unzip(byte[] bytes)
{
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(msi, CompressionMode.Decompress))
{
CopyTo(gs, mso);
}
return Encoding.UTF8.GetString(mso.ToArray());
}
}
}
}

View File

@ -119,22 +119,29 @@ namespace OpenSim.Modules.DataValue
{
if(m_storage != null)
{
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
try
{
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
if (_element != null)
return _element.get();
if (_element != null)
return _element.get();
checkRateLimit();
checkRateLimit();
String _data = m_storage.get(_host.GroupID.ToString(), key);
String _data = m_storage.get(_host.GroupID.ToString(), key);
if (_data == null)
if (_data == null)
return "";
m_cache.Add(new StorageElement(_host.GroupID.ToString(), key, _data, m_storage));
return _data;
}catch(Exception _error)
{
m_log.Error("[" + Name + "] osGetDataValue: " + _error.Message);
return "";
m_cache.Add(new StorageElement(_host.GroupID.ToString(), key, _data, m_storage));
return _data;
}
}
throw new Exception("No data Storage aviable.");
@ -145,19 +152,26 @@ namespace OpenSim.Modules.DataValue
{
if (m_storage != null)
{
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
if(_element != null)
try
{
_element.save(value);
return;
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
if (_element != null)
{
_element.save(value);
return;
}
checkRateLimit();
m_cache.Add(new StorageElement(_host.GroupID.ToString(), key, value, m_storage));
m_storage.save(_host.GroupID.ToString(), key, value);
}
catch (Exception _error)
{
m_log.Error("[" + Name + "] osSetDataValue: " + _error.Message);
}
checkRateLimit();
m_cache.Add(new StorageElement(_host.GroupID.ToString(), key, value, m_storage));
m_storage.save(_host.GroupID.ToString(), key, value);
}
throw new Exception("No data Storage aviable.");
@ -167,15 +181,23 @@ namespace OpenSim.Modules.DataValue
{
if (m_storage != null)
{
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
try
{
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
checkRateLimit();
checkRateLimit();
if (_element != null)
m_cache.Remove(_element);
if (_element != null)
m_cache.Remove(_element);
m_storage.remove(_host.GroupID.ToString(), key);
}
catch (Exception _error)
{
m_log.Error("[" + Name + "] osDeleteDataValue: " + _error.Message);
}
m_storage.remove(_host.GroupID.ToString(), key);
}
throw new Exception("No data Storage aviable.");
@ -186,18 +208,26 @@ namespace OpenSim.Modules.DataValue
{
if (m_storage != null)
{
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
try
{
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
if (_element != null)
return 1;
if (_element != null)
return 1;
checkRateLimit();
checkRateLimit();
if (m_storage.check(_host.GroupID.ToString(), key))
return 1;
if (m_storage.check(_host.GroupID.ToString(), key))
return 1;
return 0;
return 0;
}
catch (Exception _error)
{
m_log.Error("[" + Name + "] osCheckDataValue: " + _error.Message);
return 0;
}
}
throw new Exception("No data Storage aviable.");

View File

@ -19,7 +19,6 @@ namespace OpenSim.Modules.DataValue.Storage
private Scene m_scene = null;
private bool m_enabledCompress = true;
private string m_dataValueDirectory = "./ScriptDataValue";
public FileSystem(Scene scene, IConfig config)
@ -77,9 +76,6 @@ namespace OpenSim.Modules.DataValue.Storage
string _storageKey = BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(ASCIIEncoding.ASCII.GetBytes(index.Trim().ToUpper()))).Replace("-", "");
if (m_enabledCompress)
return m_dataValueDirectory + "/" + _nameSpace + "/" + _storageKey + ".gz";
return m_dataValueDirectory + "/" + _nameSpace + "/" + _storageKey + ".txt";
}
}