using System; using System.Collections.Generic; using System.Text; using System.Drawing; using GeoScene.Data; using GeoScene.Engine; using GeoScene.Globe; using System.IO; using System.Windows.Forms; using System.Collections; using System.Data; using System.Xml; using System.Net.NetworkInformation; using System.Net; using System.Security.Cryptography; namespace Cyberpipe { public class Utility1 { public static string dbdatabase; public static string userID; public static Hashtable Pipe_QueryFields; public static string DBPassword; public static string DBServer; public static string DBBackUp; public static string serverip; public static int serverport; public static string localicenseserverip; public static int localicenseserverport; public static GeoScene.Engine.GSODataSource dataSource; public static List<LayerChild> LayerChilds; public static ArrayList LayerLabels; public static ArrayList LayerNames; public static ArrayList TerrainsName; public static Hashtable LayerLabel_LayerIDs; public static Hashtable Query_Fields = new Hashtable(); public static Hashtable Pipe_Code = new Hashtable(); public static List<PipelineType> listPipelineType; public static string PicRootURL; public static string PicDefaultURL; public static double dFlyAboveLine = 2; public static string userName; public static string projectStr; public static List<string> roadNmae = new List<string>(); public static string backupurl; //传感器配置 //public static string sensorConnectString; //public static string sensorDatabase; //public static List<MarkerLayer> sensorMarkerLayers; //对象编码号 public static void SetBallons(GSOBalloon featureTooltip, GSOBalloonEx balloonEx) { featureTooltip.CacheFilePath = Path.GetDirectoryName(Application.ExecutablePath) + "/GeoScene/Globe/Temp"; featureTooltip.SetSize(EnumSizeIndex.ROUNDED_CX, 0); featureTooltip.SetSize(EnumSizeIndex.ROUNDED_CY, 0); featureTooltip.SetSize(EnumSizeIndex.MARGIN_CX, 3); featureTooltip.SetSize(EnumSizeIndex.MARGIN_CY, 3); featureTooltip.SetSize(EnumSizeIndex.ANCHOR_HEIGHT, 0); featureTooltip.SetSize(EnumSizeIndex.ANCHOR_WIDTH, 0); featureTooltip.SetSize(EnumSizeIndex.ANCHOR_MARGIN, 0); featureTooltip.SetSize(EnumSizeIndex.ANCHOR_OFFSET_CX, 1); featureTooltip.SetSize(EnumSizeIndex.ANCHOR_OFFSET_CY, -1); featureTooltip.SetDirection(EnumToolTipDirection.TD_BOTTOMEDGE_LEFT); featureTooltip.EscapeSequencesEnabled = true; featureTooltip.HyperlinkEnabled = true; featureTooltip.Opaque = 30; featureTooltip.MaxWidth = 300; featureTooltip.SetShadow(0, 0, 50, true, 0, 0); balloonEx.SetSize(EnumSizeIndexEx.CONTENT_CX, 500); balloonEx.SetSize(EnumSizeIndexEx.CONTENT_CY, 300); balloonEx.Opaque = 5; balloonEx.SetBorder(Color.White, 1, 1); balloonEx.SetColorBkType(EnumBkColorTypeEx.SKY); } public static GSOFeature FindFeatureByUserID(GSOFeatureDataset featdataset, string fieldname, string value) { GSOFeatures feats = featdataset.GetAllFeatures(); for (int i = 0; i < feats.Length; i++) { GSOFeature feat = feats[i]; if (feat.GetFieldAsString(fieldname) == value) { return feat; } } return null; } public static GeoScene.Data.GSOPoint2d XYZ_2_Latlon(double x, double y) { int id = GeoScene.Data.GSOProjectManager.AddProject(Utility1.projectStr); GeoScene.Data.GSOPoint2d pt2d = new GeoScene.Data.GSOPoint2d(x, y); GeoScene.Data.GSOPoint2d result = GeoScene.Data.GSOProjectManager.Inverse(pt2d, id); return result; } public static GeoScene.Data.GSOPoint2d Latlon_2_XYZ(double lon, double lat) { int id = GeoScene.Data.GSOProjectManager.AddProject(Utility1.projectStr); GeoScene.Data.GSOPoint2d pt2d = new GeoScene.Data.GSOPoint2d(lon, lat); GeoScene.Data.GSOPoint2d result = GeoScene.Data.GSOProjectManager.Forward(pt2d, id); return result; } /// <summary> /// MD5加密 /// </summary> /// <param name="pToEncrypt">要加密字符串</param> /// <returns></returns> public static string MD5Encrypt(string pToEncrypt) { //string sKey = "12345678";//默认8位加密密匙 //DESCryptoServiceProvider des = new DESCryptoServiceProvider(); //byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt); //des.Key = ASCIIEncoding.ASCII.GetBytes(sKey); //des.IV = ASCIIEncoding.ASCII.GetBytes(sKey); //MemoryStream ms = new MemoryStream(); //CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write); //cs.Write(inputByteArray, 0, inputByteArray.Length); //cs.FlushFinalBlock(); //StringBuilder ret = new StringBuilder(); //foreach (byte b in ms.ToArray()) //{ // ret.AppendFormat("{0:X2}", b); //} //ret.ToString(); //return ret.ToString(); byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt); MD5 md5 = new MD5CryptoServiceProvider(); byte[] output = md5.ComputeHash(inputByteArray); string ret = BitConverter.ToString(output).Replace("-", ""); ret = ret.ToLower(); return ret; } public static GSOFeatures Table2Features(DataTable table, string currentQueryLayer, GeoScene.Globe.GSOGlobeControl globeControl1) { GSOFeatures features = new GSOFeatures(); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; string featureName = row["编号"].ToString(); featureName = featureName.Trim(); //GSOLayer layer = globeControl1.Globe.Layers.GetLayerByID((int)(Utility1.LayerLabel_LayerIDs[currentQueryLayer])); GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(currentQueryLayer); GSOFeatures tempfeatures = layer.GetFeatureByName(featureName, false); if (tempfeatures.Length > 0) { features.Add(tempfeatures[0]); } } return features; } public static string filename = Application.StartupPath + "\\Config.xml"; public static string fileRoadName = Application.StartupPath + "\\EMS_roadname.xml"; public static string filenamePipelineType = Application.StartupPath + "\\PipelineType.xml"; //程序启动的时候读取配置文件 public static void SetParams() { #region 读取 filename "Config.xml" Utility1.LayerChilds = new List<LayerChild>(); Utility1.LayerLabels = new System.Collections.ArrayList(); Utility1.TerrainsName = new System.Collections.ArrayList(); Utility1.LayerNames = new System.Collections.ArrayList(); Utility1.LayerLabel_LayerIDs = new System.Collections.Hashtable(); if (File.Exists(filename)) { XmlTextReader XmlReader = new XmlTextReader(filename); try { while (XmlReader.Read()) { if (XmlReader.Name == "database") { Utility1.dbdatabase = XmlReader.ReadElementString(); } else if (XmlReader.Name == "dbpassword") { Utility1.DBPassword = XmlReader.ReadElementString(); } else if (XmlReader.Name == "user") { Utility1.userID = XmlReader.ReadElementString(); } else if (XmlReader.Name == "locaserverip") { Utility1.serverip = XmlReader.ReadElementString(); } else if (XmlReader.Name == "locaserverport") { Utility1.serverport = Convert.ToInt32(XmlReader.ReadElementString()); } else if (XmlReader.Name == "localicenseserverip") { Utility1.localicenseserverip = XmlReader.ReadElementString(); } else if (XmlReader.Name == "localicenseserverport") { Utility1.localicenseserverport = Convert.ToInt32(XmlReader.ReadElementString()); } else if (XmlReader.Name == "dbbackuppath") { Utility1.DBBackUp = XmlReader.ReadElementString(); } else if (XmlReader.Name == "layerchild") { LayerChild child = new LayerChild(); child.attriLabel = XmlReader["label"].Trim(); child.attriLayer = XmlReader["layer"].Trim(); child.attriType = XmlReader["type"].Trim(); Utility1.LayerChilds.Add(child); Utility1.LayerLabels.Add(XmlReader["label"].Trim()); Utility1.LayerNames.Add(XmlReader["layer"].Trim()); } else if (XmlReader.Name == "Terrain") { Utility1.TerrainsName.Add(XmlReader.ReadElementString()); } else if (XmlReader.Name == "dbserver") { Utility1.DBServer = XmlReader.ReadElementString(); } else if (XmlReader.Name == "rooturl") { Utility1.PicRootURL = XmlReader.ReadElementString(); } else if (XmlReader.Name == "defaultimgurl") { Utility1.PicDefaultURL = XmlReader.ReadElementString(); } else if (XmlReader.Name == "queryfield") { Utility1.Query_Fields.Add(XmlReader["label"], XmlReader.ReadElementString()); } else if (XmlReader.Name == "pipelineCode") { Utility1.Pipe_Code.Add(XmlReader["label"], XmlReader.ReadElementString()); } else if (XmlReader.Name == "projectStr") { Utility1.projectStr = XmlReader.ReadElementString(); } else if (XmlReader.Name == "backupserverurl") { Utility1.backupurl = XmlReader.ReadElementString(); } } } catch (Exception ex) { //ErrorLog.PublishError(ex); //LogError.PublishError(ex); } finally { XmlReader.Close(); } } else { MessageBox.Show("配置文件不存在!", "提示"); } #endregion #region if (File.Exists(fileRoadName)) { XmlTextReader xmlReader = new XmlTextReader(fileRoadName); try { while (xmlReader.Read()) { if (xmlReader.Name == "RoadName") { string str = xmlReader["name"]; if (str != null&&roadNmae.Contains(str)==false) { roadNmae.Add(str); } } } } catch (Exception ex) { MessageBox.Show("读取道路名文件出错!", "提示"); } finally { xmlReader.Close(); } } #endregion #region 读取 filenamePipelineType "PipelineType.xml" listPipelineType = new List<PipelineType>(); if (File.Exists(filenamePipelineType)) { XmlTextReader XmlReader = new XmlTextReader(filenamePipelineType); try { while (XmlReader.Read()) { if (XmlReader.Name == "PipelineCode") { string pipelinecode = XmlReader["code"] == null ? null : XmlReader["code"].Trim(); string pipelinename = XmlReader["name"] == null ? null : XmlReader["name"].Trim(); string pipelinetype = XmlReader["type"] == null ? null : XmlReader["type"].Trim(); if (pipelinecode != null && pipelinename != null && pipelinetype != null) { PipelineType pipelineType = new PipelineType(pipelinecode, pipelinename, pipelinetype); if (listPipelineType.Contains(pipelineType) == false) { listPipelineType.Add(pipelineType); } } } } } catch (Exception ex) { //LogError.PublishError(ex); //ErrorLog.PublishError(ex); } finally { XmlReader.Close(); } } else { MessageBox.Show("配置文件" + filenamePipelineType + "不存在!", "提示"); } #endregion } //判断网络是否连接 public static bool isNetworkConnectionSuccess(string ipAdress) { if (ipAdress == null) { return false; } if (ipAdress.Contains("\\")) { ipAdress = ipAdress.Substring(0, ipAdress.LastIndexOf('\\')); } if (ipAdress.Trim() == "localhost" || ipAdress.Trim() == "127.0.0.1" || ipAdress.Trim() == Dns.GetHostName()) { return true; } Ping ping = new Ping(); try { PingReply pr = ping.Send(ipAdress.Trim(), 3000); if (pr.Status == IPStatus.Success) { return true; } else { return false; } } catch (Exception ex) { //ErrorLog.PublishError(ex); return false; } } } }