142 lines
4.7 KiB
C#
142 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.ComponentModel;
|
|
|
|
namespace JD.Serialization
|
|
{
|
|
public class GlobalsFieldDescritor
|
|
{
|
|
public string propertyInfoStr = null;
|
|
public string displayName = "";
|
|
public string tips = "";
|
|
};
|
|
|
|
public static class Globals
|
|
{
|
|
public static string projectRoot = null;
|
|
public static string P4_Server = null;
|
|
public static string P4_Client = null;
|
|
public static string FieldsDescriptorFile = null;
|
|
public static Dictionary<string, GlobalsFieldDescritor> fieldsDescritor = null;
|
|
|
|
public static CSharpDataWrapperConfigDlg ConfigDialog = new CSharpDataWrapperConfigDlg();
|
|
|
|
public static string ProjectRoot
|
|
{
|
|
get
|
|
{
|
|
return projectRoot;
|
|
}
|
|
set
|
|
{
|
|
projectRoot = value;
|
|
projectRoot = System.IO.Path.GetFullPath(projectRoot);
|
|
}
|
|
}
|
|
|
|
|
|
public static bool loadFieldsDescriptor()
|
|
{
|
|
if (FieldsDescriptorFile == null)
|
|
return false;
|
|
|
|
try
|
|
{
|
|
System.Xml.Serialization.XmlSerializer reader =
|
|
new System.Xml.Serialization.XmlSerializer(typeof(List<GlobalsFieldDescritor>));
|
|
|
|
System.IO.StreamReader file = new System.IO.StreamReader(FieldsDescriptorFile);
|
|
List<GlobalsFieldDescritor> fdList = (List<GlobalsFieldDescritor>)reader.Deserialize(file);
|
|
file.Close();
|
|
|
|
Globals.fieldsDescritor = new Dictionary<string, GlobalsFieldDescritor>();
|
|
foreach (GlobalsFieldDescritor fd in fdList)
|
|
{
|
|
fieldsDescritor.Add(fd.propertyInfoStr, fd);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch (System.Exception /*ex*/)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static bool saveFieldsDescriptor()
|
|
{
|
|
if (FieldsDescriptorFile == null || fieldsDescritor == null)
|
|
return false;
|
|
|
|
try
|
|
{
|
|
System.Xml.Serialization.XmlSerializer writer =
|
|
new System.Xml.Serialization.XmlSerializer(typeof(List<GlobalsFieldDescritor>));
|
|
System.IO.StreamWriter file = new System.IO.StreamWriter(FieldsDescriptorFile);
|
|
|
|
List<GlobalsFieldDescritor> fdList = new List<GlobalsFieldDescritor>();
|
|
foreach (KeyValuePair<string, GlobalsFieldDescritor> fdpairs in fieldsDescritor)
|
|
{
|
|
fdList.Add(fdpairs.Value);
|
|
}
|
|
fdList.Sort(delegate(GlobalsFieldDescritor fd1, GlobalsFieldDescritor fd2)
|
|
{ return fd1.propertyInfoStr.CompareTo(fd2.propertyInfoStr); });
|
|
|
|
writer.Serialize(file, fdList);
|
|
file.Close();
|
|
}
|
|
catch (System.Exception /*ex*/)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
public static string getProperyDescritorUID(PropertyDescriptor _propDesc)
|
|
{
|
|
return _propDesc.ComponentType.Name + "." + _propDesc.Name;
|
|
}
|
|
|
|
public static GlobalsFieldDescritor newFieldDescritor(PropertyDescriptor _propDesc)
|
|
{
|
|
GlobalsFieldDescritor newFd = new GlobalsFieldDescritor();
|
|
if (fieldsDescritor == null)
|
|
fieldsDescritor = new Dictionary<string, GlobalsFieldDescritor>();
|
|
newFd.propertyInfoStr = getProperyDescritorUID(_propDesc);
|
|
fieldsDescritor.Add(newFd.propertyInfoStr, newFd);
|
|
|
|
return newFd;
|
|
}
|
|
|
|
public static GlobalsFieldDescritor getFieldDescriptor(PropertyDescriptor _propDesc)
|
|
{
|
|
if (fieldsDescritor == null)
|
|
return null;
|
|
|
|
string propertyDescriptorStr = getProperyDescritorUID(_propDesc);
|
|
if (fieldsDescritor.ContainsKey(propertyDescriptorStr))
|
|
return fieldsDescritor[propertyDescriptorStr];
|
|
|
|
return null;
|
|
}
|
|
|
|
public static void setFieldDescritorDisplayName(PropertyDescriptor _propDesc, string _name)
|
|
{
|
|
GlobalsFieldDescritor fd = getFieldDescriptor(_propDesc);
|
|
if (fd == null)
|
|
fd = newFieldDescritor(_propDesc);
|
|
fd.displayName = _name;
|
|
}
|
|
|
|
public static void setFieldDescritorTip(PropertyDescriptor _propDesc, string _tip)
|
|
{
|
|
GlobalsFieldDescritor fd = getFieldDescriptor(_propDesc);
|
|
if (fd == null)
|
|
fd = newFieldDescritor(_propDesc);
|
|
fd.tips= _tip;
|
|
}
|
|
}
|
|
}
|