示例#1
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                var param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }

                _resourceService.DeleteResource(resId);

                return(TestResult.FromByteReader(null));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#2
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                var param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);
                _unitTestVm.ReadParameterValue(paramSetId, "OWNER", param);
                _unitTestVm.ReadParameterValue(paramSetId, "INCLUDEDESCENDANTS", param);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }

                _resourceService.ChangeResourceOwner(resId, param["OWNER"], (param["INCLUDEDESCENDANTS"] == "1"));

                return(TestResult.FromByteReader(null));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#3
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                var param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "SOURCE", param);
                _unitTestVm.ReadParameterValue(paramSetId, "DESTINATION", param);

                MgResourceIdentifier srcId = null;
                if (param["SOURCE"] != null)
                {
                    srcId = new MgResourceIdentifier(param["SOURCE"]);
                }

                MgResourceIdentifier dstId = null;
                if (param["DESTINATION"] != null)
                {
                    dstId = new MgResourceIdentifier(param["DESTINATION"]);
                }

                _resourceService.CopyResource(srcId, dstId, false);

                return(TestResult.FromByteReader(null));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#4
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                var param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);
                _unitTestVm.ReadParameterValue(paramSetId, "CONTENT", param, true);
                _unitTestVm.ReadParameterValue(paramSetId, "HEADER", param, true);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }

                MgByteReader content = CommonUtility.GetByteReaderFromPath(param["CONTENT"]);
                MgByteReader header  = CommonUtility.GetByteReaderFromPath(param["HEADER"]);

                _resourceService.SetResource(resId, content, header);

                return(TestResult.FromByteReader(null));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#5
0
    //----------------------------------------------------------------------------------------
    // �� �ܣ� ��Mapguide���ص�����ת��ΪKML
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�2007.05.#
    //
    //-----------------------------------------------------------------------------------------
    public String createMuniMarker()
    {
        StringBuilder outString = new StringBuilder();
        MgGeometryFactory geoFactory = new MgGeometryFactory();
        outString.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
        MgResourceIdentifier resId = new MgResourceIdentifier("Library://MgTutorial/Data/WheatonMunicipalities.FeatureSource");
        MgFeatureReader featureReader = featureService.SelectFeatures(resId, "WheatonMunicipalities", null);

        outString.Append("<markers>");
        MgAgfReaderWriter geoReader = new MgAgfReaderWriter();
        while (featureReader.ReadNext())
        {
            String muniName = featureReader.GetString("MUNINAME");
            MgByteReader byteReader = featureReader.GetGeometry("Geometry");
            MgGeometry geo = geoReader.Read(byteReader);
            MgPoint pt = geo.GetCentroid();
            double x = pt.GetCoordinate().GetX();
            double y = pt.GetCoordinate().GetY();
            outString.Append("<marker lat=\"" + y + "\" lng=\"" + x + "\" info=\"" + muniName + "\" />");
        }
        featureReader.Close();
        outString.Append("</markers>");

        return outString.ToString();
    }
示例#6
0
        public void CreateBufferFeatureSource(MgFeatureService featureService, String wkt, MgResourceIdentifier bufferFeatureResId)
        {
            MgClassDefinition bufferClass = new MgClassDefinition();
            bufferClass.SetName("BufferClass");
            MgPropertyDefinitionCollection properties = bufferClass.GetProperties();

            MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID");
            idProperty.SetDataType(MgPropertyType.Int32);
            idProperty.SetReadOnly(true);
            idProperty.SetNullable(false);
            idProperty.SetAutoGeneration(true);
            properties.Add(idProperty);

            MgGeometricPropertyDefinition polygonProperty = new MgGeometricPropertyDefinition("BufferGeometry");
            polygonProperty.SetGeometryTypes(MgFeatureGeometricType.Surface);
            polygonProperty.SetHasElevation(false);
            polygonProperty.SetHasMeasure(false);
            polygonProperty.SetReadOnly(false);
            polygonProperty.SetSpatialContextAssociation("defaultSrs");
            properties.Add(polygonProperty);

            MgPropertyDefinitionCollection idProperties = bufferClass.GetIdentityProperties();
            idProperties.Add(idProperty);

            bufferClass.SetDefaultGeometryPropertyName("BufferGeometry");

            MgFeatureSchema bufferSchema = new MgFeatureSchema("BufferLayerSchema", "temporary schema to hold a buffer");
            bufferSchema.GetClasses().Add(bufferClass);

            MgCreateSdfParams sdfParams = new MgCreateSdfParams("defaultSrs", wkt, bufferSchema);

            featureService.CreateFeatureSource(bufferFeatureResId, sdfParams);
        }
示例#7
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                var param = new NameValueCollection();

                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);
                _unitTestVm.ReadParameterValue(paramSetId, "TYPE", param);
                _unitTestVm.ReadParameterValue(paramSetId, "DEPTH", param);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }
                MgByteReader byteReader = _resourceService.EnumerateResources(resId, Convert.ToInt32(param["DEPTH"]), param["TYPE"] ?? "");

                return(TestResult.FromByteReader(byteReader, "GETRESOURCEDATA"));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#8
0
    public bool ClearSpatialFilter()
    {
        bool result = true;
        MgUserInformation userInfo = new MgUserInformation(Request["SESSION"]);
        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(userInfo);

        MgResourceIdentifier sdfResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.FeatureSource");

        MgResourceService resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService;
        MgFeatureService featureService = siteConnection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
        MgMap map = new MgMap();
        map.Open(resourceService, Request["MAPNAME"]);

        MgFeatureCommandCollection updateCommands = new MgFeatureCommandCollection();

        MgLayer layer = null;
        MgLayerCollection layers = map.GetLayers();
        if (layers.Contains("_QuerySpatialFilter"))
        {
            layer = (MgLayer)layers.GetItem("_QuerySpatialFilter");
            updateCommands.Add(new MgDeleteFeatures("Filter", "ID > 0"));
            featureService.UpdateFeatures(sdfResId, updateCommands, false);
            layers.Remove(layer);
            map.Save(resourceService);
        }

        return result;
    }
