/* ==============================================================================
* 功能描述:加载Menu下的配置文件,转化为TszTabData
* 创 建 者:Garrett
* 创建日期:2018/9/17 17:56:32
* ==============================================================================*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using SAGA.DotNetUtils;
using SAGA.DotNetUtils.Others;
using SAGA.RevitUtils;
namespace SAGA.RevitMenu.Configuration
{
///
/// MenuData
///
class XmlMenuData
{
///
/// 根据选择的项目 确定加载的菜单 建筑 结构 水暖电
///
///
///
///
public static TszTabData[] GetConfigTabs(string strRevitVersion, out bool blnRevit)
{
blnRevit = false;
List listFea = new List();
FileInfo[] files = new DirectoryInfo(Path.Combine(AppBaseInfo.AppRunPath, "Menu")).GetFiles("*.xml");
if (files.Length == 0)
{
MessageShowBase.Infomation(@"菜单加载异常,请查看安装目录DLL\OperateLogs下的操作日志。");
return null;
}
Dictionary dictionary = new Dictionary();
#region 读取所有的文件,对所有的模块进行排序
foreach (FileInfo info3 in files)
{
try
{
FileInfo info4 = info3;
XmlDocument document = new XmlDocument();
document.Load(info4.FullName);
XmlElement xelem = document.DocumentElement;
if (xelem == null) continue;
int key = xelem.SelectSingleNode("App").SelectSingleNode("AppIndex").InnerText.Trim().ToInt();
if (!dictionary.ContainsKey(key))
{
dictionary.Add(key, info4.FullName);
}
}
catch (Exception exception)
{
MessageShow.Show(exception, false, "");
}
}
#endregion
List list2 = new List();
List pushButtonList = dictionary.Keys.ToList();
pushButtonList.Sort();
foreach (int num2 in pushButtonList)
{
TszTabData[] collection = GetConfigTabs(strRevitVersion, listFea, dictionary[num2]);
if ((collection != null) && (collection.Length > 0))
{
list2.AddRange(collection);
}
}
return list2.ToArray();
}
///
/// 从菜单配置文件中读取数据,转化为为TszTabData
/// Tab-Panels-Buttons
///
///
///
///
///
public static TszTabData[] GetConfigTabs(string strRevitVersion, List listFea, string fileName)
{
try
{
string str = Path.Combine(AppBaseInfo.AppRunPath, "RibbonImage");
XmlDocument document = new XmlDocument();
document.Load(fileName);
XmlElement documentElement = document.DocumentElement;
List list = new List();
#region 获取所有的命令
foreach (XmlNode node in documentElement.SelectNodes("Panel"))
{
string strPanelName = node.Attributes["PanelName"].Value.Trim();
bool boolGroupFlag = bool.Parse(node.Attributes["GroupFlag"].Value.Trim());
string str3 = node.Attributes["GroupImage"].Value.Trim();
string strBtnsTyle = node.Attributes["ButtonStyles"].Value.Trim();
string str5 = "Normal";
string strRevitVer = node.Attributes["RevitVer"].Value.Trim();
RevitVer revitVer = GetRevitVer(strRevitVer);
ButtonStyles buttonStyle = GetButtonStyle(strBtnsTyle);
StackStyles stackStyle = GetStackStyle(str5);
if (str3.Length <= 0)
{
str3 = Path.Combine(str, "LargeImage.png");
}
else
{
str3 = Path.Combine(str, str3);
}
TszPanelData penelData = new TszPanelData(strPanelName, boolGroupFlag, str3, buttonStyle);
#region 命令是否可见
XmlAttribute attribute = node.Attributes["Visible"];
if (attribute != null)
{
penelData.Visible = attribute.Value.Trim().ToBool();
}
#endregion
XmlNodeList pushButtonList = node.SelectNodes("Button");
List list4 = new List();
foreach (XmlNode node2 in pushButtonList)
{
ButtonStyles styles3 = buttonStyle;
StackStyles styles4 = stackStyle;
RevitVer ver2 = revitVer;
XmlAttribute attribute3 = node2.Attributes["ButtonStyles"];
if (attribute3 != null)
{
styles3 = GetButtonStyle(attribute3.Value.Trim());
}
XmlAttribute attribute4 = node2.Attributes["StackStyles"];
if (attribute4 != null)
{
styles4 = GetStackStyle(attribute4.Value.Trim());
}
XmlAttribute attribute5 = node2.Attributes["RevitVer"];
if (attribute5 != null)
{
ver2 = GetRevitVer(attribute5.Value.Trim());
}
#region 调试的命令不添加
var debugAttri = node2.Attributes["IsDebug"];
if (debugAttri != null)
{
if (debugAttri.Value.ToBool())
continue;
}
#endregion
string menuTab = node2.SelectSingleNode("MenuTab").InnerText.Trim();
string[] strArray = node2.SelectSingleNode("Modules").InnerText.Trim().Split(new char[] { ',' });
TszButtonData data2 = null;
if (node2.ChildNodes.Count > 6)
{
string strButtonName = node2.SelectSingleNode("ButtonName").InnerText.Trim();
string strButtonText = node2.SelectSingleNode("ButtonText").InnerText.Trim();
string str14 = node2.SelectSingleNode("ImageName").InnerText.Trim();
str14 = Path.Combine(str, str14);
string path = node2.SelectSingleNode("DllName").InnerText.Trim();
//..\OutputDll\SpacePlugin.dll
string strAssemblyName = Path.Combine(AppBaseInfo.AppRunPath, Path.GetFileName(path));
string addStr = @"..\";
if (path.Contains(addStr))
{
path = path.Replace(addStr, "");
strAssemblyName = Path.Combine(AppBaseInfo.AppRunPath, path);
}
string strClassName = node2.SelectSingleNode("ClassName").InnerText.Trim();
string str18 = node2.SelectSingleNode("ToolTip").InnerText.Trim();
string str19 = node2.SelectSingleNode("LongDescription").InnerText.Trim();
data2 = new TszButtonData(penelData, menuTab, strButtonName, strButtonText, str14,
strAssemblyName, strClassName)
{
ToolTip = str18,
LongDescription = str19
};
}
else if (node2.ChildNodes.Count > 3)
{
string str20 = node2.SelectSingleNode("ButtonText").InnerText.Trim();
string str21 = node2.SelectSingleNode("ImageName").InnerText.Trim();
string str23 = node2.SelectSingleNode("ToolTip").InnerText.Trim();
str21 = Path.Combine(str, str21);
data2 = new TszButtonData(menuTab)
{
TszPanelData = penelData,
ToolTip = str23,
ButtonText = str20,
ImageName = str21
};
}
else
{
data2 = new TszButtonData(menuTab);
}
XmlAttribute btnVisibleAttri = node2.Attributes["Visible"];
if (btnVisibleAttri != null)
{
data2.Visible = btnVisibleAttri.Value.Trim().ToBool();
}
data2.Styles = styles3;
data2.StackStyle = styles4;
data2.UseVersion = ver2;
list4.Add(data2);
}
if (list4.Any())
{
penelData.Buttons.AddRange(list4);
list.Add(penelData);
}
}
#endregion
List list6 = new List();
#region 对命令进行重新分组
XmlNodeList list5 = documentElement.SelectNodes("Tab");
foreach (XmlNode node3 in list5)
{
string strTabName = node3.Attributes["TabName"].Value.Trim();
string str25 = node3.SelectSingleNode("MenuTab").InnerText.Trim();
string[] strArray2 = node3.SelectSingleNode("Modules").InnerText.Trim().Split(new char[] { ',' });
List list7 = new List();
foreach (TszPanelData data5 in list)
{
TszButtonData[] collection = data5.FilterButtons(str25);
if ((collection != null) && (collection.Length > 0))
{
TszPanelData data6 =
new TszPanelData(data5.PanelName, data5.GroupFlag, data5.GroupImage, data5.Styles)
{
Visible = data5.Visible
};
data6.Buttons.AddRange(collection);
list7.Add(data6);
}
}
TszTabData item = new TszTabData(strTabName)
{
TabText = str25,
Modules = strArray2
};
if (list7.Any())
{
item.Panels.AddRange(list7);
list6.Add(item);
}
}
#endregion
return list6.ToArray();
}
catch (Exception exception)
{
MessageShow.Show(exception, false, "");
return null;
}
}
///
/// 根据配置文件设置 获取Botton样式
///
///
///
public static ButtonStyles GetButtonStyle(string strBtnsTyle)
{
if (strBtnsTyle == null)
return ButtonStyles.Pushdown;
string str = strBtnsTyle.ToLower();
if (str == "separator")
{
return ButtonStyles.Separator;
}
if (str == "large")
{
return ButtonStyles.Large;
}
if (str == "pushdown")
{
return ButtonStyles.Pushdown;
}
if (str == "stacked")
{
return ButtonStyles.Stacked;
}
if (str != "stackedbox")
{
return ButtonStyles.StackedBox;
}
return ButtonStyles.Pushdown;
}
///
/// 获取有哪些版本的命令可用 R14,R15,R16,R17,R18
///
///
///
public static RevitVer GetRevitVer(string strRevitVer)
{
RevitVer unkonw = RevitVer.Unkonw;
if (strRevitVer.ToUpper().IndexOf("R14", StringComparison.Ordinal) > -1)
{
unkonw |= RevitVer.R14;
}
if (strRevitVer.ToUpper().IndexOf("R15", StringComparison.Ordinal) > -1)
{
unkonw |= RevitVer.R15;
}
if (strRevitVer.ToUpper().IndexOf("R16", StringComparison.Ordinal) > -1)
{
unkonw |= RevitVer.R16;
}
if (strRevitVer.ToUpper().IndexOf("R17", StringComparison.Ordinal) > -1)
{
unkonw |= RevitVer.R17;
}
return unkonw;
}
///
///
///
///
///
public static StackStyles GetStackStyle(string strBtnsTyle)
{
StackStyles normal = StackStyles.Normal;
if (strBtnsTyle == null) return normal;
string str = strBtnsTyle.ToLower();
if (str == "pulldown")
{
normal = StackStyles.Pulldown;
}
if (str == "normal")
{
normal = StackStyles.Normal;
}
return normal;
}
}
}