Beispiel #1
0
 public Icon(Icon i)
 {
     location = i.getLocation();
     conditions = i.getDeepCopyOfConditions();
     iconId = i.getId();
     isLocal = i.getLocality();
 }
Beispiel #2
0
        /// <summary>
        /// Constructor. Sets the icon, color, and style name. 
        /// </summary>
        /// <param name="icon">Icon --> Used for icon location when creating styles in KML</param>
        /// <param name="color">int --> Overlay color for KML</param>
        /// <param name="styleName">String --> unique style name</param>
        public Style(Icon icon, UInt64 color, String styleName)
        {
            this.icon = new Icon();
            this.icon.setId(icon.getId());
            this.icon.setLocality(icon.getLocality());
            this.icon.setLocation(icon.getLocation());

            foreach (Condition c in icon.getConditions())
            {
                this.icon.setConditions(c);
            }

            this.color = color;
            this.styleName = styleName;
        }
Beispiel #3
0
 protected void cancelModifyIconConditionPopup_Click(object sender, EventArgs e)
 {
     Button btn = (Button)sender;
     string iconId = btn.CommandArgument;
     Icon replaceWithThisIcon = new Icon();
     foreach (Icon icon in iconList)
     {
         if (icon.getId() == iconId)
         {
             replaceWithThisIcon = icon;
             break;
         }
     }
     foreach (Icon icon in conn.icons)
     {
         if (icon.getId() == iconId)
             icon.setConditions(replaceWithThisIcon.getDeepCopyOfConditions());
     }
     try
     {
         genIconConditionTable(sender, e);
     }
     catch (ODBC2KMLException ex)
     {
         ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1);
         eh.displayError();
         return;
     }
     sessionSave();
 }
Beispiel #4
0
        protected void addSingleIconToLib(String path)
        {
            Database db = new Database();
            DataTable dt;

            try
            {
                dt = db.executeQueryLocal("SELECT ID, location, isLocal FROM IconLibrary WHERE location=\'" + path + "\'");
            }
            catch (ODBC2KMLException ex)
            {
                throw ex;
            }

            foreach (DataRow dr in dt.Rows)
            {
                Icon icon = new Icon();
                icon.setId(dr["ID"].ToString());
                icon.setLocation(dr["location"].ToString());
                icon.setLocality((bool)dr["isLocal"]);
                iconListAvailableToAdd.Add(icon);
            }
            fillIconLibraryPopup();
            sessionSave();
        }
Beispiel #5
0
        //Removes an icon assocaiated with a connection and all conditions associated with it
        protected void removeIconFromConnFunct(object sender, EventArgs e)
        {
            ImageButton sendBtn = (ImageButton)sender;
            String args = sendBtn.CommandArgument.ToString();

            Icon icn = new Icon();
            Icon iconSaved = new Icon();
            icn.setId(args);

            foreach (Icon icon in iconList)
            {
                if (icon.getId().Equals(icn.getId()))
                {
                    iconList.Remove(icon);
                    break;
                }
            }
            foreach (Icon icon in conn.icons)
            {
                if (icon.getId().Equals(icn.getId()))
                {
                    conn.icons.Remove(icon);
                    break;
                }
            }
            try
            {
                foreach (Icon icon in iconListAvailableToRemove)
                {

                    if (icon.getId().Equals(icn.getId()))
                    {
                        iconSaved.setId(icon.getId());
                        iconSaved.setLocation(icon.getLocation());
                        iconListAvailableToRemove.Remove(icon);
                        int j = 0;
                        foreach (Icon icon2 in iconListAvailableToAdd)
                        {
                            if (System.Convert.ToInt32(iconSaved.getId()) < System.Convert.ToInt32(icon2.getId()))
                            {
                                iconListAvailableToAdd.Insert(j, iconSaved);
                                break;
                            }
                            j += 1;
                            if (j == iconListAvailableToAdd.Count)
                            {
                                iconListAvailableToAdd.Add(iconSaved);
                                break;
                            }
                        }
                        this.fillIconLibraryPopup();
                        this.fillIconLibraryPopupRemove();
                        this.genIconConditionTable(sender, e);
                        break;
                    }
                }
            }
            catch (ODBC2KMLException ex)
            {
                ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1);
                eh.displayError();
                return;
            }
            sessionSave();
        }
