Esempio n. 1
0
        /// <summary>
        /// Since there is no main this fulfills the purpose for the update button
        /// it handles the connection, API call and update to the gcloud database
        /// </summary>
        /// <param name="arguments">the credentials</param>
        public void Execute()
        {
            SqlConnect dBConnect  = new SqlConnect();
            String     connString = (string)Application.Current.Resources["connString"];

            dBConnect.CheckDate(connString, out DateTime date);
            DataFormat test = new DataFormat();

            Dictionary <string, object>[] rarr = test.GetData(date);
            List <Json311> forDB = test.ParseData(rarr);

            dBConnect.Import(forDB, connString);
        }
Esempio n. 2
0
        /// <summary>
        /// our main method
        /// </summary>
        /// <param name="args">we should never really need arguments passed to main, however we may later decide to
        /// modify the program to accept the db name, ip address, username and password as command line arguments
        /// </param>
        static void Main(string[] args)
        {
            SqlConnect dBConnect  = new SqlConnect();
            String     connString = dBConnect.Connect();

            dBConnect.CheckDate(connString);
            DataFormat test = new DataFormat();

            Dictionary <string, object>[] rarr = test.getData();
            List <Json311> forDB = new List <Json311>();

            forDB = test.parseData(rarr);
            dBConnect.Import(forDB, connString);
            Console.ReadKey();
        }
Esempio n. 3
0
        public void JsonNull()
        {
            /// <remarks>
            /// Since data is often missing all fields are initialized to null if they do not have another value;
            /// </remarks>
            Json311        test  = new Json311();
            List <Json311> JList = new List <Json311>();

            JList.Add(test);
            SqlConnect DBTest = new SqlConnect();
            /// <remarks>
            /// Uses a test user who has only insert and select privelege in testtable
            /// </remarks>
            String           connString = DBTest.Connect("test", "test", false);
            NpgsqlConnection conn       = new NpgsqlConnection(connString);

            conn.Open();
            /// <remarks>
            /// Check The connection
            /// </remarks>
            Assert.AreEqual(conn.State, System.Data.ConnectionState.Open);

            /// <remarks>
            /// Test the import, making sure the data is added to the right table
            /// and our date is not updated
            /// </remarks>

            DBTest.Import(JList, connString, "testtable", false);
            using (NpgsqlCommand checkValue = new NpgsqlCommand("SELECT * FROM testtable", conn))
                using (NpgsqlDataReader reader = checkValue.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        /// <remarks>
                        /// Since the column is empty, it will throw an invalid cast exception when
                        /// attemption to convert it to a string
                        /// </remarks>
                        Assert.Throws <System.InvalidCastException>(() => { reader.GetString(0); });
                    }
                }
            conn.Close();
        }