public void TestCase_GetResourceContents() { try { var fact = new MgdServiceFactory(); var service = (MgResourceService)fact.CreateService(MgServiceType.ResourceService); //Try to get the content using NULL arguments Assert.Throws <MgNullArgumentException>(() => service.GetResourceContents(null, null)); //Try to get the content of a resource that doesn't exist MgStringCollection resourceNotExistCol = new MgStringCollection(); resourceNotExistCol.Add(resourceNotExist.ToString()); resourceNotExistCol.Add(resourceIdentifier.ToString()); Assert.Throws <MgResourceNotFoundException>(() => service.GetResourceContents(resourceNotExistCol, null)); //Get the content of the resource that was added in TestCase_SetResource MgStringCollection resIds = new MgStringCollection(); resIds.Add(resourceIdentifier.ToString()); resIds.Add(resourceIdentifier4.ToString()); var ret = service.GetResourceContents(resIds, null); Assert.AreEqual(2, ret.GetCount()); for (int i = 0; i < ret.GetCount(); i++) { Assert.False(string.IsNullOrEmpty(ret.GetItem(i))); } } catch (MgException ex) { Assert.Fail(ex.Message); ex.Dispose(); } }
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]); } }
public void Execute(IPlatformFactory factory, ITestLogger logger) { var resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService); var renderSvc = (MgRenderingService)factory.CreateService(MgServiceType.RenderingService); var root = "../../TestData/TileService/"; Utils.LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs"); Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf"); Utils.LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf"); Utils.LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs"); Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf"); Utils.LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf"); Utils.LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs"); Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf"); Utils.LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf"); Utils.LoadResource(resSvc, "Library://UnitTests/Maps/BaseMap.MapDefinition", root + "UT_BaseMap.mdf"); var mdfId = new MgResourceIdentifier("Library://UnitTests/Maps/BaseMap.MapDefinition"); //This is a sample request from the AJAX viewer. It selected 7 features. It should do the same here. var dpi = 96; var width = 773; var height = 696; var scale = 4345.697945713148; var x = -87.72117757411266; var y = 43.7527161153258; var wkt = "POLYGON((-87.72250482778884 43.75497812742761, -87.72134799968197 43.75497812742761, -87.72134799968197 43.75358373640595, -87.72250482778884 43.75358373640595, -87.72250482778884 43.75497812742761))"; var map = (MgMap)factory.CreateMap(mdfId, mdfId.Name, width, height, x, y, scale, dpi); var wktRw = new MgWktReaderWriter(); var geom = wktRw.Read(wkt); var layerNames = new MgStringCollection(); layerNames.Add("Parcels"); var result = renderSvc.QueryFeatures(map, layerNames, geom, MgFeatureSpatialOperations.Intersects, -1); var sel = result.GetSelection(); sel.SetMap(map); var total = 0; var selLayers = sel.GetLayers(); foreach (var sl in selLayers) { total += sel.GetSelectedFeaturesCount(sl, sl.FeatureClassName); } Assert.AreEqual(7, total); }
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; }
public static MgStringCollection StringToMgStringCollection(string str) { try { MgStringCollection coll = new MgStringCollection(); string[] tokens = str.Split(','); foreach (var token in tokens) { coll.Add(token); } return(coll); } catch (MgException ex) { throw new UnitTestException(string.Format("Exception from MapGuide:\n{0}", ex.GetDetails())); } }
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 override FeatureSchema DescribeFeatureSourcePartial(string resourceID, string schema, string[] classNames) { MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService; MgStringCollection names = new MgStringCollection(); foreach (var clsName in classNames) { names.Add(clsName); } string xml = fes.DescribeSchemaAsXml(new MgResourceIdentifier(resourceID), schema, names); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)); LogMethodCall("MgFeatureService::DescribeSchemaAsXml", true, resourceID, schema, "{" + string.Join(",", classNames) + "}"); return new FeatureSourceDescription(ms).Schemas[0]; }
public override string QueryMapFeatures(RuntimeMap rtMap, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions) { string runtimeMapName = rtMap.Name; MgRenderingService rs = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService; MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService; MgMap map = new MgMap(); string mapname = runtimeMapName.IndexOf(":") > 0 ? new ResourceIdentifier(runtimeMapName).Path : runtimeMapName; map.Open(res, mapname); MgWktReaderWriter r = new MgWktReaderWriter(); MgStringCollection layerNames = null; string featureFilter = ""; int layerAttributeFilter = 0; int op = MgFeatureSpatialOperations.Intersects; if (selectionVariant == "TOUCHES") op = MgFeatureSpatialOperations.Touches; else if (selectionVariant == "INTERSECTS") op = MgFeatureSpatialOperations.Intersects; else if (selectionVariant == "WITHIN") op = MgFeatureSpatialOperations.Within; else if (selectionVariant == "ENVELOPEINTERSECTS") op = MgFeatureSpatialOperations.EnvelopeIntersects; else throw new ArgumentException("Unknown or unsupported selection variant: " + selectionVariant); if (extraOptions != null) { if (!string.IsNullOrEmpty(extraOptions.FeatureFilter)) featureFilter = extraOptions.FeatureFilter; if (extraOptions.LayerNames != null && extraOptions.LayerNames.Length > 0) { layerNames = new MgStringCollection(); foreach (var name in extraOptions.LayerNames) layerNames.Add(name); } layerAttributeFilter = (int)extraOptions.LayerAttributeFilter; } MgFeatureInformation info = rs.QueryFeatures(map, layerNames, r.Read(wkt), op, featureFilter, maxFeatures, layerAttributeFilter); string xml = ""; GetByteReaderMethod fetch = () => { return info.ToXml(); }; using (var sr = new StreamReader(new MgReadOnlyStream(fetch))) { xml = sr.ReadToEnd(); } //We only want the FeatureSet element var doc = new System.Xml.XmlDocument(); doc.LoadXml(xml); xml = doc.DocumentElement["FeatureSet"].OuterXml; MgSelection sel = new MgSelection(map, xml); sel.Save(res, mapname); LogMethodCall("QueryMapFeatures", true, runtimeMapName, wkt, persist, selectionVariant, extraOptions == null ? "null" : "QueryMapOptions"); return xml; }
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(); }
public string QueryMapFeatures(RuntimeMap rtMap, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions) { var impl = rtMap as LocalRuntimeMap; if (impl == null) throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME var rs = GetRenderingService(); var res = GetResourceService(); var map = impl.GetWrappedInstance(); MgWktReaderWriter r = new MgWktReaderWriter(); MgStringCollection layerNames = null; string featureFilter = ""; int layerAttributeFilter = 0; int op = MgFeatureSpatialOperations.Intersects; if (selectionVariant == "TOUCHES") op = MgFeatureSpatialOperations.Touches; else if (selectionVariant == "INTERSECTS") op = MgFeatureSpatialOperations.Intersects; else if (selectionVariant == "WITHIN") op = MgFeatureSpatialOperations.Within; else if (selectionVariant == "ENVELOPEINTERSECTS") op = MgFeatureSpatialOperations.EnvelopeIntersects; else throw new ArgumentException("Unknown or unsupported selection variant: " + selectionVariant); if (extraOptions != null) { if (!string.IsNullOrEmpty(extraOptions.FeatureFilter)) featureFilter = extraOptions.FeatureFilter; if (extraOptions.LayerNames != null && extraOptions.LayerNames.Length > 0) { layerNames = new MgStringCollection(); foreach (var name in extraOptions.LayerNames) layerNames.Add(name); } layerAttributeFilter = (int)extraOptions.LayerAttributeFilter; } MgdFeatureInformation info = rs.QueryFeatures(map, layerNames, r.Read(wkt), op, featureFilter, maxFeatures, layerAttributeFilter); string xml = ""; GetByteReaderMethod fetch = () => { return info.ToXml(); }; using (var sr = new StreamReader(new MgReadOnlyStream(fetch))) { xml = sr.ReadToEnd(); } impl.Selection.LoadXml(xml); return xml; }
public void TestCase_GetResourceContents() { try { var fact = new MgdServiceFactory(); var service = (MgResourceService)fact.CreateService(MgServiceType.ResourceService); //Try to get the content using NULL arguments Assert.Throws<MgNullArgumentException>(() => service.GetResourceContents(null, null)); //Try to get the content of a resource that doesn't exist MgStringCollection resourceNotExistCol = new MgStringCollection(); resourceNotExistCol.Add(resourceNotExist.ToString()); resourceNotExistCol.Add(resourceIdentifier.ToString()); Assert.Throws<MgResourceNotFoundException>(() => service.GetResourceContents(resourceNotExistCol, null)); //Get the content of the resource that was added in TestCase_SetResource MgStringCollection resIds = new MgStringCollection(); resIds.Add(resourceIdentifier.ToString()); resIds.Add(resourceIdentifier4.ToString()); var ret = service.GetResourceContents(resIds, null); Assert.AreEqual(2, ret.GetCount()); for (int i = 0; i < ret.GetCount(); i++) { Assert.False(string.IsNullOrEmpty(ret.GetItem(i))); } } catch (MgException ex) { Assert.Fail(ex.Message); ex.Dispose(); } }