/// <summary> /// 读取系统配置文件里面的内容 /// </summary> /// <returns>返回所有系统配置代码</returns> public MyXTreeItem LoadCLanguageXSystemFile() { ///检测文件路劲是否存在 if (!Directory.Exists(path)) { ///如果不存在 return(null); } try { /// <summary> /// 读取XML的类 /// </summary> XmlDocument XmlAppend = new XmlDocument(); XmlAppend.Load(path + XCSystemFileName); ///查询出根节点 XmlNode root = XmlAppend.SelectSingleNode(RootName); ///树状数据的系统代码块的头结点 MyXTreeItem SystemTreeItem = new MyXTreeItem(); SystemTreeItem.XName = "C语言版系统代码"; ///组装数据 LoadData(SystemTreeItem, root); ///保存关闭文件 XmlAppend.Save(path + XCSystemFileName); return(SystemTreeItem); } catch (Exception ex) { LoggerHelp.WriteLogger(ex.ToString()); return(null); } }
/// <summary> /// 组装读取的数据 /// </summary> /// <param name="RootTreeItem">根节点数据</param> /// <param name="root">根节点XML</param> protected void LoadData(MyXTreeItem RootTreeItem, XmlNode root) { ///检查是否已经存在 foreach (XmlNode node in root.SelectNodes("CodeBox")) { XmlElement codeNode = (XmlElement)node; MyXTreeItem RetreeItem = new MyXTreeItem(); RetreeItem.IsSelected = false; RetreeItem.IsExpanded = false; RetreeItem.XName = codeNode.GetAttribute("Name"); RetreeItem.MyHitText = codeNode.GetAttribute("HitText"); RetreeItem.MyCodeBoxType = CodeBox.CodeBoxTypeMapping(codeNode.GetAttribute("CodeBoxType")); RetreeItem.SystemCodeString = codeNode.GetAttribute("SystemCodeString"); RetreeItem.ReturnValue = codeNode.GetAttribute("ReturnValue"); foreach (XmlNode xNode in codeNode.SelectNodes("XAribute")) { ///MyXTreeItem的子项 XAributeItem xaItem = new XAributeItem(); ///将内容提出填装 XmlElement xaNode = (XmlElement)xNode; xaItem.Parameter_name = xaNode.GetAttribute("Name"); xaItem.MyXAttributeType = XAribute.XAttributeTypeMapping(((XmlElement)xaNode.SelectSingleNode("PointTypeitem")).InnerText); xaItem.MyXAttributeSpec = XAribute.XAttributeSpecMapping(((XmlElement)xaNode.SelectSingleNode("ListTypeitem")).InnerText); xaItem.MyXPositonStyle = XAribute.XPositonStyleMapping(((XmlElement)xaNode.SelectSingleNode("PositionTypeitem")).InnerText); xaItem.MyCanLinkType = XAribute.CanLinkTypeMapping(((XmlElement)xaNode.SelectSingleNode("LinkTypeitem")).InnerText); xaItem.MyHittext = ((XmlElement)xaNode.SelectSingleNode("TipTypeitem")).InnerText; xaItem.MyLastExText = ((XmlElement)xaNode.SelectSingleNode("LastExTexteitem")).InnerText; ///添加到子项中 RetreeItem.MyXaributeChildren.Add(xaItem); } ///添加子节点 RootTreeItem.ChildrenItem.Add(RetreeItem); } }
/// <summary> /// 添加一个入口的属性节点 /// </summary> /// <param name="item">要添加结点</param> public static void AddEnterXAribute(MyXTreeItem item) { XAributeItem xaitem = new XAributeItem("入口", MyXAribute.XAribute.CanLinkType.More, MyXAribute.XAribute.XAttributeSpec.XNone , MyXAribute.XAribute.XAttributeType.XEnter, MyXAribute.XAribute.XPositonStyle.Left, "入口", ""); item.MyXaributeChildren.Add(xaitem); }
/// <summary> /// 添加父类目标 /// </summary> /// <param name="item">结点</param> /// <param name="exname">类名</param> /// /// <param name="nameSpace">类命名空间</param> public static void AddTargetXAribute(MyXTreeItem item, string exname, string nameSpace) { XAributeItem xaitem = new XAributeItem("Target", MyXAribute.XAribute.CanLinkType.One, MyXAribute.XAribute.XAttributeSpec.XNone , MyXAribute.XAribute.XAttributeType.XTarget, MyXAribute.XAribute.XPositonStyle.Left, "该成员的所有者类型为:" + nameSpace + "." + exname, nameSpace + exname); item.MyXaributeChildren.Add(xaitem); }
/// <summary> /// 添加一个出口属性节点 /// </summary> /// <param name="item">要添加的节点</param> public static void AddExcXAribute(MyXTreeItem item) { XAributeItem xaitem = new XAributeItem("出口", MyXAribute.XAribute.CanLinkType.One, MyXAribute.XAribute.XAttributeSpec.XNone , MyXAribute.XAribute.XAttributeType.XExc, MyXAribute.XAribute.XPositonStyle.right, "出口节点", ""); item.MyXaributeChildren.Add(xaitem); }
/// <summary> /// 设置获取属性(Get) /// </summary> /// <param name="item">属性容器</param> /// <param name="info">属性内容</param> /// /// <param name="TargetExname">该属性所属的类</param> public static void SetPropGetValue(MyXTreeItem item, FieldInfo info, string TargetExname) { ///添加一个正常的属性 AddNormailzeXAribute(item, info, 1); ///添加目标所有者 AddTargetXAribute(item, info.DeclaringType.Name, info.DeclaringType.Namespace); }
/// <summary> /// 某个类更新了一个函数属性的通知 /// </summary> /// <param name="page">类</param> /// <param name="fun">函数</param> public void UpdatePicFunctionToPicData(PicTabPage page, PicFunctionTabPage fun) { MyXTreeItem delpicitem = null; MyXTreeItem delfunitem = null; foreach (MyXTreeItem item in DataSource) { if (item.XName == page.Title) { delpicitem = item; foreach (MyXTreeItem funitem in item.ChildrenItem) { if (funitem.XName == fun.Title) { delfunitem = funitem; } } } } if (delpicitem == null || delfunitem == null) { return; } delpicitem.ChildrenItem.Remove(delfunitem); ///重新添加函数信息 AddPicFunctionToPicData(page, fun); }
/// <summary> /// 加载用户配置 /// </summary> /// <returns></returns> public MyXTreeItem LoadXUserFile() { ///检测文件路劲是否存在 if (!Directory.Exists(path)) { ///如果不存在 return(null); } /// <summary> /// 读取XML的类 /// </summary> XmlDocument XmlAppend = new XmlDocument(); XmlAppend.Load(path + XUserFileName); ///查询出根节点 XmlNode root = XmlAppend.SelectSingleNode(RootName); ///树状数据的系统代码块的头结点 MyXTreeItem UserTreeItem = new MyXTreeItem(); UserTreeItem.XName = "用户代码"; ///组装数据 LoadData(UserTreeItem, root); ///保存关闭文件 XmlAppend.Save(path + XSystemFileName); return(UserTreeItem); }
/// <summary> /// 添加一个返回值参数 /// </summary> /// <param name="item">要添加返回值的节点</param> /// <param name="type">返回值的类型</param> public static void AddReturnTypeXAribute(MyXTreeItem item, Type type) { XAributeItem xaitem = new XAributeItem(type.Name, MyXAribute.XAribute.CanLinkType.More, MyXAribute.XAribute.XAttributeSpec.XNone, MyXAribute.XAribute.XAttributeType.XClass, MyXAribute.XAribute.XPositonStyle.right, "类型: " + type.Namespace + "." + type.Name, type.Namespace + "." + type.Name); item.MyXaributeChildren.Add(xaitem); }
/// <summary> /// 添加一个正常的属性 /// </summary> /// <param name="item">要添加属性的结点</param> /// <param name="info">属性具体内容</param> /// /// <param name="type">作为输入还是输出(0 为输入 1 位输出)</param> public static void AddNormailzeXAribute(MyXTreeItem item, PropertyInfo info, int type) { XAributeItem xaitem = new XAributeItem(info.Name, type == 0 ? MyXAribute.XAribute.CanLinkType.One : MyXAribute.XAribute.CanLinkType.More, MyXAribute.XAribute.XAttributeSpec.XNone, MyXAribute.XAribute.XAttributeType.XClass, type == 0 ? MyXAribute.XAribute.XPositonStyle.Left : MyXAribute.XAribute.XPositonStyle.right, "属性类型:" + info.DeclaringType.Namespace + "." + info.DeclaringType.Name, info.DeclaringType.Namespace + "." + info.DeclaringType.Name); item.MyXaributeChildren.Add(xaitem); }
/// <summary> /// 添加一个参数 /// </summary> /// <param name="item">要添加参数的节点</param> /// <param name="info">要添加的参数信息</param> public static void AddParameterXAribute(MyXTreeItem item, ParameterInfo info) { XAributeItem xaitem = new XAributeItem(info.Name, MyXAribute.XAribute.CanLinkType.One, MyXAribute.XAribute.XAttributeSpec.XNone , MyXAribute.XAribute.XAttributeType.XClass, MyXAribute.XAribute.XPositonStyle.Left, "参数的类型" + info.ParameterType.Namespace + "." + info.ParameterType.Name, info.ParameterType.Namespace + "." + info.ParameterType.Name); item.MyXaributeChildren.Add(xaitem); }
/// <summary> /// 设置获取属性(Set) /// </summary> /// <param name="item">属性容器</param> /// <param name="info">属性内容</param> /// /// <param name="TargetExname">该属性所属的类</param> public static void SetPropSetValue(MyXTreeItem item, PropertyInfo info) { ///添加一个出口属性 AddExcXAribute(item); ///添加一个入口函数 AddEnterXAribute(item); ///添加一个正常的属性 AddNormailzeXAribute(item, info, 1); ///添加一个正常的属性 AddNormailzeXAribute(item, info, 0); ///添加目标所有者 AddTargetXAribute(item, info.DeclaringType.Name, info.DeclaringType.Namespace); }
/// <summary> /// 设置方法的代码块 /// </summary> /// <param name="item">要设置属性的节点</param> /// <param name="methodlinfo">方法信息</param> public static void SetMethodInfoXAribute(MyXTreeItem item, MethodInfo methodlinfo) { if (methodlinfo.ReturnType.Name == "void" || methodlinfo.ReturnType.Name == "Void") { AddEnterXAribute(item); AddExcXAribute(item); item.MyCodeBoxType = MyCodeBox.CodeBox.XAType.XFunction; } else { AddReturnTypeXAribute(item, methodlinfo.ReturnType); item.MyCodeBoxType = MyCodeBox.CodeBox.XAType.GetValue; } ParameterInfo[] parameterinfos = methodlinfo.GetParameters(); foreach (ParameterInfo parinfo in parameterinfos) { AddParameterXAribute(item, parinfo); } ///添加目标所有者 AddTargetXAribute(item, methodlinfo.DeclaringType.Name, methodlinfo.DeclaringType.Namespace); }
/// <summary> /// 修改类图里面的可调用方法 /// </summary> public void ModityPicTabPageFunction() { ///添加CSharp基本类型 AddBaseClassType(); DataSource.Clear(); ///初始化系统读取的数据 XCodeDataOption dataoption = new XCodeDataOption(); ///声明系统初始数据 MyXTreeItem sysdataitem; if (Language == "C#") { sysdataitem = dataoption.LoadXSystemFile(); DataSource.Add(sysdataitem); ///初始化Dll文件里面的数据 foreach (DllFile dll in MyDllFiles) { MyXTreeItem dllitem = DecomposeClass.GetDllResources(dll, ProjectUseClassType); DataSource.Add(dllitem); } } else if (Language == "C") { sysdataitem = dataoption.LoadCLanguageXSystemFile(); DataSource.Add(sysdataitem); } foreach (PicTabPage page in MyListPicPage.Values) { page.PopContentCode.MyData = DataSource; foreach (XAribute bute in page.ListXAributes) { ///添加类型 bute.ProjectUseClassType = ProjectUseClassType; } } }
/// <summary> /// 把dll文件转换为可以利用的资源 /// </summary> /// <param name="dll">dll文件的路径</param> /// /// <param name="ProjectClassType">项目可选类型</param> /// <returns>返回可以利用的资源</returns> public static MyXTreeItem GetDllResources(DllFile dll, Dictionary <string, string> ProjectClassType = null) { Assembly assembly = Assembly.LoadFrom(dll.Path); MyXTreeItem ReData = new MyXTreeItem(); ReData.XName = dll.Name; ReData.TypeImagePath = ""; ///获取所有的类型 Type [] alltypes = assembly.GetTypes(); ///循环所有类型 foreach (Type item in alltypes) { ///如果传进来一个类型变量引用 if (ProjectClassType != null) { ///添加可选类型 ProjectClassType.Add(item.FullName, item.Name); } MyXTreeItem classdata = new MyXTreeItem(); classdata.XName = item.Namespace + "." + item.Name; classdata.TypeImagePath = ""; #region 添加Proper内容 ///获取所有访问器属性 PropertyInfo[] pros = item.GetProperties(); ///循环所有访问器 MyXTreeItem prosdata = new MyXTreeItem(); prosdata.XName = "Properties"; prosdata.TypeImagePath = ""; foreach (PropertyInfo info in pros) { if (info.GetGetMethod(false) != null) {///具体的访问器属性(GET) MyXTreeItem proindataGet = new MyXTreeItem(); proindataGet.XName = "Get" + info.Name; proindataGet.MyCodeBoxType = MyCodeBox.CodeBox.XAType.get; proindataGet.TypeImagePath = ""; proindataGet.MyHitText = ""; ///添加一个该属性的Get代码块(get方法) SetPropGetValue(proindataGet, info); prosdata.ChildrenItem.Add(proindataGet); } if (info.GetSetMethod(false) != null) {///具体的访问器属性(SET) MyXTreeItem proindataSet = new MyXTreeItem(); proindataSet.XName = "Set" + info.Name; proindataSet.MyCodeBoxType = MyCodeBox.CodeBox.XAType.set; proindataSet.TypeImagePath = ""; proindataSet.MyHitText = ""; ///添加一个该属性的Get代码块(get方法) SetPropSetValue(proindataSet, info); prosdata.ChildrenItem.Add(proindataSet); } } classdata.ChildrenItem.Add(prosdata); #endregion #region 添加fieldinfos内容 ///获取该类型中所有的字段 FieldInfo[] fieldinfos = item.GetFields(); MyXTreeItem fieldinfosdata = new MyXTreeItem(); fieldinfosdata.XName = "Fieldinfos"; fieldinfosdata.TypeImagePath = ""; fieldinfosdata.MyHitText = ""; foreach (FieldInfo info in fieldinfos) { ///添加Get类型 MyXTreeItem fieldinfosdataGet = new MyXTreeItem(); fieldinfosdataGet.XName = "Get" + info.Name; fieldinfosdataGet.MyCodeBoxType = MyCodeBox.CodeBox.XAType.get; fieldinfosdataGet.TypeImagePath = ""; fieldinfosdataGet.MyHitText = ""; ///添加一个该属性的Get代码块(get方法) SetPropGetValue(fieldinfosdataGet, info, classdata.XName); fieldinfosdata.ChildrenItem.Add(fieldinfosdataGet); ///添加Set类型 MyXTreeItem fieldinfosdataSet = new MyXTreeItem(); fieldinfosdataSet.XName = "Set" + info.Name; fieldinfosdataSet.MyCodeBoxType = MyCodeBox.CodeBox.XAType.set; fieldinfosdataSet.TypeImagePath = ""; fieldinfosdataSet.MyHitText = ""; ///添加一个该属性的Get代码块(get方法) SetPropSetValue(fieldinfosdataSet, info, classdata.XName); fieldinfosdata.ChildrenItem.Add(fieldinfosdataSet); } classdata.ChildrenItem.Add(fieldinfosdata); #endregion #region 添加方法 MethodInfo [] methodlinfos = item.GetMethods(); MyXTreeItem methodlinfodata = new MyXTreeItem(); methodlinfodata.XName = "公共方法集合"; methodlinfodata.TypeImagePath = ""; methodlinfodata.MyHitText = "该类型的所有方法"; foreach (MethodInfo info in methodlinfos) { if (!((info.Name.Substring(0, 4) == "set_" || info.Name.Substring(0, 4) == "get_") && info.IsSpecialName)) { ///添加一个方法数据 MyXTreeItem methodlnfoitem = new MyXTreeItem(); methodlnfoitem.XName = info.Name; //methodlinfodata.MyCodeBoxType = MyCodeBox.CodeBox.XAType.XFunction; methodlnfoitem.TypeImagePath = ""; methodlnfoitem.MyHitText = ""; SetMethodInfoXAribute(methodlnfoitem, info); ///添加一个方法 methodlinfodata.ChildrenItem.Add(methodlnfoitem); } } classdata.ChildrenItem.Add(methodlinfodata); #endregion ReData.ChildrenItem.Add(classdata); } return(ReData); }
/// <summary> /// 子控件事件回调处理 /// </summary> /// <param name="sender"></param> /// <param name="ms"></param> protected override object ChileEventCallBack(Object sender, MouseState ms, XObjectData data = null) { base.ChileEventCallBack(sender, ms); Type sendtype = sender.GetType(); switch (ms) { case MouseState.XClick: if (SelectIDList.Count <= 1 && sendtype.Name == "CodeBox") { SetChildControlState(((XObject)sender).Id); ///设置选中状态 } break; case MouseState.XDown: break; case MouseState.XToChildControl: AddChildControlMsg(sender); break; case MouseState.XToStopControl: DelChildControlMsg(); break; case MouseState.XToDrawBezier: isDrawBezier = true; FirstXa = (XAribute)sender; ///将发出信号的子控件 赋值 ///如果ALT键被按下则删除该节点上的曲线 if (_isPressingAlt) { FirstXa.ClearBezierLine(); } if (FirstXa != null) { MyBezierLine = new BezierLine(CreateBezierID(), FirstXa.BorderColor, FirstXa.GetWorldPosition(), FirstXa.SelectPositionStyle); AddBezierLine(MyBezierLine); } break; case MouseState.XMouseEnter: if (isDrawBezier) { if (sendtype.Name == "XAribute") { SecondXa = (XAribute)sender; ///将发出信号的子控件 赋值 if (SecondXa != FirstXa) { isOverAribute = true; } } } break; case MouseState.XMouseLeave: isOverAribute = false; break; case MouseState.XMoveControl: if (sendtype.Name == "CodeBox") { MoveSelectControl((Point)data.data, ((CodeBox)sender)); } break; case MouseState.XDelBezier: if (sendtype.Name == "XAribute" && data != null) { DelBezierLine((BezierLine)data.data); } break; case MouseState.XCreateCodeBox: #region 用户选择创建代码块 ///根据用户选择创建代码块 if (sendtype.Name == "XMTreeView") { MyXTreeItem mitem = (MyXTreeItem)data.data; CodeBox box = CreateXCodeBox(mitem.XName, _createBoxPosition, mitem.MyCodeBoxType); box.Hint = mitem.MyHitText; box.SystemCodeString = mitem.SystemCodeString; box.ReturnValueName = mitem.ReturnValue; for (int i = 0; i < mitem.MyXaributeChildren.Count; i++) { XAributeItem aItem = mitem.MyXaributeChildren[i]; box.AddAttribute(aItem.MyXAttributeType, aItem.MyXAttributeSpec, aItem.MyXPositonStyle, aItem.Parameter_name, aItem.MyCanLinkType, aItem.MyHittext, aItem.MyLastExText); } ///创建完成隐藏 HiddenPopup(); } #endregion #region 属性方式选择框的回调事件 ///如果是属性方式选择框的回调事件 else if (sendtype.Name == "XAributeDropSelect") { XAribute bute = data.data as XAribute; string type = data.state as string; ///如果数据没有丢失 if (bute != null && type != null) { if (type == "set") { CodeBox box = CreateXCodeBox("设置:" + bute.Title + " 的值", _createBoxPosition, CodeBox.XAType.set); box.Hint = "设置当前类中的这个属性的值,类型:" + bute.ExName; box.AddAttribute(XAribute.XAttributeType.XEnter, XAribute.XAttributeSpec.XNone, XAribute.XPositonStyle.Left, "入口" , XAribute.CanLinkType.More, "执行入口", ""); box.AddAttribute(XAribute.XAttributeType.XExc, XAribute.XAttributeSpec.XNone, XAribute.XPositonStyle.right, "出口", XAribute.CanLinkType.One, "执行出口", ""); box.AddAttribute(bute.SelectType, bute.SelectSpc, XAribute.XPositonStyle.Left, bute.Title, XAribute.CanLinkType.One , bute.Hint, bute.ExName); XAribute rightBute = box.AddAttribute(bute.SelectType, bute.SelectSpc, XAribute.XPositonStyle.right, bute.Title, XAribute.CanLinkType.More , bute.Hint, bute.ExName); ///同样的属性不用绘制2次名称 rightBute.IsDirText = false; } else if (type == "get") { CodeBox box = CreateXCodeBox("获取:" + bute.Title + " 的值", _createBoxPosition, CodeBox.XAType.get); box.Hint = "获取当前类中的这个属性的值,类型:" + bute.ExName; XAribute rightbute = box.AddAttribute(bute.SelectType, bute.SelectSpc, XAribute.XPositonStyle.right, bute.Title, XAribute.CanLinkType.More , bute.Hint, bute.ExName); } } ///隐藏选择框 HiddenXAributeSelectPopup(); } #endregion break; } return(null); }
/// <summary> /// 某个类添加了一个函数更新通知 /// </summary> /// <param name="page">添加了函数的类</param> /// <param name="fun">被添加的函数</param> public void AddPicFunctionToPicData(PicTabPage page, PicFunctionTabPage fun) { ///新建项 MyXTreeItem item = new MyXTreeItem(); item.ChildrenItem = null; item.MyCodeBoxType = CodeBox.XAType.XFunction; item.MyHitText = fun.Hint; item.TypeImagePath = ""; item.XName = fun.Title; List <XAributeItem> xaitem = new List <XAributeItem>(); ///如果是C#则要加上函数的所属 if (Language == LanguageType.CSharp.ToString()) { XAributeItem buteitem = new XAributeItem(); buteitem.MyXPositonStyle = XAribute.XPositonStyle.Left; buteitem.Parameter_name = "Target"; buteitem.MyCanLinkType = XAribute.CanLinkType.One; buteitem.MyXAttributeSpec = XAribute.XAttributeSpec.XNone; buteitem.MyXAttributeType = XAribute.XAttributeType.XTarget; buteitem.MyHittext = "函数所属的类"; buteitem.MyLastExText = page.Title; xaitem.Add(buteitem); } //else if (Language == LanguageType.C.ToString()) //{ //} ///循环参数 foreach (XAribute bute in fun.FunctionEnterBox.RightAribute.Children) { if (bute.SelectType != XAribute.XAttributeType.XEnter) { ///填装信息 XAributeItem buteitem = new XAributeItem(bute); //buteitem.Parameter_name = bute.Title; //buteitem.MyCanLinkType = bute.CanLinkNum; //buteitem.MyXAttributeSpec = bute.SelectSpc; //buteitem.MyXAttributeType = bute.SelectType; buteitem.MyXPositonStyle = XAribute.XPositonStyle.Left; //buteitem.MyHittext = bute.Hint; //buteitem.MyLastExText = bute.ExName; ///加入列表 xaitem.Add(buteitem); } } ///组成函数的右半边属性 foreach (XAribute bute in fun.FunctionExcBox.LeftAribute.Children) { if (bute.SelectType != XAribute.XAttributeType.XExc) { XAributeItem buteitem = new XAributeItem(bute); buteitem.MyXPositonStyle = XAribute.XPositonStyle.right; xaitem.Add(buteitem); } } item.MyXaributeChildren = xaitem; bool isExect = false; ///是否已经存在类 MyXTreeItem UserTreeItem = null; foreach (MyXTreeItem myitem in DataSource) { if (myitem.XName == page.Title) { isExect = true; myitem.ChildrenItem.Add(item); return; } } if (!isExect && UserTreeItem == null) { UserTreeItem = new MyXTreeItem(); UserTreeItem.XName = page.Title; UserTreeItem.ChildrenItem.Add(item); ///添加信息和修改信息 DataSource.Add(UserTreeItem); } //ModityPicTabPageFunction(); }