mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 09:45:47 +08:00
Implemented FetchAssetMetadataSet in DB backends.
This method fetches metadata for a subset of the entries in the assets database. This functionality is used in the ForEach calls in the asset storage providers in AssetInventoryServer. With this implemented, frontends such as the BrowseFrontend should now work. - MySQL: implemented, sanity tested - SQLite: implemented, sanity tested - MSSQL: implemented, not tested - NHibernate: not implemented
This commit is contained in:
@@ -42,7 +42,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||
public class BrowseFrontendPlugin : IAssetInventoryServerPlugin
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
//private AssetInventoryServer m_server;
|
||||
private AssetInventoryServer m_server;
|
||||
|
||||
public BrowseFrontendPlugin()
|
||||
{
|
||||
@@ -52,10 +52,10 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||
|
||||
public void Initialise(AssetInventoryServer server)
|
||||
{
|
||||
//m_server = server;
|
||||
m_server = server;
|
||||
|
||||
// Request for / or /?...
|
||||
//m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server));
|
||||
m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server));
|
||||
|
||||
m_log.Info("[BROWSEFRONTEND]: Browser Frontend loaded.");
|
||||
}
|
||||
@@ -86,102 +86,87 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||
|
||||
#endregion IPlugin implementation
|
||||
|
||||
//public class BrowseRequestHandler : IStreamedRequestHandler
|
||||
//{
|
||||
// AssetInventoryServer m_server;
|
||||
// string m_contentType;
|
||||
// string m_httpMethod;
|
||||
// string m_path;
|
||||
public class BrowseRequestHandler : BaseStreamHandler
|
||||
{
|
||||
AssetInventoryServer m_server;
|
||||
|
||||
// public BrowseRequestHandler(AssetInventoryServer server)
|
||||
// {
|
||||
// m_server = server;
|
||||
// m_contentType = null;
|
||||
// m_httpMethod = "GET";
|
||||
// m_path = @"(^/$)|(^/\?.*)";
|
||||
// }
|
||||
//public BrowseRequestHandler(AssetInventoryServer server) : base("GET", "(^/$|(^/\?.*)")
|
||||
public BrowseRequestHandler(AssetInventoryServer server) : base("GET", "/")
|
||||
{
|
||||
m_server = server;
|
||||
}
|
||||
|
||||
// #region IStreamedRequestHandler implementation
|
||||
public override string ContentType
|
||||
{
|
||||
get { return "text/html"; }
|
||||
}
|
||||
|
||||
// public string ContentType
|
||||
// {
|
||||
// get { return m_contentType; }
|
||||
// }
|
||||
#region IStreamedRequestHandler implementation
|
||||
|
||||
// public string HttpMethod
|
||||
// {
|
||||
// get { return m_httpMethod; }
|
||||
// }
|
||||
public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||
{
|
||||
const int ASSETS_PER_PAGE = 25;
|
||||
const string HEADER = "<html><head><title>Asset Server</title></head><body>";
|
||||
const string TABLE_HEADER =
|
||||
"<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>";
|
||||
const string TABLE_FOOTER = "</table>";
|
||||
const string FOOTER = "</body></html>";
|
||||
|
||||
// public string Path
|
||||
// {
|
||||
// get { return m_path; }
|
||||
// }
|
||||
UUID authToken = Utils.GetAuthToken(httpRequest);
|
||||
|
||||
// public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||
// {
|
||||
// const int ASSETS_PER_PAGE = 25;
|
||||
// const string HEADER = "<html><head><title>Asset Server</title></head><body>";
|
||||
// const string TABLE_HEADER =
|
||||
// "<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>";
|
||||
// const string TABLE_FOOTER = "</table>";
|
||||
// const string FOOTER = "</body></html>";
|
||||
StringBuilder html = new StringBuilder();
|
||||
int start = 0;
|
||||
uint page = 0;
|
||||
|
||||
// UUID authToken = Utils.GetAuthToken(httpRequest);
|
||||
if (!String.IsNullOrEmpty(httpRequest.Url.Query))
|
||||
{
|
||||
NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
|
||||
if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page))
|
||||
start = (int)page * ASSETS_PER_PAGE;
|
||||
}
|
||||
|
||||
// StringBuilder html = new StringBuilder();
|
||||
// int start = 0;
|
||||
// uint page = 0;
|
||||
html.AppendLine(HEADER);
|
||||
|
||||
// if (!String.IsNullOrEmpty(httpRequest.Url.Query))
|
||||
// {
|
||||
// NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
|
||||
// if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page))
|
||||
// start = (int)page * ASSETS_PER_PAGE;
|
||||
// }
|
||||
html.AppendLine("<p>");
|
||||
if (page > 0)
|
||||
html.AppendFormat("<a href=\"{0}?page={1}\">< Previous Page</a> | ", httpRequest.RawUrl, page - 1);
|
||||
html.AppendFormat("<a href=\"{0}?page={1}\">Next Page ></a>", httpRequest.RawUrl, page + 1);
|
||||
html.AppendLine("</p>");
|
||||
|
||||
// html.AppendLine(HEADER);
|
||||
html.AppendLine(TABLE_HEADER);
|
||||
|
||||
// html.AppendLine("<p>");
|
||||
// if (page > 0)
|
||||
// html.AppendFormat("<a href=\"{0}?page={1}\">< Previous Page</a> | ", httpRequest.RawUrl, page - 1);
|
||||
// html.AppendFormat("<a href=\"{0}?page={1}\">Next Page ></a>", httpRequest.RawUrl, page + 1);
|
||||
// html.AppendLine("</p>");
|
||||
m_server.StorageProvider.ForEach(
|
||||
delegate(AssetMetadata data)
|
||||
{
|
||||
if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.FullID))
|
||||
{
|
||||
html.AppendLine(String.Format(
|
||||
"<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>",
|
||||
data.Name, data.Description, data.ContentType, data.ID, data.Temporary,
|
||||
BitConverter.ToString(data.SHA1).Replace("-", String.Empty)));
|
||||
}
|
||||
else
|
||||
{
|
||||
html.AppendLine(String.Format(
|
||||
"<tr><td>[Protected Asset]</td><td> </td><td> </td><td>{0}</td><td>{1}</td><td> </td></tr>",
|
||||
data.ID, data.Temporary));
|
||||
}
|
||||
}, start, ASSETS_PER_PAGE
|
||||
);
|
||||
|
||||
// html.AppendLine(TABLE_HEADER);
|
||||
html.AppendLine(TABLE_FOOTER);
|
||||
|
||||
// m_server.StorageProvider.ForEach(
|
||||
// delegate(Metadata data)
|
||||
// {
|
||||
// if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID))
|
||||
// {
|
||||
// html.AppendLine(String.Format(
|
||||
// "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>",
|
||||
// data.Name, data.Description, data.ContentType, data.ID, data.Temporary,
|
||||
// BitConverter.ToString(data.SHA1).Replace("-", String.Empty)));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// html.AppendLine(String.Format(
|
||||
// "<tr><td>[Protected Asset]</td><td> </td><td> </td><td>{0}</td><td>{1}</td><td> </td></tr>",
|
||||
// data.ID, data.Temporary));
|
||||
// }
|
||||
// }, start, ASSETS_PER_PAGE
|
||||
// );
|
||||
html.AppendLine(FOOTER);
|
||||
|
||||
// html.AppendLine(TABLE_FOOTER);
|
||||
byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString());
|
||||
|
||||
// html.AppendLine(FOOTER);
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.OK;
|
||||
//httpResponse.Body.Write(responseData, 0, responseData.Length);
|
||||
//httpResponse.Body.Flush();
|
||||
return responseData;
|
||||
}
|
||||
|
||||
// byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString());
|
||||
|
||||
// httpResponse.StatusCode = (int) HttpStatusCode.OK;
|
||||
// httpResponse.Body.Write(responseData, 0, responseData.Length);
|
||||
// httpResponse.Body.Flush();
|
||||
// return responseData;
|
||||
// }
|
||||
|
||||
// #endregion IStreamedRequestHandler implementation
|
||||
//}
|
||||
#endregion IStreamedRequestHandler implementation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Data;
|
||||
using System.Collections.Generic;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Data;
|
||||
@@ -117,42 +118,17 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
||||
{
|
||||
int rowCount = 0;
|
||||
|
||||
//using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect")))
|
||||
//{
|
||||
// MySqlDataReader reader;
|
||||
foreach (AssetMetadata metadata in m_assetProvider.FetchAssetMetadataSet(start, count))
|
||||
{
|
||||
// We set the ContentType here because Utils is only in
|
||||
// AssetInventoryServer. This should be moved to the DB
|
||||
// backends when the equivalent of SLAssetTypeToContentType is
|
||||
// in OpenSim.Framework or similar.
|
||||
metadata.ContentType = Utils.SLAssetTypeToContentType(metadata.Type);
|
||||
|
||||
// try
|
||||
// {
|
||||
// dbConnection.Open();
|
||||
|
||||
// MySqlCommand command = dbConnection.CreateCommand();
|
||||
// command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}",
|
||||
// start, count);
|
||||
// reader = command.ExecuteReader();
|
||||
// }
|
||||
// catch (MySqlException ex)
|
||||
// {
|
||||
// m_log.Error("[OPENSIMASSETSTORAGE]: Connection to MySQL backend failed: " + ex.Message);
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// while (reader.Read())
|
||||
// {
|
||||
// Metadata metadata = new Metadata();
|
||||
// metadata.CreationDate = OpenMetaverse.Utils.Epoch;
|
||||
// metadata.Description = reader.GetString(1);
|
||||
// metadata.ID = UUID.Parse(reader.GetString(5));
|
||||
// metadata.Name = reader.GetString(0);
|
||||
// metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4));
|
||||
// metadata.Temporary = reader.GetBoolean(3);
|
||||
// metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
|
||||
|
||||
// action(metadata);
|
||||
// ++rowCount;
|
||||
// }
|
||||
|
||||
// reader.Close();
|
||||
//}
|
||||
action(metadata);
|
||||
++rowCount;
|
||||
}
|
||||
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user