示例#9
0
        public void TestEnd()
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdResourceService   service = (MgdResourceService)fact.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier mapres1 = new MgResourceIdentifier("Library://UnitTests/Data/Shuttle.DrawingSource");
                service.DeleteResource(mapres1);

                if (service.ResourceExists(resourceIdentifier))
                {
                    service.DeleteResource(resourceIdentifier);
                }

                if (service.ResourceExists(resourceIdentifier2))
                {
                    service.DeleteResource(resourceIdentifier2);
                }

                if (service.ResourceExists(resourceIdentifier3))
                {
                    service.DeleteResource(resourceIdentifier3);
                }

                if (service.ResourceExists(resourceIdentifier4))
                {
                    service.DeleteResource(resourceIdentifier4);
                }
            }
            catch (MgException ex)
            {
                ex.Dispose();
            }
        }
示例#10
0
 public override void Invoke()
 {
     var provider = this.Viewer.GetProvider();
     var mdfId = new MgResourceIdentifier(this.MapDefinition);
     var map = provider.CreateMap(mdfId, mdfId.GetName());
     provider.LoadMap(map);
 }
示例#11
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);

                MgResourceIdentifier mdfId = new MgResourceIdentifier(txtMapDefinition.Text);
                var sw = new Stopwatch();
                sw.Start();
                MgdMap map = new MgdMap(mdfId);
                sw.Stop();
                Trace.TraceInformation("Runtime map created in {0}ms", sw.ElapsedMilliseconds);

                map.SetViewScale(Convert.ToDouble(txtScale.Text));
                sw.Reset();
                sw.Start();
                MgByteReader response = renSvc.RenderTile(map, txtBaseGroup.Text, Convert.ToInt32(txtCol.Text), Convert.ToInt32(txtRow.Text));
                sw.Stop();
                Trace.TraceInformation("RenderTile executed in {0}ms", sw.ElapsedMilliseconds);
                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
示例#12
0
        internal NameValueCollection GetPropertyMappings(MgLayerBase layer)
        {
            MgResourceIdentifier resId = layer.GetLayerDefinition();
            string resIdStr            = resId.ToString();

            if (_propertyMappings.ContainsKey(resIdStr))
            {
                return(_propertyMappings[resIdStr]);
            }

            MgByteReader content = _resSvc.GetResourceContent(resId);
            XmlDocument  doc     = new XmlDocument();
            string       xml     = content.ToString();

            doc.LoadXml(xml);

            XmlNodeList propMaps = doc.GetElementsByTagName("PropertyMapping"); //NOXLATE

            if (propMaps.Count > 0)
            {
                NameValueCollection propertyMappings = new NameValueCollection();
                foreach (XmlNode pm in propMaps)
                {
                    propertyMappings[pm["Name"].InnerText] = pm["Value"].InnerText; //NOXLATE
                }
                _propertyMappings[resIdStr] = propertyMappings;
            }
            else
            {
                //NULL is a legit dictionary value
                _propertyMappings[resIdStr] = null;
            }
            return(_propertyMappings[resIdStr]);
        }
        // GET: Home
        public ActionResult Index()
        {
            MgUserInformation user = new MgUserInformation("Anonymous", "");
            MgSiteConnection  conn = new MgSiteConnection();

            conn.Open(user);

            MgResourceService resSvc = (MgResourceService)conn.CreateService(MgServiceType.ResourceService);

            var vm = new HomeViewModel()
            {
                HasSampleResources = true,
                AjaxLayout         = AJAX_LAYOUT,
                FlexLayout         = FLEX_LAYOUT
            };

            MgResourceIdentifier mdfId   = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
            MgResourceIdentifier sample1 = new MgResourceIdentifier(vm.AjaxLayout);
            MgResourceIdentifier sample2 = new MgResourceIdentifier(vm.FlexLayout);

            vm.HasSampleResources = resSvc.ResourceExists(mdfId) &&
                                    resSvc.ResourceExists(sample1) &&
                                    resSvc.ResourceExists(sample2);

            return(View(vm));
        }
示例#14
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);

                MgResourceIdentifier mdfId = new MgResourceIdentifier(txtMapDefinition.Text);
                var sw = new Stopwatch();
                sw.Start();
                MgdMap map = new MgdMap(mdfId);
                sw.Stop();
                Trace.TraceInformation("Runtime map created in {0}ms", sw.ElapsedMilliseconds);

                map.SetViewScale(Convert.ToDouble(txtScale.Text));
                sw.Reset();
                sw.Start();
                MgByteReader response = renSvc.RenderTile(map, txtBaseGroup.Text, Convert.ToInt32(txtCol.Text), Convert.ToInt32(txtRow.Text));
                sw.Stop();
                Trace.TraceInformation("RenderTile executed in {0}ms", sw.ElapsedMilliseconds);
                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
示例#15
0
        internal void DeleteLayer(RedlineLayer layer)
        {
            var regId = GetRegistryFeatureSource();
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            MgDeleteFeatures           delete   = new MgDeleteFeatures("Default:MarkupRegistry", "ResourceId = '" + layer.FeatureSource + "'");

            commands.Add(delete);

            MgPropertyCollection results      = _featSvc.UpdateFeatures(regId, commands, false);
            MgInt32Property      deleteResult = results.GetItem(0) as MgInt32Property;

            if (deleteResult != null && deleteResult.GetValue() > 0)
            {
                var ldfId = new MgResourceIdentifier(layer.LayerDefinition);
                var fsId  = new MgResourceIdentifier(layer.FeatureSource);

                if (_resSvc.ResourceExists(ldfId))
                {
                    _resSvc.DeleteResource(ldfId);
                }

                if (_resSvc.ResourceExists(fsId))
                {
                    _resSvc.DeleteResource(fsId);
                }
            }
        }
