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
e7d9bf62
Commit
e7d9bf62
authored
Aug 20, 2020
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.优化 SQLiteHelper 删除多余
2.添加 WSCF , Reflect_Proxy 添加释放事件资源
parent
a91821bb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
136 additions
and
193 deletions
+136
-193
DBTable.cs
Project.SQLiteHelper/SQLiteHelper/DBTable.cs
+2
-7
IgnoreAttribute.cs
Project.SQLiteHelper/SQLiteHelper/IgnoreAttribute.cs
+0
-9
SQLiteHelper.cs
Project.SQLiteHelper/SQLiteHelper/SQLiteHelper.cs
+26
-167
MainWindow.xaml
WSCF/WSCF.Test.Server/MainWindow.xaml
+13
-1
MainWindow.xaml.cs
WSCF/WSCF.Test.Server/MainWindow.xaml.cs
+35
-0
WSCF.Test.Server.csproj
WSCF/WSCF.Test.Server/WSCF.Test.Server.csproj
+1
-0
WsProxy.cs
WSCF/WSCF.Test/Server.WsProxy/WsProxy.cs
+1
-1
Reflect_Proxy.cs
WSCF/WSCF/Reflect_Proxy.cs
+58
-8
No files found.
Project.SQLiteHelper/SQLiteHelper/DBTable.cs
View file @
e7d9bf62
...
...
@@ -9,8 +9,6 @@ namespace SQLite
public
class
DBTable
<
T
>
:
IDBTable
where
T
:
new
()
{
public
List
<
SQLiteHelper
.
ArrayFieldTypeInfo
>
ArrayFieldTypeInfos
=
new
List
<
SQLiteHelper
.
ArrayFieldTypeInfo
>();
public
string
TableName
{
get
;
private
set
;
}
private
long
freeID
=
0
;
...
...
@@ -32,10 +30,7 @@ namespace SQLite
{
get
{
if
(
ArrayFieldTypeInfos
.
Count
()
==
0
)
return
ddl
;
else
return
SQLiteHelper
.
GetCreateTableCommandText
(
typeof
(
T
),
ArrayFieldTypeInfos
.
ToArray
());
return
ddl
;
}
}
...
...
@@ -81,7 +76,7 @@ namespace SQLite
sql
+=
" "
+
condition
;
DataTable
dataTable
=
sqliteHelper
.
ExecuteReader
(
sql
);
return
SQLiteHelper
.
ToObjs
<
T
>(
dataTable
,
ArrayFieldTypeInfos
.
ToArray
()
);
return
SQLiteHelper
.
ToObjs
<
T
>(
dataTable
);
}
/// <summary>
...
...
Project.SQLiteHelper/SQLiteHelper/IgnoreAttribute.cs
View file @
e7d9bf62
...
...
@@ -11,15 +11,6 @@ namespace SQLite
}
}
public
class
BortherAttribute
:
Attribute
{
}
public
class
ChildAttribute
:
Attribute
{
}
public
class
PropertyIndexAttribute
:
Attribute
{
...
...
Project.SQLiteHelper/SQLiteHelper/SQLiteHelper.cs
View file @
e7d9bf62
This diff is collapsed.
Click to expand it.
WSCF/WSCF.Test.Server/MainWindow.xaml
View file @
e7d9bf62
...
...
@@ -7,7 +7,11 @@
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" >
<TextBlock>
Number=<Run Text="{Binding Number,Mode=OneWay}"/>
</TextBlock>
...
...
@@ -15,5 +19,13 @@
AddFuncTime=<Run Text="{Binding AddFuncTime,Mode=OneWay}"/>
</TextBlock>
</StackPanel>
<Grid Grid.Row="1" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="Session 开始时间:"/>
<ListBox x:Name="lst" Grid.Row="1" />
</Grid>
</Grid>
</Window>
WSCF/WSCF.Test.Server/MainWindow.xaml.cs
View file @
e7d9bf62
using
System
;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
...
...
@@ -12,6 +13,7 @@ using System.Windows.Media;
using
System.Windows.Media.Imaging
;
using
System.Windows.Navigation
;
using
System.Windows.Shapes
;
using
System.Windows.Threading
;
namespace
WSCF.Test.Server
{
...
...
@@ -22,6 +24,10 @@ namespace WSCF.Test.Server
{
WSCF
.
Test
.
Server
.
WsProxy
.
WsProxy
wsProxy
;
Foo
foo
;
DispatcherTimer
timer
;
ObservableCollection
<
DateTime
>
SessionStartTimes
=
new
ObservableCollection
<
DateTime
>();
public
MainWindow
()
{
InitializeComponent
();
...
...
@@ -30,6 +36,35 @@ namespace WSCF.Test.Server
wsProxy
=
new
WsProxy
.
WsProxy
(
"127.0.0.1:5540"
,
foo
);
this
.
DataContext
=
foo
;
timer
=
new
DispatcherTimer
();
timer
.
Interval
=
TimeSpan
.
FromSeconds
(
1
);
timer
.
Tick
+=
Timer_Tick
;
timer
.
Start
();
lst
.
ItemsSource
=
SessionStartTimes
;
}
private
void
Timer_Tick
(
object
sender
,
EventArgs
e
)
{
if
(
wsProxy
.
wssv
.
WebSocketServices
.
Hosts
.
Count
()
>
0
)
{
var
startimes
=
wsProxy
.
wssv
.
WebSocketServices
.
Hosts
.
First
().
Sessions
.
Sessions
.
Select
(
s
=>
s
.
StartTime
);
for
(
int
i
=
0
;
i
<
startimes
.
Count
();
i
++)
{
var
startime
=
startimes
.
ElementAt
(
i
);
if
(
i
<
SessionStartTimes
.
Count
)
{
SessionStartTimes
[
i
]
=
startime
;
}
else
{
SessionStartTimes
.
Add
(
startime
);
}
}
while
(
SessionStartTimes
.
Count
()
>
startimes
.
Count
())
SessionStartTimes
.
RemoveAt
(
SessionStartTimes
.
Count
()
-
1
);
}
}
}
}
WSCF/WSCF.Test.Server/WSCF.Test.Server.csproj
View file @
e7d9bf62
...
...
@@ -46,6 +46,7 @@
<Reference
Include=
"System.Xaml"
>
<RequiredTargetFramework>
4.0
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"websocket-sharp, Version=1.0.1.0, Culture=neutral, PublicKeyToken=5660b08a1845a91e"
/>
<Reference
Include=
"WindowsBase"
/>
<Reference
Include=
"PresentationCore"
/>
<Reference
Include=
"PresentationFramework"
/>
...
...
WSCF/WSCF.Test/Server.WsProxy/WsProxy.cs
View file @
e7d9bf62
...
...
@@ -10,7 +10,7 @@ namespace WSCF.Test.Server.WsProxy
{
public
class
WsProxy
{
WebSocketServer
wssv
;
public
WebSocketServer
wssv
;
public
WsProxy
(
string
addr
,
Foo
foo
)
{
wssv
=
new
WebSocketServer
(
$"ws://
{
addr
}
/"
);
...
...
WSCF/WSCF/Reflect_Proxy.cs
View file @
e7d9bf62
...
...
@@ -11,8 +11,9 @@ using WebSocketSharp.Server;
namespace
WSCF
{
public
class
Reflect_Proxy
:
WebSocketBehavior
public
class
Reflect_Proxy
:
WebSocketBehavior
,
IDisposable
{
static
NLog
.
Logger
logger
=
NLog
.
LogManager
.
GetCurrentClassLogger
();
//对象的接口类型
Type
interfaceType
;
//代理对象
...
...
@@ -45,7 +46,20 @@ namespace WSCF
//处理[Push]
InitEventPush
();
}
List
<
DisposeAction
>
DisposeActions
=
new
List
<
DisposeAction
>();
class
DisposeAction
{
public
Action
<
object
>
Dispose
;
public
object
Obj
;
public
DisposeAction
(
Action
<
object
>
dispose
,
object
obj
)
{
this
.
Dispose
=
dispose
;
this
.
Obj
=
obj
;
}
public
void
Do
()
{
Dispose
(
Obj
);
}
}
#
region
Init
void
InitPropertyChanged
()
{
...
...
@@ -55,6 +69,13 @@ namespace WSCF
//继承了INotifyPropertyChanged
((
INotifyPropertyChanged
)(
this
.
obj
)).
PropertyChanged
+=
Obj_PropertyChanged
;
//资源释放时断开引用
DisposeActions
.
Add
(
new
DisposeAction
((
_obj
)
=>
{
((
INotifyPropertyChanged
)(
_obj
)).
PropertyChanged
-=
Obj_PropertyChanged
;
},
this
.
obj
));
var
interfaceTypes
=
new
List
<
Type
>();
interfaceTypes
.
Add
(
this
.
interfaceType
);
interfaceTypes
.
AddRange
(
this
.
interfaceType
.
GetInterfaces
());
...
...
@@ -112,7 +133,7 @@ namespace WSCF
JObject
.
FromObject
(
rd
)
);
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
Send
(
json
);
Send
Ex
(
json
);
}
};
//这个事件需要推送
...
...
@@ -168,6 +189,12 @@ namespace WSCF
subProperties
.
Add
(
propertyValue
,
path
);
((
INotifyPropertyChanged
)(
propertyValue
)).
PropertyChanged
+=
Sub_PropertyChanged
;
//资源释放时断开引用
DisposeActions
.
Add
(
new
DisposeAction
((
_obj
)
=>
{
((
INotifyPropertyChanged
)(
_obj
)).
PropertyChanged
-=
Sub_PropertyChanged
;
},
propertyValue
));
//继续向下找
var
subPropertyInfos
=
propertyInfo
.
PropertyType
.
GetProperties
();
...
...
@@ -203,9 +230,19 @@ namespace WSCF
jObject
);
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
Send
(
json
);
SendEx
(
json
);
}
void
SendEx
(
string
msg
)
{
try
{
Send
(
msg
);
}
catch
(
Exception
e
)
{
//异常,通常是断开了!!
logger
.
Error
(
e
);
}
}
private
void
Sub_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
ignoreSet
)
//从服务器接收的数据,不用再推送给服务器
...
...
@@ -249,7 +286,7 @@ namespace WSCF
jObject_parent
);
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
Send
(
json
);
Send
Ex
(
json
);
}
#
endregion
...
...
@@ -264,6 +301,8 @@ namespace WSCF
{
base
.
OnClose
(
e
);
isAlive
=
false
;
Dispose
();
}
protected
override
void
OnMessage
(
MessageEventArgs
e
)
...
...
@@ -299,7 +338,7 @@ namespace WSCF
pkgData
.
data
=
jObject
;
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
Send
(
json
);
Send
Ex
(
json
);
}
break
;
case
Reflect_OBJ_INTERFACE
.
PkgName
.
CALL_SetProperty
:
...
...
@@ -361,13 +400,24 @@ namespace WSCF
);
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
Send
(
json
);
Send
Ex
(
json
);
}
public
void
Dispose
()
{
foreach
(
var
act
in
DisposeActions
)
{
act
.
Do
();
}
DisposeActions
.
Clear
();
}
class
CC
{
public
string
methodName
;
public
string
guid
;
}
}
/// <summary>
/// 事件推送包装
...
...
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