-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagDatabase.cs
81 lines (68 loc) · 2.32 KB
/
TagDatabase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections;
using System.Collections.Generic;
using ThingMagic;
namespace ReceiveAutonomousReadingDemodotNet
{
public class TagDatabase
{
public Dictionary<string, TagReadRecord> EpcIndex = new Dictionary<string, TagReadRecord>();
private List<TagReadRecord> _tagList = new List<TagReadRecord>();
static long UniqueTagCounts = 0;
static long TotalTagCounts = 0;
public long UniqueTagCount
{
get { return UniqueTagCounts; }
}
public long TotalTagCount
{
get { return TotalTagCounts; }
}
public List<TagReadRecord> TagList {
get { return _tagList; }
}
public void Add(TagReadData addData)
{
lock (new Object())
{
string key = null;
key = addData.EpcString; //if only keying on EPCID
UniqueTagCounts = 0;
TotalTagCounts = 0;
if (!EpcIndex.ContainsKey(key))
{
TagReadRecord value = new TagReadRecord(addData);
value.SerialNumber = (uint)EpcIndex.Count + 1;
EpcIndex.Add(key, value);
_tagList.Add(value);
//Call this method to calculate total tag reads and unique tag read counts
UpdateTagCountTextBox(EpcIndex);
Console.WriteLine("Add {0}", value);
}
else
{
EpcIndex[key].Update(addData); //ToDo update temperature
UpdateTagCountTextBox(EpcIndex);
}
}
}
private void UpdateTagCountTextBox(Dictionary<string, TagReadRecord> epcIndex)
{
UniqueTagCounts += EpcIndex.Count;
TagReadRecord[] dataRecord = new TagReadRecord[EpcIndex.Count];
EpcIndex.Values.CopyTo(dataRecord, 0);
TotalTagCounts = 0;
for (int i = 0; i < dataRecord.Length; i++)
{
TotalTagCounts += dataRecord[i].ReadCount;
}
}
public void Clear()
{
EpcIndex.Clear();
UniqueTagCounts = 0;
TotalTagCounts = 0;
_tagList.Clear();
}
}
}