/// <summary> /// 构造事件处理 /// </summary> /// <param name="config"></param> public static void OnCreate(NotificationObject config) { if (NotificationObject.IsLoadingMode) { return; } var type = config.GetType(); var scope = EventScope.CreateScope(config, "_create_"); if (scope == null) { return; } using (scope) { foreach (var trigger in Triggers) { if (trigger.TargetType == type || type.IsSubclassOf(trigger.TargetType)) { trigger.OnCreate(config); } } } OnLoad(config); }
/// <summary> /// 构造事件处理 /// </summary> /// <param name="config"></param> public static void OnCreate(NotificationObject config) { if (config == null) { return; } var type = config.GetType(); var scope = EventScope.CreateScope(config, "Global", "OnCreate"); if (scope == null) { return; } using (scope) { foreach (var trigger in Triggers) { if (trigger.TargetType == null || trigger.TargetType == type || type.IsSubclassOf(trigger.TargetType)) { trigger.OnCreate(config); } } } if (WorkContext.IsNoChangedNotify) { return; } OnLoad(config); }
/// <summary> /// 构造事件处理 /// </summary> /// <param name="config"></param> public static void OnCtor(NotificationObject config) { if (WorkContext.IsNoChangedNotify || config == null) { return; } Dispatcher.Invoke(() => OnCreate(config)); }
CodeGeneratorScope(NotificationObject config) { _innerScope = WorkModelScope.CreateScope(WorkModel.Coder); if (config == null) { return; } GlobalTrigger.OnCodeGeneratorBegin(config); }
/// <summary> /// 找对应节点 /// </summary> /// <returns></returns> public TreeItem Find(NotificationObject obj) { if (obj == null || Items.Count == 0) { return(null); } if (Source == obj) { return(this); } return(Items.Select(child => child.Find(obj)).FirstOrDefault(item => item != null)); }
/// <summary> /// 发出属性修改前事件 /// </summary> /// <param name="config"></param> /// <param name="property">属性</param> /// <param name="oldValue">旧值</param> /// <param name="newValue">新值</param> public void BeforePropertyChanged(NotificationObject config, string property, object oldValue, object newValue) { Target = config; var scope = EventScope.CreateScope(config, this.GetTypeName(), property); if (scope == null) { return; } using (scope) { BeforePropertyChanged(property, oldValue, newValue); } }
/// <summary> /// 属性事件处理 /// </summary> /// <param name="config"></param> /// <param name="property"></param> internal void OnPropertyChanged(NotificationObject config, string property) { Target = config; var scope = EventScope.CreateScope(config, this.GetTypeName(), property); if (scope == null) { return; } using (scope) { OnPropertyChanged(property); } }
/// <summary> /// 载入事件处理 /// </summary> /// <param name="config"></param> public void OnCreate(NotificationObject config) { Target = config; var scope = EventScope.CreateScope(config, this.GetTypeName(), "_create_"); if (scope == null) { return; } using (scope) { OnCreate(); } }
/// <summary> /// 删除事件处理 /// </summary> /// <param name="config"></param> /// <param name="parent"></param> public void OnRemoved(NotificationObject parent, NotificationObject config) { Target = parent; var scope = EventScope.CreateScope(config, this.GetTypeName(), "_del_"); if (scope == null) { return; } using (scope) { OnRemoved(config); } }
/// <summary> /// 构造 /// </summary> /// <param name="config">配置</param> /// <param name="property">属性</param> /// <returns>为空表示已重入,应该放弃处理,不为空则使用这个范围</returns> public static EventScope CreateScope(NotificationObject config, string property) { List <string> events; if (Events.TryGetValue(config, out events)) { if (events.Contains(property)) { return(null); } } else { Events.Add(config, new List <string>()); } return(new EventScope(config, property)); }
/// <summary> /// 删除事件处理 /// </summary> /// <param name="config"></param> /// <param name="parent"></param> public static void OnRemoved(NotificationObject parent, NotificationObject config) { var type = config.GetType(); var scope = EventScope.CreateScope(config, "_remove_"); if (scope == null) { return; } using (scope) { foreach (var trigger in Triggers) { if (trigger.TargetType == type || type.IsSubclassOf(trigger.TargetType)) { trigger.OnRemoved(config, config); } } } }
/// <summary> /// 开始代码生成 /// </summary> public static void OnCodeGeneratorBegin(NotificationObject config) { if (config == null) { return; } var scope = EventScope.CreateScope(My, "Global", "OnCodeGeneratorBegin"); if (scope == null) { return; } using (scope) { foreach (var trigger in Triggers) { trigger.OnCodeGeneratorBegin(config); } } }
/// <summary> /// 发出属性修改前事件 /// </summary> /// <param name="config"></param> /// <param name="property">属性</param> /// <param name="oldValue">旧值</param> /// <param name="newValue">新值</param> public static void BeforePropertyChanged(NotificationObject config, string property, object oldValue, object newValue) { if (NotificationObject.IsLoadingMode) { return; } var type = config.GetType(); var scope = EventScope.CreateScope(config, property); if (scope == null) { return; } using (scope) { foreach (var trigger in Triggers) { if (trigger.TargetType == type || type.IsSubclassOf(trigger.TargetType)) { trigger.BeforePropertyChanged(config, property, oldValue, newValue); } } } }
/// <summary> /// 删除事件处理 /// </summary> /// <param name="config"></param> /// <param name="parent"></param> public void OnRemoved(NotificationObject parent, NotificationObject config) { Target = parent; OnRemoved(config); }
/// <summary> /// 载入事件处理 /// </summary> /// <param name="config"></param> public void OnLoad(NotificationObject config) { Target = config; OnLoad(); }
/// <summary> /// 属性事件处理 /// </summary> /// <param name="config"></param> /// <param name="property"></param> internal void OnPropertyChanged(NotificationObject config, string property) { Target = config; OnPropertyChanged(property); }
/// <summary> /// 构造 /// </summary> /// <param name="config"></param> /// <param name="property"></param> private EventScope(NotificationObject config, string property) { _config = config; _property = property; Events[config].Add(property); }
/// <summary> /// 找对应节点 /// </summary> /// <returns></returns> public TreeItem Find(NotificationObject obj) { return(Items.Select(child => child.Find(obj)).FirstOrDefault(item => item != null)); }
/// <summary> /// 生成范围 /// </summary> /// <returns></returns> public static IDisposable CreateScope(NotificationObject config) { return(new CodeGeneratorScope(config)); }
/// <summary> /// 发出属性修改前事件 /// </summary> /// <param name="config"></param> /// <param name="property">属性</param> /// <param name="oldValue">旧值</param> /// <param name="newValue">新值</param> public void BeforePropertyChanged(NotificationObject config, string property, object oldValue, object newValue) { Target = config; BeforePropertyChanged(property, oldValue, newValue); }
/// <summary> /// 开始代码生成 /// </summary> public virtual void OnCodeGeneratorBegin(NotificationObject config) { }
/// <summary> /// 删除事件处理 /// </summary> /// <param name="config"></param> protected virtual void OnRemoved(NotificationObject config) { }
/// <summary> /// 加入事件处理 /// </summary> /// <param name="config"></param> protected virtual void OnAdded(NotificationObject config) { }