Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
        public Dictionary <string, string> GetResourcesByType(string resourceType)
        {
            //TODO:
            if (!IsValidMap3DResourceType(resourceType))
            {
                throw new ApplicationException("unspported resource type by Map3D");
            }

            Dictionary <string, string> resources = new Dictionary <string, string>();

            try
            {
                string rootPath = "Library://";
                MgResourceIdentifier rootResId = new MgResourceIdentifier(rootPath);
                rootResId.Validate();

                MgByteReader reader = ResourceService.EnumerateResources(rootResId, -1, resourceType.ToString());

                //Convert to string
                String resStr = reader.ToString();

                //Load into XML document so we can parse and get the names of the maps
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(resStr);

                //let's extract the resource names and list them
                XmlNodeList resIdNodeList;
                XmlElement  root = doc.DocumentElement;
                resIdNodeList = root.SelectNodes("//ResourceId");
                int resCount = resIdNodeList.Count;
                for (int i = 0; i < resCount; i++)
                {
                    XmlNode resIdNode = resIdNodeList.Item(i);
                    String  resId     = resIdNode.InnerText;
                    int     index1    = resId.LastIndexOf('/') + 1;
                    int     index2    = resId.IndexOf(resourceType) - 2;
                    int     length    = index2 - index1 + 1;
                    string  resName   = resId.Substring(index1, length);
                    resources.Add(resName, resId);
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                Debug.WriteLine(msg);
            }


            return(resources);
        }
Exemple #4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                var resId = new MgResourceIdentifier(txtResourceId.Text);
                resId.Validate();

                var fact = new MgdServiceFactory();
                var resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                if (!resSvc.ResourceExists(resId))
                {
                    MessageBox.Show("The specified resource does not exist");
                    return;
                }
                this.ResourceID = resId;
                this.DialogResult = DialogResult.OK;
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.Message);
                ex.Dispose();
            }
        }
Exemple #5
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                var resId = new MgResourceIdentifier(txtResourceId.Text);
                resId.Validate();

                var fact   = new MgdServiceFactory();
                var resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService);
                if (!resSvc.ResourceExists(resId))
                {
                    MessageBox.Show("The specified resource does not exist");
                    return;
                }
                this.ResourceID   = resId;
                this.DialogResult = DialogResult.OK;
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.Message);
                ex.Dispose();
            }
        }
        public Dictionary<string, string> GetResourcesByType(string resourceType)
        {
            //TODO:
            if (!IsValidMap3DResourceType(resourceType))
            {
                throw new ApplicationException("unspported resource type by Map3D");
            }

            Dictionary<string, string> resources = new Dictionary<string, string>();

            try
            {
                string rootPath = "Library://";
                MgResourceIdentifier rootResId = new MgResourceIdentifier(rootPath);
                rootResId.Validate();

                MgByteReader reader = ResourceService.EnumerateResources(rootResId, -1, resourceType.ToString());

                //Convert to string 
                String resStr = reader.ToString();

                //Load into XML document so we can parse and get the names of the maps
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(resStr);

                //let's extract the resource names and list them        
                XmlNodeList resIdNodeList;
                XmlElement root = doc.DocumentElement;
                resIdNodeList = root.SelectNodes("//ResourceId");
                int resCount = resIdNodeList.Count;
                for (int i = 0; i < resCount; i++)
                {
                    XmlNode resIdNode = resIdNodeList.Item(i);
                    String resId = resIdNode.InnerText;
                    int index1 = resId.LastIndexOf('/') + 1;
                    int index2 = resId.IndexOf(resourceType) - 2;
                    int length = index2 - index1 + 1;
                    string resName = resId.Substring(index1, length);
                    resources.Add(resName, resId);

                }

            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                Debug.WriteLine(msg);
            }


            return resources;
        }