Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
W
WSCF
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
潘栩锋
WSCF
Commits
fa4a5134
Commit
fa4a5134
authored
Nov 13, 2021
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复 数组property没有注册PropertyChanged 事件
parent
8a2ac8c7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
103 deletions
+95
-103
COMMON.cs
WSCF/COMMON.cs
+67
-4
IReflectSeviceClientCore.cs
WSCF/IReflectSeviceClientCore.cs
+8
-49
Reflect_Proxy.cs
WSCF/Reflect_Proxy.cs
+12
-2
Reflect_SeviceClient.cs
WSCF/Reflect_SeviceClient.cs
+1
-1
WsServiceProxy.cs
WSCF/WsServiceProxy.cs
+7
-47
No files found.
WSCF/COMMON.cs
View file @
fa4a5134
using
System
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Text
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
static
WSCF
.
Reflect_OBJ_INTERFACE
;
namespace
WSCF
namespace
WSCF
{
{
...
@@ -47,11 +50,14 @@ namespace WSCF
...
@@ -47,11 +50,14 @@ namespace WSCF
//处理[PropertyPush]
//处理[PropertyPush]
var
propertyInfos
=
GetAllPropertyInfos
(
rootNode
.
InterfaceType
);
var
propertyInfos
=
GetAllPropertyInfos
(
rootNode
.
InterfaceType
);
//找到全部[PropertyPush]
propertyInfos
=
propertyInfos
.
FindAll
(
p
=>
p
.
GetCustomAttribute
<
PropertyPushAttribute
>()
!=
null
);
if
(
propertyInfos
.
Count
()
==
0
)
return
;
foreach
(
var
propertyInfo
in
propertyInfos
)
foreach
(
var
propertyInfo
in
propertyInfos
)
{
{
if
(
propertyInfo
.
GetCustomAttribute
<
PropertyPushAttribute
>()
==
null
)
continue
;
//必须是[PropertyPush]
SubPropertyNode
node
=
new
SubPropertyNode
();
SubPropertyNode
node
=
new
SubPropertyNode
();
if
(
ReInitPropertyPush
(
node
,
rootNode
.
Obj
,
propertyInfo
,
rootNode
.
SubPropertyChanged
))
if
(
ReInitPropertyPush
(
node
,
rootNode
.
Obj
,
propertyInfo
,
rootNode
.
SubPropertyChanged
))
{
{
...
@@ -256,6 +262,63 @@ namespace WSCF
...
@@ -256,6 +262,63 @@ namespace WSCF
//重新注册
//重新注册
COMMON
.
ReInitPropertyPush
(
sub_node
,
node
.
Obj
,
propertyInfo
,
node
.
SubPropertyChanged
);
COMMON
.
ReInitPropertyPush
(
sub_node
,
node
.
Obj
,
propertyInfo
,
node
.
SubPropertyChanged
);
}
}
public
static
ReflectData
Sub_PropertyChanged
(
SubPropertyNode
node
,
PropertyChangedEventArgs
e
,
SubPropertyNode
rootNode
,
List
<
string
>
rootProperties
)
{
if
(
rootNode
==
node
)
{
//根对象
if
(!
rootProperties
.
Contains
(
e
.
PropertyName
))
//InterfaceType不包含它,不需要推送
return
null
;
}
var
type
=
node
.
Obj
.
GetType
();
var
propertyInfo
=
type
.
GetProperty
(
e
.
PropertyName
);
if
(
propertyInfo
==
null
)
return
null
;
//获取失败!!!
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()
!=
null
)
return
null
;
//这个不需要推送
var
v
=
propertyInfo
.
GetValue
(
node
.
Obj
);
var
jObject
=
new
JObject
();
if
(
v
==
null
)
jObject
.
Add
(
propertyInfo
.
Name
,
null
);
else
jObject
.
Add
(
propertyInfo
.
Name
,
JToken
.
FromObject
(
v
));
var
rData
=
new
ReflectData
{
name
=
COMMON
.
GetNodePath
(
node
),
data
=
jObject
};
return
rData
;
}
public
static
void
InitPropertyChanged
(
Type
interfaceType
,
object
obj
,
SubPropertyNode
rootNode
,
List
<
string
>
properties
)
{
if
(!
typeof
(
INotifyPropertyChanged
).
IsAssignableFrom
(
interfaceType
))
return
;
//继承了INotifyPropertyChanged
((
INotifyPropertyChanged
)
obj
).
PropertyChanged
+=
rootNode
.
PropertyChanged
;
var
propertyInfos
=
COMMON
.
GetAllPropertyInfos
(
interfaceType
);
//获取全部属性, 包括父类的属性
foreach
(
var
propertyInfo
in
propertyInfos
)
{
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()
!=
null
)
continue
;
//这个不需要推送
if
(
properties
.
Contains
(
propertyInfo
.
Name
))
continue
;
properties
.
Add
(
propertyInfo
.
Name
);
}
}
}
}
/// <summary>
/// <summary>
...
...
WSCF/IReflectSeviceClientCore.cs
View file @
fa4a5134
...
@@ -125,8 +125,12 @@ namespace WSCF
...
@@ -125,8 +125,12 @@ namespace WSCF
SubPropertyChanged
=
Sub_PropertyChanged
SubPropertyChanged
=
Sub_PropertyChanged
};
};
InitPropertyChanged
();
//注册 obj 的PropertyChanged 事件,获取 interfaceType 全部属性名称,包括它的父类的全部属性名称
COMMON
.
InitPropertyChanged
(
interfaceType
,
obj
,
rootNode
,
properties
);
//处理[PropertyPush]
COMMON
.
InitPropertyPush
(
rootNode
);
COMMON
.
InitPropertyPush
(
rootNode
);
InitEventPush
();
InitEventPush
();
InitCall
();
InitCall
();
...
@@ -142,27 +146,6 @@ namespace WSCF
...
@@ -142,27 +146,6 @@ namespace WSCF
}
}
};
};
}
}
void
InitPropertyChanged
()
{
if
(!
typeof
(
INotifyPropertyChanged
).
IsAssignableFrom
(
interfaceType
))
return
;
//继承了INotifyPropertyChanged
this
.
PropertyChanged
+=
rootNode
.
PropertyChanged
;
var
propertyInfos
=
COMMON
.
GetAllPropertyInfos
(
this
.
interfaceType
);
//获取全部属性, 包括父类的属性
foreach
(
var
propertyInfo
in
propertyInfos
)
{
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()
!=
null
)
continue
;
//这个不需要推送
if
(
properties
.
Contains
(
propertyInfo
.
Name
))
continue
;
properties
.
Add
(
propertyInfo
.
Name
);
}
}
void
InitEventPush
()
void
InitEventPush
()
{
{
...
@@ -247,34 +230,10 @@ namespace WSCF
...
@@ -247,34 +230,10 @@ namespace WSCF
if
(
ignoreSet
)
//从服务器接收的数据,不用再推送给服务器
if
(
ignoreSet
)
//从服务器接收的数据,不用再推送给服务器
return
;
return
;
if
(
rootNode
==
node
)
var
rData
=
COMMON
.
Sub_PropertyChanged
(
node
,
e
,
rootNode
,
properties
);
{
if
(
rData
==
null
)
//根对象
if
(!
properties
.
Contains
(
e
.
PropertyName
))
//InterfaceType不包含它,不需要推送
return
;
return
;
}
var
type
=
node
.
Obj
.
GetType
();
var
propertyInfo
=
type
.
GetProperty
(
e
.
PropertyName
);
if
(
propertyInfo
==
null
)
return
;
//获取失败!!!
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()
!=
null
)
return
;
//这个不需要推送
var
v
=
propertyInfo
.
GetValue
(
node
.
Obj
);
var
jObject
=
new
JObject
();
if
(
v
==
null
)
jObject
.
Add
(
propertyInfo
.
Name
,
null
);
else
jObject
.
Add
(
propertyInfo
.
Name
,
JToken
.
FromObject
(
v
));
var
rData
=
new
ReflectData
{
name
=
COMMON
.
GetNodePath
(
node
),
data
=
jObject
};
send_CALL_SetProperty
(
rData
);
send_CALL_SetProperty
(
rData
);
}
}
...
...
WSCF/Reflect_Proxy.cs
View file @
fa4a5134
...
@@ -60,11 +60,21 @@ namespace WSCF
...
@@ -60,11 +60,21 @@ namespace WSCF
Proxy
.
OnMessage
(
this
,
pkgData
);
Proxy
.
OnMessage
(
this
,
pkgData
);
}
}
protected
override
void
OnOpen
()
{
base
.
OnOpen
();
Proxy
.
OnOpen
();
}
protected
override
void
OnClose
(
CloseEventArgs
e
)
{
base
.
OnClose
(
e
);
Proxy
.
OnClose
();
}
public
virtual
void
SendTo
(
string
msg
)
public
virtual
void
SendTo
(
string
msg
)
{
{
if
(
this
.
State
!=
WebSocketState
.
Open
)
return
;
base
.
Send
(
msg
);
base
.
Send
(
msg
);
}
}
...
...
WSCF/Reflect_SeviceClient.cs
View file @
fa4a5134
...
@@ -17,7 +17,7 @@ namespace WSCF
...
@@ -17,7 +17,7 @@ namespace WSCF
/// <summary>
/// <summary>
/// 代理对象 接口类型
/// 代理对象 接口类型
/// </summary>
/// </summary>
protected
virtual
Type
InterfaceType
{
get
;
}
protected
abstract
Type
InterfaceType
{
get
;
}
/// <summary>
/// <summary>
/// 连接成功
/// 连接成功
...
...
WSCF/WsServiceProxy.cs
View file @
fa4a5134
...
@@ -90,7 +90,7 @@ namespace WSCF
...
@@ -90,7 +90,7 @@ namespace WSCF
};
};
//注册 obj 的PropertyChanged 事件,获取 interfaceType 全部属性名称,包括它的父类的全部属性名称
//注册 obj 的PropertyChanged 事件,获取 interfaceType 全部属性名称,包括它的父类的全部属性名称
InitPropertyChanged
(
);
COMMON
.
InitPropertyChanged
(
interfaceType
,
obj
,
rootNode
,
properties
);
//处理[PropertyPush]
//处理[PropertyPush]
COMMON
.
InitPropertyPush
(
rootNode
);
COMMON
.
InitPropertyPush
(
rootNode
);
...
@@ -98,27 +98,6 @@ namespace WSCF
...
@@ -98,27 +98,6 @@ namespace WSCF
//处理[Push]
//处理[Push]
InitEventPush
();
InitEventPush
();
}
}
void
InitPropertyChanged
()
{
if
(!
typeof
(
INotifyPropertyChanged
).
IsAssignableFrom
(
interfaceType
))
return
;
//继承了INotifyPropertyChanged
((
INotifyPropertyChanged
)(
this
.
obj
)).
PropertyChanged
+=
rootNode
.
PropertyChanged
;
var
propertyInfos
=
COMMON
.
GetAllPropertyInfos
(
this
.
interfaceType
);
//获取全部属性, 包括父类的属性
foreach
(
var
propertyInfo
in
propertyInfos
)
{
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()
!=
null
)
continue
;
//这个不需要推送
if
(
properties
.
Contains
(
propertyInfo
.
Name
))
continue
;
properties
.
Add
(
propertyInfo
.
Name
);
}
}
void
InitEventPush
()
void
InitEventPush
()
{
{
...
@@ -156,29 +135,10 @@ namespace WSCF
...
@@ -156,29 +135,10 @@ namespace WSCF
}
}
void
Sub_PropertyChanged
(
SubPropertyNode
node
,
PropertyChangedEventArgs
e
)
void
Sub_PropertyChanged
(
SubPropertyNode
node
,
PropertyChangedEventArgs
e
)
{
{
//if (ignoreSet)//从服务器接收的数据,不用再推送给服务器
var
rData
=
COMMON
.
Sub_PropertyChanged
(
node
,
e
,
rootNode
,
properties
);
// return;
if
(
rData
==
null
)
var
type
=
node
.
Obj
.
GetType
();
return
;
var
propertyInfo
=
type
.
GetProperty
(
e
.
PropertyName
);
if
(
propertyInfo
==
null
)
return
;
//获取失败!!!
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()
!=
null
)
return
;
//这个不需要推送
var
v
=
propertyInfo
.
GetValue
(
node
.
Obj
);
var
jObject
=
new
JObject
();
if
(
v
==
null
)
jObject
.
Add
(
propertyInfo
.
Name
,
null
);
else
jObject
.
Add
(
propertyInfo
.
Name
,
JToken
.
FromObject
(
v
));
var
rData
=
new
ReflectData
{
name
=
COMMON
.
GetNodePath
(
node
),
data
=
jObject
};
reponse_PushObjInfoEx
(
rData
,
false
);
reponse_PushObjInfoEx
(
rData
,
false
);
}
}
...
@@ -334,7 +294,7 @@ namespace WSCF
...
@@ -334,7 +294,7 @@ namespace WSCF
JToken
.
FromObject
(
rData
));
JToken
.
FromObject
(
rData
));
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
SendEx
(
json
);
SendEx
?.
Invoke
(
json
);
}
}
void
reponse_CALL_MethodInvoke
(
ReflectData
rData
,
string
guid
)
void
reponse_CALL_MethodInvoke
(
ReflectData
rData
,
string
guid
)
...
@@ -347,7 +307,7 @@ namespace WSCF
...
@@ -347,7 +307,7 @@ namespace WSCF
JToken
.
FromObject
(
rData
));
JToken
.
FromObject
(
rData
));
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
SendEx
(
json
);
SendEx
?.
Invoke
(
json
);
}
}
void
reponse_CALL_GetAllProperties
(
ReflectData
rData
,
string
guid
)
void
reponse_CALL_GetAllProperties
(
ReflectData
rData
,
string
guid
)
...
@@ -360,7 +320,7 @@ namespace WSCF
...
@@ -360,7 +320,7 @@ namespace WSCF
JToken
.
FromObject
(
rData
));
JToken
.
FromObject
(
rData
));
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
string
json
=
JsonConvert
.
SerializeObject
(
pkgData
);
SendEx
(
json
);
SendEx
?.
Invoke
(
json
);
}
}
...
...
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