mirror of
https://github.com/akpaevj/OneSTools.TechLog.git
synced 2025-02-16 18:34:27 +02:00
Добавлена возможность считывания только заданных свойств.
This commit is contained in:
parent
881d1534ee
commit
c8750c3306
@ -9,7 +9,7 @@
|
||||
<PackageProjectUrl>https://github.com/akpaevj/OneSTools.TechLog</PackageProjectUrl>
|
||||
<Copyright>Akpaev Evgeny</Copyright>
|
||||
<Description>Библиотека для парсинга технологического журнала 1С</Description>
|
||||
<Version>2.1.0</Version>
|
||||
<Version>2.1.1</Version>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<PackageIcon>onestools_icon_nuget.png</PackageIcon>
|
||||
<PackageLicenseExpression></PackageLicenseExpression>
|
||||
|
@ -13,6 +13,7 @@ namespace OneSTools.TechLog
|
||||
public class TechLogFileReader : IDisposable
|
||||
{
|
||||
private readonly string _fileDateTime;
|
||||
private readonly List<string> _properties;
|
||||
private readonly AdditionalProperty _additionalProperty;
|
||||
private FileStream _fileStream;
|
||||
private StreamReader _streamReader;
|
||||
@ -27,9 +28,10 @@ namespace OneSTools.TechLog
|
||||
set => _streamReader.SetPosition(value);
|
||||
}
|
||||
|
||||
public TechLogFileReader(string logPath, AdditionalProperty additionalProperty)
|
||||
public TechLogFileReader(string logPath, List<string> properties, AdditionalProperty additionalProperty)
|
||||
{
|
||||
LogPath = logPath;
|
||||
_properties = properties;
|
||||
_additionalProperty = additionalProperty;
|
||||
|
||||
var fileName = Path.GetFileNameWithoutExtension(LogPath);
|
||||
@ -106,19 +108,33 @@ namespace OneSTools.TechLog
|
||||
item.TrySetPropertyValue("Event", ReadNextPropertyWithoutName(rawItem, ref startPosition, ','));
|
||||
item.TrySetPropertyValue("Level", ReadNextPropertyWithoutName(rawItem, ref startPosition, ','));
|
||||
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
if (_properties.Count > 0)
|
||||
{
|
||||
var (Name, Value) = ReadNextProperty(rawItem, ref startPosition);
|
||||
foreach (var property in _properties)
|
||||
{
|
||||
var value = ReadPropertyValue(rawItem, property);
|
||||
|
||||
if (string.IsNullOrEmpty(Name))
|
||||
break;
|
||||
if (!(value is null))
|
||||
if (!item.TrySetPropertyValue(property, value))
|
||||
item.TrySetPropertyValue(GetPropertyName(item, property, 0), value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
var (Name, Value) = ReadNextProperty(rawItem, ref startPosition);
|
||||
|
||||
// Property with the same name already can exist, so we have to get a new name for the value
|
||||
if (!item.TrySetPropertyValue(Name, Value))
|
||||
item.TrySetPropertyValue(GetPropertyName(item, Name, 0), Value);
|
||||
if (string.IsNullOrEmpty(Name))
|
||||
break;
|
||||
|
||||
if (startPosition >= rawItem.Length)
|
||||
break;
|
||||
// Property with the same name already can exist, so we have to get a new name for the value
|
||||
if (!item.TrySetPropertyValue(Name, Value))
|
||||
item.TrySetPropertyValue(GetPropertyName(item, Name, 0), Value);
|
||||
|
||||
if (startPosition >= rawItem.Length)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SetAdditionalProperties(item);
|
||||
@ -160,6 +176,13 @@ namespace OneSTools.TechLog
|
||||
if (startPosition == strData.Length)
|
||||
return (name, "");
|
||||
|
||||
var value = GetPropertyValue(strData, ref startPosition);
|
||||
|
||||
return (name, value);
|
||||
}
|
||||
|
||||
private string GetPropertyValue(string strData, ref int startPosition)
|
||||
{
|
||||
var nextChar = strData[startPosition];
|
||||
|
||||
int endPosition;
|
||||
@ -170,7 +193,7 @@ namespace OneSTools.TechLog
|
||||
break;
|
||||
case ',':
|
||||
startPosition++;
|
||||
return (name, "");
|
||||
return "";
|
||||
case '"':
|
||||
endPosition = strData.IndexOf('"', startPosition + 1);
|
||||
break;
|
||||
@ -185,7 +208,21 @@ namespace OneSTools.TechLog
|
||||
var value = strData[startPosition..endPosition];
|
||||
startPosition = endPosition + 1;
|
||||
|
||||
return (name, value.Trim(new char[] { '\'', '"' }).Trim());
|
||||
return value.Trim(new char[] { '\'', '"' }).Trim();
|
||||
}
|
||||
|
||||
private string ReadPropertyValue(string strData, string name)
|
||||
{
|
||||
var index = strData.IndexOf($",{name}=");
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
int pos = index + name.Length + 2;
|
||||
|
||||
return GetPropertyValue(strData, ref pos);
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SetAdditionalProperties(TechLogItem item)
|
||||
|
@ -110,7 +110,7 @@ namespace OneSTools.TechLog
|
||||
{
|
||||
_logReader?.Dispose();
|
||||
|
||||
_logReader = new TechLogFileReader(FilePath, _settings.AdditionalProperty);
|
||||
_logReader = new TechLogFileReader(FilePath, _settings.Properties, _settings.AdditionalProperty);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
namespace OneSTools.TechLog
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OneSTools.TechLog
|
||||
{
|
||||
public class TechLogFolderReaderSettings
|
||||
{
|
||||
public string Folder { get; set; } = "";
|
||||
public List<string> Properties { get; set; } = new List<string>();
|
||||
public AdditionalProperty AdditionalProperty { get; set; } = AdditionalProperty.None;
|
||||
public bool LiveMode { get; set; } = false;
|
||||
public int ReadingTimeout { get; set; } = 1;
|
||||
|
@ -71,6 +71,7 @@ namespace OneSTools.TechLog
|
||||
var settings = new TechLogFolderReaderSettings
|
||||
{
|
||||
Folder = logFolder,
|
||||
Properties = _settings.Properties,
|
||||
AdditionalProperty = _settings.AdditionalProperty,
|
||||
LiveMode = _settings.LiveMode,
|
||||
ReadingTimeout = _settings.ReadingTimeout
|
||||
|
@ -1,10 +1,13 @@
|
||||
namespace OneSTools.TechLog
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OneSTools.TechLog
|
||||
{
|
||||
public class TechLogReaderSettings
|
||||
{
|
||||
public string LogFolder { get; set; } = "";
|
||||
public int BatchSize { get; set; } = 1000;
|
||||
public int BatchFactor { get; set; } = 2;
|
||||
public List<string> Properties { get; set; } = new List<string>();
|
||||
public AdditionalProperty AdditionalProperty { get; set; } = AdditionalProperty.None;
|
||||
public bool LiveMode { get; set; } = false;
|
||||
public int ReadingTimeout { get; set; } = 1;
|
||||
|
@ -3,6 +3,7 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OneSTools.TechLogTestApp
|
||||
{
|
||||
@ -14,6 +15,7 @@ namespace OneSTools.TechLogTestApp
|
||||
var folderReaderSettings = new TechLogReaderSettings()
|
||||
{
|
||||
LogFolder = @"C:\Users\akpaev.e.ENTERPRISE\Desktop\TechLog",
|
||||
Properties = new List<string>() { "Sql", "Context" },
|
||||
AdditionalProperty = AdditionalProperty.SqlHash | AdditionalProperty.FirstContextLine | AdditionalProperty.LastContextLine | AdditionalProperty.EndPosition,
|
||||
BatchSize = 100,
|
||||
BatchFactor = 2,
|
||||
|
Loading…
x
Reference in New Issue
Block a user