CSLA Config cleanup
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using DescriptiveEnum;
|
||||
|
||||
namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
@@ -12,21 +8,14 @@ namespace VEPROMS.CSLA.Library
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
public class RODbConfig : ConfigDynamicTypeDescriptor, INotifyPropertyChanged
|
||||
{
|
||||
#region DynamicTypeDescriptor
|
||||
internal override bool IsReadOnly
|
||||
{
|
||||
get { return _RODb == null; }
|
||||
}
|
||||
#endregion
|
||||
#region XML
|
||||
private XMLProperties _Xp;
|
||||
private XMLProperties Xp
|
||||
{
|
||||
get { return _Xp; }
|
||||
}
|
||||
#region DynamicTypeDescriptor
|
||||
internal override bool IsReadOnly => _RODb == null;
|
||||
#endregion
|
||||
#region XML
|
||||
private readonly XMLProperties _Xp;
|
||||
#endregion
|
||||
#region Constructors
|
||||
private RODb _RODb;
|
||||
private readonly RODb _RODb;
|
||||
public RODbConfig(RODb roDb)
|
||||
{
|
||||
_RODb = roDb;
|
||||
@@ -34,7 +23,7 @@ namespace VEPROMS.CSLA.Library
|
||||
if (xml == string.Empty) xml = "<Config/>";
|
||||
_Xp = new XMLProperties(xml);
|
||||
}
|
||||
private RODbInfo _RODbInfo;
|
||||
private readonly RODbInfo _RODbInfo;
|
||||
public RODbConfig(RODbInfo roDbInfo)
|
||||
{
|
||||
_RODbInfo = roDbInfo;
|
||||
@@ -52,13 +41,10 @@ namespace VEPROMS.CSLA.Library
|
||||
string xml = "<Config/>";
|
||||
_Xp = new XMLProperties(xml);
|
||||
}
|
||||
internal string GetValue(string group, string item)
|
||||
{
|
||||
return _Xp[group, item];
|
||||
}
|
||||
#endregion
|
||||
#region Local Properties
|
||||
[Category("General")]
|
||||
internal string GetValue(string group, string item) => _Xp[group, item];
|
||||
#endregion
|
||||
#region Local Properties
|
||||
[Category("General")]
|
||||
[DisplayName("ROName")]
|
||||
[Description("ROName")]
|
||||
public string ROName
|
||||
@@ -71,22 +57,20 @@ namespace VEPROMS.CSLA.Library
|
||||
[Description("FolderPath")]
|
||||
public string FolderPath
|
||||
{
|
||||
get { return (_RODb != null ? _RODb.FolderPath : _RODbInfo != null?_RODbInfo.FolderPath:null); }
|
||||
get { return (_RODb != null ? _RODb.FolderPath : _RODbInfo?.FolderPath); }
|
||||
set { if (_RODb != null) _RODb.FolderPath = value; }
|
||||
}
|
||||
public RODb MyRODb
|
||||
{ get { return _RODb; } }
|
||||
#endregion
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
public RODb MyRODb => _RODb;
|
||||
#endregion
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
string s = _Xp.ToString();
|
||||
if (s == "<Config/>" || s == "<Config></Config>") return string.Empty;
|
||||
return s;
|
||||
}
|
||||
#endregion
|
||||
#region RODefaults
|
||||
[Category("Referenced Objects")]
|
||||
return s == "<Config/>" || s == "<Config></Config>" ? string.Empty : s;
|
||||
}
|
||||
#endregion
|
||||
#region RODefaults
|
||||
[Category("Referenced Objects")]
|
||||
[DisplayName("Graphic File Extension")]
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
[Description("Default File Extension")]
|
||||
@@ -98,38 +82,41 @@ namespace VEPROMS.CSLA.Library
|
||||
// look in roapp.ini in the FolderPath directory;
|
||||
// look in top folder's config
|
||||
// set to Volian default, i.e. "TIF".
|
||||
string s = GetRoAppIniValue("ROAPP", "Extention");
|
||||
string s = GetRoAppIniValue("Extention");
|
||||
if (s == null || s == string.Empty)
|
||||
s = TopFolderConfigValue("Graphics", "defaultext");
|
||||
s = TopFolderConfigValue();
|
||||
if (s == null || s == string.Empty)
|
||||
return s = "TIF";
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
private string GetRoAppIniValue(string p, string p_2)
|
||||
{
|
||||
if (FolderPath == null) return null;
|
||||
string inipath = FolderPath + @"\roapp.ini";
|
||||
if (!File.Exists(inipath)) return null;
|
||||
StreamReader myReader = new StreamReader(inipath);
|
||||
string sLine;
|
||||
int indx = -1;
|
||||
while ((sLine = myReader.ReadLine()) != null)
|
||||
{
|
||||
if (sLine.Length > 0 && sLine.Substring(0, 1) != ";")
|
||||
{
|
||||
if ((indx = sLine.ToLower().IndexOf(p_2.ToLower())) >= 0)
|
||||
{
|
||||
indx = sLine.IndexOf("=", indx + 9);
|
||||
return sLine.Substring(indx + 1, sLine.Length - indx - 1).Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
myReader.Close();
|
||||
return null;
|
||||
}
|
||||
private string TopFolderConfigValue(string p, string p_2)
|
||||
private string GetRoAppIniValue(string p_2)
|
||||
{
|
||||
if (FolderPath == null) return null;
|
||||
string inipath = FolderPath + @"\roapp.ini";
|
||||
if (!File.Exists(inipath)) return null;
|
||||
using (StreamReader myReader = new StreamReader(inipath))
|
||||
{
|
||||
string sLine;
|
||||
int indx = -1;
|
||||
while ((sLine = myReader.ReadLine()) != null)
|
||||
{
|
||||
if (sLine.Length > 0 && sLine.Substring(0, 1) != ";")
|
||||
{
|
||||
if ((indx = sLine.ToLower().IndexOf(p_2.ToLower())) >= 0)
|
||||
{
|
||||
indx = sLine.IndexOf("=", indx + 9);
|
||||
return sLine.Substring(indx + 1, sLine.Length - indx - 1).Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
myReader.Close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private string TopFolderConfigValue()
|
||||
{
|
||||
FolderInfo fi = FolderInfo.GetTop();
|
||||
return fi.FolderConfig.Graphics_defaultext;
|
||||
@@ -145,9 +132,9 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public string GetDefaultGraphicExtensionLocation()
|
||||
{
|
||||
string s = GetRoAppIniValue("ROAPP", "Extention");
|
||||
string s = GetRoAppIniValue("Extention");
|
||||
if (s != null && s != string.Empty) return "Default Extension found in roapp.ini";
|
||||
s = TopFolderConfigValue("Graphics", "defaultext");
|
||||
s = TopFolderConfigValue();
|
||||
if (s != null && s != string.Empty) return "Default Extension defined in veproms properties";
|
||||
return "Used program default";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user