示例#16
0
        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));
            }
        }
示例#17
0
 public static void SetResourceFromXml(HtzMgHelper helper, MgResourceIdentifier resourceId, XmlDocument doc)
 {
     byte[] layerDef = new UTF8Encoding().GetBytes(doc.InnerXml);
     MgByteSource byteSource = new MgByteSource(layerDef, layerDef.Length);
     byteSource.SetMimeType("text/xml");
     helper.ResourceService.SetResource(resourceId, byteSource.GetReader(), null);
 }
示例#18
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                NameValueCollection param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);
                _unitTestVm.ReadParameterValue(paramSetId, "LONGTRANSACTIONNAME", param);
                _unitTestVm.ReadParameterValue(paramSetId, "CREATESESSION", param);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }

                if (param["CREATESESSION"] == "TRUE")
                {
                    string sessionId = _creator.CreateSession();
                    _apply.SetSessionId(sessionId);
                }

                bool bRes = _featureService.SetLongTransaction(resId, param["LONGTRANSACTIONNAME"]);

                return(new TestResult(CommonUtility.BooleanToString(bRes), "text/plain"));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#19
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                NameValueCollection param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);

                bool bRes = false;
                MgResourceIdentifier resId = null;
                if (!string.IsNullOrEmpty(param["RESOURCEID"]))
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                    bRes  = _featureService.TestConnection(resId);
                }
                else
                {
                    _unitTestVm.ReadParameterValue(paramSetId, "PROVIDER", param);
                    _unitTestVm.ReadParameterValue(paramSetId, "CONNECTIONSTRING", param);
                    bRes = _featureService.TestConnection(param["PROVIDER"] ?? "", param["CONNECTIONSTRING"] ?? "");
                }

                return(new TestResult(CommonUtility.BooleanToString(bRes), "text/plain"));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#20
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                NameValueCollection param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);
                _unitTestVm.ReadParameterValue(paramSetId, "SQL", param);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }

                MgSqlDataReader reader     = _featureService.ExecuteSqlQuery(resId, param["SQL"]);
                MgByteReader    byteReader = reader.ToXml();
                reader.Close();
                return(TestResult.FromByteReader(byteReader));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#21
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                NameValueCollection param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);
                _unitTestVm.ReadParameterValue(paramSetId, "ACTIVEONLY", param);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }

                MgLongTransactionReader reader     = _featureService.GetLongTransactions(resId, (param["ACTIVEONLY"] == "1"));
                MgByteReader            byteReader = reader.ToXml();
                reader.Close();
                return(TestResult.FromByteReader(byteReader));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#22
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                NameValueCollection param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);
                _unitTestVm.ReadParameterValue(paramSetId, "SCHEMA", param);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }

                string result = _featureService.DescribeSchemaAsXml(resId, param["SCHEMA"]);

                return(new TestResult(result, "text/xml"));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#23
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                this.CreateMapFromResource(paramSetId);

                _unitTestVm.Execute("Select ParamValue from Params WHERE ParamSet={0} AND ParamName=\"LAYERDEFINITION\"", paramSetId);
                string layerDefinition = _unitTestVm.GetString("ParamValue");

                _unitTestVm.Execute("Select ParamValue from Params WHERE ParamSet={0} AND ParamName=\"GROUPNAME\"", paramSetId);
                string groupName = _unitTestVm.GetString("ParamValue");

                var ldfId = new MgResourceIdentifier(layerDefinition);
                var layer = _creator.CreateLayer(ldfId);

                if (!string.IsNullOrEmpty(groupName))
                {
                    var groups = _map.GetLayerGroups();
                    var gidx   = groups.IndexOf(groupName);
                    if (gidx >= 0)
                    {
                        layer.SetGroup(groups.GetItem(gidx));
                    }
                }

                var layers = _map.GetLayers();
                layers.Add(layer);

                return(new TestResult(layers.GetCount().ToString(), "text/plain"));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
        }
示例#24
0
        public IEnumerable<RedlineObject> GetAllFeatures()
        {
            MgMapBase map = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();
            MgLayerBase redlineLayer = layers.GetItem(_layer.SystemName);

            MgResourceIdentifier resId = new MgResourceIdentifier(redlineLayer.GetFeatureSourceId());
            MgFeatureReader reader = null;
            try
            {
                reader = _featSvc.SelectFeatures(resId, RedlineSchemaFactory.CLASS_NAME, null);

                //HACK: Another leaky abstraction. SHP will always choose FeatId, so once again
                //use the class definition to determine the identity property name
                MgClassDefinition cls = reader.GetClassDefinition();
                MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
                MgPropertyDefinition keyProp = idProps.GetItem(0);
                string idName = keyProp.GetName();

                while (reader.ReadNext())
                {
                    int id = reader.GetInt32(idName);
                    string text = reader.IsNull(RedlineSchemaFactory.TEXT_NAME) ? string.Empty : reader.GetString(RedlineSchemaFactory.TEXT_NAME);

                    yield return new RedlineObject(id, text);
                }
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
        }
示例#25
0
        private MgByteReader Plot(MapGuideViewerInputModel input, bool useLayout, double?scale)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap            map  = new MgMap(conn);

            map.Open(input.MapName);

            MgPoint      center = map.ViewCenter;
            MgCoordinate coord  = center.Coordinate;

            MgMappingService mappingService = (MgMappingService)conn.CreateService(MgServiceType.MappingService);

            MgDwfVersion        dwfVersion = new MgDwfVersion("6.01", "1.2");
            MgPlotSpecification plotSpec   = new MgPlotSpecification(8.5f, 11f, MgPageUnitsType.Inches, 0f, 0f, 0f, 0f);

            plotSpec.SetMargins(0.5f, 0.5f, 0.5f, 0.5f);

            MgLayout layout = null;

            if (useLayout)
            {
                MgResourceIdentifier layoutRes = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
                layout = new MgLayout(layoutRes, "City of Sheboygan", MgPageUnitsType.Inches);
            }

            if (!scale.HasValue)
            {
                return(mappingService.GeneratePlot(map, plotSpec, layout, dwfVersion));
            }
            else
            {
                MgCoordinate mapCenter = map.GetViewCenter().GetCoordinate();
                return(mappingService.GeneratePlot(map, mapCenter, scale.Value, plotSpec, layout, dwfVersion));
            }
        }
