/// <summary> /// Node GetListOfMAPCSLIBRAR for export to LSP file naming of coordinate systems (all library) /// </summary> /// <param name="CS_value">Name of type "CoordinateSystem"</param> /// <param name="CS_Agree">Permit to add other associated definitions</param> /// <param name="Folder_Path">Directory path to save LSP file</param> public static void GetAllOfMAPCSLIBRARY(string Folder_Path, string CS_value, string CS_Agree) { StringBuilder sb = new StringBuilder(); var guid = Guid.NewGuid(); string writePath = $@"{Folder_Path}\{guid}.lsp"; MgCoordinateSystemFactory coordSysFactory = new MgCoordinateSystemFactory(); MgCoordinateSystemCatalog csCatalog = coordSysFactory.GetCatalog(); MgCoordinateSystemDictionary csDict = csCatalog.GetCoordinateSystemDictionary(); MgCoordinateSystemEnum csDictEnum = csDict.GetEnum(); int csCount = csDict.GetSize(); sb.AppendLine(@"(command ""MAPCSLIBRARYEXPORT"""); MgStringCollection csNames = csDictEnum.NextName(csCount); string csName = null; for (int i = 0; i < csCount; i++) { csName = csNames.GetItem(i); sb.AppendLine($@"""{csName.ToString()}""" + " " + $"\"{CS_value}\""); } string space = " "; sb.AppendLine(" " + $@"""{space}""" + " " + $@"""{CS_Agree}""" + " " + @"""""" + ")"); using (StreamWriter export_file = new StreamWriter(writePath, true, Encoding.UTF8)) { export_file.Write(sb.ToString()); } }
public static Dictionary <string, object> GetListAndCountOfCategories() //Работает! { var guid = Guid.NewGuid(); MgCoordinateSystemFactory coordSysFactory = new MgCoordinateSystemFactory(); MgCoordinateSystemCatalog csCatalog = coordSysFactory.GetCatalog(); MgCoordinateSystemCategoryDictionary csDictCat = csCatalog.GetCategoryDictionary(); MgCoordinateSystemEnum csDictCatEnum = csDictCat.GetEnum(); int csCatCount = csDictCat.GetSize(); MgStringCollection csCatNames = csDictCatEnum.NextName(csCatCount); string csCategoryName = null; List <string> csCatNamesL = new List <string>(); for (int i3 = 0; i3 < csCatCount; i3++) { csCategoryName = csCatNames.GetItem(i3); csCatNamesL.Add(csCategoryName); } return(new Dictionary <string, object> { { "CatCount", csCatCount }, { "CatList", csCatNamesL }, }); }
static void Main(string[] args) { MgdPlatform.Initialize("Platform.ini"); string currentDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //Test mapguide-api-base MgCoordinateSystemFactory csFact = new MgCoordinateSystemFactory(); Console.WriteLine("Testing coordinate system categories"); MgStringCollection csCategories = csFact.EnumerateCategories(); for (int i = 0; i < csCategories.GetCount(); i++) { Console.WriteLine(csCategories.GetItem(i)); } //Test mg-desktop MgdServiceFactory serviceFact = new MgdServiceFactory(); Console.Write("Can we create a MgdFeatureService? "); MgdFeatureService featSvc = (MgdFeatureService)serviceFact.CreateService(MgServiceType.FeatureService); Console.WriteLine("yes"); Console.Write("Can we create a MgdResourceService? "); MgdResourceService resSvc = (MgdResourceService)serviceFact.CreateService(MgServiceType.ResourceService); Console.WriteLine("yes"); MgdPlatform.Terminate(); Console.WriteLine("Things look all good :) Press any key to continue"); Console.Read(); }
public static string MgStringCollectionToString(MgStringCollection coll) { try { //Sigh, we're too smart for our own good. Yes, the trailing comma //should be there! StringBuilder sb = new StringBuilder(); for (int i = 0; i < coll.GetCount(); i++) { sb.Append(coll.GetItem(i)); sb.Append(","); } return(sb.ToString()); /* * List<string> items = new List<string>(); * for (int i = 0; i < coll.GetCount(); i++) * { * items.Add(coll.GetItem(i)); * } * return string.Join(",", items.ToArray()); */ } catch (MgException ex) { throw new UnitTestException(string.Format("Exception from MapGuide:\n{0}", ex.GetDetails())); } }
public void Execute(IPlatformFactory factory, ITestLogger logger) { StringCollection strColl = new StringCollection(); strColl.Add("string1"); strColl.Add("string2"); strColl.Add("string3"); strColl.Add("string3"); MgStringCollection coll1 = new MgStringCollection(); coll1.Add("Hello"); MgStringCollection coll2 = new MgStringCollection(strColl); Assert.AreEqual(4, coll2.GetCount()); StringCollection coll3 = coll2; Assert.AreEqual(4, coll3.Count); for (int i = 0; i < 4; i++) { Assert.AreEqual(strColl[i], coll2.GetItem(i)); Assert.AreEqual(strColl[i], coll3[i]); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); MgStringCollection categories = _fact.EnumerateCategories(); var items = new List <string>(); for (int i = 0; i < categories.GetCount(); i++) { items.Add(categories.GetItem(i)); } lstCoordSysCategories.DataSource = items; }
Dictionary <string, IResource> IGetResourceContents.Execute(IEnumerable <string> resourceIds) { //There is an implicit assumption here that all resource ids check out and that //there is no duplicates var resources = new Dictionary <string, IResource>(); if (this.Parent.SiteVersion >= new Version(2, 2)) { Trace.TraceInformation("[GetResources]: Using optimal code path provided by 2.2 Resource Service APIs"); MgStringCollection ids = new MgStringCollection(); foreach (var rid in resourceIds) { ids.Add(rid); } //Use the magic of reflection to call newer APIs even though we're referencing //and older assembly System.Reflection.MethodInfo mi = _resSvc.GetType().GetMethod("GetResourceContents"); MgStringCollection result = (MgStringCollection)mi.Invoke(_resSvc, new object[] { ids, null }); int rcount = ids.GetCount(); for (int i = 0; i < rcount; i++) { var resId = ids.GetItem(i); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(result.GetItem(i)))) { var resType = ResourceIdentifier.GetResourceTypeAsString(resId); IResource r = ObjectFactory.Deserialize(resType, ms); r.ResourceID = resId; resources.Add(resId, r); } } } else { //TODO: Maybe use a ThreadPool in conjunction with cloned connections? Trace.TraceInformation("[GetResources]: Using non-optimal code path provided by pre-2.2 Resource Service APIs"); foreach (var rid in resourceIds) { resources.Add(rid, this.Parent.ResourceService.GetResource(rid)); } } return(resources); }
Dictionary<string, IResource> IGetResourceContents.Execute(IEnumerable<string> resourceIds) { //There is an implicit assumption here that all resource ids check out and that //there is no duplicates var resources = new Dictionary<string, IResource>(); if (this.Parent.SiteVersion >= new Version(2, 2)) { Trace.TraceInformation("[GetResources]: Using optimal code path provided by 2.2 Resource Service APIs"); MgStringCollection ids = new MgStringCollection(); foreach (var rid in resourceIds) { ids.Add(rid); } //Use the magic of reflection to call newer APIs even though we're referencing //and older assembly System.Reflection.MethodInfo mi = _resSvc.GetType().GetMethod("GetResourceContents"); MgStringCollection result = (MgStringCollection)mi.Invoke(_resSvc, new object[] { ids, null }); int rcount = ids.GetCount(); for (int i = 0; i < rcount; i++) { var resId = ids.GetItem(i); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(result.GetItem(i)))) { ResourceTypes resType = ResourceIdentifier.GetResourceType(resId); IResource r = ResourceTypeRegistry.Deserialize(resType, ms); r.CurrentConnection = this.Parent; r.ResourceID = resId; resources.Add(resId, r); } } } else { //TODO: Maybe use a ThreadPool in conjunction with cloned connections? Trace.TraceInformation("[GetResources]: Using non-optimal code path provided by pre-2.2 Resource Service APIs"); foreach (var rid in resourceIds) { resources.Add(rid, this.Parent.ResourceService.GetResource(rid)); } } return resources; }
private void button1_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); MgResourceIdentifier fsId = new MgResourceIdentifier(txtFeatureSource.Text); MgStringCollection schemas = featSvc.GetSchemas(fsId); string[] values = new string[schemas.GetCount()]; for (int i = 0; i < schemas.GetCount(); i++) { values[i] = schemas.GetItem(i); } MessageBox.Show(string.Join(Environment.NewLine, values), "Schemas found"); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } }
/// <summary> /// Node GetCSList returns an external txt file that Contains strings with CS's names /// </summary> /// <param name="Folder_Path">Directory path to save TXT file</param> /// <param name="selection">If = true, export all CS in Library, if false - only Users collection</param> public static string GetCSList(string Folder_Path, bool selection) { StringBuilder sb = new StringBuilder(); var guid = Guid.NewGuid(); string writePath = $@"{Folder_Path}\{guid}CS_List.txt"; MgCoordinateSystemFactory coordSysFactory = new MgCoordinateSystemFactory(); MgCoordinateSystemCatalog csCatalog = coordSysFactory.GetCatalog(); MgCoordinateSystemDictionary csDict = csCatalog.GetCoordinateSystemDictionary(); MgCoordinateSystemEnum csDictEnum = csDict.GetEnum(); int csCount = csDict.GetSize(); MgStringCollection csNames = csDictEnum.NextName(csCount); string csName = null; MgCoordinateSystem cs = null; bool csProtect; for (int i = 0; i < csCount; i++) { csName = csNames.GetItem(i); cs = csDict.GetCoordinateSystem(csName); csProtect = cs.IsProtected(); if (csProtect == selection) { sb.AppendLine(csName.ToString()); } } using (StreamWriter export_file = new StreamWriter(writePath, true, Encoding.UTF8)) { export_file.Write(sb.ToString()); } return(writePath); }
public void StringCollection() { StringCollection strColl = new StringCollection(); strColl.Add("string1"); strColl.Add("string2"); strColl.Add("string3"); strColl.Add("string3"); MgStringCollection coll1 = new MgStringCollection(); coll1.Add("Hello"); MgStringCollection coll2 = new MgStringCollection(strColl); Assert.AreEqual(4, coll2.GetCount()); StringCollection coll3 = coll2; Assert.AreEqual(4, coll3.Count); for (int i = 0; i < 4; i++) { Assert.AreEqual(strColl[i], coll2.GetItem(i)); Assert.AreEqual(strColl[i], coll3[i]); } }
public TreeNode[] CreateNodes() { List<TreeNode> topLevelNodes = new List<TreeNode>(); var scale = _map.ViewScale; if (scale < 10.0) return topLevelNodes.ToArray(); var nodesById = new Dictionary<string, TreeNode>(); var groupsById = new Dictionary<string, TreeNode>(); var groups = _map.GetLayerGroups(); var layers = _map.GetLayers(); legendCallCount = 0; //Process groups first List<MgLayerGroup> remainingNodes = new List<MgLayerGroup>(); for (int i = 0; i < groups.GetCount(); i++) { var group = groups.GetItem(i); if (!group.GetDisplayInLegend()) continue; //Add ones without parents first. Queue up child groups if (group.Group != null) { remainingNodes.Add(group); } else { var node = CreateGroupNode(group); topLevelNodes.Add(node); nodesById.Add(group.GetObjectId(), node); groupsById.Add(group.GetObjectId(), node); } } //Process child groups while (remainingNodes.Count > 0) { List<MgLayerGroup> toRemove = new List<MgLayerGroup>(); //Establish parent-child relationship for any child groups here for (int j = 0; j < remainingNodes.Count; j++) { var parentId = remainingNodes[j].Group.GetObjectId(); if (nodesById.ContainsKey(parentId)) { MgLayerGroup grp = remainingNodes[j]; var node = CreateGroupNode(grp); nodesById[parentId].Nodes.Add(node); //Got to add this group node too, otherwise we could infinite //loop looking for a parent that's not registered nodesById.Add(grp.GetObjectId(), node); groupsById.Add(grp.GetObjectId(), node); toRemove.Add(grp); } } //Whittle down this list if (toRemove.Count > 0) { foreach (var g in toRemove) { remainingNodes.Remove(g); } } } //Collect all resource contents in a batch MgStringCollection layerIds = new MgStringCollection(); //Also collect the layer metadata nodes to create or update var layerMetaNodesToUpdate = new Dictionary<string, MgLayerBase>(); //Now process layers. Layers without metadata nodes or without layer definition content //are added to the list int layerCount = layers.GetCount(); for (int i = 0; i < layerCount; i++) { var lyr = layers.GetItem(i); bool display = lyr.DisplayInLegend; bool visible = _provider.IsLayerPotentiallyVisibleAtScale(lyr, false); if (!display) continue; if (!visible) continue; var lyrObjId = lyr.GetObjectId(); if (_layers.ContainsKey(lyrObjId)) { if (string.IsNullOrEmpty(_layers[lyrObjId].LayerDefinitionContent)) { var ldfId = lyr.LayerDefinition; var ldfIdStr = ldfId.ToString(); layerIds.Add(ldfIdStr); layerMetaNodesToUpdate[ldfIdStr] = lyr; } } else { var ldfId = lyr.LayerDefinition; var ldfIdStr = ldfId.ToString(); layerIds.Add(ldfIdStr); layerMetaNodesToUpdate[ldfIdStr] = lyr; } } int layerIdCount = layerIds.GetCount(); if (layerIdCount > 0) { int added = 0; int updated = 0; //Fetch the contents and create/update the required layer metadata nodes MgStringCollection layerContents = _resSvc.GetResourceContents(layerIds, null); for (int i = 0; i < layerIdCount; i++) { string lid = layerIds.GetItem(i); var lyr = layerMetaNodesToUpdate[lid]; var objId = lyr.GetObjectId(); LayerNodeMetadata meta = null; if (_layers.ContainsKey(objId)) { meta = _layers[objId]; updated++; } else { meta = new LayerNodeMetadata(lyr, lyr.Selectable); _layers[objId] = meta; added++; } meta.LayerDefinitionContent = layerContents.GetItem(i); } Trace.TraceInformation("CreateNodes: {0} layer contents added, {1} layer contents updated", added, updated); //NOXLATE } //Now create our layer nodes List<MgLayerBase> remainingLayers = new List<MgLayerBase>(); //NOTE: We're taking a page out of the Fusion playbook of reverse iterating the layer //collection and prepending the nodes, as this control suffered the same problem as the //Legend widget in Fusion. Doing it this way eliminates the need for doing an extra pass to fix //the layer/group ordering, which may make an impact on really chunky maps. for (int i = layerCount - 1; i >= 0; i--) { var layer = layers.GetItem(i); bool display = layer.DisplayInLegend; bool visible = _provider.IsLayerPotentiallyVisibleAtScale(layer, false); if (!display) continue; if (!visible) continue; //Add ones without parents first. if (layer.Group != null) { remainingLayers.Add(layer); } else { var node = CreateLayerNode(layer); if (node != null) { topLevelNodes.Insert(0, node); nodesById.Add(layer.GetObjectId(), node); if (layer.ExpandInLegend) node.Expand(); } } } while (remainingLayers.Count > 0) { List<MgLayerBase> toRemove = new List<MgLayerBase>(); for (int j = remainingLayers.Count - 1; j >= 0; j--) { var parentGroup = remainingLayers[j].Group; var parentId = parentGroup.GetObjectId(); if (nodesById.ContainsKey(parentId)) { var node = CreateLayerNode(remainingLayers[j]); if (node != null) { nodesById[parentId].Nodes.Insert(0, node); if (remainingLayers[j].ExpandInLegend) node.Expand(); } toRemove.Add(remainingLayers[j]); } else { if (!parentGroup.GetDisplayInLegend()) toRemove.Add(remainingLayers[j]); } } //Whittle down this list if (toRemove.Count > 0) { foreach (var g in toRemove) { remainingLayers.Remove(g); } } } //Now expand any relevant groups for (int i = 0; i < groups.GetCount(); i++) { var group = groups.GetItem(i); if (group.ExpandInLegend) { var groupId = group.GetObjectId(); if (nodesById.ContainsKey(groupId)) { nodesById[groupId].Expand(); } } } Trace.TraceInformation("{0} calls made to GenerateLegendImage", legendCallCount); //NOXLATE return topLevelNodes.ToArray(); }