private void btn_CreateWorkSpace_Click(object sender, EventArgs e) { string newName = txt_Name.Text.Trim(); Workspace existswp = getSelectedWPByName(newName); if (existswp != null) { lbl_Msg.Text = "错误:当前工作区名已存在。"; return; } else { Workspace newwp = new Workspace(); newwp.ID ="WorkspaceInfoImpl--"+ System.Guid.NewGuid().ToString(); newwp.Name = newName; newwp.Prefix = newName; newwp.URI = txt_URI.Text.Trim(); wslist.Add(newwp); SysParam.WordsSpaceSelected = newwp; string newwppathstr = SysParam.GeoserverDataPath + "workspaces\\"+newName; if (!Directory.Exists(newwppathstr)) { Directory.CreateDirectory(newwppathstr); } File.Copy(Application.StartupPath + "\\XmlTemplet\\Workspace\\namespace.xml", newwppathstr + "\\namespace.xml"); File.Copy(Application.StartupPath + "\\XmlTemplet\\Workspace\\workspace.xml", newwppathstr + "\\workspace.xml"); bool IsDefault = false; if (rb_yes.Checked) IsDefault = true; newwp.SetAttribute(newwp, newwppathstr + "\\workspace.xml", SysParam.GeoserverDataPath + "workspaces\\default.xml", IsDefault); Com_workspaceList.Items.Add(newName); Com_workspaceList.SelectedText = newName; } }
/// <summary> /// 根据添加的属性 生成workspace以及namespace 两个xml文件 /// </summary> /// <param name="workspace"></param> /// <param name="workspacepath"></param> /// <param name="defaultxmlpath">default文件路径</param> /// <param name="isDefult">是否默认</param> public void SetAttribute(Workspace workspace,string workspacepath,string defaultxmlpath,bool isDefult) { /*<workspace> <id>WorkspaceInfoImpl--68929cbb:14d9308effa:-8000</id> <name>guangxi</name> </workspace>*/ XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(workspacepath); //加载XML文档 XmlNode Node = xmlDoc.SelectSingleNode("workspace"); Node.ChildNodes[0].InnerText = workspace.ID; Node.ChildNodes[1].InnerText = workspace.Name; xmlDoc.Save(workspacepath); //NamespaceInfoImpl--68929cbb:14d9308effa:-7fff // WorkspaceInfoImpl--68929cbb:14d9308effa:-8000 /*<namespace> <id>NamespaceInfoImpl--68929cbb:14d9308effa:-7fff</id> <prefix>guangxi</prefix> <uri>www.guangxi.com</uri> </namespace>*/ string namespacepath = workspacepath.Replace("workspace.xml", "namespace.xml"); xmlDoc.Load(namespacepath); XmlNode npNode = xmlDoc.SelectSingleNode("namespace"); npNode.ChildNodes[0].InnerText = workspace.ID.Replace("WorkspaceInfoImpl", "NamespaceInfoImpl"); npNode.ChildNodes[1].InnerText = workspace.Name; npNode.ChildNodes[2].InnerText = workspace.URI; xmlDoc.Save(namespacepath); //修改default文档 if (isDefult) { XmlDocument xmlDefaultDoc = new XmlDocument(); xmlDefaultDoc.Load(defaultxmlpath); XmlNode DefaultNode = xmlDefaultDoc.SelectSingleNode("workspace"); DefaultNode.ChildNodes[0].InnerText = workspace.ID; DefaultNode.ChildNodes[1].InnerText = workspace.Name; xmlDefaultDoc.Save(defaultxmlpath); } }
private void Form1_Load(object sender, EventArgs e) { Init(); string[] diarr = Directory.GetDirectories(SysParam.GeoserverDataPath + "workspaces\\", "*", SearchOption.TopDirectoryOnly); foreach (string item in diarr) { DirectoryInfo workspacedict = new DirectoryInfo(item); FileInfo[] files = workspacedict.GetFiles("workspace.xml"); foreach (FileInfo file in files) { Workspace wp = new Workspace(file.FullName); wslist.Add(wp); Com_workspaceList.Items.Add(wp.Name); } } DirectoryInfo workspacedefaultdr = new DirectoryInfo(SysParam.GeoserverDataPath + "workspaces\\"); FileInfo[] defaultxml = workspacedefaultdr.GetFiles("default.xml"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(defaultxml[0].FullName); //加载XML文档 XmlNode Node = xmlDoc.SelectSingleNode("workspace"); string defaultName = Node.LastChild.InnerText; if (SysParam.WordsSpaceSelected == null) { Com_workspaceList.SelectedText = defaultName; SysParam.WordsSpaceSelected = getSelectedWPByName(defaultName); } else { Com_workspaceList.SelectedText = SysParam.WordsSpaceSelected.Name; } }
public void SetAttribut(Workspace wp, Store store, FeatureType featuretype, string xmlpath) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlpath); //加载XML文档 XmlNode Node = xmlDoc.SelectSingleNode("featureType"); XMLHelper.SetAttributeValue(Node, "id", featuretype.ID); XMLHelper.SetAttributeValue(Node, "name", featuretype.Name); XMLHelper.SetAttributeValue(Node, "nativeName", featuretype.NativeName); XMLHelper.SetAttributeValue(Node, "namespace","id", featuretype.NamespaceID); XMLHelper.SetAttributeValue(Node, "title", featuretype.Title); XMLHelper.SetAttributeValue(Node, "srs", featuretype.Srs); XMLHelper.SetAttributeValue(Node, "nativeBoundingBox","minx", featuretype.NativeBoundingBox_MinX); XMLHelper.SetAttributeValue(Node, "nativeBoundingBox", "miny", featuretype.NativeBoundingBox_MinY); XMLHelper.SetAttributeValue(Node, "nativeBoundingBox", "maxx", featuretype.NativeBoundingBox_MaxX); XMLHelper.SetAttributeValue(Node, "nativeBoundingBox", "maxy", featuretype.NativeBoundingBox_MaxY); XMLHelper.SetAttributeValue(Node, "latLonBoundingBox", "minx", featuretype.LatLonBoundingBox_MinX); XMLHelper.SetAttributeValue(Node, "latLonBoundingBox", "miny", featuretype.LatLonBoundingBox_MinY); XMLHelper.SetAttributeValue(Node, "latLonBoundingBox", "maxx", featuretype.LatLonBoundingBox_MaxX); XMLHelper.SetAttributeValue(Node, "latLonBoundingBox", "maxy", featuretype.LatLonBoundingBox_MaxY); XMLHelper.SetAttributeValue(Node, "latLonBoundingBox", "crs", featuretype.LatLonBoundingBox_Crs); XMLHelper.SetAttributeValue(Node, "projectionPolicy", featuretype.ProjectionPolicy); XMLHelper.SetAttributeValue(Node, "enabled", featuretype.IsEnabled); XMLHelper.SetAttributeValue(Node, "store","id", store.ID); XMLHelper.SetAttributeValue(Node, "maxFeatures", featuretype.maxFeatures); XMLHelper.SetAttributeValue(Node, "numDecimals", featuretype.numDecimals); XMLHelper.SetAttributeValue(Node, "overridingServiceSRS", featuretype.overridingServiceSRS); XMLHelper.SetAttributeValue(Node, "circularArcPresent", featuretype.circularArcPresent); xmlDoc.Save(xmlpath); }