示例#26
0
            public MgMapBase CreateMap(MgResourceIdentifier mapDefinition, string mapName, int width, int height, double x, double y, double scale, int dpi)
            {
                var map = new MgMap(_siteConn);

                map.Create(mapDefinition, mapName, width, height, x, y, scale, dpi);
                return(map);
            }
示例#27
0
            public MgMapBase CreateMap(MgResourceIdentifier mapDefinition)
            {
                var map = new MgMap(_siteConn);

                map.Create(mapDefinition, mapDefinition.Name);
                return(map);
            }
        // GET: Home
        public ActionResult Index()
        {
            MgUserInformation user = new MgUserInformation("Anonymous", "");
            MgSiteConnection conn = new MgSiteConnection();
            conn.Open(user);

            MgResourceService resSvc = (MgResourceService)conn.CreateService(MgServiceType.ResourceService);

            var vm = new HomeViewModel()
            {
                HasSampleResources = true,
                AjaxLayout = AJAX_LAYOUT,
                FlexLayout = FLEX_LAYOUT
            };

            MgResourceIdentifier mdfId = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
            MgResourceIdentifier sample1 = new MgResourceIdentifier(vm.AjaxLayout);
            MgResourceIdentifier sample2 = new MgResourceIdentifier(vm.FlexLayout);

            vm.HasSampleResources = resSvc.ResourceExists(mdfId) &&
                                    resSvc.ResourceExists(sample1) &&
                                    resSvc.ResourceExists(sample2);

            return View(vm);
        }
示例#29
0
        private void btnCreateFile_Click(object sender, EventArgs e)
        {
            try
            {
                var fact       = new MgdServiceFactory();
                var featureSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService);
                var param      = new MgFileFeatureSourceParams();
                param.CoordinateSystemWkt = txtCoordinateSystemWkt.Text;
                param.FileName            = txtFileName.Text;

                var schemas = featureSvc.XmlToSchema(File.ReadAllText(txtSchemaXml.Text));
                param.FeatureSchema = schemas.GetItem(0);

                param.ProviderName = txtProvider.Text;
                param.SpatialContextDescription = "Created from MgFileFeatureSourceParams";
                param.SpatialContextName        = txtCoordinateSystemName.Text;
                param.XYTolerance = double.Parse(txtXYTolerance.Text);
                param.ZTolerance  = double.Parse(txtZTolerance.Text);

                var fsId = new MgResourceIdentifier(txtResourceId.Text);

                featureSvc.CreateFeatureSource(fsId, param);
                MessageBox.Show("Success");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#30
0
        public void LoadMap(MgResourceIdentifier resId)
        {
            var map = new MgdMap(resId);

            viewer.Init(new MgDesktopMapViewerProvider(map));
            //viewer.RefreshMap();
        }
示例#31
0
        private void btnCreateFile_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                var featureSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService);
                var param = new MgFileFeatureSourceParams();
                param.CoordinateSystemWkt = txtCoordinateSystemWkt.Text;
                param.FileName = txtFileName.Text;

                var schemas = featureSvc.XmlToSchema(File.ReadAllText(txtSchemaXml.Text));
                param.FeatureSchema = schemas.GetItem(0);

                param.ProviderName = txtProvider.Text;
                param.SpatialContextDescription = "Created from MgFileFeatureSourceParams";
                param.SpatialContextName = txtCoordinateSystemName.Text;
                param.XYTolerance = double.Parse(txtXYTolerance.Text);
                param.ZTolerance = double.Parse(txtZTolerance.Text);

                var fsId = new MgResourceIdentifier(txtResourceId.Text);

                featureSvc.CreateFeatureSource(fsId, param);
                MessageBox.Show("Success");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#32
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService);
                MgFeatureQueryOptions query = new MgFeatureQueryOptions();
                string[] propNames = txtProps.Text.Split(',');
                foreach (var p in propNames)
                {
                    if (string.IsNullOrEmpty(p))
                        continue;

                    query.AddFeatureProperty(p);
                }

                foreach (Pair p in lstComputed.Items)
                {
                    query.AddComputedProperty(p.Name, p.Expr);
                }

                if (!string.IsNullOrEmpty(txtFilter.Text.Trim()))
                    query.SetFilter(txtFilter.Text.Trim());

                MgResourceIdentifier fsId = new MgResourceIdentifier(txtFeatureSource.Text);

                MgFeatureReader reader = featSvc.SelectFeatures(fsId, txtClass.Text, query);
                new ReaderResponseDialog(reader).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
        private MgByteReader Plot(MapGuideViewerInputModel input, bool useLayout, double? scale)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap map = new MgMap(conn);
            map.Open(input.MapName);

            MgPoint center = map.ViewCenter;
            MgCoordinate coord = center.Coordinate;

            MgMappingService mappingService = (MgMappingService)conn.CreateService(MgServiceType.MappingService);

            MgDwfVersion dwfVersion = new MgDwfVersion("6.01", "1.2");
            MgPlotSpecification plotSpec = new MgPlotSpecification(8.5f, 11f, MgPageUnitsType.Inches, 0f, 0f, 0f, 0f);
            plotSpec.SetMargins(0.5f, 0.5f, 0.5f, 0.5f);

            MgLayout layout = null;
            if (useLayout)
            {
                MgResourceIdentifier layoutRes = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
                layout = new MgLayout(layoutRes, "City of Sheboygan", MgPageUnitsType.Inches);
            }

            if (!scale.HasValue)
            {
                return mappingService.GeneratePlot(map, plotSpec, layout, dwfVersion);
            }
            else
            {
                MgCoordinate mapCenter = map.GetViewCenter().GetCoordinate();
                return mappingService.GeneratePlot(map, mapCenter, scale.Value, plotSpec, layout, dwfVersion);
            }
        }
