/// <summary> /// This function takes a connection ID and generates all the associated KML for that connection. /// It works hand-in-hand with KMLGenerationLibrary, Styles, and Placemarks. /// It also calls generateKMLFromConnection. /// /// There is also a helper class used to prevent duplicate styles (HashStyleComparer). /// </summary> /// <param name="connID">int --> connection ID for the connection that you wish to generate KML for</param> /// <returns>String --> A string that is the KML</returns> public string generateKML(int connID) { Connection connection = new Connection(connID); connection.populateFields(); return generateKMLFromConnection(connection); }
public XmlDocument getKML(int connID) { String serverPath = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + HttpContext.Current.Request.ServerVariables["SERVER_PORT"]; //create new connection a populate fields to get the connection name for KMLGenerator Connection conn = new Connection(connID); conn.populateFields(); string name = conn.getConnInfo().getConnectionName(); //create a new kml genereator with the connection name as the placemark name KMLGenerator kmlGen = new KMLGenerator(name, serverPath); string kml = ""; //generate the kml for the given connID try { kml = kmlGen.generateKML(connID); } catch (Exception e) { //if there was an error generating kml, return a kml file that contains only a screen overlay that states there was an error generating kml kml = "<ScreenOverlay> <name>KML Error</name> <Icon> <href>"+ serverPath + "/graphics/kml-error.png</href> </Icon> <overlayXY x=\"0.5\" y=\"0.5\" xunits=\"fraction\" yunits=\"fraction\"/> <screenXY x=\"0.5\" y=\"0.5\" xunits=\"fraction\" yunits=\"fraction\"/> <rotationXY x=\"0\" y=\"0\" xunits=\"fraction\" yunits=\"fraction\"/> <size x=\"1\" y=\"0.2\" xunits=\"fraction\" yunits=\"fraction\"/></ScreenOverlay>"; } //add the kml to an XMLDoc and return XmlDocument kmlDoc = new XmlDocument(); kmlDoc.LoadXml(kml); return(kmlDoc); }
public XmlDocument getKML(int connID) { String serverPath = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + HttpContext.Current.Request.ServerVariables["SERVER_PORT"]; //create new connection a populate fields to get the connection name for KMLGenerator Connection conn = new Connection(connID); conn.populateFields(); string name = conn.getConnInfo().getConnectionName(); //create a new kml genereator with the connection name as the placemark name KMLGenerator kmlGen = new KMLGenerator(name, serverPath); string kml = ""; //generate the kml for the given connID try { kml = kmlGen.generateKML(connID); } catch (Exception e) { //if there was an error generating kml, return a kml file that contains only a screen overlay that states there was an error generating kml kml = "<ScreenOverlay> <name>KML Error</name> <Icon> <href>" + serverPath + "/graphics/kml-error.png</href> </Icon> <overlayXY x=\"0.5\" y=\"0.5\" xunits=\"fraction\" yunits=\"fraction\"/> <screenXY x=\"0.5\" y=\"0.5\" xunits=\"fraction\" yunits=\"fraction\"/> <rotationXY x=\"0\" y=\"0\" xunits=\"fraction\" yunits=\"fraction\"/> <size x=\"1\" y=\"0.2\" xunits=\"fraction\" yunits=\"fraction\"/></ScreenOverlay>"; } //add the kml to an XMLDoc and return XmlDocument kmlDoc = new XmlDocument(); kmlDoc.LoadXml(kml); return kmlDoc; }
protected void updateConnection(object sender, CommandEventArgs e) { Button sendBtn = (Button)sender; String args = sendBtn.CommandArgument.ToString(); ConnInfo tempConnInfo = new ConnInfo(); tempConnInfo.setConnectionName(editConnName.Text); tempConnInfo.setDatabaseName(editConnDBName.Text); tempConnInfo.setServerAddress(editConnDBAddr.Text); tempConnInfo.setPortNumber(editConnDBPort.Text); tempConnInfo.setUserName(editConnUser.Text); tempConnInfo.setPassword(editConnPass.Text); tempConnInfo.setDatabaseType((editConnDBType.SelectedIndex)); tempConnInfo.setOracleProtocol(editOracleProtocol.Text); tempConnInfo.setOracleServiceName(editOracleService.Text); tempConnInfo.setOracleSID(editOracleSID.Text); //If the connection information is bad, report the error and cancel the function. This does NOT run against the database. try { if (!tempConnInfo.isValid(Convert.ToInt32(args))) { throw new ODBC2KMLException(""); // Throw any error. The catch is generic. } } catch { String error = "The entered connection information is invalid. Please make sure all fields are filled and that they are in proper format."; if (tempConnInfo.getDatabaseType() == ConnInfo.ORACLE) { error = "The entered connection information is invalid. Please verify that all fields have a value and the value is of proper type." + " Also, make sure that Oracle SID or Oracle Service Name and Oracle Protocol have been entered."; } ErrorHandler eh = new ErrorHandler(error, errorPanel1); this.editConnModalPopUp.Hide(); eh.displayError(); return; } //Create database and test it Database db = new Database(tempConnInfo); //See if you can reach the database. If not, error out and don't save. try { if (tempConnInfo.getDatabaseType() == ConnInfo.MSSQL) { String query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA != 'information_schema' AND TABLE_NAME != 'sysdiagrams'"; db.executeQueryRemote(query); } else if (tempConnInfo.getDatabaseType() == ConnInfo.MYSQL) { String query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA != 'information_schema' && TABLE_SCHEMA != 'mysql'"; db.executeQueryRemote(query); } else if (tempConnInfo.getDatabaseType() == ConnInfo.ORACLE) { String query = "select TABLE_NAME from user_tables"; db.executeQueryRemote(query); } } catch { ErrorHandler eh = new ErrorHandler("The database entered could not be connected to. Please verify the information is correct.", errorPanel1); this.editConnModalPopUp.Hide(); eh.displayError(); return; } db.executeQueryLocal("UPDATE Connection SET name='" + tempConnInfo.getConnectionName() + "', dbName='" + tempConnInfo.getDatabaseName() + "', userName='******', password='******', port='" + tempConnInfo.getPortNumber() + "', address='" + tempConnInfo.getServerAddress() + "', type='" + tempConnInfo.getDatabaseType() + "', protocol='" + tempConnInfo.getOracleProtocol() + "', serviceName='" + tempConnInfo.getOracleServiceName() + "', SID='" + tempConnInfo.getOracleSID() + "' WHERE (ID='" + args + "')"); Connection conn = new Connection(Convert.ToInt16(args)); try { conn.populateFields(); //Force the connection into a safe state, if it is not if (!conn.safeStateConnection()) { String error = "Invalid connection information. Please verify all of your fields are filled in correctly." + "If you are using an oracle connection, please make sure you filled out the oracle specific information."; ErrorHandler eh = new ErrorHandler(error, errorPanel1); this.editConnModalPopUp.Hide(); eh.displayError(); return; } } catch (ODBC2KMLException err) { ErrorHandler eh = new ErrorHandler(err.errorText, errorPanel1); this.editConnModalPopUp.Hide(); eh.displayError(); return; } if (e.CommandName.Equals("saveConn")) { this.editConnModalPopUp.Hide(); Response.Redirect("Main.aspx"); } else { this.editConnModalPopUp.Hide(); Response.Redirect("ConnDetails.aspx?ConnID=" + ((Button)sender).CommandArgument.ToString() + "&locked=false"); } }
protected void genKMLFunction(object sender, EventArgs e) { try { //Generate the KML from the connection ImageButton sendBtn = (ImageButton)sender; String serverPath = "http://" + Request.ServerVariables["SERVER_NAME"] + ":" + Request.ServerVariables["SERVER_PORT"]; string args = sendBtn.CommandArgument.ToString(); KMLGenerator kml = new KMLGenerator(ConnInfo.getConnInfo(Convert.ToInt32(args)).getConnectionName(), serverPath); //Generate the KML string based on the connection id String kmlString = kml.generateKML(int.Parse(args)); Connection conn = new Connection(int.Parse(args)); conn.populateFields(); //Write the KML string to a downloadable file Response.ClearHeaders(); Response.ClearContent(); Response.ContentType = "application/vnd.google-earth.kml+xml kml"; Response.AddHeader("Content-Disposition", "attachment; filename=\"" + (conn.getConnInfo()).getConnectionName() + ".kml"); Response.Write(kmlString); Response.End(); return; } catch (ODBC2KMLException ex) { ErrorHandler err = new ErrorHandler(ex.errorText, errorPanel1); err.displayError(); return; } //Response.Redirect("Main.aspx", true); }