ImageSavingBl.cs
5.41 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using OS.Spin.Common;
using OS.Spin.Modle.BusinessLayer;
using OS.Spin.Running;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Threading;
namespace OS.Spin.BusinessLayer.SubBusiness
{
public class ImageSavingBl
{
private static ImageSavingBl _savingBl = null;
private static object _objLock = new object();
public List<string> lstManMade = new List<string>();
private System.Threading.Thread _runing;
private ConcurrentQueue<MFileCopy> _copys = new ConcurrentQueue<MFileCopy>();
private bool _stop = false;
private ImageSavingBl()
{
_runing = new System.Threading.Thread(Working);
_runing.Start();
}
public static ImageSavingBl Getinstance()
{
lock (_objLock)
{
if (null == _savingBl)
{
_savingBl = new ImageSavingBl();
}
return _savingBl;
}
}
public void PutCopy(MFileCopy copy)
{
_copys.Enqueue(copy);
}
private void Working()
{
while (true)
{
try
{
if (_copys.Count == 0)
{
System.Threading.Thread.Sleep(100);
continue;
}
var id = Cache.GetInstance().CacheImgId;
MFileCopy copy;
_copys.TryDequeue(out copy);
Copying(copy);
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("Working:{0}",ex.Message));
}
//var count = _copys.Count();
//var stop = _stop;
//for (var i = 0; i < count; i++)
//{
// var copy = _copys[i];
// if (id < copy.MaxId && !stop)
// {
// continue;
// }
// Copying(copy);
// _copys.Remove(copy);
//}
//if(stop)
//{
// _stop = false;
//}
}
}
public void Stop()
{
_stop = true;
}
public void Dispose()
{
if (null != _runing && _runing.IsAlive)
{
_runing.Abort();
}
_runing = null;
}
private void Copying(MFileCopy copy)
{
try
{
var auto = "AutoMade";
var file = Path.Combine(System.IO.Directory.GetCurrentDirectory(), string.Format(@"Flaws\{0}\{1}", auto, DateTime.Now.ToString("yyyyMMdd")));
switch (copy.CopyType)
{
case 0:
auto = "AutoMade";
file = Path.Combine(System.IO.Directory.GetCurrentDirectory(), string.Format(@"Flaws\{0}\{1}", auto, DateTime.Now.ToString("yyyyMMdd")));
break;
case 1:
auto = "ManMade";
file = Path.Combine(System.IO.Directory.GetCurrentDirectory(), string.Format(@"Flaws\{0}\{1}\{2}", auto, DateTime.Now.ToString("yyyyMMdd"), copy.FileName));
break;
case 2:
auto = "ManSnap";
file = Path.Combine(System.IO.Directory.GetCurrentDirectory(), string.Format(@"Flaws\{0}\{1}", auto, DateTime.Now.ToString("yyyyMMdd")));
break;
}
if (!Directory.Exists(file))
{
Directory.CreateDirectory(file);
}
for (var id = copy.MinId; id <= copy.MaxId; id++)
{
for (var c = 0; c < copy.CameraCount; c++)
{
var src = Path.Combine(System.IO.Directory.GetCurrentDirectory(), string.Format(@"running\camera\{0}\{1}.jpg", c, id));
bool isBreak = true;
for (var i = 0; i < 3; i++)
{
if (File.Exists(src))
{
isBreak = false;
break;
}
Thread.Sleep(300);
}
if (isBreak)
{
continue;
}
var des = Path.Combine(file, string.Format("{0}_{1}.jpg", (copy.CopyType == 1) ? (id - copy.MinId).ToString() : copy.FileName, c + 1));
File.Copy(src, des, true);
if (copy.CopyType == 0)
{
//每次只存最新的三张
if (lstManMade.Count == 3)
lstManMade.Clear();
lstManMade.Add(des);
}
}
}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("Copying:{0}", ex.Message));
}
}
}
}