示例#34
0
        private void AddRedlineLayerToMap(MgResourceIdentifier ldfId)
        {
            MgLayerGroup group  = null;
            var          layers = _map.GetLayers();
            var          groups = _map.GetLayerGroups();

            if (groups.Contains(GROUP_NAME))
            {
                group = groups.GetItem(GROUP_NAME);
            }
            else
            {
                group = new MgLayerGroup(GROUP_NAME);
                group.SetVisible(true);
                group.SetLegendLabel(Strings.RedlineLayerGroupLabel);
                group.SetDisplayInLegend(true);
                groups.Add(group);
            }

            var provider = _viewer.GetProvider();
            var newLayer = provider.CreateLayer(ldfId);

            newLayer.SetDisplayInLegend(true);
            newLayer.SetName("_" + ldfId.Name);
            newLayer.SetLegendLabel(ldfId.Name);
            newLayer.SetSelectable(true);
            newLayer.SetGroup(group);

            layers.Insert(0, newLayer);
        }
示例#35
0
        public override TestResult Execute(int paramSetId)
        {
            try
            {
                var param = new NameValueCollection();
                _unitTestVm.ReadParameterValue(paramSetId, "RESOURCEID", param);
                _unitTestVm.ReadParameterValue(paramSetId, "DATANAME", param);
                _unitTestVm.ReadParameterValue(paramSetId, "DATATYPE", param);
                _unitTestVm.ReadParameterValue(paramSetId, "DATA", param, true);

                MgResourceIdentifier resId = null;
                if (param["RESOURCEID"] != null)
                {
                    resId = new MgResourceIdentifier(param["RESOURCEID"]);
                }

                string       extension  = CommonUtility.GetExtension(param["DATANAME"]);
                string       mimeType   = CommonUtility.GetMimeType(extension);
                MgByteSource dataSource = new MgByteSource(param["DATA"]);
                dataSource.SetMimeType(mimeType);
                MgByteReader dataReader = dataSource.GetReader();

                _resourceService.SetResourceData(resId, param["DATANAME"], param["DATATYPE"], dataReader);

                return(TestResult.FromByteReader(null));
            }
            catch (MgException ex)
            {
                return(TestResult.FromMgException(ex));
            }
            catch (Exception ex)
            {
                return(TestResult.FromException(ex));
            }
        }
示例#36
0
        public void TestEnd()
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdResourceService service = (MgdResourceService)fact.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier mapres1 = new MgResourceIdentifier("Library://UnitTests/Data/Shuttle.DrawingSource");
                service.DeleteResource(mapres1);

                if (service.ResourceExists(resourceIdentifier))
                    service.DeleteResource(resourceIdentifier);

                if (service.ResourceExists(resourceIdentifier2))
                    service.DeleteResource(resourceIdentifier2);

                if (service.ResourceExists(resourceIdentifier3))
                    service.DeleteResource(resourceIdentifier3);

                if (service.ResourceExists(resourceIdentifier4))
                    service.DeleteResource(resourceIdentifier4);
            }
            catch (MgException ex)
            {
                ex.Dispose();
            }
        }
示例#37
0
        private void btnSinglePlot_Click(object sender, EventArgs e)
        {
            MgdMap map = (MgdMap)_viewer.GetMap();
            MgMapViewerProvider  provider   = _viewer.GetProvider();
            MgdMappingService    mappingSvc = (MgdMappingService)provider.CreateService(MgServiceType.MappingService);
            MgResourceIdentifier layoutId   = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");

            using (SaveFileDialog save = new SaveFileDialog())
            {
                save.Filter = "DWF Files (*.dwf)|*.dwf";
                if (save.ShowDialog() == DialogResult.OK)
                {
                    MgdDwfVersion dwfVer = new MgdDwfVersion("6.01", "1.2");

                    MgdLayout            layout   = new MgdLayout(layoutId, "City of Sheboygan", MgdPageUnitsType.Inches);
                    MgdPlotSpecification plotSpec = new MgdPlotSpecification(8.5f, 11.0f, MgdPageUnitsType.Inches, 0.5f, 0.5f, 0.5f, 0.5f);

                    MgByteReader result = mappingSvc.GeneratePlot(map, plotSpec, layout, dwfVer);
                    MgByteSink   sink   = new MgByteSink(result);
                    sink.ToFile(save.FileName);

                    MessageBox.Show("Saved to " + save.FileName);
                }
            }
        }
