committing broken stuff as i have to stop

This commit is contained in:
Tommy Parnell
2014-05-07 16:25:51 -07:00
parent e5ed166572
commit 5157dbac46
9 changed files with 77 additions and 31 deletions

View File

@@ -5,31 +5,25 @@ using NOCQ.Plugins.Email;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using NOCQ.Extensability;
namespace NOCQ.Application namespace NOCQ.Application
{ {
class MainClass class MainClass
{ {
public static void Main (string[] args) public static void Main (string[] args)
{
var list = new List<Alert>();
for (var i = 0; i < 3000; i++)
{
var al = new Alert()
{Data = "data" + Guid.NewGuid(), Runbook = "runbook", Service = "service",
Severity = "sev",
Source = "Source",
System = "System",
TimeStamp = new DateTime(2011,1,1)
};
list.Add(al);
}
list.ForEach(al => RedisDatabase.SaveAlert(al, "127.0.0.1", RedisQueues.Input, 6379, 3000));
for (var i = 0; i < 3000; i++)
{ {
var s = RedisDatabase.GetNextAlert("127.0.0.1", RedisQueues.Input, 6379, 3000); var s = RedisDatabase.GetNextAlert("127.0.0.1", RedisQueues.Input, 6379, 3000);
Console.WriteLine(s.Data);
} // process s
var importPlugs = CatalogRepository.GetImportPlugins();
importPlugs.ToList().ForEach(x =>
{
Task.Factory.StartNew(x.Value.Run, TaskCreationOptions.LongRunning);
Console.WriteLine(x.Value.Name);
});
//RedisDatabase.SaveAlert(, "127.0.0.1", RedisQueues.Output, 6379, 3000);
Console.ReadLine(); Console.ReadLine();

View File

@@ -5,7 +5,7 @@ using System.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace NOCQ namespace NOCQ
{ {
public class RedisDatabase public sealed class RedisDatabase
{ {
public RedisDatabase(){} public RedisDatabase(){}

View File

@@ -2,17 +2,19 @@ using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Reflection; using System.Reflection;
namespace NOCQ namespace NOCQ.Extensability
{ {
public class Catalog public class Catalog
{ {
static DirectoryCatalog dcatalog = new DirectoryCatalog("plugins", "*.dll"); //static DirectoryCatalog dcatalog = new DirectoryCatalog("plugins", "*.dll");
static AssemblyCatalog acatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); static AssemblyCatalog acatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
static AggregateCatalog catalog = new AggregateCatalog(dcatalog, acatalog); private static AggregateCatalog Cat = new AggregateCatalog(acatalog);
static public CompositionContainer Container = new CompositionContainer(catalog); private static CompositionContainer _container = new CompositionContainer(Cat);
public CompositionContainer Container { get { return _container; } }
public Catalog() public Catalog()
{ {
Container.ComposeParts(this); _container.ComposeParts(this);
} }
} }
} }

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace NOCQ.Extensability
{
public static class CatalogRepository
{
public static IEnumerable<Lazy<IDataImportHook>> GetImportPlugins()
{
var ts = new Catalog().Container.GetExports<IDataImportHook>();
return ts;
}
}
}

View File

@@ -6,8 +6,8 @@ namespace NOCQ
[Export] [Export]
public class DataImports public class DataImports
{ {
[ImportMany] [ImportMany(AllowRecomposition = true)]
IEnumerable<IDataImportHook> DataHooks {get; set;} public IEnumerable<System.Lazy<IDataImportHook,IDataImportMetadata>> DataHooks {get; set;}
} }
} }

View File

@@ -3,10 +3,10 @@ using System.ComponentModel.Composition;
namespace NOCQ namespace NOCQ
{ {
[InheritedExport]
public interface IDataImportHook public interface IDataImportHook
{ {
string Name { get; set; } string Name { get; set;}
void Run(); void Run();
void Stop(); void Stop();
} }

View File

@@ -0,0 +1,22 @@
using System;
using System.ComponentModel.Composition;
namespace NOCQ
{
interface IDataImportMetadata
{
string Name {get;set;}
}
[MetadataAttribute]
public class IDataImportAttr : ExportAttribute, IDataImportMetadata
{
public string Name {get;set;}
IDataImportAttr(string name)
:base(typeof(IDataImportHook))
{
Name = name;
}
}
}

View File

@@ -73,6 +73,8 @@
<Compile Include="Model\Alert.cs" /> <Compile Include="Model\Alert.cs" />
<Compile Include="DB\RedisQueues.cs" /> <Compile Include="DB\RedisQueues.cs" />
<Compile Include="DB\RedisDatabase.cs" /> <Compile Include="DB\RedisDatabase.cs" />
<Compile Include="Extensability\CatalogRepository.cs" />
<Compile Include="Imports\IDataImportMetadata.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@@ -4,11 +4,22 @@ using AE.Net.Mail;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.ComponentModel.Composition;
namespace NOCQ.Plugins.Email namespace NOCQ.Plugins.Email
{ {
public class ImapInput
[IDataImportAttr("Email")]
public class ImapInput: IDataImportHook
{ {
public string Name
{
get
{
{return "IMAP";}
}
}
string loginName { get; set; } string loginName { get; set; }
string password { get; set; } string password { get; set; }
string server { get; set; } string server { get; set; }