Exemplo n.º 1
0
        /// <summary>
        /// Returns a list of available images without the type or data for performence reasons.
        /// </summary>
        /// <returns>a list of images</returns>
        public List <OSAEImage> GetImageList()
        {
            List <OSAEImage> imageList = new List <OSAEImage>();

            if (API.Common.TestConnection())
            {
                using (MySqlConnection connection = new MySqlConnection(API.Common.ConnectionString))
                {
                    try
                    {
                        connection.Open();

                        MySqlCommand    command = new MySqlCommand("SELECT image_id, image_name FROM osae_images", connection);
                        MySqlDataReader reader  = command.ExecuteReader();

                        while (reader.Read())
                        {
                            OSAEImage osaeImage = new OSAEImage();
                            osaeImage.ID   = reader.GetUInt32("image_id");
                            osaeImage.Name = reader.GetString("image_name");

                            imageList.Add(osaeImage);
                        }
                    }
                    catch (Exception e)
                    {
                        osae.AddToLog("API.Images - GetImageList - Failed \r\n\r\n" + e.Message, true);
                    }
                }
            }
            return(imageList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets an image from the DB
        /// </summary>
        /// <param name="imageId">The id of the image to get</param>
        /// <returns>the requested image</returns>
        public OSAEImage GetImage(int imageId)
        {
            OSAEImage osaeImage = new OSAEImage();

            if (API.Common.TestConnection())
            {
                using (MySqlConnection connection = new MySqlConnection(API.Common.ConnectionString))
                {
                    MySqlCommand command = new MySqlCommand("SELECT * FROM osae_images WHERE image_id = " + imageId, connection);
                    connection.Open();

                    MySqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        osaeImage.ID   = reader.GetUInt32("image_id");
                        osaeImage.Name = reader.GetString("image_name");
                        osaeImage.Type = reader.GetString("image_type");
                        osaeImage.Data = (byte[])reader.GetValue(1);
                    }
                    else
                    {
                        osae.AddToLog("API.Images - Failed to get requested image from DB: ", true);
                    }
                }
            }

            return(new OSAEImage());
        }
        /// <summary>
        /// Gets an image from the DB
        /// </summary>
        /// <param name="imageId">The id of the image to get</param>
        /// <returns>the requested image</returns>
        public OSAEImage GetImage(int imageId)
        {
            OSAEImage osaeImage = new OSAEImage();
            if (Common.TestConnection())
            {
                using (MySqlConnection connection = new MySqlConnection(Common.ConnectionString))
                {
                    MySqlCommand command = new MySqlCommand("SELECT * FROM osae_images WHERE image_id = " + imageId, connection);
                    connection.Open();

                    MySqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        osaeImage.ID = reader.GetUInt32("image_id");
                        osaeImage.Name = reader.GetString("image_name");
                        osaeImage.Type = reader.GetString("image_type");
                        osaeImage.Data = (byte[])reader.GetValue(1);
                    }
                    else
                    {
                        logging.AddToLog("API - Failed to get requested image from DB: ", true);
                    }
                }
            }

            return new OSAEImage();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds an image to the DB
 /// </summary>
 /// <param name="osaeImage">The image information to add</param>
 public void AddImage(OSAEImage osaeImage)
 {
     AddImage(osaeImage.Name, osaeImage.Type, osaeImage.Data);
 }
 /// <summary>
 /// Adds an image to the DB
 /// </summary>
 /// <param name="osaeImage">The image information to add</param>
 public void AddImage(OSAEImage osaeImage)
 {
     AddImage(osaeImage.Name, osaeImage.Type, osaeImage.Data);
 }
        /// <summary>
        /// Gets all the images available in the DB
        /// </summary>
        /// <returns>returns the images available in the DB</returns>
        /// <remarks>Only call this method if you have to as retrieving all images can take a short while</remarks>
        public List<OSAEImage> GetImages()
        {
            List<OSAEImage> imageList = new List<OSAEImage>();

            if (Common.TestConnection())
            {
                using (MySqlConnection connection = new MySqlConnection(Common.ConnectionString))
                {
                    try
                    {
                        connection.Open();

                        MySqlCommand command = new MySqlCommand("SELECT * FROM osae_images", connection);
                        MySqlDataReader reader = command.ExecuteReader();

                        while (reader.Read())
                        {
                            OSAEImage osaeImage = new OSAEImage();
                            osaeImage.ID = reader.GetUInt32("image_id");
                            osaeImage.Name = reader.GetString("image_name");
                            osaeImage.Type = reader.GetString("image_type");
                            osaeImage.Data = (byte[])reader.GetValue(1);

                            imageList.Add(osaeImage);
                        }
                    }
                    catch (Exception e)
                    {
                        logging.AddToLog("API - GetImages - Failed \r\n\r\n" + e.Message, true);
                    }
                }
            }
            return imageList;
        }