static BuildTarget decodeTarget(XmlElement e, Project proj)
        {
            BuildTarget target = null;
            if (e != null)
            {
                target = new BuildTarget();
                target.setName(e.GetAttribute("name"));

                Terrain terrain = proj.getTerrain(e.GetAttribute("terrain"));
                target.setTerrain(terrain);

                XmlNodeList layers = e.GetElementsByTagName("layer");
                foreach (XmlNode i in layers)
                {
                    XmlElement elem = (XmlElement)i;
                    string layer_name = elem.InnerText;
                    if (!string.IsNullOrEmpty(layer_name))
                    {
                        BuildLayer layer = proj.getLayer(layer_name);
                        if (layer != null)
                            target.addLayer(layer);
                    }
                }
            }
            return target;
        }
Exemple #2
0
        static Project decodeProject(XmlElement e, string source_uri)
        {
            if (e == null || !e.Name.Equals("project"))
                throw new ApplicationException("First XML element must be <project/> tag");

            Project project = null;
            if (e != null)
            {
                project = new Project();
                project.setSourceURI(source_uri);
                project.setName(e.GetAttribute("name"));
                project.setWorkingDirectory(e.GetAttribute("workdir"));


                // resources
                XmlNodeList resources = e.GetElementsByTagName("resource");
                foreach (XmlNode j in resources)
                {
                    MogreGis.Resource resource = decodeResource((XmlElement)j, project);
                    if (resource != null)
                        project.getResources().Add(resource);
                }

                #region TODO_PH_FILTERGRAPHS
#if TODO_PH
                // graphs
                XmlNodeList graphs = e.GetElementsByTagName("graph");
                foreach (XmlNode j in graphs)
                {
                    FilterGraph graph = decodeFilterGraph((XmlElement)j, project);
                    if (graph != null)
                        project.getFilterGraphs().Add(graph);
                }
#endif
                #endregion

                // sources - 2 passes, since a source can reference another source
                XmlNodeList sources = e.GetElementsByTagName("source");
                foreach (XmlNode j in sources)
                {

                    // TODO Dani, meter esto en un try catch
                    
                    ShapeFile shapeFile = decodeShapeFile((XmlElement)j, project, 0);
                    if (shapeFile != null)
                    {
                        project.getShapeFiles().Add(shapeFile);
                    }
                }
                foreach (XmlNode j in sources)
                {
                    decodeShapeFile((XmlElement)j, project, 1);
                }

                #region TODO_PH_LAYERS
#if TODO_PH_LAYERS
                XmlNodeList layers = e.GetElementsByTagName("layer");
                foreach (XmlNode j in layers)
                {
                    SharpMap.Layers.VectorLayer l = new SharpMap.Layers.VectorLayer(
                    BuildLayer layer = decodeLayer((XmlElement)j, project);
                    if (layer != null)
                    {
                        project.getLayers().Add(layer);

                        // automatically add a target for this layer alone:
                        BuildTarget layer_target = new BuildTarget();
                        layer_target.setName(layer.getName());
                        layer_target.addLayer(layer);
                        project.getTargets().Add(layer_target);
                    }
                }
#endif
                #endregion

            }
            return project;
        }
        static Project decodeProject(XmlElement e, string source_uri)
        {
            if (e == null || !e.Name.Equals("project"))
                throw new ApplicationException("First XML element must be <project/> tag");

            Project project = null;
            if (e != null)
            {
                project = new Project();
                project.setSourceURI(source_uri);
                project.setName(e.GetAttribute("name"));
                project.setWorkingDirectory(e.GetAttribute("workdir"));

            #if TODO_DANI //includes
                // includes
                XmlNodeList includes = e.GetElementsByTagName("include");
                foreach (XmlNode j in includes)
                {
                    decodeInclude((XmlElement)j, project);
                }
            #endif
                // scripts
                XmlNodeList scripts = e.GetElementsByTagName("script");
                foreach (XmlNode j in scripts)
                {
                    Script script = decodeScript((XmlElement)j, project);
                    if (script != null)
                        project.getScripts().Add(script);
                }

                //some project variables.
                XmlNodeList engines = e.GetElementsByTagName("scriptEngine");
                foreach (XmlElement engine in engines)
                {
                    Registry.instance().LoadAndRegistryEngine(engine.GetAttribute("Class"), engine.GetAttribute("Assembly"));
                }

                XmlNodeList nl = e.GetElementsByTagName("mogreRender");
                foreach (XmlElement n in nl)
                {
                    decodeMogreRender(n, project);
                }

            #if !TODO_DANI //resources

                // resources
                XmlNodeList resources = e.GetElementsByTagName("resource");
                foreach (XmlNode j in resources)
                {
                    Resource resource = decodeResource((XmlElement)j, project);
                    if (resource != null)
                        project.getResources().Add(resource);
                }

            #endif

                // graphs
                XmlNodeList graphs = e.GetElementsByTagName("graph");
                foreach (XmlNode j in graphs)
                {
                    FilterGraph graph = decodeFilterGraph((XmlElement)j, project);
                    if (graph != null)
                        project.getFilterGraphs().Add(graph);
                }

            #if TODO_DANI //terrains

                // terrains (depends on resources)
                XmlNodeList terrains = e.GetElementsByTagName("terrain");
                foreach (XmlNode j in terrains)
                {
                    Terrain terrain = decodeTerrain((XmlElement)j, project);
                    if (terrain != null)
                        project.getTerrains().Add(terrain);
                }

            #endif

                // sources - 2 passes, since a source can reference another source
                XmlNodeList sources = e.GetElementsByTagName("source");
                foreach (XmlNode j in sources)
                {

                    // TODO Dani, meter esto en un try catch

                    Source source = decodeSource((XmlElement)j, project, 0);
                    if (source != null)
                    {
                        project.getSources().Add(source);

            #if TODO_DANI
                        // also add each source as a feature layer resource
                        Resource resource = MogreGis.Registry.instance().createResourceByType("FeatureLayerResource");
                        resource.setBaseURI(project.getBaseURI());
                        resource.setURI(source.getURI());
                        resource.setName(source.getName());
                        project.getResources().Add(resource);
            #endif
                    }
                }
                foreach (XmlNode j in sources)
                {
                    decodeSource((XmlElement)j, project, 1);
                }

                //#if TODO_DANI //layers

                // layers
                XmlNodeList layers = e.GetElementsByTagName("layer");
                foreach (XmlNode j in layers)
                {
                    BuildLayer layer = decodeLayer((XmlElement)j, project);
                    if (layer != null)
                    {
                        project.getLayers().Add(layer);

                        // automatically add a target for this layer alone:
                        BuildTarget layer_target = new BuildTarget();
                        layer_target.setName(layer.getName());
                        layer_target.addLayer(layer);
                        project.getTargets().Add(layer_target);
                    }
                }

                //#endif

            #if TODO_DANI //targets

                // targets
                XmlNodeList targets = e.GetElementsByTagName("target");
                foreach (XmlNode j in targets)
                {
                    BuildTarget target = decodeTarget((XmlElement)j, project);
                    if (target != null)
                        project.getTargets().Add(target);
                }

            #endif

            #if TODO_DANI //maps

                // maps
                XmlNodeList maps = e.GetElementsByTagName("map");
                foreach (XmlNode j in maps)
                {
                    RuntimeMap map = decodeRuntimeMap((XmlElement)j, project);
                    if (map != null)
                        project.getMaps().Add(map);
                }

            #endif

            }
            return project;
        }
        static Project decodeProject(XmlElement e, string source_uri)
        {
            if (e == null || !e.Name.Equals("project"))
                throw new ApplicationException("First XML element must be <project/> tag");

            Project project = null;
            if (e != null)
            {
                project = new Project();
                project.setSourceURI(source_uri);
                project.setName(e.GetAttribute("name"));
                project.setWorkingDirectory(e.GetAttribute("workdir"));

                // resources
                XmlNodeList resources = e.GetElementsByTagName("resource");
                foreach (XmlNode j in resources)
                {
                    MogreGis.Resource resource = decodeResource((XmlElement)j, project);
                    if (resource != null)
                        project.getResources().Add(resource);
                }

                #region TODO_PH_FILTERGRAPHS
            #if TODO_PH
                // graphs
                XmlNodeList graphs = e.GetElementsByTagName("graph");
                foreach (XmlNode j in graphs)
                {
                    FilterGraph graph = decodeFilterGraph((XmlElement)j, project);
                    if (graph != null)
                        project.getFilterGraphs().Add(graph);
                }
            #endif
                #endregion

                // sources - 2 passes, since a source can reference another source
                XmlNodeList sources = e.GetElementsByTagName("source");
                foreach (XmlNode j in sources)
                {

                    // TODO Dani, meter esto en un try catch

                    ShapeFile shapeFile = decodeShapeFile((XmlElement)j, project, 0);
                    if (shapeFile != null)
                    {
                        project.getShapeFiles().Add(shapeFile);
                    }
                }
                foreach (XmlNode j in sources)
                {
                    decodeShapeFile((XmlElement)j, project, 1);
                }

                #region TODO_PH_LAYERS
            #if TODO_PH_LAYERS
                XmlNodeList layers = e.GetElementsByTagName("layer");
                foreach (XmlNode j in layers)
                {
                    SharpMap.Layers.VectorLayer l = new SharpMap.Layers.VectorLayer(
                    BuildLayer layer = decodeLayer((XmlElement)j, project);
                    if (layer != null)
                    {
                        project.getLayers().Add(layer);

                        // automatically add a target for this layer alone:
                        BuildTarget layer_target = new BuildTarget();
                        layer_target.setName(layer.getName());
                        layer_target.addLayer(layer);
                        project.getTargets().Add(layer_target);
                    }
                }
            #endif
                #endregion

            }
            return project;
        }