示例#38
0
        private void btnDisplaySpatialReference_Click(object sender, EventArgs e)
        {
            MgMapBase            map   = _viewer.GetMap();
            MgResourceIdentifier resId = map.MapDefinition;
            string mapSrs = map.GetMapSRS();

            MessageBox.Show("Map: (" + resId.ToString() + ") uses this reference system: " + Environment.NewLine + Environment.NewLine + mapSrs);
        }
示例#39
0
        private static void LoadResourceData(MgResourceService resSvc, string resIdStr, string dataName, string dataType, string path)
        {
            MgResourceIdentifier resId = new MgResourceIdentifier(resIdStr);
            MgByteSource         bs    = new MgByteSource(path);
            MgByteReader         br    = bs.GetReader();

            resSvc.SetResourceData(resId, dataName, dataType, br);
        }
示例#40
0
        private static void LoadResource(MgResourceService resSvc, string resIdStr, string path)
        {
            MgResourceIdentifier resId = new MgResourceIdentifier(resIdStr);
            MgByteSource         bs    = new MgByteSource(path);
            MgByteReader         br    = bs.GetReader();

            resSvc.SetResource(resId, br, null);
        }
示例#41
0
文件: Util.cs 项目: achilex/MgDev
        public static void ClearDataSource(MgFeatureService featSvc, MgResourceIdentifier fsId, String featureName)
        {
            MgDeleteFeatures           deleteCmd = new MgDeleteFeatures(featureName, "ID >= 0"); //NOXLATE
            MgFeatureCommandCollection commands  = new MgFeatureCommandCollection();

            commands.Add(deleteCmd);
            featSvc.UpdateFeatures(fsId, commands, false);
        }
示例#42
0
        public override void Invoke()
        {
            var provider = this.Viewer.GetProvider();
            var mdfId    = new MgResourceIdentifier(this.MapDefinition);
            var map      = provider.CreateMap(mdfId, mdfId.GetName());

            provider.LoadMap(map);
        }
示例#43
0
 private void btnReload_Click(object sender, EventArgs e)
 {
     _viewer.ClearSelection();
     MgResourceIdentifier mdfId = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
     MgdMap map = new MgdMap(mdfId);
     MgDesktopMapViewerProvider provider = new MgDesktopMapViewerProvider(map);
     Shell.Instance.ReloadViewer(provider);
 }
示例#44
0
 // Methods
 public static XmlDocument GetResourceXml(HtzMgHelper helper, MgResourceIdentifier resourceId)
 {
     XmlDocument result = new XmlDocument();
     if (resourceId != null)
     {
         result.LoadXml(helper.ResourceService.GetResourceContent(resourceId).ToString());
     }
     return result;
 }
示例#45
0
 public static void AddPointFeature(string FeatureName, MgPropertyCollection featureProps, MgPoint geom, MgFeatureService featureSrvc, MgResourceIdentifier dataSourceId)
 {
     MgByteReader geomReader = new MgAgfReaderWriter().Write(geom);
     MgGeometryProperty geometryProp = new MgGeometryProperty("GEOM", geomReader);
     featureProps.Add(geometryProp);
     MgInsertFeatures cmd = new MgInsertFeatures(FeatureName, featureProps);
     MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
     commands.Add(cmd);
     ReleaseReader(featureSrvc.UpdateFeatures(dataSourceId, commands, false));
 }
示例#46
0
 public HtzMgHelper(string userName, string userPass, string layoutId, string mapDefinition)
 {
     Init();
     this._connection = new MgSiteConnection();
     this._connection.Open(new MgUserInformation(userName, userPass));
     this._sessionId = this._connection.GetSite().CreateSession();
     this._map = new MgMap();
     MgResourceIdentifier mapDef = new MgResourceIdentifier(mapDefinition);
     this._map.Create(this.ResourceService, mapDef, mapDef.Name);
     this._layoutId = layoutId;
 }
