use settings object
This commit is contained in:
@@ -7,13 +7,14 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NOCQ.Extensability;
|
||||
using System.IO;
|
||||
namespace NOCQ.Application
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
var s = RedisDatabase.GetNextAlert("127.0.0.1", RedisQueues.Input, 6379, 3000);
|
||||
var s = RedisDatabase.GetNextAlert(SettingsParser.SettingsFile(File.ReadAllText(Path.Combine(".","settings.json"))));
|
||||
|
||||
// process s
|
||||
var importPlugs = CatalogRepository.GetImportPlugins();
|
||||
|
||||
@@ -3,36 +3,43 @@ using ctstone.Redis;
|
||||
using System.Threading.Tasks;
|
||||
using System.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using NOCQ.Settings;
|
||||
|
||||
|
||||
namespace NOCQ
|
||||
{
|
||||
public sealed class RedisDatabase
|
||||
{
|
||||
private string host { get; set; }
|
||||
private string q { get; set; }
|
||||
private string port {get;set;}
|
||||
private int timeout { get; set;}
|
||||
public RedisDatabase(){}
|
||||
|
||||
public static void SaveAlert(Alert alert, string host, string q, int port, int timeout)
|
||||
public static void SaveAlert(Alert alert, RedisSettings setting)
|
||||
{
|
||||
using (var redis = new RedisClient(host,
|
||||
port,
|
||||
timeout
|
||||
using (var redis = new RedisClient(setting.Hostname,
|
||||
setting.Port,
|
||||
setting.Timeout
|
||||
))
|
||||
{
|
||||
|
||||
|
||||
redis.LPush(q, JsonConvert.SerializeObject(alert));
|
||||
redis.LPush(setting.InputQueue, JsonConvert.SerializeObject(alert));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Alert GetNextAlert(string host, string q, int port, int timeout )
|
||||
public static Alert GetNextAlert(RedisSettings setting)
|
||||
{
|
||||
|
||||
using (var redis = new RedisClient(host,
|
||||
port,
|
||||
timeout
|
||||
using (var redis = new RedisClient(setting.Hostname,
|
||||
setting.Port,
|
||||
setting.Timeout
|
||||
))
|
||||
{
|
||||
var ts = redis.RPop(q);
|
||||
var ts = redis.RPop(setting.OutputQueue);
|
||||
|
||||
return JsonConvert.DeserializeObject<Alert>(ts);
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{83651B7D-B58F-46B8-BFE2-BCC0A6C92C7A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>NOCQ</RootNamespace>
|
||||
@@ -72,7 +70,9 @@
|
||||
<DependentUpon>EmailSettings.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Model\Alert.cs" />
|
||||
<Compile Include="DB\RedisQueues.cs" />
|
||||
<Compile Include="DB\RedisQueues.cs">
|
||||
<DependentUpon>RedisDatabase.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Settings\SettingsFIle.cs" />
|
||||
<Compile Include="Settings\RedisSettings.cs" />
|
||||
<Compile Include="Settings\SettingsParser.cs" />
|
||||
|
||||
@@ -4,11 +4,11 @@ namespace NOCQ.Settings
|
||||
{
|
||||
public class RedisSettings
|
||||
{
|
||||
public string hostname {get;set;}
|
||||
public string port {get;set;}
|
||||
public string timeout{get;set;}
|
||||
public string inputQueue{get;set;}
|
||||
public string outputQueue{get;set;}
|
||||
public string Hostname {get;set;}
|
||||
public int Port {get;set;}
|
||||
public int Timeout{get;set;}
|
||||
public string InputQueue{get;set;}
|
||||
public string OutputQueue{get;set;}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user