committing broken stuff as i have to stop
This commit is contained in:
@@ -5,31 +5,25 @@ using NOCQ.Plugins.Email;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using NOCQ.Extensability;
|
||||
namespace NOCQ.Application
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
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);
|
||||
Console.WriteLine(s.Data);
|
||||
}
|
||||
var s = RedisDatabase.GetNextAlert("127.0.0.1", RedisQueues.Input, 6379, 3000);
|
||||
|
||||
// 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();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
namespace NOCQ
|
||||
{
|
||||
public class RedisDatabase
|
||||
public sealed class RedisDatabase
|
||||
{
|
||||
public RedisDatabase(){}
|
||||
|
||||
|
||||
@@ -2,17 +2,19 @@ using System.ComponentModel.Composition.Hosting;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NOCQ
|
||||
namespace NOCQ.Extensability
|
||||
{
|
||||
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 AggregateCatalog catalog = new AggregateCatalog(dcatalog, acatalog);
|
||||
static public CompositionContainer Container = new CompositionContainer(catalog);
|
||||
public Catalog()
|
||||
private static AggregateCatalog Cat = new AggregateCatalog(acatalog);
|
||||
private static CompositionContainer _container = new CompositionContainer(Cat);
|
||||
public CompositionContainer Container { get { return _container; } }
|
||||
public Catalog()
|
||||
{
|
||||
Container.ComposeParts(this);
|
||||
_container.ComposeParts(this);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
src/NOCQ/Extensability/CatalogRepository.cs
Normal file
15
src/NOCQ/Extensability/CatalogRepository.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace NOCQ
|
||||
[Export]
|
||||
public class DataImports
|
||||
{
|
||||
[ImportMany]
|
||||
IEnumerable<IDataImportHook> DataHooks {get; set;}
|
||||
[ImportMany(AllowRecomposition = true)]
|
||||
public IEnumerable<System.Lazy<IDataImportHook,IDataImportMetadata>> DataHooks {get; set;}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ using System.ComponentModel.Composition;
|
||||
|
||||
namespace NOCQ
|
||||
{
|
||||
[InheritedExport]
|
||||
|
||||
public interface IDataImportHook
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Name { get; set;}
|
||||
void Run();
|
||||
void Stop();
|
||||
}
|
||||
|
||||
22
src/NOCQ/Imports/IDataImportMetadata.cs
Normal file
22
src/NOCQ/Imports/IDataImportMetadata.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@
|
||||
<Compile Include="Model\Alert.cs" />
|
||||
<Compile Include="DB\RedisQueues.cs" />
|
||||
<Compile Include="DB\RedisDatabase.cs" />
|
||||
<Compile Include="Extensability\CatalogRepository.cs" />
|
||||
<Compile Include="Imports\IDataImportMetadata.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,11 +4,22 @@ using AE.Net.Mail;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.ComponentModel.Composition;
|
||||
|
||||
namespace NOCQ.Plugins.Email
|
||||
{
|
||||
public class ImapInput
|
||||
|
||||
[IDataImportAttr("Email")]
|
||||
public class ImapInput: IDataImportHook
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
{return "IMAP";}
|
||||
}
|
||||
}
|
||||
|
||||
string loginName { get; set; }
|
||||
string password { get; set; }
|
||||
string server { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user