mirror of
https://github.com/akpaevj/OneSTools.TechLog.git
synced 2024-11-24 08:02:22 +02:00
Добавлен наблюдатель каталога журнала
This commit is contained in:
parent
6a49a7d672
commit
fea68b13d5
@ -91,7 +91,7 @@ namespace OneSTools.TechLog.Exporter.ClickHouse.Properties {
|
||||
/// Position Int64 Codec(DoubleDelta, LZ4)
|
||||
///)
|
||||
///engine = MergeTree()
|
||||
///ORDER BY (Folder).
|
||||
///ORDER BY (Folder, File).
|
||||
/// </summary>
|
||||
internal static string CreateLastPositionsTable {
|
||||
get {
|
||||
|
@ -143,6 +143,7 @@ DeadlockInfo String Codec(ZSTD),
|
||||
Descr String Codec(ZSTD)
|
||||
)
|
||||
engine = MergeTree()
|
||||
PARTITION BY toYYYYMMDD(DateTime)
|
||||
ORDER BY (DateTime, EndTicks, EventName)</value>
|
||||
<comment>Создание таблицы для событий EXCP</comment>
|
||||
</data>
|
||||
@ -154,7 +155,7 @@ ORDER BY (DateTime, EndTicks, EventName)</value>
|
||||
Position Int64 Codec(DoubleDelta, LZ4)
|
||||
)
|
||||
engine = MergeTree()
|
||||
ORDER BY (Folder)</value>
|
||||
ORDER BY (Folder, File)</value>
|
||||
<comment>Таблица для хранения позиций в прочитанных файлах *.log</comment>
|
||||
</data>
|
||||
</root>
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<UserSecretsId>dotnet-TechLogExporter-E9ACEC9F-C3D8-45CE-A879-75285C05F850</UserSecretsId>
|
||||
<AssemblyName>OneSTools.TechLog.Exporter</AssemblyName>
|
||||
<RootNamespace>OneSTools.TechLog.Exporter</RootNamespace>
|
||||
|
@ -10,7 +10,7 @@
|
||||
"StorageType": 1
|
||||
},
|
||||
"ClickHouse": {
|
||||
"ConnectionString": "Host=172.19.149.61;Port=8123;Database=techlog_all_rds;Username=default;password=;"
|
||||
"ConnectionString": "Host=172.21.238.42;Port=8123;Database=techlog_all_rds;Username=default;password=;"
|
||||
},
|
||||
"Reader": {
|
||||
"LogFolder": "E:\\techlog_all_rds"
|
||||
|
@ -9,7 +9,7 @@
|
||||
<PackageProjectUrl>https://github.com/akpaevj/OneSTools.TechLog</PackageProjectUrl>
|
||||
<Copyright>Akpaev Evgeny</Copyright>
|
||||
<Description>Библиотека для чтения и парсинга технологического журнала 1С</Description>
|
||||
<Version>2.1.5</Version>
|
||||
<Version>2.1.6</Version>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<PackageIcon>onestools_icon_nuget.png</PackageIcon>
|
||||
<PackageLicenseExpression></PackageLicenseExpression>
|
||||
@ -28,11 +28,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="C:\Users\akpaev.e.ENTERPRISE\source\repos\OneSTools.TechLog\LICENSE">
|
||||
<None Include="..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
<None Include="C:\Users\akpaev.e.ENTERPRISE\source\repos\onestools_icon_nuget.png">
|
||||
<None Include="..\..\onestools_icon_nuget.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
|
87
OneSTools.TechLog/TechLogFolderWatcher.cs
Normal file
87
OneSTools.TechLog/TechLogFolderWatcher.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace OneSTools.TechLog
|
||||
{
|
||||
/// <summary>
|
||||
/// Watch tech log folder and raise created/changed events
|
||||
/// </summary>
|
||||
class TechLogFolderWatcher: IDisposable
|
||||
{
|
||||
private FileSystemWatcher _watcher;
|
||||
private bool disposedValue;
|
||||
|
||||
public string Folder { get; private set; }
|
||||
public HashSet<string> ExceceptionPaths { get; private set; } = new HashSet<string>();
|
||||
|
||||
delegate void FileCreatedHandler(string path);
|
||||
event FileCreatedHandler FileCreated;
|
||||
|
||||
delegate void FileChangedHandler(string path);
|
||||
event FileChangedHandler FileChanged;
|
||||
|
||||
public TechLogFolderWatcher(string folder)
|
||||
{
|
||||
Folder = folder;
|
||||
}
|
||||
|
||||
public void StartWatching()
|
||||
{
|
||||
_watcher = new FileSystemWatcher(Folder, "*.log")
|
||||
{
|
||||
NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.LastWrite
|
||||
};
|
||||
_watcher.IncludeSubdirectories = true;
|
||||
_watcher.Changed += Watcher_Changed;
|
||||
_watcher.Created += Watcher_Created;
|
||||
_watcher.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
private void Watcher_Created(object sender, FileSystemEventArgs e)
|
||||
=> FileCreated?.Invoke(e.FullPath);
|
||||
|
||||
private void Watcher_Changed(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if (ExceceptionPaths.Contains(e.FullPath))
|
||||
return;
|
||||
|
||||
FileChanged?.Invoke(e.FullPath);
|
||||
}
|
||||
|
||||
public void StopWatching()
|
||||
{
|
||||
_watcher.EnableRaisingEvents = false;
|
||||
_watcher.Changed -= Watcher_Changed;
|
||||
_watcher.Created -= Watcher_Created;
|
||||
_watcher.Dispose();
|
||||
_watcher = null;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
ExceceptionPaths.Clear();
|
||||
}
|
||||
|
||||
StopWatching();
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
~TechLogFolderWatcher()
|
||||
{
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace OneSTools.TechLog
|
||||
{
|
||||
public class TechLogItem {
|
||||
public class TechLogItem {
|
||||
/// <summary>
|
||||
/// Collection of key/value pairs
|
||||
/// </summary>
|
||||
@ -19,6 +19,7 @@ namespace OneSTools.TechLog
|
||||
public DateTime DateTime { get; internal set; }
|
||||
|
||||
public long StartTicks { get; internal set; }
|
||||
|
||||
public long EndTicks { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user