Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
smallproject
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mahaisong
smallproject
Commits
7fc356d7
Commit
7fc356d7
authored
May 04, 2018
by
mahaisong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:修正并发后数量统计,确保之后的数值和与文件中的记录条数相同。
parent
2d4dee73
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
327 additions
and
364 deletions
+327
-364
CsvCount_ES.csproj
6.CsvCount_ES/CsvCount_ES/CsvCount_ES.csproj
+0
-1
Form1.cs
6.CsvCount_ES/CsvCount_ES/Form1.cs
+9
-14
V1.cs
6.CsvCount_ES/CsvCount_ES/V1.cs
+318
-328
CsvCount_ES.exe
6.CsvCount_ES/CsvCount_ES/bin/Debug/CsvCount_ES.exe
+0
-0
CsvCount_ES.exe.config
6.CsvCount_ES/CsvCount_ES/bin/Debug/CsvCount_ES.exe.config
+0
-7
CsvCount_ES.pdb
6.CsvCount_ES/CsvCount_ES/bin/Debug/CsvCount_ES.pdb
+0
-0
CsvCount_ES.vshost.exe.manifest
..._ES/CsvCount_ES/bin/Debug/CsvCount_ES.vshost.exe.manifest
+0
-11
CsvCount_ES.Form1.resources
...ount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.Form1.resources
+0
-0
CsvCount_ES.Properties.Resources.resources
...t_ES/obj/Debug/CsvCount_ES.Properties.Resources.resources
+0
-0
CsvCount_ES.csproj.FileListAbsolute.txt
...ount_ES/obj/Debug/CsvCount_ES.csproj.FileListAbsolute.txt
+0
-3
CsvCount_ES.csproj.GenerateResource.Cache
...nt_ES/obj/Debug/CsvCount_ES.csproj.GenerateResource.Cache
+0
-0
CsvCount_ES.csprojResolveAssemblyReference.cache
...bj/Debug/CsvCount_ES.csprojResolveAssemblyReference.cache
+0
-0
CsvCount_ES.exe
6.CsvCount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.exe
+0
-0
CsvCount_ES.pdb
6.CsvCount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.pdb
+0
-0
No files found.
6.CsvCount_ES/CsvCount_ES/CsvCount_ES.csproj
View file @
7fc356d7
...
...
@@ -67,7 +67,6 @@
<AutoGen>
True
</AutoGen>
<DependentUpon>
Resources.resx
</DependentUpon>
</Compile>
<None
Include=
"hive_export .csv"
/>
<None
Include=
"Properties\Settings.settings"
>
<Generator>
SettingsSingleFileGenerator
</Generator>
<LastGenOutput>
Settings.Designer.cs
</LastGenOutput>
...
...
6.CsvCount_ES/CsvCount_ES/Form1.cs
View file @
7fc356d7
...
...
@@ -81,7 +81,7 @@ namespace CsvCount_ES
{
Stopwatch
st
=
new
Stopwatch
();
st
.
Start
();
int
Btotal
=
0
;
if
(!
String
.
IsNullOrWhiteSpace
(
textBox1
.
Text
))
{
...
...
@@ -278,7 +278,7 @@ namespace CsvCount_ES
try
{
string
key
=
k
[
j
].
Split
(
','
)[
1
].
Replace
(
"\0"
,
string
.
Empty
).
Replace
(
"\r"
,
string
.
Empty
).
Trim
();
totalCountDic
.
AddOrUpdate
(
key
,
0
,
(
skey
,
scount
)
=>
{
return
scount
=
scount
+
1
;
});
totalCountDic
.
AddOrUpdate
(
key
,
1
,
(
skey
,
scount
)
=>
{
return
scount
=
scount
+
1
;
});
}
catch
(
Exception
ext
)
...
...
@@ -415,9 +415,9 @@ namespace CsvCount_ES
try
{
count
=
count
+
1
;
//记录计算了多少次,
与分块对应(其实就是与listModelDic的key-1对应即代表完整)
count
=
count
+
1
;
//记录计算了多少次,
多少行
string
key
=
line
.
Split
(
','
)[
1
];
BtotalCountDic
.
AddOrUpdate
(
key
,
0
,
(
skey
,
scount
)
=>
{
return
scount
=
scount
+
1
;
});
BtotalCountDic
.
AddOrUpdate
(
key
,
1
,
(
skey
,
scount
)
=>
{
return
scount
=
scount
+
1
;
});
}
catch
(
Exception
ext
)
...
...
@@ -430,12 +430,6 @@ namespace CsvCount_ES
MessageBox
.
Show
(
"完整性测试运行时间:"
+
swtp
.
ElapsedMilliseconds
.
ToString
());
#
endregion
//可能出现重复,这里的条数与日志文件的条数可能不同。
foreach
(
var
item
in
BtotalCountDic
)
{
Btotal
=
Btotal
+
item
.
Value
;
}
//全比较
var
dz1
=
BtotalCountDic
.
Except
(
totalCountDic
);
...
...
@@ -480,17 +474,18 @@ namespace CsvCount_ES
total
=
total
+
item
.
Value
;
}
if
(
total
==
Btotal
)
if
(
total
==
count
)
{
MessageBox
.
Show
(
"正确:点击数
和为总条数"
);
MessageBox
.
Show
(
"正确:点击数
计算后之和"
+
total
.
ToString
()+
" ===文件记录总行数,"
+
count
.
ToString
()
);
}
else
{
MessageBox
.
Show
(
"错误
:点击数和不等于总条数"
);
MessageBox
.
Show
(
"错误
(不相等):点击数计算后之和"
+
total
.
ToString
()
+
" !=!=!=文件记录总行数,"
+
count
.
ToString
()
);
}
MessageBox
.
Show
(
"结果行数:"
+
count
.
ToString
());
total
=
0
;
errorCount
=
0
;
count
=
0
;
...
...
6.CsvCount_ES/CsvCount_ES/V1.cs
View file @
7fc356d7
...
...
@@ -15,95 +15,172 @@ using System.Windows.Forms;
namespace
CsvCount_ES
{
/// <summary>
/// 此类用来做完整性测试,测试程序是否正常问题,及效率。
/// </summary>
public
class
V1
{
//key:newsid字段,也是itemid字段,value:int-次数累计
private
ConcurrentDictionary
<
string
,
int
>
totalCountDic
=
new
ConcurrentDictionary
<
string
,
int
>();
//链式结构 key: Int64 累加(对应分块的块号), value:这一块的ListModel的第一行和最后一行的string内容
private
ConcurrentDictionary
<
Int64
,
ListModel
>
listModelDic
=
new
ConcurrentDictionary
<
Int64
,
ListModel
>();
private
static
Int64
sn
=
0
;
//警告 在 32 位 Intel 计算机上分配 64 位值不是原子操作;即该操作不是线程安全的。这意味着,如果两个人同时将一个值分配给一个静态 Int64 字段,则该字段的最终值是无法预测的。
/// <summary>
/// 得到编号加1的值
/// 完整性测试时使用的方法,可以直接copy到form1中,代替button2_Click来执行。
/// 目的:读取csv文件,去重。(V2将包括ES、JSON等)
/// </summary>
/// <returns></returns>
public
static
Int64
ADD
()
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
button2_Click
(
object
sender
,
EventArgs
e
)
{
//新建线程,线程数加一
return
Interlocked
.
Increment
(
ref
sn
);
}
//Stopwatch st = new Stopwatch();
//st.Start();
//if (!String.IsNullOrWhiteSpace(textBox1.Text))
//{
public
V1
()
{
// #region 执行内存映射方案
// label_wait.Text = "正在执行分析,请耐心等待........!";
}
// button1.Enabled = false;
// textBox1.Enabled = false;
// button2.Enabled = false;
// listBox1.Enabled = true;
// Application.DoEvents();
private
void
button2_Click
(
object
sender
,
EventArgs
e
)
{
Stopwatch
st
=
new
Stopwatch
();
st
.
Start
();
int
Btotal
=
0
;
int
count
=
0
;
// //输出测试
// //for (int i = 0; i < 500; i++)
// //{
// // //跨线程访问
// // this.BeginInvoke(new MethodInvoker(delegate ()
// // {
// // count = count + 1;
// // this.listBox1.SuspendLayout();
// // this.listBox1.Items.Add("开始:" + count.ToString() + "————————————————————————————————结束");
int
errorCount
=
0
;
// // this.listBox1.ResumeLayout();
// // Application.DoEvents();
// // }));
#
region
执行内存映射方案
// //}
// string filepath = openFileDialog1.FileName;
// setup:
// try
// {
// #region 基本用法--820W行数据,439MB,转成字符串、split后,执行消耗24~25秒。
// ////读取文件
// //FileInfo fi = new FileInfo(filepath);
// //Int64 size = fi.Length;//byte长度
Application
.
DoEvents
();
// //int offset = 0;
// //int length = 512000;//每次块大小 512000byte 500KB 这样1个G转2010次算完
// ////UTF-8编码中,一个英文字符等于一个字节,一个中文(含繁体)等于三个字节。 本次文件中主要是英文和数字,没有中文。所以要多少字就配多大块。
// //string fp2 = @filepath;
// //using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fp2, FileMode.Open, "mapname"))
// //{
//输出测试
//for (int i = 0; i < 500; i++)
//{
// //跨线程访问
// this.BeginInvoke(new MethodInvoker(delegate ()
// {
// count = count + 1;
// this.listBox1.SuspendLayout();
// this.listBox1.Items.Add("开始:" + count.ToString() + "————————————————————————————————结束");
// // using (var accessor = mmf.CreateViewAccessor(offset, size))
// // {
// // List<string> list = new List<string>();
// this.listBox1.ResumeLayout();
// Application.DoEvents();
// // //每隔100是1行
// // for (int i = 0; i < size; i += length)
// // {
// // byte[] byteArray = new byte[length];
// }));
//}
// // //ReadArray参数
// // //position
// // //Type: System.Int64
// // //访问器中的字节偏移量,从此处开始读取。
// // //array
// // //Type: T[]
// // //包含从访问器读取的结构的数组。
// // //offset
// // //Type: System.Int32
// // //array 中要将第一个复制的结构放置到的索引。
// // //count
// // //Type: System.Int32
// // //要从访问器读取的 T 类型的结构的数目。
string
filepath
=
""
;
// openFileDialog1.FileName;
setup
:
try
{
#
region
基本用法
--
820
W
行数据,
439
MB
,转成字符串、
split
后,执行消耗
24
~
25
秒。
////读取文件
//FileInfo fi = new FileInfo(filepath);
//Int64 size = fi.Length;//byte长度
// // //resultcount:读入 array 的结构数。 如果可用结构较少,则此值可能小于 count;如果到达访问器末尾,则为零。
// // int resultcount = accessor.ReadArray(i, byteArray, 0, length);
// // //\r\n 空格 \n 都测试通过
// // //\r 空格 \n 都算1个字符 规则:最后必须是\n结尾
// // string str = System.Text.Encoding.Default.GetString(byteArray);
// // int index = str.LastIndexOf('\n');
//int offset = 0;
//int length = 512000;//每次块大小 512000byte 500KB 这样1个G转2010次算完
////UTF-8编码中,一个英文字符等于一个字节,一个中文(含繁体)等于三个字节。 本次文件中主要是英文和数字,没有中文。所以要多少字就配多大块。
//string fp2 = @filepath;
//using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fp2, FileMode.Open, "mapname"))
//{
// // string[] k = str.Split();
// // count = count + k.Length;
// // if (str.Length==index)
// // {
// // //最后一行可以分析
// // }
// // else
// // {
// // //str.IndexOf
// // //不相等,最后一行不能分析。
// // //spilt时,将最后一行保存起来,本次处理索引-1。
// // //头条保存起来,也不处理,本次处理索引-2。(标志是否是第一条,异步时,第一个肯定是完整的,不需要存入)
// // }
// using (var accessor = mmf.CreateViewAccessor(offset, size))
// // }
// // }
// //}
// #endregion
// #region 并发用法:真正大文件时比StreamReader有用--820W行数据,439MB,转成字符串、split后,执行消耗7~8秒。 10K 为1块。
// //读取文件
// FileInfo fi = new FileInfo(filepath);
// Int64 size = fi.Length;//byte长度
// int length = 10240;//每次块大小 512000byte 500KB 这样1个G转2010次算完
// //10兆字节(mb)=10485760字节(b)
// //UTF-8编码中,一个英文字符等于一个字节,一个中文(含繁体)等于三个字节。 本次文件中主要是英文和数字,没有中文。所以要多少字就配多大块。
// //50千字节(kb)=51200字节(b)
// //200千字节(kb)=204800字节(b)
// Int64 portion = (Int64)Math.Ceiling(size * 1.0 / length); //分成多少块
// string fp2 = @filepath;
// //统一使用总文件大小的内存隐射对象
// using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fp2, FileMode.Open, "mapname", size))
// {
// //从零开始,每块单独并行处理。
// Parallel.For(0, portion, (index, ParallelLoopState) =>
// {
// //块大小和 文件总大小-第几分区位置的剩余位置,取两者较小的
// Int64 fileSize = Math.Min(length, size - length * index);
// if (fileSize > 0)
// {
// List<string> list = new List<string>();
// //每隔100是1行
// for (int i = 0; i < size; i += length)
// using (var accessor = mmf.CreateViewAccessor(length * index, fileSize, MemoryMappedFileAccess.Read))
// {
// byte[] byteArray = new byte[length];
// List<string> list = new List<string>();
// ////每隔100是1行
// //for (int i = 0; i < fileSize; i += length)
// //{
// //Int64 listkey = ADD();
// byte[] byteArray = new byte[length];
// #region 函数参数说明
// //ReadArray参数
// //position
// //Type: System.Int64
...
...
@@ -119,337 +196,250 @@ namespace CsvCount_ES
// //要从访问器读取的 T 类型的结构的数目。
// //resultcount:读入 array 的结构数。 如果可用结构较少,则此值可能小于 count;如果到达访问器末尾,则为零。
// int resultcount = accessor.ReadArray(i, byteArray, 0, length);
// #endregion
// int resultcount = accessor.ReadArray(0, byteArray, 0, (int)fileSize);
// //\r\n 空格 \n 都测试通过
// //\r 空格 \n 都算1个字符 规则:最后必须是\n结尾
// //测试通过:\r\n \r 空格 \n(注意:\r 空格 \n 都算1个字符,\r\n算2个字符)
// //规则:最后必须是\n结尾,cvs的换行都是\n结尾。
// string str = System.Text.Encoding.Default.GetString(byteArray);
// int index = str.LastIndexOf('\n');
// string[] k = str.Split();
// count = count + k.Length;
// if (str.Length==index)
// {
// //最后一行可以分析
// }
// else
// int index1 = str.LastIndexOf('\n');
// string[] k = str.Split('\n');
// string endstr = null;
// if (str.Length != index1)
// {
// //str.IndexOf
// //不相等,最后一行不能分析。
// //不相等,最后一行不能Split分析。
// //spilt时,将最后一行保存起来,本次处理索引-1。
// //头条保存起来,也不处理,本次处理索引-2。(标志是否是第一条,异步时,第一个肯定是完整的,不需要存入)
// //头条保存起来,也不处理,本次处理索引-2。
// endstr = k[k.Count() - 1].Replace("\0", string.Empty).Replace("\r", string.Empty).Trim(); ;
// }
// //else
// //{
// // //最后一行可以Split分析,不再处理
// //}
// //先简化开发,将头部和尾部都另外保存。只计算中间的。然后调用ES (索引-2:从1开始,尾部-1)
// //测试: 820W条记录,执行完毕 20~ 22秒。 最终结果3w2013条记录。有的直接点击3000多次。
// for (int j = 1; j < k.Count() - 1; j++)
// {
// try
// {
// string key = k[j].Split(',')[1].Replace("\0", string.Empty).Replace("\r", string.Empty).Trim();
// totalCountDic.AddOrUpdate(key, 1, (skey, scount) => { return scount = scount + 1; });
// }
// catch (Exception ext)
// {
// MessageBox.Show("某行数据第2列可能为空" + ext.ToString());
// }
//}
#
endregion
#
region
并发用法:真正大文件时比
StreamReader
有用
--
820
W
行数据,
439
MB
,转成字符串、
split
后,执行消耗
7
~
8
秒。
10
K
为
1
块。
//读取文件
FileInfo
fi
=
new
FileInfo
(
filepath
);
Int64
size
=
fi
.
Length
;
//byte长度
int
length
=
10240
;
//每次块大小 512000byte 500KB 这样1个G转2010次算完
//10兆字节(mb)=10485760字节(b)
//UTF-8编码中,一个英文字符等于一个字节,一个中文(含繁体)等于三个字节。 本次文件中主要是英文和数字,没有中文。所以要多少字就配多大块。
//50千字节(kb)=51200字节(b)
//200千字节(kb)=204800字节(b)
Int64
portion
=
(
Int64
)
Math
.
Ceiling
(
size
*
1.0
/
length
);
//分成多少块
string
fp2
=
@filepath
;
//统一使用总文件大小的内存隐射对象
using
(
MemoryMappedFile
mmf
=
MemoryMappedFile
.
CreateFromFile
(
fp2
,
FileMode
.
Open
,
"mapname"
,
size
))
{
//从零开始,每块单独并行处理。
Parallel
.
For
(
0
,
portion
,
(
index
,
ParallelLoopState
)
=>
{
//块大小和 文件总大小-第几分区位置的剩余位置,取两者较小的
Int64
fileSize
=
Math
.
Min
(
length
,
size
-
length
*
index
);
if
(
fileSize
>
0
)
{
using
(
var
accessor
=
mmf
.
CreateViewAccessor
(
length
*
index
,
fileSize
,
MemoryMappedFileAccess
.
Read
))
{
List
<
string
>
list
=
new
List
<
string
>();
////每隔100是1行
//for (int i = 0; i < fileSize; i += length)
//{
//Int64 listkey = ADD();
byte
[]
byteArray
=
new
byte
[
length
];
#
region
函数参数说明
//ReadArray参数
//position
//Type: System.Int64
//访问器中的字节偏移量,从此处开始读取。
//array
//Type: T[]
//包含从访问器读取的结构的数组。
//offset
//Type: System.Int32
//array 中要将第一个复制的结构放置到的索引。
//count
//Type: System.Int32
//要从访问器读取的 T 类型的结构的数目。
//resultcount:读入 array 的结构数。 如果可用结构较少,则此值可能小于 count;如果到达访问器末尾,则为零。
#
endregion
int
resultcount
=
accessor
.
ReadArray
(
0
,
byteArray
,
0
,
(
int
)
fileSize
);
//测试通过:\r\n \r 空格 \n(注意:\r 空格 \n 都算1个字符,\r\n算2个字符)
//规则:最后必须是\n结尾,cvs的换行都是\n结尾。
string
str
=
System
.
Text
.
Encoding
.
Default
.
GetString
(
byteArray
);
int
index1
=
str
.
LastIndexOf
(
'\n'
);
string
[]
k
=
str
.
Split
(
'\n'
);
string
endstr
=
null
;
if
(
str
.
Length
!=
index1
)
{
//不相等,最后一行不能Split分析。
//spilt时,将最后一行保存起来,本次处理索引-1。
//头条保存起来,也不处理,本次处理索引-2。
endstr
=
k
[
k
.
Count
()
-
1
].
Replace
(
"\0"
,
string
.
Empty
).
Replace
(
"\r"
,
string
.
Empty
).
Trim
();
;
}
//else
//{
// //最后一行可以Split分析,不再处理
//}
//先简化开发,将头部和尾部都另外保存。只计算中间的。然后调用ES (索引-2:从1开始,尾部-1)
//测试: 820W条记录,执行完毕 20~ 22秒。 最终结果3w2013条记录。有的直接点击3000多次。
for
(
int
j
=
1
;
j
<
k
.
Count
()
-
1
;
j
++)
{
try
{
string
key
=
k
[
j
].
Split
(
','
)[
1
].
Replace
(
"\0"
,
string
.
Empty
).
Replace
(
"\r"
,
string
.
Empty
).
Trim
();
totalCountDic
.
AddOrUpdate
(
key
,
0
,
(
skey
,
scount
)
=>
{
return
scount
=
scount
+
1
;
});
}
catch
(
Exception
ext
)
{
MessageBox
.
Show
(
"某行数据第2列可能为空"
+
ext
.
ToString
());
}
}
//头尾:另外保存
ListModel
listmodel
=
new
ListModel
(
k
[
0
].
Replace
(
"\0"
,
string
.
Empty
).
Replace
(
"\r"
,
string
.
Empty
).
Trim
(),
endstr
);
listModelDic
.
TryAdd
(
index
,
listmodel
);
// }
// //头尾:另外保存
// ListModel listmodel = new ListModel(k[0].Replace("\0", string.Empty).Replace("\r", string.Empty).Trim(), endstr);
// listModelDic.TryAdd(index, listmodel);
//}
}
//分区时,最后一个为0则忽略。
// //}
}
// }
// //分区时,最后一个为0则忽略。
});
// }
}
// });
if
(
listModelDic
.
Count
()
>
0
)
{
if
(
listModelDic
.
Count
()
==
1
)
{
// }
try
{
string
key
=
listModelDic
[
1
].
End
;
if
(!
String
.
IsNullOrWhiteSpace
(
key
))
totalCountDic
.
AddOrUpdate
(
listModelDic
[
1
].
End
.
Split
(
','
)[
1
],
0
,
(
skey
,
scount
)
=>
{
return
scount
=
scount
+
1
;
});
}
catch
(
Exception
ext
)
{
MessageBox
.
Show
(
"只有一块时(文件小):第一行数据第2列可能为空"
+
ext
.
ToString
());
// if (listModelDic.Count() > 0)
// {
// if (listModelDic.Count() == 1)
// {
}
}
else
{
//头尾单独链式处理: 从1开始。第0行的begin 是列名称,不需要分析。
for
(
int
i
=
1
;
i
<
listModelDic
.
Count
();
i
++)
{
try
{
//count = count + 1;//记录计算了多少次,与分块对应(其实就是与listModelDic的key-1对应即代表完整)
// try
// {
// string key = listModelDic[1].End;
// if (!String.IsNullOrWhiteSpace(key))
// totalCountDic.AddOrUpdate(listModelDic[1].End.Split(',')[1], 0, (skey, scount) => { return scount = scount + 1; });
// }
// catch (Exception ext)
// {
// MessageBox.Show("只有一块时(文件小):第一行数据第2列可能为空" + ext.ToString());
string
str
=
""
;
if
(!
String
.
IsNullOrWhiteSpace
(
listModelDic
[
i
-
1
].
End
))
{
//上一个的end+本轮的begin拼接,不需要去除/n
str
=
listModelDic
[
i
-
1
].
End
+
listModelDic
[
i
].
Begin
;
}
else
{
//上一个的end(为空)+本轮的begin拼接,不需要去除/n
str
=
listModelDic
[
i
].
Begin
;
// }
// }
// else
// {
// //头尾单独链式处理: 从1开始。第0行的begin 是列名称,不需要分析。
// for (int i = 1; i < listModelDic.Count(); i++)
// {
// try
// {
// //count = count + 1;//记录计算了多少次,与分块对应(其实就是与listModelDic的key-1对应即代表完整)
}
// string str = "";
// if (!String.IsNullOrWhiteSpace(listModelDic[i - 1].End))
// {
// //上一个的end+本轮的begin拼接,不需要去除/n
// str = listModelDic[i - 1].End + listModelDic[i].Begin;
// }
// else
// {
// //上一个的end(为空)+本轮的begin拼接,不需要去除/n
// str = listModelDic[i].Begin;
// }
string
key
=
str
.
Split
(
','
)[
1
];
totalCountDic
.
AddOrUpdate
(
key
,
0
,
(
skey
,
scount
)
=>
{
return
scount
=
scount
+
1
;
});
}
catch
(
Exception
ext
)
{
MessageBox
.
Show
(
"头尾单独链式处理:某行数据第2列可能为空"
+
ext
.
ToString
());
// string key = str.Split(',')[1];
// totalCountDic.AddOrUpdate(key, 0, (skey, scount) => { return scount = scount + 1; });
}
}
// }
// catch (Exception ext)
// {
// MessageBox.Show("头尾单独链式处理:某行数据第2列可能为空" + ext.ToString());
// }
// }
//最后补充最后一条的end 是没有换行了。所以不需要处理。肯定为null。 keyend.end 是空字符串。
//object keyend = listModelDic[listModelDic.Count()];
}
}
#
endregion
}
catch
(
IOException
ex
)
{
errorCount
=
errorCount
+
1
;
if
(
errorCount
>
2
)
{
MessageBox
.
Show
(
ex
.
ToString
());
errorCount
=
0
;
}
else
{
//遇到csv无法文件无法使用时,通过修改扩展名实现。
filepath
=
Path
.
ChangeExtension
(
filepath
,
".txt"
);
//个别CSV\ppt\word等文件类型,则必须强转为任何其他类型的文本后缀结构。否则MemoryMappedFile不识别.
goto
setup
;
}
}
catch
(
Exception
ex
)
{
// //最后补充最后一条的end 是没有换行了。所以不需要处理。肯定为null。 keyend.end 是空字符串。
// //object keyend = listModelDic[listModelDic.Count()];
MessageBox
.
Show
(
ex
.
ToString
());
}
// }
// }
// #endregion
// }
// catch (IOException ex)
// {
// errorCount = errorCount + 1;
// if (errorCount > 2)
// {
// MessageBox.Show(ex.ToString());
// errorCount = 0;
// }
// else
// {
// //遇到csv无法文件无法使用时,通过修改扩展名实现。
// filepath = Path.ChangeExtension(filepath, ".txt");
// //个别CSV\ppt\word等文件类型,则必须强转为任何其他类型的文本后缀结构。否则MemoryMappedFile不识别.
// goto setup;
// }
// }
// catch (Exception ex)
// {
#
endregion
// MessageBox.Show(ex.ToString());
// }
st
.
Stop
();
MessageBox
.
Show
(
"运行时间:"
+
st
.
ElapsedMilliseconds
.
ToString
());
// #endregion
#
region
完整性测试
---
使用时注释掉。
执行效率
5
-
6
秒
// st.Stop();
// MessageBox.Show("运行时间:" + st.ElapsedMilliseconds.ToString());
try
{
// #region 完整性测试---使用时注释掉。 执行效率 5-6秒
//通过一行行的输入,最终获得1个列表B,以B为左,求差集
ConcurrentDictionary
<
string
,
int
>
BtotalCountDic
=
new
ConcurrentDictionary
<
string
,
int
>();
#
region
按行读取代码
// try
// {
//读取文件
// //通过一行行的输入,最终获得1个列表B,以B为左,求差集
// ConcurrentDictionary<string, int> BtotalCountDic = new ConcurrentDictionary<string, int>();
// #region 按行读取代码
Stopwatch
swtp
=
new
Stopwatch
();
swtp
.
Start
();
count
=
0
;
StreamReader
sr
=
new
StreamReader
(
filepath
,
Encoding
.
Default
);
String
line
;
line
=
sr
.
ReadLine
();
//第一行,头部列名称,不进入集合
while
((
line
=
sr
.
ReadLine
())
!=
null
)
{
try
{
// //读取文件
count
=
count
+
1
;
//记录计算了多少次,与分块对应(其实就是与listModelDic的key-1对应即代表完整)
string
key
=
line
.
Split
(
','
)[
1
];
BtotalCountDic
.
AddOrUpdate
(
key
,
0
,
(
skey
,
scount
)
=>
{
return
scount
=
scount
+
1
;
});
// Stopwatch swtp = new Stopwatch();
// swtp.Start();
// count = 0;
// StreamReader sr = new StreamReader(filepath, Encoding.Default);
// String line;
// line = sr.ReadLine();//第一行,头部列名称,不进入集合
// while ((line = sr.ReadLine()) != null)
// {
// try
// {
}
catch
(
Exception
ext
)
{
MessageBox
.
Show
(
"完整性测试:某行数据第2列可能为空"
+
ext
.
ToString
());
// count = count + 1;//记录计算了多少次,多少行
// string key = line.Split(',')[1];
// BtotalCountDic.AddOrUpdate(key, 1, (skey, scount) => { return scount = scount + 1; });
}
}
swtp
.
Stop
();
MessageBox
.
Show
(
"完整性测试运行时间:"
+
swtp
.
ElapsedMilliseconds
.
ToString
());
#
endregion
// }
// catch (Exception ext)
// {
// MessageBox.Show("完整性测试:某行数据第2列可能为空" + ext.ToString());
//可能出现重复,这里的条数与日志文件的条数可能不同。
foreach
(
var
item
in
BtotalCountDic
)
{
Btotal
=
Btotal
+
item
.
Value
;
// }
// }
// swtp.Stop();
// MessageBox.Show("完整性测试运行时间:" + swtp.ElapsedMilliseconds.ToString());
// #endregion
}
//全比较
var
dz1
=
BtotalCountDic
.
Except
(
totalCountDic
);
//key比较
var
dz2
=
BtotalCountDic
.
Keys
.
Except
(
totalCountDic
.
Keys
);
//
//全比较
//
var dz1 = BtotalCountDic.Except(totalCountDic);
//
//key比较
//
var dz2 = BtotalCountDic.Keys.Except(totalCountDic.Keys);
if
(
dz1
.
Count
()
==
0
&&
dz2
.
Count
()
==
0
)
{
MessageBox
.
Show
(
"两个方式结果一致"
);
}
else
{
MessageBox
.
Show
(
"完整性测试报错"
);
}
}
catch
(
Exception
exe1
)
{
//
if (dz1.Count() == 0 && dz2.Count() == 0)
//
{
//
MessageBox.Show("两个方式结果一致");
//
}
//
else
//
{
//
MessageBox.Show("完整性测试报错");
//
}
//
}
//
catch (Exception exe1)
//
{
MessageBox
.
Show
(
"完整性测试"
+
exe1
.
ToString
());
}
//
MessageBox.Show("完整性测试" + exe1.ToString());
//
}
#
endregion
//
#endregion
//}
//else
//{
// MessageBox.Show("请选择文件夹!");
//}
//#region 执行完成
//label_wait.Text = "执行完毕!";
//this.textBox_path.Text = "文件路径";
////listBox1.Enabled = false;
//textBox1.Enabled = true;
//button1.Enabled = true;
#
region
执行完成
//int total = 0;
//foreach (var item in totalCountDic)
//{
// total = total + item.Value;
int
total
=
0
;
foreach
(
var
item
in
totalCountDic
)
{
total
=
total
+
item
.
Value
;
//}
}
if
(
total
==
Btotal
)
{
MessageBox
.
Show
(
"正确:点击数和为总条数"
);
}
else
{
MessageBox
.
Show
(
"错误:点击数和不等于总条数"
);
}
//if (total == count)
//{
// MessageBox.Show("正确:点击数计算后之和" + total.ToString() + " ===文件记录总行数," + count.ToString());
//}
//else
//{
// MessageBox.Show("错误(不相等):点击数计算后之和" + total.ToString() + " !=!=!=文件记录总行数," + count.ToString());
//}
MessageBox
.
Show
(
"结果行数:"
+
count
.
ToString
());
errorCount
=
0
;
count
=
0
;
//total = 0;
//errorCount = 0;
//count = 0;
#
endregion
//
#endregion
}
...
...
6.CsvCount_ES/CsvCount_ES/bin/Debug/CsvCount_ES.exe
deleted
100644 → 0
View file @
2d4dee73
File deleted
6.CsvCount_ES/CsvCount_ES/bin/Debug/CsvCount_ES.exe.config
deleted
100644 → 0
View file @
2d4dee73
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.5"
/>
</
startup
>
</
configuration
>
\ No newline at end of file
6.CsvCount_ES/CsvCount_ES/bin/Debug/CsvCount_ES.pdb
deleted
100644 → 0
View file @
2d4dee73
File deleted
6.CsvCount_ES/CsvCount_ES/bin/Debug/CsvCount_ES.vshost.exe.manifest
deleted
100644 → 0
View file @
2d4dee73
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
xmlns=
"urn:schemas-microsoft-com:asm.v1"
manifestVersion=
"1.0"
>
<assemblyIdentity
version=
"1.0.0.0"
name=
"MyApplication.app"
/>
<trustInfo
xmlns=
"urn:schemas-microsoft-com:asm.v2"
>
<security>
<requestedPrivileges
xmlns=
"urn:schemas-microsoft-com:asm.v3"
>
<requestedExecutionLevel
level=
"asInvoker"
uiAccess=
"false"
/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
6.CsvCount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.Form1.resources
deleted
100644 → 0
View file @
2d4dee73
File deleted
6.CsvCount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.Properties.Resources.resources
deleted
100644 → 0
View file @
2d4dee73
File deleted
6.CsvCount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.csproj.FileListAbsolute.txt
View file @
7fc356d7
...
...
@@ -15,6 +15,3 @@ C:\Users\admin\Desktop\CsvCount_ES\CsvCount_ES\bin\Debug\CsvCount_ES.pdb
C:\Users\admin\Desktop\CsvCount_ES\CsvCount_ES\obj\Debug\CsvCount_ES.Form1.resources
C:\Users\admin\Desktop\CsvCount_ES\CsvCount_ES\obj\Debug\CsvCount_ES.Properties.Resources.resources
C:\Users\admin\Desktop\CsvCount_ES\CsvCount_ES\obj\Debug\CsvCount_ES.csproj.GenerateResource.Cache
D:\smallproject\6.CsvCount_ES\CsvCount_ES\bin\Debug\CsvCount_ES.exe.config
D:\smallproject\6.CsvCount_ES\CsvCount_ES\obj\Debug\CsvCount_ES.exe
D:\smallproject\6.CsvCount_ES\CsvCount_ES\obj\Debug\CsvCount_ES.pdb
6.CsvCount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.csproj.GenerateResource.Cache
deleted
100644 → 0
View file @
2d4dee73
File deleted
6.CsvCount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.csprojResolveAssemblyReference.cache
deleted
100644 → 0
View file @
2d4dee73
File deleted
6.CsvCount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.exe
deleted
100644 → 0
View file @
2d4dee73
File deleted
6.CsvCount_ES/CsvCount_ES/obj/Debug/CsvCount_ES.pdb
deleted
100644 → 0
View file @
2d4dee73
File deleted
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment