// 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));
        }
Exemplo n.º 2
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");
            }
        }
Exemplo n.º 3
0
 public static bool DataSourceExists(MgResourceService resourceSrvc, MgResourceIdentifier dataSourceId)
 {
     try
     {
         string MGServerVersion = ConfigurationManager.AppSettings["MGServerVersion"];
         if (MGServerVersion == "2009")
         {
             MgByteReader cnt = resourceSrvc.GetResourceContent(dataSourceId);
             cnt = null;
             return true;
         }
         return resourceSrvc.ResourceExists(dataSourceId);
     }
     catch (MgResourceNotFoundException)
     {
         return false;
     }
 }
Exemplo n.º 4
0
        public RedlineLayer CreateRedlineLayer(CreateRedlineLayerParams param, out bool bAddedToMap)
        {
            bAddedToMap = false;
            MgResourceIdentifier fsId = GenerateRedlineFeatureSourceId(param);

            string className    = null;
            string providerName = null;

            if (_resSvc.ResourceExists(fsId))
            {
                MgFeatureSchemaCollection   schemas = _featSvc.DescribeSchema(fsId, string.Empty, null);
                MgFeatureSchema             schema  = schemas.GetItem(0);
                MgClassDefinitionCollection classes = schema.GetClasses();
                MgClassDefinition           cls     = classes.GetItem(0);
                className = schema.Name + ":" + cls.Name;
            }
            else
            {
                MgFeatureSchema schema = RedlineSchemaFactory.CreateSchema(param.GeometryTypes);

                providerName = "OSGeo.SDF";
                if (param.Format == RedlineDataStoreFormat.SHP)
                {
                    providerName = "OSGeo.SHP";
                }
                else if (param.Format == RedlineDataStoreFormat.SQLite)
                {
                    providerName = "OSGeo.SQLite";
                }

                MgFileFeatureSourceParams createParams = new MgFileFeatureSourceParams(providerName, RedlineSchemaFactory.SPATIAL_CONTEXT, _map.GetMapSRS(), schema);
                _featSvc.CreateFeatureSource(fsId, createParams);

                //HACK: SQLite leaky abstraction (hard-coded schema name), SHP probably has some leaks of its own, so we can't assume MarkupSchema:Markup
                //as the class name so re-interrogate our schema to figure it out
                MgFeatureSchemaCollection schemas = _featSvc.DescribeSchema(fsId, string.Empty, null);
                schema = schemas.GetItem(0);
                MgClassDefinitionCollection classes = schema.GetClasses();
                MgClassDefinition           cls     = classes.GetItem(0);
                className = schema.Name + ":" + cls.Name;
            }

            MgResourceIdentifier ldfId = GenerateRedlineLayerDefinitionId(param);

            if (!_resSvc.ResourceExists(ldfId))
            {
                string       layerDefContent = CreateRedlineLayerDefinitionContent(fsId, className, param.Style, param.StyleType);
                byte[]       bytes           = Encoding.UTF8.GetBytes(layerDefContent);
                MgByteSource byteSource      = new MgByteSource(bytes, bytes.Length);
                MgByteReader byteReader      = byteSource.GetReader();

                _resSvc.SetResource(ldfId, byteReader, null);
            }

            if (param.AddToMap)
            {
                AddRedlineLayerToMap(ldfId);
                bAddedToMap = true;
            }

            var layer = new RedlineLayer(ldfId.Name, fsId.ToString(), ldfId.ToString(), param.GeometryTypes, param.StyleType);

            //If provider name was set, then we register this layer in the registry. Otherwise it means
            //the layer already exists and by extension already registered
            if (providerName != null)
            {
                _registry.AddRedlineLayer(layer, providerName);
            }
            return(layer);
        }
Exemplo n.º 5
0
        private void Ensure()
        {
            if (_registryFsId == null)
            {
                _registryFsId = new MgResourceIdentifier("Session:" + _sessionID + "//MarkupRegistry.FeatureSource");

                if (!_resSvc.ResourceExists(_registryFsId))
                {
                    //Markup Registry Feature Source Schema
                    //
                    //Default
                    //  MarkupRegistry
                    //    ResourceId (String, Identity, Not Null)
                    //    LayerDefintion (String, Not Null)
                    //    Name (String, Not Null)
                    //    FdoProvider (String, Not Null)
                    //    GeometryTypes (Int, Not Null)
                    MgFeatureSchema   schema = new MgFeatureSchema("Default", "");
                    MgClassDefinition cls    = new MgClassDefinition();
                    cls.SetName("MarkupRegistry");

                    MgDataPropertyDefinition regId = new MgDataPropertyDefinition("ResourceId");
                    regId.SetDataType(MgPropertyType.String);
                    regId.SetLength(1024);
                    regId.SetNullable(false);

                    MgDataPropertyDefinition layerDefId = new MgDataPropertyDefinition("LayerDefinition");
                    layerDefId.SetDataType(MgPropertyType.String);
                    layerDefId.SetLength(1024);
                    layerDefId.SetNullable(false);

                    MgDataPropertyDefinition name = new MgDataPropertyDefinition("Name");
                    name.SetDataType(MgPropertyType.String);
                    name.SetLength(512);
                    name.SetNullable(false);

                    MgDataPropertyDefinition provider = new MgDataPropertyDefinition("FdoProvider");
                    provider.SetDataType(MgPropertyType.String);
                    provider.SetLength(512);
                    provider.SetNullable(false);

                    MgDataPropertyDefinition geomTypes = new MgDataPropertyDefinition("GeometryTypes");
                    geomTypes.SetDataType(MgPropertyType.Int32);
                    geomTypes.SetNullable(false);

                    MgDataPropertyDefinition styleType = new MgDataPropertyDefinition("StyleType");
                    styleType.SetDataType(MgPropertyType.Int32);
                    styleType.SetNullable(false);

                    MgPropertyDefinitionCollection dataProps = cls.GetProperties();
                    dataProps.Add(regId);
                    dataProps.Add(layerDefId);
                    dataProps.Add(name);
                    dataProps.Add(provider);
                    dataProps.Add(geomTypes);
                    dataProps.Add(styleType);

                    MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
                    idProps.Add(regId);

                    MgClassDefinitionCollection classes = schema.GetClasses();
                    classes.Add(cls);

                    //No coordinate system required here because we're not storing spatial data
                    MgFileFeatureSourceParams createSdf = new MgFileFeatureSourceParams("OSGeo.SDF", "Default", "", schema);
                    _featSvc.CreateFeatureSource(_registryFsId, createSdf);
                }
            }
        }