private static void LoadExtensions()
{
if (HttpRuntime.Cache["Extensions"] != null &&
((Dictionary<string, ManagedExtension>)HttpRuntime.Cache["Extensions"]).Count != 0)
{
return;
}
var codeAssemblies = Utils.CodeAssemblies();
var meta = DataStoreExtension("MetaExtension");
if (meta == null)
{
extensions.Add("MetaExtension", new ManagedExtension("MetaExtension", "1.0", "Meta extension", "BlogEngine.net"));
}
else
{
if (!extensions.ContainsKey("MetaExtension"))
{
extensions.Add("MetaExtension", meta);
}
}
foreach (Assembly a in codeAssemblies)
{
var types = a.GetTypes();
foreach (var type in types)
{
var attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false);
foreach (var xa in attributes.Cast<ExtensionAttribute>())
{
// try to load from storage
try
{
var x = DataStoreExtension(type.Name);
// if nothing, crete new extension
if (x == null)
{
x = new ManagedExtension(type.Name, xa.Version, xa.Description, xa.Author);
newExtensions.Add(type.Name);
SaveToStorage(x);
}
else
{
// update attributes from assembly
x.Version = xa.Version;
x.Description = xa.Description;
x.Author = xa.Author;
if (x.Priority == 0)
{
x.Priority = xa.Priority;
}
}
if (!extensions.ContainsKey(x.Name))
extensions.Add(x.Name, x);
}
catch (Exception e)
{
Utils.Log(string.Format("Can not load {0}: {1}", type.Name, e.Message));
}
}
}
}
// SaveToStorage();
SaveToCache();
}