提交 f6475de3 编写于 作者: cdy816's avatar cdy816

修复值改变记录Bug 2020/7/3 三沙永兴岛

上级 e095321e
......@@ -270,7 +270,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{local:ResMarker RecordType,:}" VerticalAlignment="Center" />
<ComboBox Margin="4,0" Grid.Column="1" Width="100" VerticalAlignment="Center" Text="{Binding RecordTypeString,Mode=OneWay}" SelectedIndex="{Binding RecordType,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding RecordTypeList}"/>
<ComboBox Margin="4,0" Grid.Column="1" Width="160" VerticalAlignment="Center" Text="{Binding RecordTypeString,Mode=OneWay}" SelectedIndex="{Binding RecordType,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding RecordTypeList}"/>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Grid Margin="4,0" Visibility="{Binding IsTimerRecord,Converter={StaticResource btv}}">
<Grid.ColumnDefinitions>
......@@ -281,7 +281,7 @@
<TextBox Margin="8,0" Grid.Column="1" Width="60" Text="{Binding CompressCircle,Mode=TwoWay}" VerticalAlignment="Center" />
</Grid>
<TextBlock Text="{local:ResMarker CompressType,:}" VerticalAlignment="Center"/>
<ComboBox Margin="8,0" Width="100" VerticalAlignment="Center" ItemsSource="{Binding CompressTypeList}" SelectedIndex="{Binding CompressType,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<ComboBox Margin="8,0" Width="160" VerticalAlignment="Center" ItemsSource="{Binding CompressTypeList}" SelectedIndex="{Binding CompressType,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<ContentControl VerticalAlignment="Center" Content="{Binding CompressParameterModel}" HorizontalAlignment="Stretch" />
</StackPanel>
......
......@@ -227,7 +227,7 @@ namespace Cdy.Tag
}
catch(Exception ex)
{
LoggerService.Service.Erro("CompressEnginer", ex.Message);
LoggerService.Service.Erro("CompressEnginer", ex.StackTrace+" "+ex.Message);
}
mIsRunning = false;
}
......
......@@ -339,11 +339,12 @@ namespace Cdy.Tag
// int count = MemoryCachTime * 1000 / MemoryTimeTick;
int count = MergeMemoryTime;
//对于值改变的记录方式,提高内存分配量,以提高值改变记录的数据个数
if(recordType == RecordType.ValueChanged)
{
count = MergeMemoryTime * 1000 / MemoryTimeTick;
}
////对于值改变的记录方式,提高内存分配量,以提高值改变记录的数据个数
//if(recordType == RecordType.ValueChanged)
//{
// count = MergeMemoryTime * 1000 / MemoryTimeTick;
//}
//用于解码时在头尾分别记录前一个区域的值和后一个区域的值
count += 2;
......@@ -404,10 +405,10 @@ namespace Cdy.Tag
int count = CachMemoryTime;
//对于值改变的记录方式,提高内存分配量,以提高值改变记录的数据个数
if (recordType == RecordType.ValueChanged)
{
count = CachMemoryTime * 1000 / MemoryTimeTick;
}
//if (recordType == RecordType.ValueChanged)
//{
// count = CachMemoryTime * 1000 / MemoryTimeTick;
//}
//数据区偏移,时间戳占2个字节,质量戳占1个字节
dataOffset = headSize + count * 2;
......
......@@ -325,11 +325,11 @@ namespace Cdy.Tag
// int count = MemoryCachTime * 1000 / MemoryTimeTick;
int count = MergeMemoryTime;
//对于值改变的记录方式,提高内存分配量,以提高值改变记录的数据个数
if(recordType == RecordType.ValueChanged)
{
count = MergeMemoryTime * 1000 / MemoryTimeTick;
}
////对于值改变的记录方式,提高内存分配量,以提高值改变记录的数据个数
//if(recordType == RecordType.ValueChanged)
//{
// count = MergeMemoryTime * 1000 / MemoryTimeTick;
//}
//用于解码时在头尾分别记录前一个区域的值和后一个区域的值
count += 2;
......@@ -389,11 +389,11 @@ namespace Cdy.Tag
qulityOffset = headSize;
int count = CachMemoryTime;
//对于值改变的记录方式,提高内存分配量,以提高值改变记录的数据个数
if (recordType == RecordType.ValueChanged)
{
count = CachMemoryTime * 1000 / MemoryTimeTick;
}
////对于值改变的记录方式,提高内存分配量,以提高值改变记录的数据个数
//if (recordType == RecordType.ValueChanged)
//{
// count = CachMemoryTime * 1000 / MemoryTimeTick;
//}
//数据区偏移,时间戳占2个字节,质量戳占1个字节
dataOffset = headSize + count * 2;
......
......@@ -11,11 +11,14 @@ using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Linq;
using System.Collections.Concurrent;
namespace Cdy.Tag
{
/// <summary>
///
/// 值改变记录,记录周期同定时记录的周期的一样1s
/// 每隔1s毫秒检查一次变量是否改变,如果改变则记录。
/// 变化周期超过1s的情况,则会被忽略
/// </summary>
public class ValueChangedMemoryCacheProcesser:IDisposable
{
......@@ -31,7 +34,7 @@ namespace Cdy.Tag
/// <summary>
///
/// </summary>
private Dictionary<int, bool> mChangedTags = new Dictionary<int, bool>();
private ConcurrentDictionary<int, bool> mChangedTags = new ConcurrentDictionary<int, bool>();
public const int MaxTagCount = 100000;
......@@ -87,6 +90,8 @@ namespace Cdy.Tag
/// </summary>
private DateTime mLastUpdateTime;
private int mLastUpdateSecond = -1;
#endregion ...Properties...
#region ... Methods ...
......@@ -98,7 +103,11 @@ namespace Cdy.Tag
public void Notify(DateTime time)
{
mLastUpdateTime = time;
resetEvent.Set();
if(mLastUpdateTime.Second!=mLastUpdateSecond)
{
mLastUpdateSecond = mLastUpdateTime.Second;
resetEvent.Set();
}
}
/// <summary>
......@@ -110,13 +119,16 @@ namespace Cdy.Tag
ServiceLocator.Locator.Resolve<IRealDataNotify>().SubscribeValueChangedForConsumer(this.Name, new ValueChangedNotifyProcesser.ValueChangedDelegate((ids) => {
foreach(var vv in ids)
{
if(mChangedTags.ContainsKey(vv))
{
mChangedTags[vv] = true;
}
mChangedTags[vv] = true;
}
}),null,null, new Func<List<int>>(() => { return mTags.Keys.ToList(); }));
foreach(var vv in mTags.Keys)
{
mChangedTags.TryAdd(vv, false);
}
mRecordThread = new Thread(ThreadProcess);
mRecordThread.IsBackground=true;
mRecordThread.Start();
......@@ -130,6 +142,9 @@ namespace Cdy.Tag
mIsClosed = true;
resetEvent.Set();
closedEvent.WaitOne();
Clear();
ServiceLocator.Locator.Resolve<IRealDataNotify>().UnSubscribeValueChangedForConsumer(this.Name);
}
/// <summary>
......@@ -157,75 +172,11 @@ namespace Cdy.Tag
public void Clear()
{
mTags.Clear();
mChangedTags.Clear();
mCurrentCount = 0;
}
///// <summary>
/////
///// </summary>
//public void WriteHeader()
//{
// foreach (var vv in mTags.Values)
// {
// vv.UpdateHeader();
// }
//}
///// <summary>
/////
///// </summary>
///// <param name="time"></param>
//public void RecordFirstValue(DateTime time)
//{
// mLastUpdateTime = time;
// int tim = (int)((mLastUpdateTime - HisRunTag.StartTime).TotalMilliseconds / HisEnginer.MemoryTimeTick);
// foreach (var vv in mTags)
// {
// vv.Value.UpdateFirstValue(tim);
// }
//}
///// <summary>
/////
///// </summary>
///// <param name="time"></param>
//public void RecordLastValue(DateTime time)
//{
// mLastUpdateTime = time;
// int tim = (int)((mLastUpdateTime - HisRunTag.StartTime).TotalMilliseconds / HisEnginer.MemoryTimeTick);
// foreach (var vv in mTags)
// {
// vv.Value.UpdateLastValue(tim);
// }
//}
///// <summary>
///// 记录所有值
///// </summary>
//public void RecordAllValue(DateTime time)
//{
// try
// {
// mLastUpdateTime = time;
// int tim = (int)((mLastUpdateTime - HisRunTag.StartTime).TotalMilliseconds / HisEnginer.MemoryTimeTick);
// foreach (var vv in mTags)
// {
// if (mChangedTags.ContainsKey(vv.Key) && mChangedTags[vv.Key])
// {
// mTags[vv.Key].UpdateValue(tim);
// }
// else
// {
// vv.Value.AppendValue(tim);
// }
// }
// }
// catch
// {
// }
//}
/// <summary>
///
......@@ -238,6 +189,8 @@ namespace Cdy.Tag
resetEvent.WaitOne();
resetEvent.Reset();
if (mIsClosed) break;
//LoggerService.Service.Info("ValueChangedMemoryCacheProcesser", Name + " 执行!");
try
{
int tim = (int)((mLastUpdateTime - HisRunTag.StartTime).TotalMilliseconds / HisEnginer.MemoryTimeTick);
......@@ -245,18 +198,14 @@ namespace Cdy.Tag
{
if (vv.Value)
{
mTags[vv.Key].UpdateValue(tim/10,tim);
mChangedTags[vv.Key] = false;
mTags[vv.Key].UpdateValue(tim);
}
else
{
mTags[vv.Key].UpdateNone();
}
mChangedTags[vv.Key] = false;
}
}
catch
catch(Exception ex)
{
LoggerService.Service.Erro("ValueChangedMemoryCacheProcesser", ex.Message);
}
resetEvent.Reset();
}
......@@ -271,6 +220,8 @@ namespace Cdy.Tag
{
resetEvent.Close();
closedEvent.Close();
mChangedTags.Clear();
mTags.Clear();
}
#endregion ...Methods...
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册