123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.IO;
- using System.Net;
- using System.Reflection;
- using Nini.Config;
- using log4net;
- using OpenSim.Server.Base;
- using OpenSim.Services.Interfaces;
- using OpenSim.Framework.Servers.HttpServer;
- using OpenSim.Server.Handlers.Base;
- namespace OpenSim.Server.Handlers.MapImage
- {
- public class MapGetServiceConnector : ServiceConnector
- {
- private IMapImageService m_MapService;
- private string m_ConfigName = "MapImageService";
- public MapGetServiceConnector(IConfigSource config, IHttpServer server, string configName) :
- base(config, server, configName)
- {
- IConfig serverConfig = config.Configs[m_ConfigName];
- if (serverConfig == null)
- throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
- string gridService = serverConfig.GetString("LocalServiceModule",
- String.Empty);
- if (gridService == String.Empty)
- throw new Exception("No LocalServiceModule in config file");
- Object[] args = new Object[] { config };
- m_MapService = ServerUtils.LoadPlugin<IMapImageService>(gridService, args);
- server.AddStreamHandler(new MapServerGetHandler(m_MapService));
- }
- }
- class MapServerGetHandler : BaseStreamHandler
- {
- private IMapImageService m_MapService;
- public MapServerGetHandler(IMapImageService service) :
- base("GET", "/map")
- {
- m_MapService = service;
- }
- protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
- {
- byte[] result = new byte[0];
- string format = string.Empty;
- result = m_MapService.GetMapTile(path.Trim('/'), out format);
- if (result.Length > 0)
- {
- httpResponse.StatusCode = (int)HttpStatusCode.OK;
- if (format.Equals(".png"))
- httpResponse.ContentType = "image/png";
- else if (format.Equals(".jpg") || format.Equals(".jpeg"))
- httpResponse.ContentType = "image/jpeg";
- }
- else
- {
- httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
- httpResponse.ContentType = "text/plain";
- }
- return result;
- }
- }
- }
|