示例#47
0
文件: Program.cs 项目: kanbang/Colt
        static void Main(string [] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            
            //Must call MgPlatform.Initialize() before we can work with anything from the MapGuide API
            try
            {
                var sw = new Stopwatch();
                sw.Start();
                MgdPlatform.Initialize("Platform.ini");
                sw.Stop();
                Trace.TraceInformation("Platform initialization took {0}ms", sw.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
                return;
            }
            
            //MgAppWindow is our Main Window class full of drag-and-drop component goodness. Go ahead and
            //take a look at MgAppWindow.cs source, not much code there except for the 3 generic invoke components and the
            //single custom selection handler. Everything else is encapsulated by designer-friendly drag and drop components
            //Most of the work is dragging and dropping components into the designer surface, and setting lots of properties
            var frm = new MgAppWindow();
            
            //We can initialize without specifying a map (allowing for components that do not 
            //require a loaded map to still be used). You just have to call LoadMap() on the MgMapViewer
            //instance when ready (not demonstrated here). So if you do load a package here, you will
            //have to restart the application
            MgResourceIdentifier resId = null;
            if (args.Length == 1)
            {
                resId = new MgResourceIdentifier(args[0]);
                resId.Validate();
            }

            var fact = new MgdServiceFactory();
            var resSvc = (MgdResourceService)fact.CreateService(MgServiceType.ResourceService);
            MgdMap map = null;

            if (resId != null && resSvc.ResourceExists(resId))
                map = new MgdMap(resId);

            //This is just a pass-through call to MgMapViewer.Init()
            frm.LoadMap(new MgDesktopMapViewerProvider(map));

            Application.ApplicationExit += new EventHandler(OnAppExit);
            Application.Run(frm);
        }
示例#48
0
 // Methods
 public HtzMaintenanceHelper(HtzMgHelper helper, MgLayer parentLayer, string uidKey)
 {
     this.ModuleAllowed = true;
     this.InitDefaultInfraTypes();
     this._helper = helper;
     this._uidKey = string.IsNullOrEmpty(uidKey) ? "UID" : uidKey;
     this._parentLayer = parentLayer;
     //if (this._helper.Configuration != null)
     //{
     //    this._config = this._helper.Configuration.GetProperties("FeatureCard");
     //    Dictionary<string, string> tmp = new Dictionary<string, string>();
     //    foreach (KeyValuePair<string, string> item in this._infraTypes)
     //    {
     //        if (!this._config.ContainsKey("ShowMaintFor" + item.Key))
     //        {
     //            this._helper.Configuration.RegisterPropertyDefinition("FeatureCard", "ShowMaintFor" + item.Key, item.Value, ConfigPropertyType.Boolean, "תחזוקה - הצגת שכבות", false);
     //        }
     //        else if ((bool)this._config["ShowMaintFor" + item.Key].Value)
     //        {
     //            tmp.Add(item.Key, item.Value);
     //        }
     //    }
     //    this._infraTypes = tmp;
     //}
     string mapPath = this._helper.Map.MapDefinition.Path;
     if (mapPath.LastIndexOf("/Maps") < 0)
     {
         this.ModuleAllowed = false;
     }
     else
     {
         this._maintenancePath = mapPath.Substring(0, mapPath.IndexOf("/Maps"));
         this._sdfResId = new MgResourceIdentifier(string.Format("Library://{0}/Maintenance/Data/Maintenance.FeatureSource", this._maintenancePath));
         this._layersResId = new List<MgResourceIdentifier>();
         if (!this._helper.ResourceService.ResourceExists(this._sdfResId))
         {
             this.CreateSdf(this._sdfResId);
         }
         foreach (KeyValuePair<string, string> item in this._infraTypes)
         {
             MgResourceIdentifier resId = new MgResourceIdentifier(string.Format("Library://{0}/Maintenance/Layers/Maint_{1}.LayerDefinition", this._maintenancePath, item.Key));
             this._layersResId.Add(resId);
             if (!this._helper.ResourceService.ResourceExists(resId))
             {
                 this.CreateLayer(resId, string.Format("InfrastructureType='{0}'", item.Value));
             }
         }
         this.AttachLayers();
         this._infraTypes.Add("none", "בחר מרשימה");
     }
 }
示例#49
0
    // Create a temporary Feature Source to store geocode results.
    public void CreateLocationMarkerFeatureSource(MgFeatureService featureService, MgResourceIdentifier locationMarkerDataResId, MgMap map)
    {
        //String ll84Wkt = "GEOGCS[\"LL84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.25722293287],TOWGS84[0,0,0,0,0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degrees\",1]]";
        //string ll84Wkt = "LOCAL_CS[\"*XY-MT*\",LOCAL_DATUM[\"*X-Y*\",10000],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]] ";
        MgCoordinateSystemFactory sysCoordsFactory = new MgCoordinateSystemFactory();
        string srsDefMap = map.GetMapSRS();
        string mapSrsUnits = string.Empty;

        srsDefMap = !string.IsNullOrEmpty(srsDefMap) ? srsDefMap : "LOCAL_CS[\"*XY-MT*\",LOCAL_DATUM[\"*X-Y*\",10000],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]] ";

        MgCoordinateSystem srsMap = sysCoordsFactory.Create(srsDefMap);
        MgClassDefinition locationClass = new MgClassDefinition();
        locationClass.SetName("LocationMarker");
        MgPropertyDefinitionCollection properties = locationClass.GetProperties();

        MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID");
        idProperty.SetDataType(MgPropertyType.Int32);
        idProperty.SetReadOnly(true);
        idProperty.SetNullable(false);
        idProperty.SetAutoGeneration(true);
        properties.Add(idProperty);

        MgDataPropertyDefinition addressProperty = new MgDataPropertyDefinition("Address");
        addressProperty.SetDataType(MgPropertyType.String);
        addressProperty.SetLength(512);
        properties.Add(addressProperty);

        MgGeometricPropertyDefinition locationProperty = new MgGeometricPropertyDefinition("Location");
        locationProperty.SetGeometryTypes(MgGeometryType.Point);
        locationProperty.SetHasElevation(false);
        locationProperty.SetHasMeasure(false);
        locationProperty.SetReadOnly(false);
        locationProperty.SetSpatialContextAssociation(srsMap.GetCsCode());
        properties.Add(locationProperty);

        MgPropertyDefinitionCollection idProperties = locationClass.GetIdentityProperties();
        idProperties.Add(idProperty);

        locationClass.SetDefaultGeometryPropertyName("Location");

        MgFeatureSchema locationSchema = new MgFeatureSchema();
        locationSchema.SetName("LocationMarkerSchema");
        locationSchema.GetClasses().Add(locationClass);

        MgCreateSdfParams sdfParams = new MgCreateSdfParams(srsMap.GetCsCode(), srsDefMap, locationSchema);

        featureService.CreateFeatureSource(locationMarkerDataResId, sdfParams);
    }
示例#50
0
        public MgdLayer CreateBufferLayer(MgResourceService resourceService, MgResourceIdentifier bufferFeatureResId, String sessionId)
        {
            // Load the layer definition template into
            // a XmlDocument object, find the "ResourceId" element, and
            // modify its content to reference the temporary
            // feature source.

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(Layers.BufferLayerDefinition);
            XmlNode featureSourceNode = doc.GetElementsByTagName("ResourceId")[0];
            featureSourceNode.InnerText = bufferFeatureResId.ToString();

            // Get the updated layer definition from the XmlDocument
            // and save it to the session repository using the
            // ResourceService object.

            MgByteSource byteSource = null;
            using (MemoryStream ms = new MemoryStream())
            {
                doc.Save(ms);
                ms.Position = 0L;

                //Note we do this to ensure our XML content is free of any BOM characters
                byte[] layerDefinition = ms.ToArray();
                Encoding utf8 = Encoding.UTF8;
                String layerDefStr = new String(utf8.GetChars(layerDefinition));
                layerDefinition = new byte[layerDefStr.Length - 1];
                int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0);

                byteSource = new MgByteSource(layerDefinition, layerDefinition.Length);
                byteSource.SetMimeType(MgMimeType.Xml);
            }

            MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.LayerDefinition");

            resourceService.SetResource(tempLayerResId, byteSource.GetReader(), null);

            // Create an MgLayer object based on the new layer definition
            // and return it to the caller.

            MgdLayer bufferLayer = new MgdLayer(tempLayerResId, resourceService);
            bufferLayer.SetName("Buffer");
            bufferLayer.SetLegendLabel("Buffer");
            bufferLayer.SetDisplayInLegend(true);
            bufferLayer.SetSelectable(false);

            return bufferLayer;
        }
