|
@@ -13,16 +13,52 @@ using System.Linq;
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
|
+using SAGA.DotNetUtils.Utilities;
|
|
|
|
|
|
namespace SAGA.DotNetUtils.Extend
|
|
namespace SAGA.DotNetUtils.Extend
|
|
{
|
|
{
|
|
public static class ConfigurationUtil
|
|
public static class ConfigurationUtil
|
|
{
|
|
{
|
|
|
|
+ #region 默认路径持久化保存,应对向revit这种,启动之后设置,然后又跳转到其他程序的情况
|
|
|
|
+ private static string GetDefuatPathLocation()
|
|
|
|
+ {
|
|
|
|
+ return CommonUtil.GetPath(typeof(ConfigurationUtil), ".txt");
|
|
|
|
+ }
|
|
|
|
+ private static bool SavePersistenceDefuatPath(string defualtPath)
|
|
|
|
+ {
|
|
|
|
+ var path = GetDefuatPathLocation();
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(path))
|
|
|
|
+ {
|
|
|
|
+ var directory = Directory.GetParent(path);
|
|
|
|
+ if (!directory.Exists)
|
|
|
|
+ {
|
|
|
|
+ directory.Create();
|
|
|
|
+ }
|
|
|
|
+ File.WriteAllText(path, defualtPath);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ private static string GetPersistencetDefuatPath()
|
|
|
|
+ {
|
|
|
|
+ var path = GetDefuatPathLocation();
|
|
|
|
+ if (!CommonUtil.InvalidFilePath(path))
|
|
|
|
+ {
|
|
|
|
+ return File.ReadAllText(path); ;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
private static string m_DefaultPath;
|
|
private static string m_DefaultPath;
|
|
private static string GetDefaultPath()
|
|
private static string GetDefaultPath()
|
|
{
|
|
{
|
|
var defualtPath = m_DefaultPath;
|
|
var defualtPath = m_DefaultPath;
|
|
- if (string.IsNullOrWhiteSpace(defualtPath) || !File.Exists(defualtPath))
|
|
|
|
|
|
+ if (CommonUtil.InvalidFilePath(defualtPath))
|
|
|
|
+ {
|
|
|
|
+ defualtPath = GetPersistencetDefuatPath();
|
|
|
|
+ }
|
|
|
|
+ if (CommonUtil.InvalidFilePath(defualtPath))
|
|
{
|
|
{
|
|
defualtPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "BaseSettings.config");
|
|
defualtPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "BaseSettings.config");
|
|
}
|
|
}
|
|
@@ -83,6 +119,7 @@ namespace SAGA.DotNetUtils.Extend
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
m_DefaultPath = path;
|
|
m_DefaultPath = path;
|
|
|
|
+ SavePersistenceDefuatPath(path);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
public static string GetSettingValue(this Configuration config,string appsettingKey)
|
|
public static string GetSettingValue(this Configuration config,string appsettingKey)
|