Beispiel #6
0
        protected void fillIconLibraryLists()
        {
            iconListAvailableToAdd.Clear();
            iconListAvailableToRemove.Clear();
            string conId = Request.QueryString.Get("ConnID");

            Database db = new Database();
            DataTable dt;

            try
            {
                dt = db.executeQueryLocal("SELECT ID, location, isLocal FROM IconLibrary AS IL WHERE (NOT EXISTS (SELECT ID, connID FROM Icon AS IC WHERE (connID = " + conId + " ) AND (iconLibraryID = IL.ID)))");
            }
            catch (ODBC2KMLException ex)
            {
                throw ex;
            }

            foreach (DataRow dr in dt.Rows)
            {
                Icon icon = new Icon();
                icon.setId(dr["ID"].ToString());
                icon.setLocation(dr["location"].ToString());
                icon.setLocality((bool)dr["isLocal"]);
                iconListAvailableToAdd.Add(icon);
            }

            Database db2 = new Database();
            DataTable dt2;
            try
            {
                dt2 = db2.executeQueryLocal("SELECT IconLibrary.ID, IconLibrary.location, IconLibrary.isLocal FROM IconLibrary,Icon Where IconLibrary.ID=Icon.iconLibraryID AND Icon.ConnID=" + conId);
            }
            catch (ODBC2KMLException ex)
            {
                throw ex;
            }

            foreach (DataRow dr2 in dt2.Rows)
            {
                string iconId = dr2["ID"].ToString();
                string iconLoc = dr2["location"].ToString();
                Icon icon = new Icon();
                icon.setId(iconId);
                icon.setLocation(iconLoc);
                icon.setLocality((bool)dr2["isLocal"]);
                iconListAvailableToRemove.Add(icon);
            }
        }
Beispiel #7
0
        public static ArrayList getIcons(int connID)
        {
            ArrayList icons = new ArrayList();
            Database localDatabase = new Database();

            //Create icon query and populate table
            string query = "SELECT * FROM Icon WHERE connID=" + connID + " ORDER BY ID";
            DataTable table = null;

            try
            {
                table = localDatabase.executeQueryLocal(query);
            }
            catch (ODBC2KMLException ex)
            {
                ex.errorText = "There was an error getting icons for the connection";
                throw ex;
            }

            foreach (DataRow row in table.Rows)
            {
                //Create a new icon
                Icon newIcon = new Icon();

                //Create a new table to perform subqueries on
                DataTable newTable = new DataTable();

                //IconLibrary query
                string locQuery = "SELECT * FROM IconLibrary WHERE ID=" + ((int)row["iconLibraryID"]) + " ORDER BY ID";

                try
                {
                    newTable = localDatabase.executeQueryLocal(locQuery);
                }
                catch (ODBC2KMLException ex)
                {
                    ex.errorText = "There was an error populating the Icon Library";
                    throw ex;
                }

                foreach (DataRow nRow in newTable.Rows)
                {
                    //Set the location of the icon
                    newIcon.setLocation(nRow["location"].ToString());
                    newIcon.setId(nRow["ID"].ToString());
                    if ((Boolean)nRow["isLocal"] == false)
                    {
                        newIcon.setLocality(false);
                    }
                    else
                    {
                        newIcon.setLocality(true);
                    }
                }//End outer loop

                newTable.Clear();

                //IconCondition query
                string conQuery = "SELECT * FROM IconCondition WHERE iconID="
                    + ((int)row["ID"]) + " AND connID=" + connID;

                try
                {
                    newTable = localDatabase.executeQueryLocal(conQuery);
                }
                catch (ODBC2KMLException ex)
                {
                    ex.errorText = "There was a problem selecting icon conditions for icon " + (int)row["iconLibraryID"];
                    throw ex;
                }

                //Cycle through each condition
                foreach (DataRow nRow in newTable.Rows)
                {
                    //Create the condition and add its values
                    Condition condition = new Condition();

                    if (nRow["lowerBound"] != null)
                    {
                        condition.setLowerBound(nRow["lowerBound"].ToString());
                    }
                    else
                    {
                        condition.setLowerBound("");
                    }

                    if (nRow["upperBound"] != null)
                    {
                        condition.setUpperBound(nRow["upperBound"].ToString());
                    }
                    else
                    {
                        condition.setUpperBound("");
                    }

                    condition.setLowerOperator((int)nRow["lowerOperator"]);
                    condition.setUpperOperator((int)nRow["upperOperator"]);
                    condition.setTableName(nRow["tableName"].ToString());
                    condition.setFieldName(nRow["fieldName"].ToString());
                    condition.setId(Convert.ToInt16(nRow["ID"].ToString()));

                    //Add the condition to the icon array
                    newIcon.setConditions(condition);
                    //Free up condition memory
                    condition = null;
                }//End outer loop
                //Free up table memory
                newTable = null;

                icons.Add(newIcon);
                //Free up icon memory
                newIcon = null;

            }//End outer loop

            return icons;
        }
