[mapguide-users] Creating batch process to produce DWF's, code bombing out

SteveS steve.calpoly at gmail.com
Fri Dec 16 17:11:47 EST 2011


Hello,

Without displaying the MG viewer in the browser i want to have an ASPX page
that connects, sets up the map, and then spits out a DWF. I have done these
two processes separately with the latter using an invoke URL page. when
combining them I'm getting a useless error: "Invalid argument(s): [0] = "
The string cannot be empty."

Here is the code to my page, i think the problem has to do with the MgMap
object I create towards the end but I'm not sure what else to try.

protected void Page_Load(object sender, EventArgs e)
    {
        List<string> layerList = new List<string>() {"bunch of layers going
in here"};

        InitializeWebTier();
        MgUserInformation userInfo = new MgUserInformation(defaultUser,
defaultPassword);
        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(userInfo);
        MgSite site = siteConnection.GetSite();
        sessionId = site.CreateSession();
        MgResourceService resourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;

        //copy dynamic layer definitions to session repository
        foreach (string currLayer in layerList)
        {
            CopyLayerToSession(currLayer, resourceService, floor1,
planType);
        }
        
        //copy dynamic map to session repository
        MgByteReader mapByteReader = resourceService.GetResourceContent(new
MgResourceIdentifier("Library://MAPS/LEABDG.MapDefinition"));
        XmlDocument mapDoc = new XmlDocument();
        mapDoc.PreserveWhitespace = true;
        mapDoc.LoadXml(mapByteReader.ToString());
        int layerCount = mapDoc.GetElementsByTagName("ResourceId").Count;
        for (int i = 0; i < layerCount; i++)
        {
            string innerText =
mapDoc.GetElementsByTagName("ResourceId").Item(i).InnerText;
            string innerTextFinal = innerText.Replace("Library://LAYERS/",
"Session:" + sessionId + "//");
            mapDoc.GetElementsByTagName("ResourceId").Item(i).InnerText =
innerTextFinal;
        }
        //string mapReplaceStr = floor1.Replace(".","");
        MgResourceIdentifier newMap = new MgResourceIdentifier("Session:" +
sessionId + "//LEASING.MapDefinition");
        resourceService.SetResource(newMap, new
MgByteReader(mapDoc.OuterXml, "text/xml"), null);

        //copy dynamic web layout to session repository 
        MgByteReader layoutByteReader =
resourceService.GetResourceContent(new
MgResourceIdentifier("Library://LAYOUTS/Web Layout.WebLayout"));
        XmlDocument layoutDoc = new XmlDocument();
        layoutDoc.PreserveWhitespace = true;
        layoutDoc.LoadXml(layoutByteReader.ToString());
        layoutDoc.GetElementsByTagName("ResourceId").Item(0).InnerText =
"Session:" + sessionId + "//" + planType + ".MapDefinition";
        MgResourceIdentifier newLayout = new MgResourceIdentifier("Session:"
+ sessionId + "//Web Layout.WebLayout");
        resourceService.SetResource(newLayout, new
MgByteReader(layoutDoc.OuterXml, "text/xml"), null);

        double scale;
        double x;
        double y;
        string mapName= "LEASING";

        try
        {
            MgMap map = new MgMap();
            map.Open(resourceService, mapName);

            //Set Map Name to same format as database
            DataTable dt = new DataTable();
            OracleConnection connection = new OracleConnection("my database
connection string");
            connection.Open();
            OracleCommand sqlCmd = new OracleCommand("SELECT SCALE, CENTERX,
CENTERY FROM MYTABLE WHERE LOCATION_CODE='My Location'", connection);
            OracleDataAdapter sqlDa = new OracleDataAdapter(sqlCmd);
            sqlDa.Fill(dt);

            scale = Convert.ToDouble(dt.Rows[0]["SCALE"]);
            x = Convert.ToDouble(dt.Rows[0]["CENTERX"]);
            y = Convert.ToDouble(dt.Rows[0]["CENTERY"]);

            connection.Close();

            // Now create an instance of MappingService and use it to plot
the
            // current view of the map.

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

            MgMappingService mappingService =
siteConnection.CreateService(MgServiceType.MappingService) as
MgMappingService;

            MgByteReader byteReader = null;

            MgGeometryFactory geometryFactory = new MgGeometryFactory();
            MgCoordinate mapCenter = geometryFactory.CreateCoordinateXY(x,
y);
            byteReader = mappingService.GeneratePlot(map, mapCenter, scale,
plotSpec, null, dwfVersion);

            // Now output the resulting DWF.
            OutputReaderContent(Response, byteReader);
        }
        catch (MgException mge)
        {
            String result = mge.GetExceptionMessage() + "<br><br>" +
mge.GetDetails();

            Response.ContentType = "text/html";
            Response.Write(result);
        }
    }

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Creating-batch-process-to-produce-DWF-s-code-bombing-out-tp7102657p7102657.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list