139 lines
3.0 KiB
C#
139 lines
3.0 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
|
|
namespace VEPROMS.CSLA.Library
|
|
{
|
|
[Serializable]
|
|
[TypeConverter(typeof(ExpandableObjectConverter))]
|
|
public class ImageConfig : ConfigDynamicTypeDescriptor, INotifyPropertyChanged
|
|
{
|
|
#region DynamicTypeDescriptor
|
|
internal override bool IsReadOnly => _ImageInfo == null;
|
|
#endregion
|
|
#region XML
|
|
private readonly XMLProperties _Xp;
|
|
#endregion
|
|
#region Constructors
|
|
private readonly ImageInfo _ImageInfo;
|
|
public ImageConfig(ImageInfo imageInfo)
|
|
{
|
|
if (imageInfo == null)
|
|
{
|
|
string xmlx = "<Config/>";
|
|
_Xp = new XMLProperties(xmlx);
|
|
return;
|
|
}
|
|
_ImageInfo = imageInfo;
|
|
string xml = imageInfo.Config;
|
|
if (xml == string.Empty) xml = "<Config/>";
|
|
_Xp = new XMLProperties(xml);
|
|
}
|
|
public ImageConfig()
|
|
{
|
|
string xml = "<Config/>";
|
|
_Xp = new XMLProperties(xml);
|
|
}
|
|
internal string GetValue(string group, string item) => _Xp[group, item];
|
|
#endregion
|
|
#region Local Properties
|
|
[Category("Image")]
|
|
[Browsable(false)]
|
|
[DisplayName("DataSize")]
|
|
[RefreshProperties(RefreshProperties.All)]
|
|
[Description("DataSize")]
|
|
public int Image_DataSize // original size of image data, if it is compressed
|
|
{
|
|
get
|
|
{
|
|
string s = _Xp["Image", "DataSize"];
|
|
if (s == string.Empty) return 0;
|
|
int tst;
|
|
try
|
|
{
|
|
tst = int.Parse(s);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return 0;
|
|
}
|
|
return tst;
|
|
}
|
|
set
|
|
{
|
|
string s = _Xp["Image", "DataSize"];
|
|
if (value.ToString() == s) return;
|
|
_Xp["Image", "DataSize"] = value.ToString();
|
|
OnPropertyChanged("Image_DataSize");
|
|
}
|
|
}
|
|
[Category("Image")]
|
|
[Browsable(false)]
|
|
[DisplayName("Width")]
|
|
[RefreshProperties(RefreshProperties.All)]
|
|
[Description("Width")]
|
|
public int Image_Width // resized image's resized width
|
|
{
|
|
get
|
|
{
|
|
string s = _Xp["Image", "Width"];
|
|
if (s == string.Empty) return 0;
|
|
int tst;
|
|
try
|
|
{
|
|
tst = int.Parse(s);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return 0;
|
|
}
|
|
return tst;
|
|
}
|
|
set
|
|
{
|
|
string s = _Xp["Image", "Width"];
|
|
if (value.ToString() == s) return;
|
|
_Xp["Image", "Width"] = value.ToString();
|
|
OnPropertyChanged("Image_Width");
|
|
}
|
|
}
|
|
[Category("Image")]
|
|
[Browsable(false)]
|
|
[DisplayName("Height")]
|
|
[RefreshProperties(RefreshProperties.All)]
|
|
[Description("Height")]
|
|
public int Image_Height // resized image's resized height
|
|
{
|
|
get
|
|
{
|
|
string s = _Xp["Image", "Height"];
|
|
if (s == string.Empty) return 0;
|
|
int tst;
|
|
try
|
|
{
|
|
tst = int.Parse(s);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return 0;
|
|
}
|
|
return tst;
|
|
}
|
|
set
|
|
{
|
|
string s = _Xp["Image", "Height"];
|
|
if (value.ToString() == s) return;
|
|
_Xp["Image", "Height"] = value.ToString();
|
|
OnPropertyChanged("Image_Height");
|
|
}
|
|
}
|
|
#endregion
|
|
#region ToString
|
|
public override string ToString()
|
|
{
|
|
string s = _Xp.ToString();
|
|
return s == "<Config/>" || s == "<Config></Config>" ? string.Empty : s;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|