Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
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
潘栩锋
Thick-Common
Commits
925e79d0
Commit
925e79d0
authored
Nov 13, 2019
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 添加 OBJComponets.BufferSQLite 支持写入数据库
parent
3961213e
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
284 additions
and
120 deletions
+284
-120
FlyData_WarningHistory.cs
...Components/OBJComponents/Common/FlyData_WarningHistory.cs
+3
-1
NotifyBufferChangedEventArgs.cs
...ents/OBJComponents/Common/NotifyBufferChangedEventArgs.cs
+1
-1
IBufferAdd.cs
...ct.FLY.OBJComponents/OBJComponents/IService/IBufferAdd.cs
+1
-0
OBJComponents.csproj
Project.FLY.OBJComponents/OBJComponents/OBJComponents.csproj
+1
-0
Buffer.cs
Project.FLY.OBJComponents/OBJComponents/Server/Buffer.cs
+1
-1
BufferError.cs
...ect.FLY.OBJComponents/OBJComponents/Server/BufferError.cs
+15
-116
BufferSQLite.cs
...ct.FLY.OBJComponents/OBJComponents/Server/BufferSQLite.cs
+261
-0
DB_Error.cs
....FLY.OBJComponents/OBJComponents/Server/Model/DB_Error.cs
+1
-1
No files found.
Project.FLY.OBJComponents/OBJComponents/Common/FlyData_WarningHistory.cs
View file @
925e79d0
using
FLY.Thick.RemoteHistory
;
using
FLY.Thick.RemoteHistory
;
using
FObjBase
;
using
FObjBase
;
using
SQLite
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
...
@@ -9,8 +10,9 @@ using System.Threading.Tasks;
...
@@ -9,8 +10,9 @@ using System.Threading.Tasks;
namespace
FLY.OBJComponents.Common
namespace
FLY.OBJComponents.Common
{
{
public
class
FlyData_WarningHistory
:
IFlyData
public
class
FlyData_WarningHistory
:
IFlyData
,
IDbBase
{
{
public
Int64
ID
{
get
;
set
;
}
/// <summary>
/// <summary>
/// 时间
/// 时间
/// </summary>
/// </summary>
...
...
Project.FLY.OBJComponents/OBJComponents/Common/NotifyBufferChangedEventArgs.cs
View file @
925e79d0
...
@@ -19,7 +19,7 @@ namespace FLY.OBJComponents.Common
...
@@ -19,7 +19,7 @@ namespace FLY.OBJComponents.Common
public
class
NotifyBufferChangedEventArgs
<
T
>
:
EventArgs
public
class
NotifyBufferChangedEventArgs
<
T
>
:
EventArgs
{
{
public
NotifyBufferChangedAction
Action
{
get
;
set
;
}
public
NotifyBufferChangedAction
Action
{
get
;
set
;
}
public
I
List
<
T
>
Items
{
get
;
set
;
}
public
I
Enumerable
<
T
>
Items
{
get
;
set
;
}
public
int
EndingID
{
get
;
set
;
}
public
int
EndingID
{
get
;
set
;
}
}
}
...
...
Project.FLY.OBJComponents/OBJComponents/IService/IBufferAdd.cs
View file @
925e79d0
...
@@ -9,5 +9,6 @@ namespace FLY.OBJComponents.IService
...
@@ -9,5 +9,6 @@ namespace FLY.OBJComponents.IService
public
interface
IBufferAdd
<
T
>
:
IBuffer
<
T
>
public
interface
IBufferAdd
<
T
>
:
IBuffer
<
T
>
{
{
void
Add
(
T
t
);
void
Add
(
T
t
);
void
AddRange
(
IEnumerable
<
T
>
t
);
}
}
}
}
Project.FLY.OBJComponents/OBJComponents/OBJComponents.csproj
View file @
925e79d0
...
@@ -75,6 +75,7 @@
...
@@ -75,6 +75,7 @@
<Compile
Include=
"Server.OBJProxy\SyncProp_OBJProxy.cs"
/>
<Compile
Include=
"Server.OBJProxy\SyncProp_OBJProxy.cs"
/>
<Compile
Include=
"Server.OBJProxy\WarningSystem_OBJProxy.cs"
/>
<Compile
Include=
"Server.OBJProxy\WarningSystem_OBJProxy.cs"
/>
<Compile
Include=
"Server\Buffer.cs"
/>
<Compile
Include=
"Server\Buffer.cs"
/>
<Compile
Include=
"Server\BufferSQLite.cs"
/>
<Compile
Include=
"Server\BufferStorage.cs"
/>
<Compile
Include=
"Server\BufferStorage.cs"
/>
<Compile
Include=
"Server\BufferError.cs"
/>
<Compile
Include=
"Server\BufferError.cs"
/>
<Compile
Include=
"Server\History.cs"
/>
<Compile
Include=
"Server\History.cs"
/>
...
...
Project.FLY.OBJComponents/OBJComponents/Server/Buffer.cs
View file @
925e79d0
...
@@ -77,7 +77,7 @@ namespace FLY.OBJComponents.Server
...
@@ -77,7 +77,7 @@ namespace FLY.OBJComponents.Server
EndingID
=
NewestID
EndingID
=
NewestID
});
});
}
}
public
void
AddRange
(
I
List
<
T
>
array
)
public
void
AddRange
(
I
Enumerable
<
T
>
array
)
{
{
list
.
AddRange
(
array
);
list
.
AddRange
(
array
);
...
...
Project.FLY.OBJComponents/OBJComponents/Server/BufferError.cs
View file @
925e79d0
...
@@ -12,135 +12,34 @@ using System.Threading.Tasks;
...
@@ -12,135 +12,34 @@ using System.Threading.Tasks;
namespace
FLY.OBJComponents.Server
namespace
FLY.OBJComponents.Server
{
{
public
class
BufferError
:
IBufferAdd
<
FlyData_WarningHistory
>
public
class
BufferError
:
BufferSQLite
<
FlyData_WarningHistory
,
DB_Error
>
{
{
IErrorDBModel
dBModel
;
public
int
NewestID
{
get
;
private
set
;
}
public
int
Count
{
get
;
private
set
;
}
public
int
Capacity
{
get
;
set
;
}
=
int
.
MaxValue
;
public
event
NotifyBufferChangedEventHandler
<
FlyData_WarningHistory
>
BufferChanged
;
public
event
PropertyChangedEventHandler
PropertyChanged
;
public
BufferError
()
{
}
public
void
Init
(
IErrorDBModel
dBModel
)
public
void
Init
(
IErrorDBModel
dBModel
)
{
{
this
.
dBModel
=
dBModel
;
base
.
Init
(
dBModel
.
TbError
,
mapLc2Db
,
mapDb2Lc
);
Load
();
}
void
Load
()
{
var
n
=
dBModel
.
sqliteHelper
.
ExecuteScalar
(
$"SELECT COUNT(*) FROM
{
dBModel
.
TbError
.
TableName
}
"
);
int
count
=
System
.
Convert
.
ToInt32
(
n
);
NewestID
=
count
-
1
;
Count
=
count
;
}
}
static
DB_Error
mapLc2Db
(
FlyData_WarningHistory
lc
)
public
void
Add
(
FlyData_WarningHistory
t
)
{
{
var
db_errorData
=
new
DB_Error
()
return
new
DB_Error
()
{
{
ID
=
dBModel
.
TbError
.
FreeID
,
//添加 数据库必要的 field
ID
=
lc
.
ID
,
Time
=
t
.
Time
,
Time
=
lc
.
Time
,
ErrCode
=
t
.
ErrCode
,
ErrCode
=
lc
.
ErrCode
,
Descrption
=
t
.
Description
,
Descrption
=
lc
.
Description
,
IsOn
=
t
.
State
==
ERR_STATE
.
ON
IsOn
=
lc
.
State
==
ERR_STATE
.
ON
};
};
//SQLs
List
<
string
>
sqls
=
new
List
<
string
>();
sqls
.
Add
(
SQLiteHelper
.
GetInsertCommandText
(
db_errorData
));
dBModel
.
sqliteHelper
.
QueryTranAsync
(
sqls
);
NewestID
=
Count
;
Count
++;
}
}
static
FlyData_WarningHistory
mapDb2Lc
(
DB_Error
db
)
/// <summary>
/// 清空全部数据
/// </summary>
public
void
Reset
()
{
//SQLs
List
<
string
>
sqls
=
new
List
<
string
>();
sqls
.
Add
(
$"DELETE FROM
{
dBModel
.
TbError
.
TableName
}
"
);
dBModel
.
sqliteHelper
.
QueryTranAsync
(
sqls
);
NewestID
=
0
;
Count
=
0
;
}
/// <summary>
/// 获取指定位置的N个数据
/// </summary>
/// <param name="last_id">最后的ID</param>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public
async
void
GetRecord
(
int
last_id
,
int
count
,
AsyncCBHandler
asyncCB
,
object
asyncContext
)
{
if
(
Count
==
0
)
{
asyncCB
(
asyncContext
,
new
GetRecordReponse
<
FlyData_WarningHistory
>()
{
LastID
=
0
,
Items
=
null
});
return
;
}
await
Task
.
Factory
.
StartNew
(()
=>
{
var
reponse
=
new
GetRecordReponse
<
FlyData_WarningHistory
>();
var
db_errors
=
dBModel
.
TbError
.
Find
(
$"ORDER BY ID LIMIT
{
last_id
-
count
+
1
}
,
{
count
}
"
);
reponse
.
LastID
=
last_id
;
reponse
.
Items
=
Map_DB_Errors2FlyData_WarningHistorys
(
db_errors
);
asyncCB
(
asyncContext
,
reponse
);
});
}
/// <summary>
/// 获取最新的N个数据
/// </summary>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public
void
GetRecord
(
int
count
,
AsyncCBHandler
asyncCB
,
object
asyncContext
)
{
GetRecord
(
NewestID
,
count
,
asyncCB
,
asyncContext
);
}
FlyData_WarningHistory
Map_DB_Error2FlyData_WarningHistory
(
DB_Error
dB_Error
)
{
{
return
new
FlyData_WarningHistory
()
return
new
FlyData_WarningHistory
()
{
{
Time
=
dB_Error
.
Time
,
ID
=
db
.
ID
,
ErrCode
=
dB_Error
.
ErrCod
e
,
Time
=
db
.
Tim
e
,
State
=
dB_Error
.
IsOn
?
ERR_STATE
.
ON
:
ERR_STATE
.
OFF
,
ErrCode
=
db
.
ErrCode
,
Description
=
d
B_Error
.
Descrption
,
Description
=
d
b
.
Descrption
,
Accessory
=
dB_Error
.
Accessory
State
=
db
.
IsOn
?
ERR_STATE
.
ON
:
ERR_STATE
.
OFF
};
};
}
}
List
<
FlyData_WarningHistory
>
Map_DB_Errors2FlyData_WarningHistorys
(
List
<
DB_Error
>
dB_Errors
)
{
List
<
FlyData_WarningHistory
>
flyDatas
=
new
List
<
FlyData_WarningHistory
>();
foreach
(
var
db_error
in
dB_Errors
)
{
flyDatas
.
Add
(
Map_DB_Error2FlyData_WarningHistory
(
db_error
));
}
return
flyDatas
;
}
}
}
}
}
Project.FLY.OBJComponents/OBJComponents/Server/BufferSQLite.cs
0 → 100644
View file @
925e79d0
using
FLY.OBJComponents.Common
;
using
FLY.OBJComponents.IService
;
using
FObjBase
;
using
SQLite
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
FLY.OBJComponents.Server
{
public
class
BufferSQLite
<
TLc
,
TDb
>
:
IBufferAdd
<
TLc
>
where
TLc
:
IDbBase
,
new
()
where
TDb
:
IDbBase
,
new
()
{
DBTable
<
TDb
>
dbTable
;
SQLiteHelper
sqliteHelper
;
Func
<
TLc
,
TDb
>
mapLc2Db
;
Func
<
TDb
,
TLc
>
mapDb2Lc
;
public
int
NewestID
=>
Count
-
1
;
public
int
Count
{
get
;
private
set
;
}
/// <summary>
/// 不能设置,设了也没有用
/// </summary>
public
int
Capacity
{
get
;
set
;
}
=
int
.
MaxValue
;
public
event
NotifyBufferChangedEventHandler
<
TLc
>
BufferChanged
;
public
event
PropertyChangedEventHandler
PropertyChanged
;
public
BufferSQLite
()
{
}
public
void
Init
(
DBTable
<
TDb
>
dbTable
,
Func
<
TLc
,
TDb
>
mapLc2Db
,
Func
<
TDb
,
TLc
>
mapDb2Lc
)
{
this
.
dbTable
=
dbTable
;
this
.
sqliteHelper
=
dbTable
.
sqliteHelper
;
this
.
mapLc2Db
=
mapLc2Db
;
this
.
mapDb2Lc
=
mapDb2Lc
;
Load
();
}
void
Load
()
{
var
n
=
sqliteHelper
.
ExecuteScalar
(
$"SELECT COUNT(*) FROM
{
dbTable
.
TableName
}
"
);
int
count
=
System
.
Convert
.
ToInt32
(
n
);
Count
=
count
;
}
public
void
Add
(
TLc
lc
)
{
//添加 数据库必要的 field
lc
.
ID
=
dbTable
.
FreeID
;
//SQLs
List
<
string
>
sqls
=
new
List
<
string
>();
sqls
.
Add
(
SQLiteHelper
.
GetInsertCommandText
(
mapLc2Db
(
lc
)));
sqliteHelper
.
QueryTranAsync
(
sqls
);
Count
++;
}
public
void
AddRange
(
IEnumerable
<
TLc
>
lcs
)
{
List
<
string
>
sqls
=
new
List
<
string
>();
foreach
(
var
lc
in
lcs
)
{
//添加 数据库必要的 field
lc
.
ID
=
dbTable
.
FreeID
;
//SQLs
sqls
.
Add
(
SQLiteHelper
.
GetInsertCommandText
(
mapLc2Db
(
lc
)));
}
sqliteHelper
.
QueryTranAsync
(
sqls
);
Count
+=
lcs
.
Count
();
}
/// <summary>
/// 清空全部数据
/// </summary>
public
void
Reset
()
{
//SQLs
List
<
string
>
sqls
=
new
List
<
string
>();
sqls
.
Add
(
$"DELETE FROM
{
dbTable
.
TableName
}
"
);
sqliteHelper
.
QueryTranAsync
(
sqls
);
Count
=
0
;
}
/// <summary>
/// 获取指定位置的N个数据
/// </summary>
/// <param name="last_id">最后的ID</param>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public
async
void
GetRecord
(
int
last_id
,
int
count
,
AsyncCBHandler
asyncCB
,
object
asyncContext
)
{
if
(
Count
==
0
)
{
asyncCB
(
asyncContext
,
new
GetRecordReponse
<
TLc
>()
{
LastID
=
0
,
Items
=
null
});
return
;
}
await
Task
.
Factory
.
StartNew
(()
=>
{
var
reponse
=
new
GetRecordReponse
<
TLc
>();
var
dbs
=
dbTable
.
Find
(
$"ORDER BY ID LIMIT
{
last_id
-
count
+
1
}
,
{
count
}
"
);
reponse
.
LastID
=
last_id
;
List
<
TLc
>
lcs
=
new
List
<
TLc
>();
foreach
(
var
db
in
dbs
)
{
lcs
.
Add
(
mapDb2Lc
(
db
));
}
reponse
.
Items
=
lcs
;
asyncCB
(
asyncContext
,
reponse
);
});
}
/// <summary>
/// 获取最新的N个数据
/// </summary>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public
void
GetRecord
(
int
count
,
AsyncCBHandler
asyncCB
,
object
asyncContext
)
{
GetRecord
(
NewestID
,
count
,
asyncCB
,
asyncContext
);
}
}
public
class
BufferSQLite
<
TDb
>
:
IBufferAdd
<
TDb
>
where
TDb
:
IDbBase
,
new
()
{
SQLiteDbContext
dbModel
;
DBTable
<
TDb
>
dbTable
;
public
int
NewestID
=>
Count
-
1
;
public
int
Count
{
get
;
private
set
;
}
/// <summary>
/// 不能设置,设了也没有用
/// </summary>
public
int
Capacity
{
get
;
set
;
}
=
int
.
MaxValue
;
public
event
NotifyBufferChangedEventHandler
<
TDb
>
BufferChanged
;
public
event
PropertyChangedEventHandler
PropertyChanged
;
public
BufferSQLite
()
{
}
public
void
Init
(
SQLiteDbContext
dbModel
,
DBTable
<
TDb
>
dbTable
)
{
this
.
dbModel
=
dbModel
;
this
.
dbTable
=
dbTable
;
Load
();
}
void
Load
()
{
var
n
=
dbModel
.
sqliteHelper
.
ExecuteScalar
(
$"SELECT COUNT(*) FROM
{
dbTable
.
TableName
}
"
);
int
count
=
System
.
Convert
.
ToInt32
(
n
);
Count
=
count
;
}
public
void
Add
(
TDb
db
)
{
//添加 数据库必要的 field
db
.
ID
=
dbTable
.
FreeID
;
//SQLs
List
<
string
>
sqls
=
new
List
<
string
>();
sqls
.
Add
(
SQLiteHelper
.
GetInsertCommandText
(
db
));
dbModel
.
sqliteHelper
.
QueryTranAsync
(
sqls
);
Count
++;
}
public
void
AddRange
(
IEnumerable
<
TDb
>
dbs
)
{
List
<
string
>
sqls
=
new
List
<
string
>();
foreach
(
var
db
in
dbs
)
{
//添加 数据库必要的 field
db
.
ID
=
dbTable
.
FreeID
;
//SQLs
sqls
.
Add
(
SQLiteHelper
.
GetInsertCommandText
(
db
));
}
dbModel
.
sqliteHelper
.
QueryTranAsync
(
sqls
);
Count
+=
dbs
.
Count
();
}
/// <summary>
/// 清空全部数据
/// </summary>
public
void
Reset
()
{
//SQLs
List
<
string
>
sqls
=
new
List
<
string
>();
sqls
.
Add
(
$"DELETE FROM
{
dbTable
.
TableName
}
"
);
dbModel
.
sqliteHelper
.
QueryTranAsync
(
sqls
);
Count
=
0
;
}
/// <summary>
/// 获取指定位置的N个数据
/// </summary>
/// <param name="last_id">最后的ID</param>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public
async
void
GetRecord
(
int
last_id
,
int
count
,
AsyncCBHandler
asyncCB
,
object
asyncContext
)
{
if
(
Count
==
0
)
{
asyncCB
(
asyncContext
,
new
GetRecordReponse
<
TDb
>()
{
LastID
=
0
,
Items
=
null
});
return
;
}
await
Task
.
Factory
.
StartNew
(()
=>
{
var
reponse
=
new
GetRecordReponse
<
TDb
>();
var
dbs
=
dbTable
.
Find
(
$"ORDER BY ID LIMIT
{
last_id
-
count
+
1
}
,
{
count
}
"
);
reponse
.
LastID
=
last_id
;
reponse
.
Items
=
dbs
;
asyncCB
(
asyncContext
,
reponse
);
});
}
/// <summary>
/// 获取最新的N个数据
/// </summary>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public
void
GetRecord
(
int
count
,
AsyncCBHandler
asyncCB
,
object
asyncContext
)
{
GetRecord
(
NewestID
,
count
,
asyncCB
,
asyncContext
);
}
}
}
Project.FLY.OBJComponents/OBJComponents/Server/Model/DB_Error.cs
View file @
925e79d0
...
@@ -13,7 +13,7 @@ namespace FLY.OBJComponents.Server.Model
...
@@ -13,7 +13,7 @@ namespace FLY.OBJComponents.Server.Model
/// 异常记录
/// 异常记录
/// </summary>
/// </summary>
[
Table
(
"Error"
)]
[
Table
(
"Error"
)]
public
class
DB_Error
public
class
DB_Error
:
IDbBase
{
{
[
Key
]
[
Key
]
[
PropertyIndex
(
0
)]
[
PropertyIndex
(
0
)]
...
...
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