Exemplo n.º 1
0
        static void addMalamPolygon(String connectionParams)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionParams);

            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();

            try
            {
                Polygon             polygon = new Polygon(Guid.NewGuid().ToString(), "Malam");
                List <PolygonPoint> points  = new List <PolygonPoint>();
                points.Add(new PolygonPoint(polygon.guid, 0, 34.850942194461823, 32.098860770959512));
                points.Add(new PolygonPoint(polygon.guid, 1, 34.85137939453125, 32.098815327220322));
                points.Add(new PolygonPoint(polygon.guid, 2, 34.851290881633759, 32.098213195541732));
                points.Add(new PolygonPoint(polygon.guid, 3, 34.850845634937286, 32.098260911781828));
                points.Add(new PolygonPoint(polygon.guid, 4, 34.85086977481842, 32.098408604747945));
                points.Add(new PolygonPoint(polygon.guid, 5, 34.851129949092865, 32.098381338372178));
                points.Add(new PolygonPoint(polygon.guid, 6, 34.8511728644371, 32.098667634911841));
                points.Add(new PolygonPoint(polygon.guid, 7, 34.850918054580688, 32.098697173392637));


                PolygonDB db = new PolygonDB(connection);

                db.addPolygonToDB(polygon);
                db.addPolygonPoints(polygon, points);

                int[] edgesToAdd = new int[] { 1 };

                foreach (int i in edgesToAdd)
                {
                    double         openingX = (points[i].x + points[(i + 1) % points.Count()].x) / 2;
                    double         openingY = (points[i].y + points[(i + 1) % points.Count()].y) / 2;
                    PolygonOpening opening  = new PolygonOpening(polygon.guid, i, openingX, openingY, 3);
                    db.addPolygonOpeningToPolygon(opening);
                }

                transaction.Commit();
            }
            catch (Exception exception)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollbackException)
                {
                    Console.WriteLine("Rollback failed :(");
                }
            }

            connection.Close();
        }
Exemplo n.º 2
0
 public void addPolygonOpeningToPolygon(PolygonOpening opening)
 {
     String query = "INSERT INTO polygon_openings(opening_guid, polygon_guid, polygon_edge_num, position_x, position_y, opening_size_meters)"
      + " VALUES (:opening_guid, :polygon_guid, :polygon_edge_num, :position_x, :position_y, :opening_size_meters)";
     NpgsqlCommand command = new NpgsqlCommand(query, connection);
     command.Parameters.Add(new NpgsqlParameter("opening_guid", opening.openingGuid));
     command.Parameters.Add(new NpgsqlParameter("polygon_guid", opening.polygonGuid));
     command.Parameters.Add(new NpgsqlParameter("polygon_edge_num", opening.polygonEdgeNum));
     command.Parameters.Add(new NpgsqlParameter("position_x", opening.x));
     command.Parameters.Add(new NpgsqlParameter("position_y", opening.y));
     command.Parameters.Add(new NpgsqlParameter("opening_size_meters", opening.openingSize));
     command.ExecuteNonQuery();
 }
Exemplo n.º 3
0
        public void addPolygonOpeningToPolygon(PolygonOpening opening)
        {
            String query = "INSERT INTO polygon_openings(opening_guid, polygon_guid, polygon_edge_num, position_x, position_y, opening_size_meters)"
                           + " VALUES (:opening_guid, :polygon_guid, :polygon_edge_num, :position_x, :position_y, :opening_size_meters)";
            NpgsqlCommand command = new NpgsqlCommand(query, connection);

            command.Parameters.Add(new NpgsqlParameter("opening_guid", opening.openingGuid));
            command.Parameters.Add(new NpgsqlParameter("polygon_guid", opening.polygonGuid));
            command.Parameters.Add(new NpgsqlParameter("polygon_edge_num", opening.polygonEdgeNum));
            command.Parameters.Add(new NpgsqlParameter("position_x", opening.x));
            command.Parameters.Add(new NpgsqlParameter("position_y", opening.y));
            command.Parameters.Add(new NpgsqlParameter("opening_size_meters", opening.openingSize));
            command.ExecuteNonQuery();
        }