Beispiel #8
0
 /// <summary>
 /// Basic constructor.
 /// </summary>
 public Style()
 {
     icon = new Icon();
     color = 0;
     styleName = "";
 }
Beispiel #9
0
 //set style icon
 public void setStyleIcon(Icon icon)
 {
     this.icon = icon;
 }
Beispiel #10
0
        /// <summary>
        /// This function takes a connection object and generates all the associated KML for that connection.
        /// It works hand-in-hand with KMLGenerationLibrary, Styles, and Placemarks.
        /// 
        /// There is also a helper class used to prevent duplicate styles (HashStyleComparer).
        /// </summary>
        /// <param name="connection">Connection --> connection object for the connection that you wish to generate KML for</param>
        /// <returns>String --> A string that is the KML</returns>
        public string generateKMLFromConnection(Connection connection)
        {
            //if the mapping is invalid, throw an exception and don't try to continue
            if (!connection.mapping.isValid(connection.connInfo))
            {
                throw new ODBC2KMLException("There was an exception generating KML. Mapping is invalid.");
            }

            //Needed to generate KML, parameter is desired file name within KML file
            KMLGenerationLibrary kmlGenerator = new KMLGenerationLibrary(this.fileName);

            try
            {
                //Get mappings fromc onnection object
                Mapping map = connection.getMapping();

                //Create array list to hold places
                ArrayList placemarks = new ArrayList();
                //Create hashset to hold unique styles, takes HashStyleComparer which is a helper class
                HashSet<Style> styles = new HashSet<Style>(new HashStyleComparer());

                //Create the Icon array and grabs the icons for the connection
                ArrayList icons = new ArrayList();
                icons = connection.getIcons();

                //Create the overlay array and grab the overlays for the connection
                ArrayList overlays = new ArrayList();
                overlays = connection.getOverlays();

                //Retrieve description string
                String descString = connection.getDescription().getDesc();

                //Create an array to store new description values
                ArrayList descArray = new ArrayList();

                //Create data table to pass to parser
                DataTable remote = null;

                //Create database
                Database DB = new Database(connection.getConnInfo());

                //Grab the tablename out of mapping
                String tableName = map.getTableName();

                try
                {
                    if (connection.getConnInfo().getDatabaseType() == ConnInfo.MSSQL)
                    {
                        remote = DB.executeQueryRemote("SELECT * FROM " + tableName);
                    }
                    else if (connection.getConnInfo().getDatabaseType() == ConnInfo.MYSQL)
                    {
                        remote = DB.executeQueryRemote("SELECT * FROM " + tableName + ";");
                    }
                    else if (connection.getConnInfo().getDatabaseType() == ConnInfo.ORACLE)
                    {
                        remote = DB.executeQueryRemote("SELECT * FROM \"" + tableName + "\"");
                    }
                }
                catch
                {
                    throw new ODBC2KMLException("There was an exception generating KML. There was a problem retreiving data from the remote server");
                }

                //Parsed descriptions for rows
                descArray = Description.parseDesc(remote, descString, tableName);

                int counter = 0;
                //For each row in the table!!!
                foreach (DataRow remoteRow in remote.Rows)
                {
                    //Set placemark name
                    string placemarkName;
                    try
                    {
                        if (map.getPlacemarkFieldName() == null || map.getPlacemarkFieldName().Trim().Equals("") || map.getPlacemarkFieldName().Trim().Equals("No placemark name mapped"))
                        {
                            placemarkName = "";
                        }
                        else
                        {
                            placemarkName = (String)remoteRow[map.getPlacemarkFieldName()];

                        }
                    }
                    catch
                    {
                        throw new ODBC2KMLException("There was an exception generating KML. Error parsing placemark.");
                    }

                    //Foreach row set the description for each row
                    String rowDesc = descArray[counter].ToString();

                    //Declare the lat and long holders
                    Double rowLat = 0, rowLon = 0;

                    //Check to see how many columns there are
                    try
                    {
                        if (map.getFormat() != Mapping.SEPARATE)
                        {
                            //Select the column value
                            String column = "";
                            foreach (DataColumn remoteColumn in remote.Columns)
                            {
                                if (remoteColumn.ColumnName == map.getLatFieldName())
                                {
                                    column = remoteRow[remoteColumn].ToString();
                                }
                            }

                            //Create the array to hold the coordinates
                            double[] coordinates;

                            //Separate the coordinates
                            //Order == Latitude First
                            if (map.getFormat() == Mapping.LATFIRST)
                            {
                                coordinates = map.separate(column, Mapping.LATFIRST);
                                rowLat = coordinates[0];
                                rowLon = coordinates[1];
                            }
                            else //Order == Longitude first
                            {
                                coordinates = map.separate(column, Mapping.LONGFIRST);
                                rowLon = coordinates[0];
                                rowLat = coordinates[1];
                            }
                        }
                        else//Two separate columns
                        {
                            //Get coordinates
                            foreach (DataColumn remoteColumn in remote.Columns)
                            {
                                if (remoteColumn.ColumnName == map.getLatFieldName())
                                {
                                    rowLat = Double.Parse(remoteRow[remoteColumn].ToString());
                                }
                                else if (remoteColumn.ColumnName == map.getLongFieldName())
                                {
                                    rowLon = Double.Parse(remoteRow[remoteColumn].ToString());
                                }
                            }//End for each
                        }//End else
                    }
                    catch
                    {
                        throw new ODBC2KMLException("There was an exception generating KML. Error parsing lat/long rows.");
                    }

                    //Row's icon
                    Icon rowIcon = new Icon();
                    rowIcon.setLocation("");

                    //For each icon until the first one found, compare the icons
                    //conditions against the given row
                    Boolean breakLoop = false;
                    foreach (Icon i in icons)
                    {
                        foreach (Condition c in i.getConditions())
                        {
                            //See if the condition applies to the given row
                            if (c.evaluateCondition(remoteRow, c, tableName))
                            {
                                //Set temp icon to row icon and tell it to break out
                                rowIcon = new Icon(i);
                                breakLoop = true;
                            }

                            //Grabbed the first icon, break out
                            if (breakLoop)
                                break;
                        }//End inner for each

                        //Grabbed the first icon, break out
                        if (breakLoop)
                            break;
                    }//End outer for each

                    //Long unsigned int, needed to properly interpret colors
                    UInt64 color = 0;
                    foreach (Overlay o in overlays)
                    {
                        foreach (Condition c in o.getConditions())
                        {
                            //See if the condition applies
                            if (c.evaluateCondition(remoteRow, c, tableName))
                            {
                                if (color == 0)
                                {
                                    //Set the color to hex value
                                    color = 0xFF000000;
                                }
                                //Mix the colors, if multiple colors work
                                color = color | (Convert.ToUInt64(o.getColor(), 16));
                            }
                        }//End inner for each
                    }//End outer for each

                    //Create Style and placemark for this coordinate set
                    Style rowStyle = new Style();
                    Placemark rowPlacemark;

                    //if there is an icon, create the name of the style based on the icon name and color
                    if (rowIcon.getLocation() != "")
                    {
                        if (rowIcon.getLocality() == false)
                        {
                            //Create new style with external icon
                            rowStyle = new Style(rowIcon, color, (rowIcon.getLocation() + "_" + color.ToString("X")));
                            rowIcon.setLocation("");
                        }
                        else //If the icon is local, append server data
                        {
                            //Create the new style, with local icon
                            rowIcon.setLocation(this.serverPath + rowIcon.getLocation());
                            rowStyle = new Style(rowIcon, color, (rowIcon.getLocation() + "_" + color.ToString("X")));
                            rowIcon.setLocation("");
                        }
                    }
                    else if (rowIcon.getLocation() == "" && color != 0) //Create the style name based on the color
                    {
                        rowStyle = new Style(rowIcon, color, color.ToString("X"));
                    }
                    else //If rowstyle is null, ignore it
                    {
                        rowStyle = null;
                    }

                    //Create placemark and add it to array list
                    rowPlacemark = new Placemark(rowLat, rowLon, rowDesc, placemarkName);

                    placemarks.Add(rowPlacemark);

                    //If there is a row style, add it to the placemark and the array list
                    if (rowStyle != null)
                    {
                        rowPlacemark.setPlacemarkStyleName("#" + rowStyle.getStyleName());
                        styles.Add(rowStyle);
                    }
                    else
                    {
                        //Default value which won't add a style to this placemark in KML
                        rowPlacemark.setPlacemarkStyleName("");
                    }

                    //Increment counter for next row (associated with getting the row description)
                    counter++;

                }//End for each
                // }//End for each

                //Add each style to the KML
                foreach (Style s in styles)
                {
                    kmlGenerator.addStyle(s);
                }

                //Used to check if a look at has been added
                Boolean addLookAt = false;

                //Add each placemark to the KML
                foreach (Placemark p in placemarks)
                {
                    kmlGenerator.addPlacemark(p);
                    if (!addLookAt) //Add the first placemark as default lookat
                    {
                        kmlGenerator.addLookAt(p);
                        addLookAt = true;
                    }
                }
            }
            catch (ODBC2KMLException e) //If bad things happen pass it up to connection details
            {
                throw e;
            }

            //Return KML string
            return kmlGenerator.finalizeKML();
        }