示例#51
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier resId = new MgResourceIdentifier(textBox1.Text);
                resSvc.DeleteResourceData(resId, textBox2.Text);

                MessageBox.Show("Success");
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
示例#52
0
        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);

                bool res = featSvc.TestConnection(fsId);
                MessageBox.Show("Result: " + res);
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                MgResourceIdentifier resId = new MgResourceIdentifier(textBox1.Text);
                MgByteReader response = resSvc.EnumerateResourceData(resId);

                new XmlResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
示例#54
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService);
                MgResourceIdentifier fsId = new MgResourceIdentifier(textBox1.Text);
                MgSpatialContextReader response = featSvc.GetSpatialContexts(fsId, checkBox1.Checked);

                new SpatialContextResultDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
示例#55
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgResourceService resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);

                MgResourceIdentifier resId = new MgResourceIdentifier(textBox1.Text);
                bool exists = resSvc.ResourceExists(resId);
                MessageBox.Show("Exists: " + exists);
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
        public ActionResult LoadSampleData(SetupInputModel input)
        {
            MgUserInformation user = new MgUserInformation(input.Username, input.Password);
            MgSiteConnection conn = new MgSiteConnection();
            conn.Open(user);

            MgResourceService resSvc = (MgResourceService)conn.CreateService(MgServiceType.ResourceService);

            //Load the package file if specified
            if (input.Package != null && input.Package.ContentLength > 0)
            {
                var path = Path.GetTempFileName();
                try
                {
                    input.Package.SaveAs(path);
                    MgByteSource bs = new MgByteSource(path);
                    MgByteReader br = bs.GetReader();

                    resSvc.ApplyResourcePackage(br);
                }
                finally
                {
                    try
                    {
                        if (System.IO.File.Exists(path))
                            System.IO.File.Delete(path);
                    }
                    catch { }
                }
            }

            //Load in our sample-specific resources
            MgResourceIdentifier sample1 = new MgResourceIdentifier(AJAX_LAYOUT);
            MgResourceIdentifier sample2 = new MgResourceIdentifier(FLEX_LAYOUT);

            MgByteSource bs1 = new MgByteSource(Server.MapPath("~/App_Data/SheboyganAspMvc.WebLayout.xml"));
            MgByteReader br1 = bs1.GetReader();

            resSvc.SetResource(sample1, br1, null);

            MgByteSource bs2 = new MgByteSource(Server.MapPath("~/App_Data/SheboyganAspMvc.ApplicationDefinition.xml"));
            MgByteReader br2 = bs2.GetReader();

            resSvc.SetResource(sample2, br2, null);

            return RedirectToAction("Index");
        }
示例#57
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService);
                MgResourceIdentifier resId = new MgResourceIdentifier(textBox1.Text);
                string sql = textBox2.Text;

                int res = featSvc.ExecuteSqlNonQuery(resId, sql);
                MessageBox.Show(res + " results affected");
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
示例#58
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService);
                MgResourceIdentifier fsId = new MgResourceIdentifier(textBox1.Text);
                string sql = textBox2.Text;

                MgSqlDataReader reader = featSvc.ExecuteSqlQuery(fsId, sql);
                new ReaderResponseDialog(reader).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
示例#59
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         var fact = new MgdServiceFactory();
         MgResourceService resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
         MgResourceIdentifier resId = new MgResourceIdentifier(txtResourceId.Text);
         string type = txtType.Text;
         int depth = Convert.ToInt32(txtDepth.Text);
         MgByteReader response = resSvc.EnumerateResources(resId, depth, type);
         new XmlResponseDialog(response).ShowDialog();
     }
     catch (MgException ex)
     {
         MessageBox.Show(ex.ToString(), "Error from MapGuide");
     }
 }
示例#60
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);
                MgResourceIdentifier resId = new MgResourceIdentifier(textBox1.Text);

                MgdMap map = new MgdMap(resId);

                double x;
                double y;
                if (double.TryParse(textBox2.Text, out x) &&
                    double.TryParse(textBox3.Text, out y))
                {
                    map.SetViewCenterXY(x, y);
                }

                int w;
                int h;
                if (int.TryParse(txtWidth.Text, out w) &&
                    int.TryParse(txtHeight.Text, out h))
                {
                    map.SetDisplaySize(w, h);
                }

                double scale;
                if (double.TryParse(textBox4.Text, out scale))
                {
                    map.SetViewScale(scale);
                }

                var sw = new Stopwatch();
                sw.Start();
                MgByteReader response = renSvc.RenderMap(map, null, textBox5.Text);
                sw.Stop();
                Trace.TraceInformation("RenderMap executed in {0}ms", sw.ElapsedMilliseconds);

                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }