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
69dd847a
Commit
69dd847a
authored
Jun 04, 2020
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 修复 FObject.Reflect 接口无法或者父接口的事件
parent
74173d07
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
224 additions
and
76 deletions
+224
-76
Reflect_Proxy.cs
Project.FLY.FObjSys/FObjBaseReflect/Reflect_Proxy.cs
+88
-48
Reflect_SeviceClient.cs
Project.FLY.FObjSys/FObjBaseReflect/Reflect_SeviceClient.cs
+135
-27
FilmPositionDetectServiceClient.cs
.../FLY.Thick.Base/Client/FilmPositionDetectServiceClient.cs
+1
-1
No files found.
Project.FLY.FObjSys/FObjBaseReflect/Reflect_Proxy.cs
View file @
69dd847a
...
...
@@ -18,53 +18,110 @@ namespace FObjBase.Reflect
public
bool
ignoreSet
=
false
;
List
<
AnyEvent
>
anyEvents
=
new
List
<
AnyEvent
>();
Dictionary
<
object
,
string
>
subProperties
=
new
Dictionary
<
object
,
string
>();
List
<
string
>
properties
=
new
List
<
string
>();
public
Reflect_Proxy
(
int
objsys_idx
,
UInt32
id
,
Type
interfaceType
,
object
obj
)
:
base
(
objsys_idx
)
{
ID
=
id
;
this
.
interfaceType
=
interfaceType
;
this
.
obj
=
obj
;
if
(
typeof
(
INotifyPropertyChanged
).
IsAssignableFrom
(
interfaceType
))
{
//继承了INotifyPropertyChanged
((
INotifyPropertyChanged
)(
this
.
obj
)).
PropertyChanged
+=
Obj_PropertyChanged
;
}
InitPropertyChanged
();
//处理[PropertyPush]
InitPropertyPush
();
//注册全部事件
var
eventInfos
=
this
.
interfaceType
.
GetEvents
();
//处理[Push]
InitEventPush
();
}
void
InitPropertyChanged
()
{
if
(!
typeof
(
INotifyPropertyChanged
).
IsAssignableFrom
(
interfaceType
))
return
;
//继承了INotifyPropertyChanged
((
INotifyPropertyChanged
)(
this
.
obj
)).
PropertyChanged
+=
Obj_PropertyChanged
;
var
interfaceTypes
=
new
List
<
Type
>();
interfaceTypes
.
Add
(
this
.
interfaceType
);
interfaceTypes
.
AddRange
(
this
.
interfaceType
.
GetInterfaces
());
var
propertyInfos
=
new
List
<
PropertyInfo
>();
foreach
(
var
ifaceType
in
interfaceTypes
)
{
propertyInfos
.
AddRange
(
ifaceType
.
GetProperties
());
}
foreach
(
var
propertyInfo
in
propertyInfos
)
{
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()
!=
null
)
continue
;
//这个不需要推送
if
(
properties
.
Contains
(
propertyInfo
.
Name
))
continue
;
properties
.
Add
(
propertyInfo
.
Name
);
}
}
void
InitEventPush
()
{
var
interfaceTypes
=
new
List
<
Type
>();
interfaceTypes
.
Add
(
this
.
interfaceType
);
interfaceTypes
.
AddRange
(
this
.
interfaceType
.
GetInterfaces
());
var
eventInfos
=
new
List
<
EventInfo
>();
foreach
(
var
ifaceType
in
interfaceTypes
)
{
eventInfos
.
AddRange
(
ifaceType
.
GetEvents
());
}
foreach
(
var
eventInfo
in
eventInfos
)
{
var
pushAttribute
=
eventInfo
.
GetCustomAttribute
<
PushAttribute
>();
if
(
pushAttribute
!=
null
)
if
(
pushAttribute
==
null
)
return
;
if
(
anyEvents
.
Any
(
ae
=>
ae
.
eventName
==
eventInfo
.
Name
))
return
;
//已经添加了
var
anyEvent
=
new
AnyEvent
()
{
var
anyEvent
=
new
AnyEvent
()
{
eventName
=
eventInfo
.
Name
,
PushObjInfoEx
=
(
msg
)
=>
{
var
buf
=
Misc
.
Converter
.
StringToBytes
(
msg
);
CurrObjSys
.
PushObjInfoEx
(
this
,
Reflect_OBJ_INTERFACE
.
PUSH_Event
,
buf
);
}
};
//这个事件需要推送
eventInfo
.
AddEventHandler
(
obj
,
anyEvent
.
eventHandler
);
anyEvents
.
Add
(
anyEvent
);
}
eventName
=
eventInfo
.
Name
,
PushObjInfoEx
=
(
msg
)
=>
{
var
buf
=
Misc
.
Converter
.
StringToBytes
(
msg
);
CurrObjSys
.
PushObjInfoEx
(
this
,
Reflect_OBJ_INTERFACE
.
PUSH_Event
,
buf
);
}
};
//这个事件需要推送
eventInfo
.
AddEventHandler
(
obj
,
anyEvent
.
eventHandler
);
anyEvents
.
Add
(
anyEvent
);
}
}
void
InitPropertyPush
()
{
//处理[PropertyPush]
var
propertyInfos
=
interfaceType
.
GetProperties
();
var
interfaceTypes
=
new
List
<
Type
>();
interfaceTypes
.
Add
(
this
.
interfaceType
);
interfaceTypes
.
AddRange
(
this
.
interfaceType
.
GetInterfaces
());
var
propertyInfos
=
new
List
<
PropertyInfo
>();
foreach
(
var
ifaceType
in
interfaceTypes
)
propertyInfos
.
AddRange
(
ifaceType
.
GetProperties
());
foreach
(
var
propertyInfo
in
propertyInfos
)
{
if
(!
IsPropertyPush
(
propertyInfo
))
continue
;
if
(!
properties
.
Contains
(
propertyInfo
.
Name
))
{
properties
.
Add
(
propertyInfo
.
Name
);
}
InitSubPropertyPush
(
this
.
obj
.
GetType
().
GetProperty
(
propertyInfo
.
Name
),
this
.
obj
,
null
);
}
}
...
...
@@ -122,11 +179,7 @@ namespace FObjBase.Reflect
}
}
class
SubProperty
{
public
string
propertyName
;
public
object
value
;
}
private
void
Obj_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
...
...
@@ -136,22 +189,15 @@ namespace FObjBase.Reflect
if
(
interfaceType
==
null
)
return
;
var
type
=
interfaceType
;
var
propertyInfo
=
type
.
GetProperty
(
e
.
PropertyName
);
if
(
propertyInfo
==
null
)
return
;
//获取失败!!!
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()!=
null
)
if
(!
properties
.
Contains
(
e
.
PropertyName
))
return
;
//这个不需要推送
var
v
=
this
.
obj
.
GetType
().
GetProperty
(
propertyInfo
.
Name
).
GetValue
(
sender
);
var
v
=
this
.
obj
.
GetType
().
GetProperty
(
e
.
Property
Name
).
GetValue
(
sender
);
var
jObject
=
new
JObject
();
if
(
v
==
null
)
jObject
.
Add
(
propertyInfo
.
Name
,
null
);
jObject
.
Add
(
e
.
Property
Name
,
null
);
else
jObject
.
Add
(
propertyInfo
.
Name
,
JToken
.
FromObject
(
v
));
jObject
.
Add
(
e
.
Property
Name
,
JToken
.
FromObject
(
v
));
string
json
=
jObject
.
ToString
(
Formatting
.
None
);
var
buf
=
Misc
.
Converter
.
StringToBytes
(
json
);
CurrObjSys
.
PushObjInfoEx
(
...
...
@@ -212,15 +258,9 @@ namespace FObjBase.Reflect
var
type
=
obj
.
GetType
();
var
propertyInfos
=
type
.
GetProperties
();
foreach
(
var
propertyInfo
in
propertyInfos
)
foreach
(
var
propertyName
in
properties
)
{
var
attr
=
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>(
false
);
if
(
attr
!=
null
)
{
return
;
//这个不需要推送
}
var
propertyInfo
=
type
.
GetProperty
(
propertyName
);
var
v
=
propertyInfo
.
GetValue
(
obj
);
if
(
v
==
null
)
jObject
.
Add
(
propertyInfo
.
Name
,
null
);
...
...
Project.FLY.FObjSys/FObjBaseReflect/Reflect_SeviceClient.cs
View file @
69dd847a
...
...
@@ -16,7 +16,23 @@ namespace FObjBase.Reflect
protected
virtual
Type
InterfaceType
{
get
;
}
List
<
AnyEvent
>
anyEvents
=
new
List
<
AnyEvent
>();
List
<
AnyCall
>
anyCalls
=
new
List
<
AnyCall
>();
class
AnyEvent
{
public
string
name
;
public
string
triggerName
;
public
Type
retType
;
}
class
AnyCall
{
public
string
name
;
public
Type
retType
;
}
Dictionary
<
object
,
string
>
subProperties
=
new
Dictionary
<
object
,
string
>();
List
<
string
>
properties
=
new
List
<
string
>();
public
Reflect_SeviceClient
(
UInt32
id
)
:
base
(
id
)
{
init
();
}
...
...
@@ -26,19 +42,54 @@ namespace FObjBase.Reflect
init
();
}
void
init
()
{
if
(
typeof
(
INotifyPropertyChanged
).
IsAssignableFrom
(
InterfaceType
))
InitPropertyChanged
();
InitPropertyPush
();
InitEventPush
();
InitCall
();
}
void
InitPropertyChanged
()
{
if
(!
typeof
(
INotifyPropertyChanged
).
IsAssignableFrom
(
InterfaceType
))
return
;
//继承了INotifyPropertyChanged
this
.
PropertyChanged
+=
Obj_PropertyChanged
;
var
interfaceTypes
=
new
List
<
Type
>();
interfaceTypes
.
Add
(
this
.
InterfaceType
);
interfaceTypes
.
AddRange
(
this
.
InterfaceType
.
GetInterfaces
());
var
propertyInfos
=
new
List
<
PropertyInfo
>();
foreach
(
var
ifaceType
in
interfaceTypes
)
{
//继承了INotifyPropertyChanged
this
.
PropertyChanged
+=
Obj_PropertyChanged
;
propertyInfos
.
AddRange
(
ifaceType
.
GetProperties
());
}
InitPropertyPush
();
foreach
(
var
propertyInfo
in
propertyInfos
)
{
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()
!=
null
)
continue
;
//这个不需要推送
if
(
properties
.
Contains
(
propertyInfo
.
Name
))
continue
;
properties
.
Add
(
propertyInfo
.
Name
);
}
}
void
InitPropertyPush
()
{
//处理[PropertyPush]
var
propertyInfos
=
InterfaceType
.
GetProperties
();
var
interfaceTypes
=
new
List
<
Type
>();
interfaceTypes
.
Add
(
this
.
InterfaceType
);
interfaceTypes
.
AddRange
(
this
.
InterfaceType
.
GetInterfaces
());
var
propertyInfos
=
new
List
<
PropertyInfo
>();
foreach
(
var
ifaceType
in
interfaceTypes
)
propertyInfos
.
AddRange
(
ifaceType
.
GetProperties
());
foreach
(
var
propertyInfo
in
propertyInfos
)
{
if
(!
IsPropertyPush
(
propertyInfo
))
...
...
@@ -80,7 +131,72 @@ namespace FObjBase.Reflect
}
}
void
InitEventPush
()
{
var
interfaceTypes
=
new
List
<
Type
>();
interfaceTypes
.
Add
(
InterfaceType
);
interfaceTypes
.
AddRange
(
InterfaceType
.
GetInterfaces
());
var
eventInfos
=
new
List
<
EventInfo
>();
foreach
(
var
ifaceType
in
interfaceTypes
)
{
eventInfos
.
AddRange
(
ifaceType
.
GetEvents
());
}
foreach
(
var
eventInfo
in
eventInfos
)
{
var
pushAttribute
=
eventInfo
.
GetCustomAttribute
<
PushAttribute
>();
if
(
pushAttribute
==
null
)
return
;
if
(
anyEvents
.
Any
(
ae
=>
ae
.
name
==
eventInfo
.
Name
))
return
;
//已经添加了
var
anyEvent
=
new
AnyEvent
()
{
name
=
eventInfo
.
Name
,
triggerName
=
pushAttribute
.
TriggerName
,
retType
=
pushAttribute
.
EventArgsType
};
anyEvents
.
Add
(
anyEvent
);
}
}
void
InitCall
()
{
var
interfaceTypes
=
new
List
<
Type
>();
interfaceTypes
.
Add
(
InterfaceType
);
interfaceTypes
.
AddRange
(
InterfaceType
.
GetInterfaces
());
var
methodInfos
=
new
List
<
MethodInfo
>();
foreach
(
var
ifaceType
in
interfaceTypes
)
{
methodInfos
.
AddRange
(
ifaceType
.
GetMethods
());
}
foreach
(
var
methodInfo
in
methodInfos
)
{
var
callAttribute
=
methodInfo
.
GetCustomAttribute
<
CallAttribute
>();
if
(
callAttribute
==
null
)
return
;
if
(
anyCalls
.
Any
(
ae
=>
ae
.
name
==
methodInfo
.
Name
))
return
;
//已经添加了
var
anyCall
=
new
AnyCall
()
{
name
=
methodInfo
.
Name
,
retType
=
callAttribute
.
ReponseType
};
anyCalls
.
Add
(
anyCall
);
}
}
private
void
Obj_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(!
IsConnected
)
...
...
@@ -92,21 +208,16 @@ namespace FObjBase.Reflect
if
(
InterfaceType
==
null
)
return
;
var
type
=
InterfaceType
;
var
propertyInfo
=
type
.
GetProperty
(
e
.
PropertyName
);
if
(
propertyInfo
==
null
)
return
;
//获取失败!!!
if
(
propertyInfo
.
GetCustomAttribute
<
JsonIgnoreAttribute
>()
!=
null
)
if
(!
properties
.
Contains
(
e
.
PropertyName
))
return
;
//这个不需要推送
var
v
=
GetType
().
GetProperty
(
propertyInfo
.
Name
).
GetValue
(
sender
);
var
v
=
GetType
().
GetProperty
(
e
.
PropertyName
).
GetValue
(
sender
);
var
jObject
=
new
JObject
();
if
(
v
==
null
)
jObject
.
Add
(
propertyInfo
.
Name
,
null
);
jObject
.
Add
(
e
.
Property
Name
,
null
);
else
jObject
.
Add
(
propertyInfo
.
Name
,
JToken
.
FromObject
(
v
));
jObject
.
Add
(
e
.
Property
Name
,
JToken
.
FromObject
(
v
));
string
json
=
jObject
.
ToString
(
Formatting
.
None
);
...
...
@@ -205,14 +316,14 @@ namespace FObjBase.Reflect
string
json
=
Misc
.
Converter
.
BytesToString
(
infodata
);
var
rData
=
JsonConvert
.
DeserializeObject
<
Reflect_OBJ_INTERFACE
.
ReflectData
>(
json
);
var
type
=
InterfaceType
;
var
anyEvent
=
anyEvents
.
Find
(
ae
=>
ae
.
name
==
rData
.
name
);
if
(
anyEvent
==
null
)
return
;
//异常!!!
var
eventInfo
=
type
.
GetEvent
(
rData
.
name
);
var
pushAttribute
=
eventInfo
.
GetCustomAttribute
<
PushAttribute
>();
//触发事件!!!
var
methodInfo
=
GetType
().
GetMethod
(
pushAttribute
.
T
riggerName
);
var
obj
=
rData
.
data
.
ToObject
(
pushAttribute
.
EventArgs
Type
);
var
methodInfo
=
GetType
().
GetMethod
(
anyEvent
.
t
riggerName
);
var
obj
=
rData
.
data
.
ToObject
(
anyEvent
.
ret
Type
);
methodInfo
.
Invoke
(
this
,
new
object
[]
{
obj
});
}
break
;
...
...
@@ -239,17 +350,14 @@ namespace FObjBase.Reflect
string
json
=
Misc
.
Converter
.
BytesToString
(
retdata
);
var
reponse
=
JsonConvert
.
DeserializeObject
<
Reflect_OBJ_INTERFACE
.
ReflectData
>(
json
);
var
type
=
InterfaceType
;
var
methodInfo
=
type
.
GetMethod
(
reponse
.
name
);
var
callAttribute
=
methodInfo
.
GetCustomAttribute
<
CallAttribute
>();
if
(
callAttribute
==
null
)
{
var
anyCall
=
anyCalls
.
Find
(
ac
=>
ac
.
name
==
reponse
.
name
);
if
(
anyCall
==
null
)
{
//异常!!!应该有[Call]注明返回的类型
throw
new
Exception
(
$"
{
reponse
.
name
}
异常!!!应该有[Call]注明返回的类型"
);
}
var
retData
=
reponse
.
data
.
ToObject
(
callAttribute
.
Reponse
Type
);
var
retData
=
reponse
.
data
.
ToObject
(
anyCall
.
ret
Type
);
((
AsyncCBHandler
)
asyncDelegate
).
Invoke
(
asyncContext
,
retData
);
}
break
;
...
...
Project.FLY.Thick.Base/FLY.Thick.Base/Client/FilmPositionDetectServiceClient.cs
View file @
69dd847a
...
...
@@ -147,7 +147,7 @@ namespace FLY.Thick.Base.Client
/// <param name="filmPos">极片位置m</param>
public
void
SetFilmPosAt01
(
double
filmPos
)
{
Call
(
"SetFilmPosAt01"
,
filmPos
);
Call
(
"SetFilmPosAt01"
,
new
{
filmPos
}
);
}
/// <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