Bläddra i källkod

mxg:building和floor,信息点DataSource,接口更新

mengxiangge 6 år sedan
förälder
incheckning
272ff546b9

+ 31 - 0
MBI/SAGA.DotNetUtils/Extend/ObjectExtend.cs

@@ -5,6 +5,8 @@
  * ==============================================================================*/
 
 using System;
+using System.ComponentModel;
+using System.Reflection;
 
 namespace SAGA.DotNetUtils.Extend
 {
@@ -44,6 +46,35 @@ namespace SAGA.DotNetUtils.Extend
         {
             return !obj.IsNullOrEmpty();
         }
+        /// <summary>
+        /// 通过反射对有DescriptionAttribute标记的属性进行赋值
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="mode"></param>
+        /// <param name="values"></param>
+        /// <param name="func"></param>
+        /// <returns></returns>
+        public static void ReflectSetPropertyValue<T>(this T mode, object values, Func<object, string, string> func)
+        {
+            foreach (PropertyInfo property in mode.GetType().GetProperties())
+            {
+                var description = property.GetCustomAttribute<DescriptionAttribute>()?.Description;
+                string value = "";
+                try
+                {
+                    value = func.Invoke(values,description);
+                }
+                catch (Exception e)
+                {
+
+                }
+                if (value.IsNotNullEmpty())
+                {
+                    object obj = Convert.ChangeType(value, property.PropertyType);
+                    property.SetValue(mode, obj);
+                }
+            }
+        }
 
     }
 }

+ 6 - 6
MBI/SAGA.DotNetUtils/WPF/UserControl/ComboboxTreeView/DalCMBTreeView.cs

@@ -85,8 +85,8 @@ namespace SAGA.DotNetUtils.WPF.UserControl.ComboboxTreeView
                 foreach (JObject jObject in jArray)
                 {
                     BaseCodeName codeName = new BaseCodeName();
-                    codeName.Name = (string)jObject["name"];
-                    codeName.Code = (string)jObject["code"];
+                    codeName.Name = (string)jObject["Name"];
+                    codeName.Code = (string)jObject["Code"];
                     list.Add(new CMBTreeNodeItem<ICMBTreeNodeItem>(codeName, null));
                 }
             }
