public override TestResult Execute(int paramSetId) { try { var param = new NameValueCollection(); _unitTestVm.ReadParameterValue(paramSetId, "USER", param); _unitTestVm.ReadParameterValue(paramSetId, "LOGIN", param); _unitTestVm.ReadParameterValue(paramSetId, "PASSWORD", param); var userInfo = new MgUserInformation(); userInfo.SetMgUsernamePassword(param["LOGIN"], param["PASSWORD"]); userInfo.SetLocale("en"); var site = new MgSite(); site.Open(userInfo); MgStringCollection roles = site.EnumerateRoles(param["USER"]); site.Close(); return(new TestResult(CommonUtility.MgStringCollectionToString(roles), "text/plain")); } catch (MgException ex) { return(TestResult.FromMgException(ex)); } }
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 override TestResult Execute(int paramSetId) { try { NameValueCollection param = new NameValueCollection(); _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param); _unitTestVm.ReadParameterValue(paramSetId, "SCHEMANAME", param); MgResourceIdentifier resId = null; if (param["RESOURCEID"] != null) { resId = new MgResourceIdentifier(param["RESOURCEID"]); } MgStringCollection result = _featureService.GetClasses(resId, param["SCHEMANAME"]); return(new TestResult(CommonUtility.MgStringCollectionToString(result), "text/plain")); } catch (MgException ex) { return(TestResult.FromMgException(ex)); } catch (Exception ex) { return(TestResult.FromException(ex)); } }
/// <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 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 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 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 }, }); }
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); }
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)))) { 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; }
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); }
public override TestResult Execute(int paramSetId) { try { var param = new NameValueCollection(); _unitTestVm.ReadParameterValue(paramSetId, "GROUPS", param); MgStringCollection groups = CommonUtility.StringToMgStringCollection(param["GROUPS"]); _site.DeleteGroups(groups); return(new TestResult()); } catch (MgException ex) { return(TestResult.FromMgException(ex)); } }
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 override TestResult Execute(int paramSetId) { try { var param = new NameValueCollection(); _unitTestVm.ReadParameterValue(paramSetId, "USER", param); _unitTestVm.ReadParameterValue(paramSetId, "GROUP", param); MgStringCollection roles = _site.EnumerateRoles(param["USER"], param["GROUP"]); return(new TestResult(CommonUtility.MgStringCollectionToString(roles), "text/plain")); } catch (MgException ex) { return(TestResult.FromMgException(ex)); } }
public override TestResult Execute(int paramSetId) { try { var param = new NameValueCollection(); _unitTestVm.ReadParameterValue(paramSetId, "ROLES", param); _unitTestVm.ReadParameterValue(paramSetId, "USERS", param); MgStringCollection roles = CommonUtility.StringToMgStringCollection(param["ROLES"]); MgStringCollection users = CommonUtility.StringToMgStringCollection(param["USERS"]); _site.RevokeRoleMembershipsFromUsers(roles, users); return(new TestResult()); } catch (MgException ex) { return(TestResult.FromMgException(ex)); } }
public override TestResult Execute(int paramSetId) { try { NameValueCollection param = new NameValueCollection(); _unitTestVm.ReadParameterValue(paramSetId, "PROVIDER", param); _unitTestVm.ReadParameterValue(paramSetId, "PROPERTY", param); _unitTestVm.ReadParameterValue(paramSetId, "CONNECTIONSTRING", param); MgStringCollection result = _featureService.GetConnectionPropertyValues(param["PROVIDER"], param["PROPERTY"], param["CONNECTIONSTRING"]); return(new TestResult(CommonUtility.MgStringCollectionToString(result), "text/plain")); } catch (MgException ex) { return(TestResult.FromMgException(ex)); } catch (Exception ex) { return(TestResult.FromException(ex)); } }
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"); } }
public override TestResult Execute(int paramSetId) { try { var param = new NameValueCollection(); _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param); _unitTestVm.ReadParameterValue(paramSetId, "SECTION", param); MgResourceIdentifier resId = null; if (param["RESOURCEID"] != null) { resId = new MgResourceIdentifier(param["RESOURCEID"]); } MgStringCollection coll = _drawingService.EnumerateLayers(resId, param["SECTION"] ?? ""); MgByteReader reader = coll.ToXml(); return(TestResult.FromByteReader(reader)); } catch (MgException ex) { return(TestResult.FromMgException(ex)); } }
/// <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 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 override MgQueryMapFeaturesResult QueryMapFeatures(MgQueryRequestType queryType, MgStringCollection layerNames, MgGeometry filterGeom, int selectionVariant, string featureFilter, int maxFeatures, int layerAttributeFilter) { var fi = _renderSvc.QueryFeatures(_implMap, layerNames, filterGeom, selectionVariant, featureFilter, maxFeatures, layerAttributeFilter); try { if (queryType == MgQueryRequestType.Tooltip) { return(MakeTooltip(fi.GetTooltip())); } else { return(MakeSelectionResult(fi.GetSelection())); } } finally { fi.Dispose(); } }
/// <summary> /// /// </summary> /// <param name="queryType"></param> /// <param name="layerNames"></param> /// <param name="filterGeom"></param> /// <param name="selectionVariant"></param> /// <param name="featureFilter"></param> /// <param name="maxFeatures"></param> /// <param name="layerAttributeFilter"></param> /// <returns></returns> public abstract MgQueryMapFeaturesResult QueryMapFeatures(MgQueryRequestType queryType, MgStringCollection layerNames, MgGeometry filterGeom, int selectionVariant, string featureFilter, int maxFeatures, int layerAttributeFilter);
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 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 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 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 MgQueryMapFeaturesResult QueryMapFeatures(MgQueryRequestType queryType, MgStringCollection layerNames, MgGeometry filterGeom, int selectionVariant, string featureFilter, int maxFeatures, int layerAttributeFilter) { var fi = _renderSvc.QueryFeatures(_implMap, layerNames, filterGeom, selectionVariant, featureFilter, maxFeatures, layerAttributeFilter); try { if (queryType == MgQueryRequestType.Tooltip) return MakeTooltip(fi.GetTooltip()); else return MakeSelectionResult(fi.GetSelection()); } finally { fi.Dispose(); } }