Commit d3e677c0 authored by 潘栩锋's avatar 潘栩锋 🚴

1. 修复 COMMON.NodeDispose 当子property不是INotifyProperty 会出错

2. 修复 刚连接成功,当全部properties 太多,导致下载慢,此时服务器有属性改变了,新改变很快的到达客户端,但之前的 GetProperty 后来才到达。 数据都不同步了。
parent 1b294c14
...@@ -53,14 +53,14 @@ namespace WSCF ...@@ -53,14 +53,14 @@ namespace WSCF
continue;//必须是[PropertyPush] 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))
{ {
node.Parent = rootNode; node.Parent = rootNode;
rootNode.Children.Add(node); rootNode.Children.Add(node);
} }
} }
} }
public static bool ReInitPropertyPush(SubPropertyNode node, object parentObj, PropertyInfo propertyInfo, SubPropertyChangedEventHandler sub_PropertyChanged) public static bool ReInitPropertyPush(SubPropertyNode node, object parentObj, PropertyInfo propertyInfo, SubPropertyChangedEventHandler sub_PropertyChanged)
{ {
var propertyValue = propertyInfo.GetValue(parentObj); var propertyValue = propertyInfo.GetValue(parentObj);
// propertyValue==null 也注册 // propertyValue==null 也注册
...@@ -72,7 +72,7 @@ namespace WSCF ...@@ -72,7 +72,7 @@ namespace WSCF
node.InterfaceType = propertyInfo.PropertyType; node.InterfaceType = propertyInfo.PropertyType;
node.Obj = propertyValue; node.Obj = propertyValue;
node.SubPropertyChanged = sub_PropertyChanged; node.SubPropertyChanged = sub_PropertyChanged;
if (node.Obj != null) if (node.Obj != null)
{ {
//下级推送!!!! //下级推送!!!!
...@@ -91,7 +91,7 @@ namespace WSCF ...@@ -91,7 +91,7 @@ namespace WSCF
var list = node.Obj as System.Collections.IList; var list = node.Obj as System.Collections.IList;
if (list != null && list.Count>0) if (list != null && list.Count > 0)
{ {
InitSubPropertyPushs(list, node, sub_PropertyChanged); InitSubPropertyPushs(list, node, sub_PropertyChanged);
} }
...@@ -164,8 +164,10 @@ namespace WSCF ...@@ -164,8 +164,10 @@ namespace WSCF
} }
public static string GetNodePath(SubPropertyNode node) { public static string GetNodePath(SubPropertyNode node)
if (string.IsNullOrEmpty(node.Name)) { {
if (string.IsNullOrEmpty(node.Name))
{
//已经是最上级 //已经是最上级
return null; return null;
} }
...@@ -173,17 +175,19 @@ namespace WSCF ...@@ -173,17 +175,19 @@ namespace WSCF
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append(node.Name); sb.Append(node.Name);
while (node.Parent != null) { while (node.Parent != null)
{
node = node.Parent; node = node.Parent;
if (string.IsNullOrEmpty(node.Name)) { if (string.IsNullOrEmpty(node.Name))
{
//到了最上级 //到了最上级
break; break;
} }
sb.Insert(0, node.Name+"."); sb.Insert(0, node.Name + ".");
} }
return sb.ToString(); return sb.ToString();
} }
public static SubPropertyNode FindNode(SubPropertyNode rootNode, string path) public static SubPropertyNode FindNode(SubPropertyNode rootNode, string path)
{ {
SubPropertyNode node = null; SubPropertyNode node = null;
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
...@@ -192,13 +196,16 @@ namespace WSCF ...@@ -192,13 +196,16 @@ namespace WSCF
var nodes = rootNode.Children; var nodes = rootNode.Children;
//分解路径 //分解路径
string[] names = path.Split('.'); string[] names = path.Split('.');
foreach (string name in names) { foreach (string name in names)
if (string.IsNullOrEmpty(name)) { {
if (string.IsNullOrEmpty(name))
{
//这个不算 //这个不算
continue; continue;
} }
node = nodes.Find(n => n.Name == name); node = nodes.Find(n => n.Name == name);
if (node == null) { if (node == null)
{
//异常 //异常
return null; return null;
} }
...@@ -206,18 +213,18 @@ namespace WSCF ...@@ -206,18 +213,18 @@ namespace WSCF
} }
return node; return node;
} }
public static void NodeChildrenDispose(List<SubPropertyNode> nodes) public static void NodeChildrenDispose(List<SubPropertyNode> nodes)
{ {
foreach (var node in nodes) foreach (var node in nodes)
{ {
NodeDispose(node); NodeDispose(node);
} }
} }
public static void NodeDispose(SubPropertyNode node) public static void NodeDispose(SubPropertyNode node)
{ {
if (!node.IsArray) if (!node.IsArray)
{ {
if(node.Obj!=null) if (node.Obj != null && node.Obj is INotifyPropertyChanged)
((INotifyPropertyChanged)(node.Obj)).PropertyChanged -= node.PropertyChanged; ((INotifyPropertyChanged)(node.Obj)).PropertyChanged -= node.PropertyChanged;
} }
...@@ -286,10 +293,11 @@ namespace WSCF ...@@ -286,10 +293,11 @@ namespace WSCF
public PropertyChangedEventHandler PropertyChanged; public PropertyChangedEventHandler PropertyChanged;
public SubPropertyChangedEventHandler SubPropertyChanged; public SubPropertyChangedEventHandler SubPropertyChanged;
public SubPropertyNode() { public SubPropertyNode()
{
PropertyChanged = new PropertyChangedEventHandler(_PropertyChanged); PropertyChanged = new PropertyChangedEventHandler(_PropertyChanged);
} }
public void _PropertyChanged(object sender, PropertyChangedEventArgs e) public void _PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
//处理[PropertyPush]重新注册问题 //处理[PropertyPush]重新注册问题
COMMON.PropertyChanged_reInitPropertyPush(this, e); COMMON.PropertyChanged_reInitPropertyPush(this, e);
......
...@@ -13,6 +13,7 @@ namespace WSCF ...@@ -13,6 +13,7 @@ namespace WSCF
/// </summary> /// </summary>
public class PushAttribute : Attribute public class PushAttribute : Attribute
{ {
public const string DefaultTriggerNameHeader = "Trigger_";
public Type EventArgsType; public Type EventArgsType;
public string TriggerName; public string TriggerName;
public PushAttribute(Type eventArgsType) public PushAttribute(Type eventArgsType)
......
This diff is collapsed.
This diff is collapsed.
...@@ -175,7 +175,7 @@ namespace WSCF ...@@ -175,7 +175,7 @@ namespace WSCF
public void Dispose() public virtual void Dispose()
{ {
ws.Close(); ws.Close();
FObjServiceClientManager.Instance.ObjClientDisponse(this); FObjServiceClientManager.Instance.ObjClientDisponse(this);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment