mirror of
https://github.com/krugersu/YY.EventLogExportAssistant.git
synced 2026-06-20 01:16:51 +02:00
Первая порция архитектурных изменений классов и интерфейсов
This commit is contained in:
@@ -12,41 +12,41 @@ namespace YY.EventLogExportToPostgreSQL
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
using (EventLogContext context = new EventLogContext())
|
||||
{
|
||||
long isCount = context.InformationSystems.Count();
|
||||
Console.WriteLine("Количество информационных систем: {0}", isCount);
|
||||
}
|
||||
//using (EventLogContext context = new EventLogContext())
|
||||
//{
|
||||
// long isCount = context.InformationSystems.Count();
|
||||
// Console.WriteLine("Количество информационных систем: {0}", isCount);
|
||||
//}
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.WriteLine("Не передан путь к файлам журнала регистрации.");
|
||||
}
|
||||
else
|
||||
{
|
||||
string eventLogPath = args[0];
|
||||
int queueLength = 1000;
|
||||
EventLogTargetDefinition exporterDefination = new EventLogTargetDefinitionForPostgreSQL();
|
||||
//if (args.Length == 0)
|
||||
//{
|
||||
// Console.WriteLine("Не передан путь к файлам журнала регистрации.");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// string eventLogPath = args[0];
|
||||
// int queueLength = 1000;
|
||||
// EventLogOnTarget exporterDefination = new EventLogOnPostgreSQL();
|
||||
|
||||
using (EventLogExportMaster exporter = EventLogExportMaster.CreateExportMaster(exporterDefination))
|
||||
{
|
||||
using (EventLogReader reader = EventLogReader.CreateReader(eventLogPath))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
exporter.AddItem(reader.CurrentRow);
|
||||
// using (EventLogExportMaster exporter = EventLogExportMaster.CreateExportMaster(exporterDefination))
|
||||
// {
|
||||
// using (EventLogReader reader = EventLogReader.CreateReader(eventLogPath))
|
||||
// {
|
||||
// if (reader.Read())
|
||||
// {
|
||||
// exporter.AddItem(reader.CurrentRow);
|
||||
|
||||
// Отправляем порцию накопившихся элементов
|
||||
if (exporter.QueueLength >= queueLength)
|
||||
exporter.Send();
|
||||
}
|
||||
}
|
||||
// // Отправляем порцию накопившихся элементов
|
||||
// if (exporter.QueueLength >= queueLength)
|
||||
// exporter.Send();
|
||||
// }
|
||||
// }
|
||||
|
||||
// Отправляем оставшиеся элементы
|
||||
if (exporter.QueueLength > 0)
|
||||
exporter.Send();
|
||||
}
|
||||
}
|
||||
// // Отправляем оставшиеся элементы
|
||||
// if (exporter.QueueLength > 0)
|
||||
// exporter.Send();
|
||||
// }
|
||||
//}
|
||||
|
||||
Console.WriteLine("Для выхода нажмите любую клавишу...");
|
||||
Console.ReadKey();
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
using System;
|
||||
using YY.EventLogReaderAssistant.Models;
|
||||
|
||||
namespace YY.EventLogExportAssistant
|
||||
{
|
||||
public sealed class EventLogExportMaster : IEventLogExportMaster, IDisposable
|
||||
public sealed class EventLogExportMaster<T> : IEventLogExportMaster<T>, IDisposable where T : CommonLogObject
|
||||
{
|
||||
public static EventLogExportMaster CreateExportMaster(EventLogTargetDefinition target)
|
||||
public static EventLogExportMaster<T> CreateExportMaster(EventLogOnTarget<T> target)
|
||||
{
|
||||
return new EventLogExportMaster(target);
|
||||
return new EventLogExportMaster<T>(target);
|
||||
}
|
||||
|
||||
private IEventLogTargetDefinition _target;
|
||||
private IEventLogTarget<T> _target;
|
||||
|
||||
private EventLogExportMaster()
|
||||
{
|
||||
}
|
||||
private EventLogExportMaster(EventLogTargetDefinition target)
|
||||
private EventLogExportMaster(EventLogOnTarget<T> target)
|
||||
{
|
||||
_target = target;
|
||||
_target = (IEventLogTarget<T>)target;
|
||||
}
|
||||
|
||||
public void AddItem(object item)
|
||||
public void AddItem(T item)
|
||||
{
|
||||
Console.WriteLine("Item added");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YY.EventLogExportAssistant
|
||||
{
|
||||
public abstract class EventLogOnTarget<T> : IEventLogTarget<T>, IDisposable where T : CommonLogObject
|
||||
{
|
||||
public virtual void Save(T rowData)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual void Save(IList<T> rowsData)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using YY.EventLogReaderAssistant.Models;
|
||||
|
||||
namespace YY.EventLogExportAssistant
|
||||
{
|
||||
public abstract class EventLogTargetDefinition : IEventLogTargetDefinition
|
||||
{
|
||||
public virtual void Save(RowData rowData)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Save(IList<RowData> rowsData)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace YY.EventLogExportAssistant
|
||||
{
|
||||
public interface IEventLogExportMaster
|
||||
public interface IEventLogExportMaster<T> where T : CommonLogObject
|
||||
{
|
||||
void AddItem(object item);
|
||||
void AddItem(T item);
|
||||
|
||||
void Send();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YY.EventLogExportAssistant
|
||||
{
|
||||
public interface IEventLogTarget<T> where T : CommonLogObject
|
||||
{
|
||||
void Save(T rowData);
|
||||
void Save(IList<T> rowsData);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using YY.EventLogReaderAssistant.Models;
|
||||
|
||||
namespace YY.EventLogExportAssistant
|
||||
{
|
||||
public interface IEventLogTargetDefinition
|
||||
{
|
||||
void Save(RowData rowData);
|
||||
void Save(IList<RowData> rowsData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace YY.EventLogExportAssistant
|
||||
{
|
||||
public class CommonLogObject
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace YY.EventLogExportAssistant.ElasticSearch
|
||||
{
|
||||
public class EventLogOnElasticSearch<T> : EventLogOnTarget<T> where T : CommonLogObject
|
||||
{
|
||||
}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace YY.EventLogExportAssistant.ElasticSearch
|
||||
{
|
||||
public class EventLogTargetDefinitionForElasticSearch : EventLogTargetDefinition
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace YY.EventLogExportAssistant.PostgreSQL
|
||||
{
|
||||
public class EventLogOnPostgreSQL<T> : EventLogOnTarget<T> where T : CommonLogObject
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace YY.EventLogExportAssistant.PostgreSQL
|
||||
{
|
||||
public class EventLogTargetDefinitionForPostgreSQL : EventLogTargetDefinition
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace YY.EventLogExportAssistant.PostgreSQL.Models
|
||||
{
|
||||
public abstract class LogObject
|
||||
public abstract class LogObject : CommonLogObject
|
||||
{
|
||||
public virtual long InformationSystemId { get; set; }
|
||||
public virtual InformationSystems InformationSystem { get; set; }
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
namespace YY.EventLogExportAssistant.SQLServer
|
||||
{
|
||||
public class EventLogOnSQLServer<T> : EventLogOnTarget<T> where T : CommonLogObject
|
||||
{
|
||||
private const int _defaultPortion = 1000;
|
||||
private int _portion;
|
||||
private EventLogContext _context;
|
||||
|
||||
|
||||
public EventLogOnSQLServer() : this(null, _defaultPortion)
|
||||
{
|
||||
|
||||
}
|
||||
public EventLogOnSQLServer(int portion)
|
||||
{
|
||||
_portion = portion;
|
||||
}
|
||||
public EventLogOnSQLServer(EventLogContext context, int portion)
|
||||
{
|
||||
_portion = portion;
|
||||
if(context == null)
|
||||
_context = new EventLogContext();
|
||||
else
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public override void Save(T rowData)
|
||||
{
|
||||
_context.Add(rowData);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace YY.EventLogExportAssistant.SQLServer
|
||||
{
|
||||
public class EventLogTargetDefinitionForSQLServer : EventLogTargetDefinition
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace YY.EventLogExportAssistant.SQLServer.Models
|
||||
namespace YY.EventLogExportAssistant.SQLServer.Models
|
||||
{
|
||||
public abstract class LogObject
|
||||
public abstract class LogObject : CommonLogObject
|
||||
{
|
||||
public virtual long InformationSystemId { get; set; }
|
||||
public virtual InformationSystems InformationSystem { get; set; }
|
||||
|
||||
@@ -4,6 +4,7 @@ using System;
|
||||
using System.Linq;
|
||||
using YY.EventLogExportAssistant;
|
||||
using YY.EventLogExportAssistant.SQLServer;
|
||||
using YY.EventLogExportAssistant.SQLServer.Models;
|
||||
using YY.EventLogReaderAssistant;
|
||||
|
||||
namespace YY.EventLogExportToSQLServer
|
||||
@@ -26,27 +27,28 @@ namespace YY.EventLogExportToSQLServer
|
||||
{
|
||||
string eventLogPath = args[0];
|
||||
int queueLength = 1000;
|
||||
EventLogTargetDefinition exporterDefination = new EventLogTargetDefinitionForSQLServer();
|
||||
|
||||
using (EventLogExportMaster exporter = EventLogExportMaster.CreateExportMaster(exporterDefination))
|
||||
using (EventLogOnTarget<LogObject> target = new EventLogOnSQLServer<LogObject>())
|
||||
{
|
||||
using (EventLogReader reader = EventLogReader.CreateReader(eventLogPath))
|
||||
using (EventLogExportMaster<LogObject> exporter = EventLogExportMaster<LogObject>.CreateExportMaster(target))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
exporter.AddItem(reader.CurrentRow);
|
||||
//using (EventLogReader reader = EventLogReader.CreateReader(eventLogPath))
|
||||
//{
|
||||
// if (reader.Read())
|
||||
// {
|
||||
// exporter.AddItem(reader.CurrentRow);
|
||||
|
||||
// Отправляем порцию накопившихся элементов
|
||||
if (exporter.QueueLength >= queueLength)
|
||||
exporter.Send();
|
||||
}
|
||||
// // Отправляем порцию накопившихся элементов
|
||||
// if (exporter.QueueLength >= queueLength)
|
||||
// exporter.Send();
|
||||
// }
|
||||
//}
|
||||
|
||||
// Отправляем оставшиеся элементы
|
||||
if (exporter.QueueLength > 0)
|
||||
exporter.Send();
|
||||
}
|
||||
|
||||
// Отправляем оставшиеся элементы
|
||||
if (exporter.QueueLength > 0)
|
||||
exporter.Send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Для выхода нажмите любую клавишу...");
|
||||
Console.ReadKey();
|
||||
|
||||
Reference in New Issue
Block a user