@@ -113,14 +113,14 @@ namespace SAGA.DotNetUtils.WPF.UserControl.ComboboxTreeView
         private static CMBTreeNodeItem<ICMBTreeNodeItem> GetSubItem(JObject jObject)
         {
             BaseCodeName codeName = new BaseCodeName();
-            codeName.Name = (string)jObject["name"];
-            codeName.Code = (string)jObject["code"];
+            codeName.Name = (string)jObject["Name"];
+            codeName.Code = (string)jObject["Code"];
             var subItems = new List<CMBTreeNodeItem<ICMBTreeNodeItem>>();
-            if (jObject.GetValueEx("content").IsNotNullEmpty())
+            if (jObject.GetValueEx("Content").IsNotNullEmpty())
             {
                 try
                 {
-                    foreach (JObject subJObject in (JArray)jObject["content"])
+                    foreach (JObject subJObject in (JArray)jObject["Content"])
                     {
                         var subItem = GetSubItem(subJObject);
                         subItems.Add(subItem);

+ 4 - 3
MBI/SAGA.DotNetUtils/WPF/UserControl/SelectPath_Start.xaml.cs

@@ -9,6 +9,7 @@
 using System;
 using System.Windows;
 using System.Windows.Forms;
+using System.Windows.Media;
 using System.Windows.Media.Imaging;
 
 namespace SAGA.DotNetUtils.WPF.UserControl
@@ -29,10 +30,10 @@ namespace SAGA.DotNetUtils.WPF.UserControl
             set { SetValue(TextProperty, value); }
         }
 
-        public static readonly DependencyProperty BtnImageProperty = DependencyProperty.Register("BtnImage", typeof(BitmapImage), typeof(SelectPath_Start));
-        public BitmapImage BtnImage
+        public static readonly DependencyProperty BtnImageProperty = DependencyProperty.Register("BtnImage", typeof(ImageSource), typeof(SelectPath_Start));
+        public ImageSource BtnImage
         {
-            get { return (BitmapImage)GetValue(BtnImageProperty); }
+            get { return (ImageSource)GetValue(BtnImageProperty); }
             set { SetValue(BtnImageProperty, value); }
         }
 

+ 2 - 2
MBI/SAGA.MBI/App.xaml.cs

@@ -41,7 +41,7 @@ namespace SAGA.MBI
             string fullPath = Path.Combine(AppBaseInfo.AppRunPath, "Updater", "Update.exe");
             //有参数时直接启动
             if (args != null && args.Length > 0 || !File.Exists(fullPath))
-            {
+            { 
                 WinLogin win = new WinLogin();
                 Application myAp = new Application();
                 myAp.ShutdownMode = ShutdownMode.OnExplicitShutdown;
@@ -50,7 +50,7 @@ namespace SAGA.MBI
             else
             {
                 try
-                {
+                { 
                     //无参数可看做双击启动,启动前检测版本
                     //arguments参数用空格分开,"Program Files"使用时被拆分成两个参数,使用时请注意
                     //设置启动动作,确保以管理员身份运行

+ 4 - 1
MBI/SAGA.MBI/CmbData/BuildingCmbVm.cs

@@ -24,7 +24,10 @@ namespace SAGA.MBI.CmbData
         public Action<string> NotifyAction { get; set; }
         public ObservableCollection<CMBTreeNodeItem<ICMBTreeNodeItem>> TreeFuncTypeInfos
         {
-            get { return new ObservableCollection<CMBTreeNodeItem<ICMBTreeNodeItem>>(CmbDataSourceConvert.BuildFuncTypeDic()); }
+            get {
+                return new ObservableCollection<CMBTreeNodeItem<ICMBTreeNodeItem>>(
+                CmbDataSourceConvert.BuildingInfoDS("BuildFuncType"));
+            }
         }
 
         private CMBTreeNodeItem<ICMBTreeNodeItem> m_TreeFuncTypeInfoCur;

+ 8 - 64
MBI/SAGA.MBI/JsonConvert/CmbDataSourceConvert.cs

@@ -226,26 +226,7 @@ namespace SAGA.MBI.JsonConvert
             return DalCMBTreeView.ConvertToDataSource(json); ;
         }
 
-        /// <summary>
-        /// 获取数据字典的某一信息点的定义
-        /// </summary>
-        /// <param name="json"></param>
-        /// <returns></returns>
-        private static MInfoCode GetMInfoCode(string json)
-        {
-            MInfoCode mInfo = new MInfoCode();
-            JObject jObject = JObject.Parse(json);
-            foreach (PropertyInfo property in mInfo.GetType().GetProperties())
-            {
-                var description = property.GetCustomAttribute<DescriptionAttribute>();
-                if (description?.Description != null)
-                {
-                    property.SetValue(mInfo, jObject[description.Description].ToString());
-                }
-            }
-            return mInfo;
 
-        }
         /// <summary>
         /// 建筑 信息点的数据源
         /// </summary>
@@ -254,30 +235,12 @@ namespace SAGA.MBI.JsonConvert
         [CacheAspect]
         public static List<CMBTreeNodeItem<ICMBTreeNodeItem>> BuildingInfoDS(string infoPointCode)
         {
-            MInfoCode infoCode = BuildingDic().FirstOrDefault(t => t.InfoPointCode == infoPointCode);
-            return DalCMBTreeView.ConvertToDataSource(infoCode?.DataSource); ;
+            string code = "building";
+            var pdtb = PEPCodeConvert.GetPropertyDefineTb(code);
+            var infoDefine = pdtb.PropertyDefineItems.FirstOrDefault(t => t.CodeName == infoPointCode);
+            return DalCMBTreeView.ConvertToDataSource(infoDefine?.EnumSource); 
         }
-        /// <summary>
-        /// 建筑体的数据字典
-        /// </summary>
-        /// <returns></returns>
-        [CacheAspect]
-        public static List<MInfoCode> BuildingDic()
-        {
-            List<MInfoCode> list = new List<MInfoCode>();
-            string json = CmbDataSourceRequest.BuildingDic();
-            if (!json.IsSuccessRequest()) return list;
-
-            JObject jObject = JObject.Parse(json);
-            foreach (JObject contentJObject in (JArray)jObject["Content"])
-            {
-                MInfoCode mInfo = GetMInfoCode(contentJObject.ToString());
 
-                list.Add(mInfo);
-            }
-
-            return list;
-        }
         /// <summary>
         /// 楼层 信息点的数据源
         /// </summary>
@@ -286,31 +249,12 @@ namespace SAGA.MBI.JsonConvert
         [CacheAspect]
         public static List<CMBTreeNodeItem<ICMBTreeNodeItem>> FloorInfoDS(string infoPointCode)
         {
-            List<MInfoCode> list = FloorDic();
-            MInfoCode infoCode = list.FirstOrDefault(t => t.InfoPointCode == infoPointCode);
-            return DalCMBTreeView.ConvertToDataSource(infoCode?.DataSource);
+            string code = "floor";
+            var pdtb = PEPCodeConvert.GetPropertyDefineTb(code);
+            var infoDefine = pdtb.PropertyDefineItems.FirstOrDefault(t => t.CodeName == infoPointCode);
+            return DalCMBTreeView.ConvertToDataSource(infoDefine?.EnumSource);
         }
-        /// <summary>
-        /// 楼层的数据字典
-        /// </summary>
-        /// <returns></returns>
-        [CacheAspect]
-        public static List<MInfoCode> FloorDic()
-        {
-            List<MInfoCode> list = new List<MInfoCode>();
-            string json = CmbDataSourceRequest.FloorDic();
-            if (!json.IsSuccessRequest()) return list;
-
-            JObject jObject = JObject.Parse(json);
-            foreach (JObject contentJObject in (JArray)jObject["Content"])
-            {
-                MInfoCode mInfo = GetMInfoCode(contentJObject.ToString());
 
-                list.Add(mInfo);
-            }
-
-            return list;
-        }
 
         /// <summary>
         /// 设备种族类型编码

+ 12 - 14
MBI/SAGA.MBI/JsonConvert/PEPCodeConvert.cs

@@ -5,6 +5,7 @@
  * ==============================================================================*/
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -17,6 +18,7 @@ using SAGA.MBI.Model;
 using SAGA.MBI.RequestData;
 using SAGA.MBI.Tools;
 using SAGA.RevitUtils;
+using System.Reflection;
 
 namespace SAGA.MBI.JsonConvert
 {
@@ -37,7 +39,7 @@ namespace SAGA.MBI.JsonConvert
             if (tb == null)
             {
                 //暂时只处理独有的信息点
-                tb =  DataPlatFormSysOrEqInfos(code);
+                tb = QueryInfosDefineByCode(code);
                 tbs.Add(tb);
             }
             return tb;
@@ -46,7 +48,7 @@ namespace SAGA.MBI.JsonConvert
         /// 数据平台系统和设备的完整信息点
         /// </summary>
         /// <returns></returns>
-        public static PropertyDefineTb DataPlatFormSysOrEqInfos(string code)
+        private static PropertyDefineTb QueryInfosDefineByCode(string code)
         {
             PropertyDefineTb tb = new PropertyDefineTb(code);
             try
@@ -56,20 +58,15 @@ namespace SAGA.MBI.JsonConvert
                 if (json.IsSuccessRequest())
                 {
                     JObject jObject = JObject.Parse(json);
-                    foreach (JObject subj in jObject["Content"])
+
+                    foreach (JObject subJObject in jObject["Content"])
                     {
                         PropertyDefineItem item = new PropertyDefineItem();
-                        item.Category = (string)subj["FirstTag"];
-                        item.SubCategory = (string)subj["SecondTag"];
-                        item.Name = (string)subj["InfoPointName"];
-                        item.CodeName = (string)subj["InfoPointCode"];
-                        item.Unit = (string)subj["Unit"];
-                        item.Type = (string)subj["DataType"];
-                        item.InputType = (string)subj["InputMode"]; 
-                        item.EnumSource = subj.GetValueEx("DataSource");
-                        item.Remark = (string)subj["Note"];
-                        item.Classification = (string)subj["Classification"];
-                        item.IsShow = (bool)subj["Visible"];
+                        item.ReflectSetPropertyValue(subJObject, (values, key) =>
+                        {
+                            JObject tempJObject = values as JObject;
+                            return tempJObject.GetValueEx(key);
+                        });
                         item.CollectionCmptCode = DalInfoCode.GetInputType(item.InputType);
                         tb.PropertyDefineItems.Add(item);
                     }
@@ -82,5 +79,6 @@ namespace SAGA.MBI.JsonConvert
 
             return tb;
         }
+        
     }
 }

+ 0 - 61
MBI/SAGA.MBI/Model/MDataDictionary.cs

@@ -1,61 +0,0 @@
-/* ==============================================================================
- * 功能描述:MDictionary  
- * 创 建 者:Garrett
- * 创建日期:2018/3/18 12:33:00
- * ==============================================================================*/
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using SAGA.MBI.JsonConvert;
-
-namespace SAGA.MBI.Model
-{
-    /// <summary>
-    /// MDictionary
-    /// </summary>
-    public class MDataDictionary
-    {
-        public static Dictionary<DicType, List<MInfoCode>> m_DataDic;
-        public static List<MInfoCode> GetDataDic(DicType key)
-        {
-            List<MInfoCode> list=new List<MInfoCode>();
-            if (m_DataDic.ContainsKey(key))
-            {
-                list = m_DataDic[key];
-            }
-            else
-            {
-                switch (key)
-                {
-                    case DicType.Project:
-                        break;
-                    case DicType.Building:
-                        list = CmbDataSourceConvert.BuildingDic();
-                        m_DataDic.Add(key, list);
-                        break;
-                    case DicType.Floor:
-                        list = CmbDataSourceConvert.FloorDic();
-                        m_DataDic.Add(key, list);
-                        break;
-                    case DicType.Space:
-                        break;
-                    case DicType.SysOrEquip:
-                        break;
-                }
-            }
-            return list;
-        }
-        
-    }
-
-    public enum DicType
-    {
-        Project=0,
-        Building,
-        Floor,
-        Space,
-        SysOrEquip
-    }
-}

+ 5 - 25
MBI/SAGA.MBI/Model/MFileBase.cs

@@ -17,6 +17,7 @@ using System.Windows.Controls;
 using System.Xml.Serialization;
 using Newtonsoft.Json.Linq;
 using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Extend;
 using SAGA.DotNetUtils.Serializer;
 using SAGA.DotNetUtils.WPF;
 using SAGA.MBI.Common;
@@ -376,32 +377,11 @@ namespace SAGA.MBI.Model
         /// <param name="json"></param>
         public virtual void SetJsonProperty(string json)
         {
-            JObject jObject = JObject.Parse(json);
-            foreach (PropertyInfo info in this.GetType().GetProperties())
+            this.ReflectSetPropertyValue(json, (values, key) =>
             {
-                var attributes = info.GetCustomAttributes(typeof(DescriptionAttribute));
-                var att = attributes.FirstOrDefault();
-
-                if (att is DescriptionAttribute descriptionAttribute)
-                {
-                    var description = descriptionAttribute.Description;
-                    string value = "";
-                    try
-                    {
-                        value = (string)jObject[description];
-                    }
-                    catch (Exception e)
-                    {
-
-                    }
-                    if (value.IsNotNullEmpty())
-                    {
-                        object obj = Convert.ChangeType(value, info.PropertyType);
-                        info.SetValue(this, obj);
-                    }
-
-                }
-            }
+                JObject jObject = JObject.Parse(values.ToString());
+                return jObject.GetValueEx(key);
+            });
         }
         /// <summary>
         /// 将本地数据整理是json格式,待上传

+ 0 - 48
MBI/SAGA.MBI/Model/MInfoCode.cs

@@ -1,48 +0,0 @@
-/* ==============================================================================
- * 功能描述:MInfoCode  
- * 创 建 者:Garrett
- * 创建日期:2018/3/18 11:42:59
- * ==============================================================================*/
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SAGA.MBI.Model
-{
-    /// <summary>
-    /// MInfoCode
-    /// </summary>
-    public class MInfoCode
-    {
-        [Description("note")]
-        public string Note { get;  set; }
-
-        [Description("secondTag")]
-        public string SecondTag { get; set; }
-
-        [Description("unit")]
-        public string Unit { get; set; }
-
-        [Description("firstTag")]
-        public string  FirstTag { get; set; }
-
-        [Description("inputMode")]
-        public string InputMode { get; set; }
-        [Description("infoPointName")]
-        public string InfoPointName { get; set; }
-        [Description("dataType")]
-        public string DataType { get; set; }
-        [Description("infoPointCode")]
-        public string InfoPointCode { get; set; }
-        [Description("func-id")]
-        public string Func_Id { get; set; }
-        [Description("dataSource")]
-
-        public string DataSource { get; set; }
-        [Description("classification")]
-        public string  Classification { get; set; }      
-    }
-}

+ 11 - 27
MBI/SAGA.MBI/Model/PropertyDefineTb.cs

@@ -47,9 +47,6 @@ namespace SAGA.MBI.Model
         public PropertyDefineItem()
         { }
         #region Model
-        private int _id;
-        private string _owner;
-        private string _architecture;
         private string _category;
         private string _subcategory;
         private string _name;
@@ -62,30 +59,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 
         /// </summary>
-        public int ID
-        {
-            set { _id = value; }
-            get { return _id; }
-        }
-        /// <summary>
-        /// 
-        /// </summary>
-        public string Owner
-        {
-            set { _owner = value; }
-            get { return _owner; }
-        }
-        /// <summary>
-        /// 
-        /// </summary>
-        public string Architecture
-        {
-            set { _architecture = value; }
-            get { return _architecture; }
-        }
-        /// <summary>
-        /// 
-        /// </summary>
+        [Description("FirstTag")]
         public string Category
         {
             set { _category = value; }
@@ -94,6 +68,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 
         /// </summary>
+        [Description("SecondTag")]
         public string SubCategory
         {
             set { _subcategory = value; }
@@ -102,6 +77,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 
         /// </summary>
+        [Description("InfoPointName")]
         public string Name
         {
             set { _name = value; }
@@ -110,6 +86,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 
         /// </summary>
+        [Description("InfoPointCode")]
         public string CodeName
         {
             set { _codename = value; }
@@ -118,6 +95,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 
         /// </summary>
+        [Description("Unit")]
         public string Unit
         {
             set { _unit = value; }
@@ -126,6 +104,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 
         /// </summary>
+        [Description("DataType")]
         public string Type
         {
             set { _type = value; }
@@ -134,6 +113,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 
         /// </summary>
+        [Description("InputMode")]
         public string InputType
         {
             set { _inputtype = value; }
@@ -142,6 +122,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 
         /// </summary>
+        [Description("DataSource")]
         public string EnumSource
         {
             set { _enumsource = value; }
@@ -150,6 +131,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 
         /// </summary>
+        [Description("Note")]
 
         public string Remark
         {
@@ -170,6 +152,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 是否显示
         /// </summary>
+        [Description("Visible")]
         public bool IsShow
         {
             get { return m_IsShow; }
@@ -179,6 +162,7 @@ namespace SAGA.MBI.Model
         /// <summary>
         /// 信息点所属类别
         /// </summary>
+        [Description("Classification")]
         public string Classification
         {
             get { return classification; }

+ 0 - 26
MBI/SAGA.MBI/RequestData/CmbDataSourceRequest.cs

@@ -58,32 +58,6 @@ namespace SAGA.MBI.RequestData
             return request;
         }
 
-
-        /// <summary>
-        /// 建筑体的数据字典
-        /// </summary>
-        /// <returns></returns>
-        public static string BuildingDic()
-        {
-            string url = MBIConst.DataPlatformLocalHost + "data-platform-3/infocode/query/building";
-
-            RestClient client = new RestClient(url, HttpVerb.GET);
-            string request = client.PostRequest();
-            return request;
-        }
-        /// <summary>
-        /// 楼层的数据字典
-        /// </summary>
-        /// <returns></returns>
-        public static string FloorDic()
-        {
-            string url = MBIConst.DataPlatformLocalHost + "data-platform-3/infocode/query/floor";
-
-            RestClient client = new RestClient(url, HttpVerb.GET);
-            string request = client.PostRequest();
-            return request;
-        }
-
         /// <summary>
         /// 所有种族类型编码
         /// </summary>

+ 0 - 2
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -610,11 +610,9 @@
     <Compile Include="WinView\Login\WinTreeLeftMouseTip.xaml.cs">
       <DependentUpon>WinTreeLeftMouseTip.xaml</DependentUpon>
     </Compile>
-    <Compile Include="Model\MDataDictionary.cs" />
     <Compile Include="Model\MFileBase.cs" />
     <Compile Include="Model\MFloor.cs" />
     <Compile Include="Model\MBuilding.cs" />
-    <Compile Include="Model\MInfoCode.cs" />
     <Compile Include="Model\MProject.cs" />
     <Compile Include="WinView\Login\WinLogin.xaml.cs">
       <DependentUpon>WinLogin.xaml</DependentUpon>

BIN
MBI/Updater/Update.exe