xm
2020-04-29 07466c19110693e3e439a7d7c8ad0bc21d9b3287
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 住宅对象的逻辑
    /// </summary>
    public class HdlResidenceLogic
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 住宅对象的逻辑
        /// </summary>
        private static HdlResidenceLogic m_Current = null;
        /// <summary>
        /// 住宅对象的逻辑
        /// </summary>
        public static HdlResidenceLogic Current
        {
            get
            {
                if (m_Current == null)
                {
                    m_Current = new HdlResidenceLogic();
                }
                return m_Current;
            }
        }
 
        #endregion
 
        #region ■ 获取本地住宅列表___________________
 
        /// <summary>
        /// 获取本地住宅列表
        /// </summary>
        /// <returns></returns>
        public List<Common.House> GetLocalResidenceList()
        {
            //如果是虚拟住宅,则从根目录中获取
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                //从文件夹中获取全部的住宅对象
                return this.GetAllLocalResidenceListByDirectory();
            }
 
            var listHome = new List<Common.House>();
            foreach (var housePath in Common.Config.Instance.HomeFilePathList)
            {
                var home = Common.House.GetHouseByFilePath(housePath);
                if (home == null)
                {
                    continue;
                }
                listHome.Add(home);
            }
            return listHome;
        }
 
        /// <summary>
        /// 从文件夹中获取全部的住宅对象
        /// </summary>
        /// <returns></returns>
        public List<Common.House> GetAllLocalResidenceListByDirectory()
        {
            var strPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid);
            var listHome = new List<Common.House>();
            //获取全部的文件夹
            var listDirectory = new List<string>();
            var arryDirs = System.IO.Directory.GetDirectories(strPath);
            foreach (var file in arryDirs)
            {
                string[] arry = file.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                listDirectory.Add(arry[arry.Length - 1]);
            }
            foreach (var myDir in listDirectory)
            {
                //获取各个文件夹里面的住宅文件
                string nowPath = System.IO.Path.Combine(strPath, myDir);
                var arryHouse = System.IO.Directory.GetFiles(nowPath, "House_*");
                if (arryHouse.Length > 0)
                {
                    //读取文件内容
                    var textValue = UserCenterLogic.LoadFileContent(System.IO.Path.Combine(nowPath, arryHouse[0]));
                    if (textValue != null)
                    {
                        var myHouse = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.House>(textValue);
                        listHome.Add(myHouse);
                    }
                }
            }
            return listHome;
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 获取楼层名称
        /// </summary>
        /// <param name="i_FloorId">楼层ID</param>
        /// <returns></returns>
        public string GetFloorNameById(string i_FloorId)
        {
            return Common.Config.Instance.Home.GetFloorNameById(i_FloorId);
        }
 
        #endregion
    }
}