Exemplo n.º 4
0
        private static void addDubekPolygonOpenings(String connectionParams)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionParams);

            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();

            int[] edgesToAdd = new int[] { 0, 4, 5 };

            try
            {
                // get polygon points
                PolygonDB           db      = new PolygonDB(connection);
                Polygon             polygon = db.getPolygonByName("Polygon1");
                List <PolygonPoint> points  = db.getPolygonPointsByPolygonGUID(polygon.guid);

                // add an opening
                foreach (int i in edgesToAdd)
                {
                    double         openingX = (points[i].x + points[(i + 1) % points.Count()].x) / 2;
                    double         openingY = (points[i].y + points[(i + 1) % points.Count()].y) / 2;
                    PolygonOpening opening  = new PolygonOpening(polygon.guid, i, openingX, openingY, 3);
                    db.addPolygonOpeningToPolygon(opening);
                }

                transaction.Commit();
            }
            catch (Exception exception)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollbackException)
                {
                    Console.WriteLine("Rollback failed :(");
                }
            }

            connection.Close();
        }
Exemplo n.º 5
0
        private static void addDubekPolygonOpenings(String connectionParams)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionParams);
            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();

            int[] edgesToAdd = new int[] { 0, 4, 5 };

            try
            {
                // get polygon points
                PolygonDB db = new PolygonDB(connection);
                Polygon polygon = db.getPolygonByName("Polygon1");
                List<PolygonPoint> points = db.getPolygonPointsByPolygonGUID(polygon.guid);
                
                // add an opening
                foreach (int i in edgesToAdd)
                {
                    double openingX = (points[i].x + points[(i + 1) % points.Count()].x) / 2;
                    double openingY = (points[i].y + points[(i + 1) % points.Count()].y) / 2;
                    PolygonOpening opening = new PolygonOpening(polygon.guid, i, openingX, openingY, 3);
                    db.addPolygonOpeningToPolygon(opening);
                }

                transaction.Commit();
            }
            catch (Exception exception)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollbackException)
                {
                    Console.WriteLine("Rollback failed :(");
                }
            }

            connection.Close();
        }
Exemplo n.º 6
0
        static void addMalamPolygon(String connectionParams)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionParams);
            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();

            try
            {
                Polygon polygon = new Polygon(Guid.NewGuid().ToString(), "Malam");
                List<PolygonPoint> points = new List<PolygonPoint>();
                points.Add(new PolygonPoint(polygon.guid, 0, 34.850942194461823, 32.098860770959512));
                points.Add(new PolygonPoint(polygon.guid, 1, 34.85137939453125, 32.098815327220322));
                points.Add(new PolygonPoint(polygon.guid, 2, 34.851290881633759, 32.098213195541732));
                points.Add(new PolygonPoint(polygon.guid, 3, 34.850845634937286, 32.098260911781828));
                points.Add(new PolygonPoint(polygon.guid, 4, 34.85086977481842, 32.098408604747945));
                points.Add(new PolygonPoint(polygon.guid, 5, 34.851129949092865, 32.098381338372178));
                points.Add(new PolygonPoint(polygon.guid, 6, 34.8511728644371, 32.098667634911841));
                points.Add(new PolygonPoint(polygon.guid, 7, 34.850918054580688, 32.098697173392637));


                PolygonDB db = new PolygonDB(connection);

                db.addPolygonToDB(polygon);
                db.addPolygonPoints(polygon, points);

                int[] edgesToAdd = new int[] { 1 };

                foreach (int i in edgesToAdd)
                {
                    double openingX = (points[i].x + points[(i + 1) % points.Count()].x) / 2;
                    double openingY = (points[i].y + points[(i + 1) % points.Count()].y) / 2;
                    PolygonOpening opening = new PolygonOpening(polygon.guid, i, openingX, openingY, 3);
                    db.addPolygonOpeningToPolygon(opening);
                }

                transaction.Commit();
            }
            catch (Exception exception)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollbackException)
                {
                    Console.WriteLine("Rollback failed :(");
                }
            }

            connection.Close();
        }