using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
///
/// 住宅对象的逻辑
///
public class HdlResidenceLogic
{
#region ■ 变量声明___________________________
///
/// 住宅对象的逻辑
///
private static HdlResidenceLogic m_Current = null;
///
/// 住宅对象的逻辑
///
public static HdlResidenceLogic Current
{
get
{
if (m_Current == null)
{
m_Current = new HdlResidenceLogic();
}
return m_Current;
}
}
#endregion
#region ■ 获取本地住宅列表___________________
///
/// 获取本地住宅列表
///
///
public List GetLocalResidenceList()
{
//如果是虚拟住宅,则从根目录中获取
if (Common.Config.Instance.Home.IsVirtually == true)
{
//从文件夹中获取全部的住宅对象
return this.GetAllLocalResidenceListByDirectory();
}
var listHome = new List();
foreach (var housePath in Common.Config.Instance.HomeFilePathList)
{
var home = Common.House.GetHouseByFilePath(housePath);
if (home == null)
{
continue;
}
listHome.Add(home);
}
return listHome;
}
///
/// 从文件夹中获取全部的住宅对象
///
///
public List GetAllLocalResidenceListByDirectory()
{
var strPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid);
var listHome = new List();
//获取全部的文件夹
var listDirectory = new List();
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(textValue);
listHome.Add(myHouse);
}
}
}
return listHome;
}
#endregion
#region ■ 一般方法___________________________
///
/// 获取楼层名称
///
/// 楼层ID
///
public string GetFloorNameById(string i_FloorId)
{
return Common.Config.Instance.Home.GetFloorNameById(i_FloorId);
}
#endregion
}
}