年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

773 lines
27 KiB

using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Plugin.LayerProperty.Interface;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace KGIS.Plugin.LayerProperty.Model
{
internal class DoStyleGallery : IDoStyleGallery, IDoStyleGalleryStorage
{
private const string FIELD_ID = "ID";
private const string FIELD_CATEGORY = "CATEGORY";
private const string FIELD_NAME = "NAME";
private const string FIELD_OBJECT = "OBJECT";
private IStyleGalleryStorage m_StyleGalleryStorage;
private IStyleGallery m_StyleGallery;
private List<IDoStyleGalleryClass> m_GalleryClassList;
private List<IDoStyleGalleryPath> m_DistStylePathList;
private Dictionary<IDoStyleGalleryPath, string> m_LoadDistStylePathList;
private IDoStyleGalleryPath m_DefaultDistStylePath;
private IDoStyleGalleryPath m_TargetDistStyleGalleryPath;
public List<IDoStyleGalleryClass> GalleryClassList
{
get
{
if (this.m_GalleryClassList == null)
{
this.m_GalleryClassList = new List<IDoStyleGalleryClass>();
}
if (this.m_GalleryClassList.Count == 0)
{
List<IDoStyleGalleryClass> arg_26_0 = this.get_Classes();
}
return this.m_GalleryClassList;
}
set
{
this.m_GalleryClassList = value;
}
}
public int DoClassCount
{
get
{
return this.get_Classes().Count;
}
}
public bool CanUpdateDoStyle
{
get
{
return true;
}
}
public IDoStyleGalleryPath DefaultDoStyleGalleryPath
{
get
{
return this.m_DefaultDistStylePath;
}
}
public int DoStyleGalleryPathCount
{
get
{
return this.m_DistStylePathList.Count;
}
}
public IDoStyleGalleryPath TargetDoStyleGalleryPath
{
get
{
return this.m_TargetDistStyleGalleryPath;
}
set
{
this.m_TargetDistStyleGalleryPath = value;
}
}
public int ClassCount
{
get
{
return this.m_StyleGallery.ClassCount;
}
}
public string DefaultStylePath
{
get
{
if (this.m_StyleGallery == null)
{
this.m_StyleGallery = new ServerStyleGalleryClass();
this.m_StyleGalleryStorage = (this.m_StyleGallery as IStyleGalleryStorage);
}
return this.m_StyleGalleryStorage.DefaultStylePath;
}
}
public int FileCount
{
get
{
if (this.GalleryStorageIsNull())
{
return 0;
}
return this.m_StyleGalleryStorage.FileCount;
}
}
public string TargetFile
{
get
{
if (this.GalleryStorageIsNull())
{
return "";
}
return this.m_StyleGalleryStorage.TargetFile;
}
set
{
if (this.m_StyleGallery == null)
{
this.m_StyleGallery = new ServerStyleGalleryClass();
this.m_StyleGalleryStorage = (this.m_StyleGallery as IStyleGalleryStorage);
}
this.m_StyleGalleryStorage.TargetFile = value;
}
}
public DoStyleGallery()
{
this.m_DistStylePathList = new List<IDoStyleGalleryPath>();
this.m_LoadDistStylePathList = new Dictionary<IDoStyleGalleryPath, string>();
this.m_GalleryClassList = new List<IDoStyleGalleryClass>();
}
public void ImportStyle2DB(string fileName)
{
try
{
this.ImportStyle2DB(fileName, "");
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public void ImportStyle2DB(string fileName, string className)
{
try
{
if (Path.GetExtension(fileName).ToLower() == ".serverstyle")
{
this.ImportServerStyle(fileName, className);
}
else
{
if (Path.GetExtension(fileName).ToLower() == ".aystyle")
{
this.ImportMdb(fileName, className);
}
else
{
if (Path.GetExtension(fileName).ToLower() == ".style")
{
this.ImportFromStyle(fileName, className);
}
}
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public bool RemoveItem(IDoStyleGalleryItem Item)
{
//if (StyleGalleryOptDB.DeleteStyleGalleryItem(Item))
//{
// Item = null;
// return true;
//}
return false;
}
public bool RemoveDoItems(IDoStyleGalleryPath path, string className)
{
try
{
int classIndex = -1;
IDoStyleGalleryClass doStyleGalleryClass = this.get_DoClass(className);
if (doStyleGalleryClass != null)
{
classIndex = doStyleGalleryClass.Index;
}
bool result = false;
if (path == null)
{
using (List<IDoStyleGalleryPath>.Enumerator enumerator = this.m_DistStylePathList.GetEnumerator())
{
while (enumerator.MoveNext())
{
IDoStyleGalleryPath current = enumerator.Current;
//StyleGalleryOptDB.DeleteStyleGalleryItems(current, classIndex);
}
goto IL_5A;
}
//goto IL_4F;
IL_5A:
result = true;
return result;
}
//IL_4F:
//result = StyleGalleryOptDB.DeleteStyleGalleryItems(path, classIndex);
return result;
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return false;
}
public bool UpdateItem(IDoStyleGalleryItem Item)
{
try
{
//return StyleGalleryOptDB.UpdateGalleryItem(Item);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return false;
}
public List<IDoStyleGalleryClass> get_Classes()
{
this.m_GalleryClassList = null;// StyleGalleryOptDB.GetAllGalleryClasses(this);
return this.m_GalleryClassList;
}
public IDoStyleGalleryClass get_DoClass(int index)
{
return null;// StyleGalleryOptDB.GetGalleryClassByIndex(index, this);
}
public IDoStyleGalleryClass get_DoClass(string className)
{
return null;// StyleGalleryOptDB.GetGalleryClassByName(className, this);
}
public List<string> get_DoCategories(string className)
{
List<string> list = new List<string>();
try
{
IDoStyleGalleryClass doStyleGalleryClass = this.get_DoClass(className);
if (doStyleGalleryClass == null)
{
//RdbUtil.AddErrorMessage("未能获得该图库类:" + className);
return list;
}
//list.AddRange(StyleGalleryOptDB.GetCategories(doStyleGalleryClass.Index, this.m_DistStylePathList));
foreach (KeyValuePair<IDoStyleGalleryPath, string> current in this.m_LoadDistStylePathList)
{
if (current.Value == className)
{
//list.AddRange(StyleGalleryOptDB.GetCategories(doStyleGalleryClass.Index, current.Key));
}
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return list;
}
public bool AddDoItem(IDoStyleGalleryItem Item)
{
if (this.m_TargetDistStyleGalleryPath == null)
{
//RdbUtil.AddErrorMessage("未设置目标图库路径,不能添加项");
return false;
}
return false;// StyleGalleryOptDB.AddStyleGalleryItem(this.m_TargetDistStyleGalleryPath, Item);
}
public bool AddDoItems(List<IDoStyleGalleryItem> items)
{
try
{
bool result;
if (this.m_TargetDistStyleGalleryPath == null)
{
//RdbUtil.AddErrorMessage("未设置目标图库路径,不能添加项");
result = false;
return result;
}
result = false;// StyleGalleryOptDB.AddStyleGalleryItems(this.m_TargetDistStyleGalleryPath, items);
return result;
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return false;
}
public bool Update()
{
throw new Exception("The method or operation is not implemented.");
}
public bool ReCreateStyleGalleryClass()
{
return false;// StyleGalleryOptDB.ReCreateStyleGalleryClass();
}
public int get_ItemsCount(string className, IDoStyleGalleryPath path, string category)
{
int num = 0;
int classIndex = -1;
if (className != "")
{
classIndex = this.get_DoClass(className).Index;
}
if (path != null)
{
num = 0;// StyleGalleryOptDB.GetItemsCount(path.Number, classIndex, category);
}
else
{
foreach (IDoStyleGalleryPath current in this.m_DistStylePathList)
{
num += 0;// StyleGalleryOptDB.GetItemsCount(current.Number, classIndex, category);
}
foreach (KeyValuePair<IDoStyleGalleryPath, string> current2 in this.m_LoadDistStylePathList)
{
if (current2.Value == className)
{
num += 0;// StyleGalleryOptDB.GetItemsCount(current2.Key.Number, classIndex, category);
}
}
}
return num;
}
public List<IDoStyleGalleryItem> get_Items(string className, IDoStyleGalleryPath path, string category)
{
List<IDoStyleGalleryItem> list = new List<IDoStyleGalleryItem>();
try
{
IDoStyleGalleryClass doStyleGalleryClass = this.get_DoClass(className);
if (doStyleGalleryClass == null)
{
return list;
}
int arg_1F_0 = doStyleGalleryClass.Index;
if (path == null)
{
//list.AddRange(StyleGalleryOptDB.GetStyleGalleryItems(this.m_DistStylePathList, doStyleGalleryClass, category));
using (Dictionary<IDoStyleGalleryPath, string>.Enumerator enumerator = this.m_LoadDistStylePathList.GetEnumerator())
{
while (enumerator.MoveNext())
{
KeyValuePair<IDoStyleGalleryPath, string> current = enumerator.Current;
if (current.Value == className)
{
//list.AddRange(StyleGalleryOptDB.GetStyleGalleryItems(current.Key, doStyleGalleryClass, category));
}
}
goto IL_97;
}
}
//list.AddRange(StyleGalleryOptDB.GetStyleGalleryItems(path, doStyleGalleryClass, category));
IL_97:;
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return list;
}
public void LoadDoStyle(IDoStyleGalleryPath path, string ClassName)
{
try
{
this.m_LoadDistStylePathList.Add(path, ClassName);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public void Clear()
{
try
{
if (!this.GalleryStorageIsNull())
{
this.m_StyleGallery.Clear();
}
this.m_DistStylePathList.Clear();
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
private void ImportMdb(string fileName, string className)
{
try
{
IFeatureWorkspace featureWorkspace = this.OpenMdb(fileName);
if (featureWorkspace != null)
{
List<IDoStyleGalleryItem> list = new List<IDoStyleGalleryItem>();
ITable table = null;
foreach (IDoStyleGalleryClass current in this.GalleryClassList)
{
if (!(className != "") || current.Name.Equals(className))
{
string name = current.Name.Replace(' ', '_');
try
{
table = featureWorkspace.OpenTable(name);
if (table == null)
{
continue;
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
continue;
}
ICursor cursor = table.Search(null, false);
for (IRow row = cursor.NextRow(); row != null; row = cursor.NextRow())
{
IPropertySet propertySet = new PropertySetClass();
IPersistStream persistStream = propertySet as IPersistStream;
IMemoryBlobStream pstm = row.get_Value(3) as IMemoryBlobStream;
persistStream.Load(pstm);
IStyleGalleryItem styleItem = propertySet.GetProperty("Object") as IStyleGalleryItem;
IDoStyleGalleryItem doStyleGalleryItem = this.CreateFromEsriGalleryItem(styleItem);
if (doStyleGalleryItem != null)
{
doStyleGalleryItem.StyleGalleryClass = current;
list.Add(doStyleGalleryItem);
}
}
}
}
this.AddDoItems(list);
ComReleaser.ReleaseCOMObject(featureWorkspace);
}
}
catch (Exception ex2)
{
//RdbUtil.AddException(ex2);
}
}
private void ImportServerStyle(string fileName, string className)
{
IStyleGallery styleGallery = new ServerStyleGalleryClass();
IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;
styleGalleryStorage.AddFile(fileName);
List<IDoStyleGalleryItem> list = new List<IDoStyleGalleryItem>();
foreach (IDoStyleGalleryClass current in this.GalleryClassList)
{
if (className != "")
{
if (!className.Equals(current.Name))
{
continue;
}
}
try
{
IEnumStyleGalleryItem enumStyleGalleryItem = styleGallery.get_Items(current.Name, fileName, "");
if (enumStyleGalleryItem != null)
{
for (IStyleGalleryItem styleItem = enumStyleGalleryItem.Next(); styleItem != null; styleItem = enumStyleGalleryItem.Next())
{
Application.DoEvents();
IDoStyleGalleryItem doStyleGalleryItem = this.CreateFromEsriGalleryItem(styleItem);
if (doStyleGalleryItem != null)
{
doStyleGalleryItem.StyleGalleryClass = current;
list.Add(doStyleGalleryItem);
}
}
}
}
catch
{
}
}
this.AddDoItems(list);
styleGalleryStorage.RemoveFile(fileName);
styleGallery.Clear();
ComReleaser.ReleaseCOMObject(styleGalleryStorage);
ComReleaser.ReleaseCOMObject(styleGallery);
}
private void ImportFromStyle(string fileName, string className)
{
}
private IDoStyleGalleryItem CreateFromEsriGalleryItem(IStyleGalleryItem StyleItem)
{
try
{
return new DoStyleGalleryItem
{
Name = StyleItem.Name,
Item = StyleItem,
Category = StyleItem.Category,
Number = (long)StyleItem.ID
};
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return null;
}
private IDoStyleGalleryItem CreateFromCoustomGalleryItem(string name, string category, ISymbol symbol)
{
try
{
return this.CreateFromEsriGalleryItem(new ServerStyleGalleryItemClass
{
Name = name,
Category = category,
Item = symbol
});
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return null;
}
private StyleItemTemp CreateFromEsriGalleryItem(string name, string Category, object StyleItem)
{
StyleItemTemp result = default(StyleItemTemp);
try
{
result.Name = name;
result.Item = StyleItem;
result.Category = Category;
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return result;
}
private bool GalleryStorageIsNull()
{
if (this.m_StyleGalleryStorage == null)
{
//RdbUtil.AddErrorMessage("未添加任何符号文件");
return true;
}
return false;
}
private IFeatureWorkspace OpenMdb(string GWStylePath)
{
try
{
IPropertySet propertySet = new PropertySetClass();
propertySet.SetProperty("DATABASE", GWStylePath);
IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
IWorkspace workspace = workspaceFactory.Open(propertySet, 0);
return workspace as IFeatureWorkspace;
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return null;
}
public void AddDoStyleGalleryPath(IDoStyleGalleryPath path)
{
if (!this.m_DistStylePathList.Contains(path))
{
this.m_DistStylePathList.Add(path);
}
}
public IDoStyleGalleryPath DoStyleGalleryPath(int index)
{
return this.m_DistStylePathList[index];
}
public void RemoveDoStyleGalleryPath(IDoStyleGalleryPath path)
{
this.m_DistStylePathList.Remove(path);
}
public void ClearGalleryPaths()
{
this.m_DistStylePathList.Clear();
}
public void AddItem(IStyleGalleryItem item)
{
try
{
this.m_StyleGallery.AddItem(item);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public IStyleGalleryClass get_Class(int index)
{
try
{
return this.m_StyleGallery.get_Class(index);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return null;
}
public List<string> get_Categories(string className)
{
List<string> list = new List<string>();
try
{
List<string> result;
if (this.m_StyleGallery == null)
{
result = list;
return result;
}
IEnumBSTR enumBSTR = this.m_StyleGallery.get_Categories(className);
for (string item = enumBSTR.Next(); item != null; item = enumBSTR.Next())
{
list.Add(item);
}
result = list;
return result;
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return list;
}
public void ImportStyle(string fileName)
{
try
{
this.m_StyleGallery.ImportStyle(fileName);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public List<IDoStyleGalleryItem> get_Items(string ClassName, string styleSet, string Category)
{
List<IDoStyleGalleryItem> list = new List<IDoStyleGalleryItem>();
try
{
List<IDoStyleGalleryItem> result;
if (this.m_StyleGallery == null)
{
result = list;
return result;
}
IEnumStyleGalleryItem enumStyleGalleryItem = this.m_StyleGallery.get_Items(ClassName, styleSet, Category);
enumStyleGalleryItem.Reset();
for (IStyleGalleryItem styleItem = enumStyleGalleryItem.Next(); styleItem != null; styleItem = enumStyleGalleryItem.Next())
{
IDoStyleGalleryItem doStyleGalleryItem = this.CreateFromEsriGalleryItem(styleItem);
if (doStyleGalleryItem != null)
{
IDoStyleGalleryClass styleGalleryClass = this.get_DoClass(ClassName);
doStyleGalleryItem.StyleGalleryClass = styleGalleryClass;
list.Add(doStyleGalleryItem);
}
}
result = list;
return result;
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
return list;
}
public void LoadStyle(string fileName, string ClassName)
{
try
{
this.m_StyleGallery.LoadStyle(fileName, ClassName);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public void RemoveItem(IStyleGalleryItem Item)
{
try
{
this.m_StyleGallery.RemoveItem(Item);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public void UpdateItem(IStyleGalleryItem Item)
{
try
{
this.m_StyleGallery.UpdateItem(Item);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public void SaveStyle(string fileName, string styleSet, string ClassName)
{
throw new Exception("The method or operation is not implemented.");
}
public void AddFile(string path)
{
if (this.m_StyleGallery == null)
{
this.m_StyleGallery = new ServerStyleGalleryClass();
this.m_StyleGalleryStorage = (this.m_StyleGallery as IStyleGalleryStorage);
}
this.m_StyleGalleryStorage.AddFile(path);
}
public bool get_CanUpdate(string path)
{
return !this.GalleryStorageIsNull() && this.m_StyleGalleryStorage.get_CanUpdate(path);
}
public string File(int index)
{
if (this.GalleryStorageIsNull())
{
return "";
}
return this.m_StyleGalleryStorage.get_File(index);
}
public void RemoveFile(string path)
{
if (!this.GalleryStorageIsNull())
{
this.m_StyleGalleryStorage.RemoveFile(path);
}
}
public void ClearFiles()
{
try
{
if (this.m_StyleGalleryStorage == null)
return;
for (int i = 0; i < this.m_StyleGalleryStorage.FileCount; i++)
{
this.m_StyleGalleryStorage.RemoveFile(this.m_StyleGalleryStorage.get_File(i));
i--;
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
}
}