From fc6c4dc399587f6f920d3f0759b1bd7a8b9b4ac8 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 1 May 2008 16:41:01 +0000 Subject: * Cleaning code still. --- OpenSim/Grid/AssetServer/Main.cs | 81 +++++++++++----------- .../Grid/AssetServer/Properties/AssemblyInfo.cs | 2 +- OpenSim/Grid/AssetServer/RestService.cs | 42 +++++------ 3 files changed, 64 insertions(+), 61 deletions(-) (limited to 'OpenSim/Grid/AssetServer') diff --git a/OpenSim/Grid/AssetServer/Main.cs b/OpenSim/Grid/AssetServer/Main.cs index 26f4bc8..c26c506 100644 --- a/OpenSim/Grid/AssetServer/Main.cs +++ b/OpenSim/Grid/AssetServer/Main.cs @@ -46,14 +46,48 @@ namespace OpenSim.Grid.AssetServer { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - public AssetConfig m_config; + public static OpenAsset_Main assetserver; - public static OpenAsset_Main assetserver; - // Temporarily hardcoded - should be a plugin - protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); - + protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); + private IAssetProvider m_assetProvider; + public AssetConfig m_config; + + public OpenAsset_Main() + { + m_console = new ConsoleBase("OpenAsset", this); + + MainConsole.Instance = m_console; + } + + #region conscmd_callback Members + + public override void RunCmd(string cmd, string[] cmdparams) + { + base.RunCmd(cmd, cmdparams); + + switch (cmd) + { + case "help": + m_console.Notice( + @"shutdown - shutdown this asset server (USE CAUTION!) + stats - statistical information for this server"); + + break; + + case "stats": + m_console.Notice("STATS", Environment.NewLine + StatsManager.AssetStats.Report()); + break; + + case "shutdown": + m_console.Close(); + Environment.Exit(0); + break; + } + } + + #endregion [STAThread] public static void Main(string[] args) @@ -78,13 +112,6 @@ namespace OpenSim.Grid.AssetServer } } - public OpenAsset_Main() - { - m_console = new ConsoleBase("OpenAsset", this); - - MainConsole.Instance = m_console; - } - public void Startup() { m_config = new AssetConfig("ASSET SERVER", (Path.Combine(Util.configDir(), "AssetServer_Config.xml"))); @@ -160,42 +187,18 @@ namespace OpenSim.Grid.AssetServer catch (Exception e) { m_log.Warn("[ASSET]: setupDB() - Exception occured"); - m_log.Warn("[ASSET]: " + e.ToString()); + m_log.Warn("[ASSET]: " + e); } } public void LoadDefaultAssets() { - assetLoader.ForEachDefaultXmlAsset(StoreAsset); + assetLoader.ForEachDefaultXmlAsset(StoreAsset); } protected void StoreAsset(AssetBase asset) { m_assetProvider.CreateAsset(asset); } - - public override void RunCmd(string cmd, string[] cmdparams) - { - base.RunCmd(cmd, cmdparams); - - switch (cmd) - { - case "help": - m_console.Notice( - @"shutdown - shutdown this asset server (USE CAUTION!) - stats - statistical information for this server"); - - break; - - case "stats": - m_console.Notice("STATS", Environment.NewLine + StatsManager.AssetStats.Report()); - break; - - case "shutdown": - m_console.Close(); - Environment.Exit(0); - break; - } - } } -} +} \ No newline at end of file diff --git a/OpenSim/Grid/AssetServer/Properties/AssemblyInfo.cs b/OpenSim/Grid/AssetServer/Properties/AssemblyInfo.cs index 6f219a6..3bae064 100644 --- a/OpenSim/Grid/AssetServer/Properties/AssemblyInfo.cs +++ b/OpenSim/Grid/AssetServer/Properties/AssemblyInfo.cs @@ -60,4 +60,4 @@ using System.Runtime.InteropServices; // [assembly : AssemblyVersion("1.0.0.0")] -[assembly : AssemblyFileVersion("1.0.0.0")] +[assembly : AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/OpenSim/Grid/AssetServer/RestService.cs b/OpenSim/Grid/AssetServer/RestService.cs index ece826e..93f86b8 100644 --- a/OpenSim/Grid/AssetServer/RestService.cs +++ b/OpenSim/Grid/AssetServer/RestService.cs @@ -43,8 +43,8 @@ namespace OpenSim.Grid.AssetServer { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private readonly IAssetProvider m_assetProvider; private OpenAsset_Main m_assetManager; - private IAssetProvider m_assetProvider; /// /// Constructor. @@ -58,28 +58,28 @@ namespace OpenSim.Grid.AssetServer m_assetManager = assetManager; m_assetProvider = assetProvider; } - + public override byte[] Handle(string path, Stream request) { string param = GetParam(path); byte[] result = new byte[] {}; - string[] p = param.Split(new char[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries); + string[] p = param.Split(new[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries); if (p.Length > 0) { - LLUUID assetID = null; - + LLUUID assetID = null; + if (!LLUUID.TryParse(p[0], out assetID)) { m_log.InfoFormat( "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]); return result; - } + } if (StatsManager.AssetStats != null) StatsManager.AssetStats.AddRequest(); - + AssetBase asset = m_assetProvider.FetchAsset(assetID); if (asset != null) { @@ -94,32 +94,39 @@ namespace OpenSim.Grid.AssetServer //StreamReader sr = new StreamReader(ms); result = ms.GetBuffer(); - + m_log.InfoFormat( "[REST]: GET:/asset found {0} with name {1}, size {2} bytes", assetID, asset.Name, result.Length); - Array.Resize(ref result, (int) ms.Length); + Array.Resize(ref result, (int) ms.Length); } else { if (StatsManager.AssetStats != null) StatsManager.AssetStats.AddNotFoundRequest(); - + m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID); } } - return result; - } + return result; + } } public class PostAssetStreamHandler : BaseStreamHandler { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private readonly IAssetProvider m_assetProvider; private OpenAsset_Main m_assetManager; - private IAssetProvider m_assetProvider; + + public PostAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider) + : base("POST", "/assets") + { + m_assetManager = assetManager; + m_assetProvider = assetProvider; + } public override byte[] Handle(string path, Stream request) { @@ -139,12 +146,5 @@ namespace OpenSim.Grid.AssetServer return new byte[] {}; } - - public PostAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider) - : base("POST", "/assets") - { - m_assetManager = assetManager; - m_assetProvider = assetProvider; - } } -} +} \ No newline at end of file -- cgit v1.1