Esempio n. 1
0
        public static List <Domain> getDomains()
        {
            List <Domain> domains = new List <Domain>();

            try
            {
                String query = "SELECT * FROM Domain;";
                using (SqlCommand command = new SqlCommand(query, con))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            domains.Add(SerializeToXml.DeSerializeXmlToObject <Domain>(reader.GetString(0)));
                            domains[domains.Count - 1].setURL(reader.GetString(1));
                            domains[domains.Count - 1].setDomainURL(reader.GetString(1));
                            domains[domains.Count - 1].setCountry(reader.GetString(3));
                            domains[domains.Count - 1].setPriority(reader.GetInt32(2));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return(domains);
        }
Esempio n. 2
0
        public static void insertDomain(Domain domain)
        {
            SqlTransaction transaction = con.BeginTransaction();

            try
            {
                using (SqlCommand command = con.CreateCommand())
                {
                    command.Connection  = con;
                    command.Transaction = transaction;

                    command.CommandText = "IF NOT EXISTS (SELECT URL FROM Domain WHERE URL = '" + domain.getURL() + "') " +
                                          "INSERT INTO Domain(Object, URL, Priority, Country) VALUES('"
                                          + escapeApostrophe(SerializeToXml.SerializeObjectToXml <Domain>(domain)) + "', '"
                                          + domain.getURL() + "', "
                                          + domain.getPriority() + ", '"
                                          + domain.getCountry() + "');";
                    command.ExecuteNonQuery();
                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                if (con != null)
                {
                    transaction.Rollback();
                }
            }
            finally
            {
                transaction.Dispose();
            }
        }
Esempio n. 3
0
        public static void alterDomain(Domain domain)
        {
            SqlTransaction transaction = con.BeginTransaction();

            try
            {
                using (SqlCommand command = con.CreateCommand())
                {
                    command.Connection  = con;
                    command.Transaction = transaction;

                    command.CommandText = "IF EXISTS (SELECT * FROM Domain WHERE URL = '" + domain.getDomainURL() + "')" +
                                          "UPDATE Domain SET Object = '" + escapeApostrophe(SerializeToXml.SerializeObjectToXml <Domain>(domain)) + "' WHERE URL = '" + domain.getDomainURL() + "';";
                    command.ExecuteNonQuery();
                    transaction.Commit();
                }
            }
            catch (SqlException ex)
            {
                if (con != null)
                {
                    transaction.Rollback();
                }
                throw ex;
            }
            finally
            {
                transaction.Dispose();
            }
        }