コード例 #1
0
        public void ExtractDataFromDB(PhotoAttribute attr)
        {
            string query = "SELECT photo_id ,photo_url FROM photos";

            switch (attr)
            {
            case PhotoAttribute.all:
                query = "SELECT photo_id, photo_url, isFunny FROM photos";

                break;

            case PhotoAttribute.funny:
                query = "SELECT photo_id, photo_url, isFunny FROM photos WHERE isfunny = true";

                break;

            case PhotoAttribute.notFunny:
                query = "SELECT photo_id, photo_url, isFunny FROM photos WHERE isfunny = false";
                break;

            default:
                break;
            }
            Log.AddToLog("Reading Database. Query " + query);

            try
            {
                conn.Open();
                NpgsqlCommand command = new NpgsqlCommand(query, conn);

                this.PhotosInfoList.Clear();

                // Get the reader
                dr = command.ExecuteReader();

                while (dr.Read())
                {
                    this.PhotosInfoList.Add(new PhotoInfo(int.Parse(dr[0].ToString()), dr[1].ToString(), bool.Parse(dr[2].ToString())));
                }
                dr.Close();
            }
            catch (Exception)
            {
                Log.AddToLog("Error when connecting to database.");
                //dont throw;
            }
            finally
            {
                // Close connection
                if (conn != null)
                {
                    conn.Close();
                }
            }
            // Notify that the data from DB is ready to be processed
            DBDataIsReady(attr);
        }
コード例 #2
0
        private void DBDataIsReady(PhotoAttribute attr)
        {
            // Make sure someone is listening to event
            if (OnDatabasIsReady == null)
            {
                return;
            }

            ProgressEventArgs args = new ProgressEventArgs(attr);

            // Broadcast to listeners
            OnDatabasIsReady(this, args);
        }
コード例 #3
0
 public ProgressEventArgs(PhotoAttribute attr)
 {
     Attr = attr;
 }