init
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class Zone //: Common.BindableBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Image { get; set; }
|
||||
|
||||
public TemplateZone ISODllZone { get; }
|
||||
|
||||
public Zone(TemplateZone z, TestObjectTemplate template)
|
||||
{
|
||||
ISODllZone = z;
|
||||
|
||||
if (null == z || null == z.Description)
|
||||
{
|
||||
Description = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
Description = z.Description;
|
||||
}
|
||||
Image = z.Picture;
|
||||
var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZonePictures");
|
||||
|
||||
//if (string.IsNullOrEmpty(Image)) { Image = "H3_2_11.png"; }
|
||||
if (!string.IsNullOrEmpty(Image))
|
||||
{
|
||||
path = System.IO.Path.Combine(path, Image);
|
||||
if (!System.IO.File.Exists(path))
|
||||
{
|
||||
PictureIndex = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
var src = new System.Windows.Media.Imaging.BitmapImage();
|
||||
src.BeginInit();
|
||||
src.UriSource = new Uri(path, UriKind.Absolute);
|
||||
try
|
||||
{
|
||||
src.EndInit();
|
||||
PictureSource = src;
|
||||
_pictureIndex = AllPictures.ToList().IndexOf(Image);
|
||||
}
|
||||
catch
|
||||
{
|
||||
PictureIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Name = z.ZoneName;
|
||||
_regions = new List<Region>();
|
||||
foreach (var r in z.TemplateRegions)
|
||||
{
|
||||
var region = new Region(template, r);
|
||||
_regions.Add(region);
|
||||
}
|
||||
}
|
||||
|
||||
public class FileInfoComparer : IComparer<System.IO.FileInfo>
|
||||
{
|
||||
int IComparer<System.IO.FileInfo>.Compare(System.IO.FileInfo left, System.IO.FileInfo right)
|
||||
{
|
||||
if (left == right)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (left == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (right == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return left.FullName.CompareTo(right.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
private List<System.IO.FileInfo> _fileNames = null;
|
||||
|
||||
public string[] AllPictures
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _fileNames)
|
||||
{
|
||||
var files = new List<string>();
|
||||
files.AddRange(System.IO.Directory.EnumerateFiles(
|
||||
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZonePictures")));
|
||||
_fileNames = new List<System.IO.FileInfo>();
|
||||
foreach (var file in files)
|
||||
{
|
||||
_fileNames.Add(new System.IO.FileInfo(file));
|
||||
}
|
||||
_fileNames.Sort(new FileInfoComparer());
|
||||
}
|
||||
var l = new List<string>();
|
||||
foreach (var fi in _fileNames)
|
||||
{
|
||||
l.Add(fi.Name);
|
||||
}
|
||||
return l.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private int _pictureIndex = -1;
|
||||
|
||||
public int PictureIndex
|
||||
{
|
||||
get => _pictureIndex;
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
PictureSource = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var src = new System.Windows.Media.Imaging.BitmapImage();
|
||||
src.BeginInit();
|
||||
src.UriSource = new Uri(_fileNames[value].FullName, UriKind.Absolute);
|
||||
src.EndInit();
|
||||
PictureSource = src;
|
||||
}
|
||||
_pictureIndex = value;
|
||||
//if (null != _template) { _template.MarkChanged(Tags.PictureIndex.ToString()); }
|
||||
}
|
||||
}
|
||||
|
||||
public string GetPictureName()
|
||||
{
|
||||
return _pictureIndex < 0 ? "" : _fileNames[_pictureIndex].Name;
|
||||
}
|
||||
|
||||
public System.Windows.Media.ImageSource PictureSource { get; set; } = null;
|
||||
|
||||
private List<Region> _regions = new List<Region>();
|
||||
|
||||
public Region[] Regions
|
||||
{
|
||||
get => _regions.ToArray();
|
||||
set => _regions = new List<Region>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user