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

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

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