View of /trunk/AssetServer/AssetServer.cs
Parent Directory
|
Revision Log
Revision 48 -
(download)
(annotate)
Mon Dec 15 20:00:59 2008 UTC (4 years, 6 months ago) by jhurliman
File size: 7015 byte(s)
Mon Dec 15 20:00:59 2008 UTC (4 years, 6 months ago) by jhurliman
File size: 7015 byte(s)
Shuffling files around, SVN is currently in a state of flux
/*
* Copyright (c) 2008 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using ExtensionLoader;
using ExtensionLoader.Config;
using OpenMetaverse;
namespace AssetServer
{
public class AssetServer
{
public const string CONFIG_FILE = "AssetServer.ini";
public HttpServer HttpServer;
public IniConfigSource ConfigFile;
public IStorageProvider StorageProvider;
public IInventoryProvider InventoryProvider;
public IAuthenticationProvider AuthenticationProvider;
public IAuthorizationProvider AuthorizationProvider;
public IMetricsProvider MetricsProvider;
public AssetServer()
{
}
public bool Start()
{
List<string> extensionList = null;
List<string> listenPrefixes = null;
try { ConfigFile = new IniConfigSource(CONFIG_FILE); }
catch (Exception)
{
Logger.Log.Error("Failed to load the config file " + CONFIG_FILE);
return false;
}
try
{
IConfig extensionConfig = ConfigFile.Configs["Config"];
// Load the addresses to listen at
string[] prefixes = extensionConfig.GetString("ListenAddress").Split(',');
listenPrefixes = new List<string>(prefixes.Length);
foreach (string prefix in prefixes)
listenPrefixes.Add(prefix.Trim());
}
catch (Exception)
{
Logger.Log.Error("Failed to load [Config] section from " + CONFIG_FILE);
return false;
}
try
{
// Load the extension list (and ordering) from our config file
IConfig extensionConfig = ConfigFile.Configs["Extensions"];
extensionList = new List<string>(extensionConfig.GetKeys());
}
catch (Exception)
{
Logger.Log.Error("Failed to load [Extensions] section from " + CONFIG_FILE);
return false;
}
try
{
// Create a reference list for C# extensions compiled at runtime
List<string> references = new List<string>();
references.Add("OpenMetaverseTypes.dll");
references.Add("OpenMetaverse.dll");
references.Add("ExtensionLoader.dll");
references.Add("AssetServer.exe");
// Get a list of all of the members of AssetServer that are interfaces
List<FieldInfo> assignables = ExtensionLoader<AssetServer>.GetInterfaces(this);
// Load all of the extensions
ExtensionLoader<AssetServer>.LoadAllExtensions(
Assembly.GetExecutingAssembly(),
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
extensionList,
references,
"AssetServer.*.dll",
"AssetServer.*.cs",
this,
assignables);
}
catch (ExtensionException ex)
{
Logger.Log.Error("Interface loading failed, shutting down: " + ex.Message);
if (ex.InnerException != null)
Logger.Log.Error(ex.InnerException.Message, ex.InnerException);
Stop();
return false;
}
try
{
InitHttpServer(listenPrefixes);
}
catch (Exception ex)
{
Logger.Log.Error("Initializing the HTTP server failed, shutting down: " + ex.Message);
Stop();
return false;
}
// Start all of the extensions
foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions)
{
Logger.Log.Info("Starting extension " + extension.GetType().Name);
extension.Start(this);
}
return true;
}
public void Stop()
{
foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions)
{
Logger.Log.Debug("Stopping extension " + extension.GetType().Name);
try { extension.Stop(); }
catch (Exception ex)
{ Logger.Log.ErrorFormat("Failure shutting down extension {0}: {1}", extension.GetType().Name, ex.Message); }
}
if (HttpServer != null)
HttpServer.Stop();
}
void InitHttpServer(List<string> listenPrefixes)
{
HttpServer = new HttpServer(listenPrefixes);
HttpServer.Start();
System.Text.StringBuilder output = new System.Text.StringBuilder("Asset server is listening at: ");
for (int i = 0; i < listenPrefixes.Count; i++)
{
output.Append(listenPrefixes[i]);
if (i != listenPrefixes.Count - 1) output.Append(", ");
}
Logger.Log.Info(output.ToString());
}
}
}
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

