示例#1
0
        /// <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>();

            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)
                {
                    // Exceptions should be caught by calling application
                    throw new Exception("API - GetImages - Failed: " + e.Message, e);
                }
            }

            return(imageList);
        }
        /// <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: " + imageId.ToString(), true);
                    }
                }
            }

            return(osaeImage);
        }
        /// <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);
        }
示例#4
0
        public void Load_Screen(string sScreen)
        {
            try
            {
                while (updatingScreen)
                {
                    System.Threading.Thread.Sleep(100);
                }
                loadingScreen = true;
                //this.Log.Debug("Loading screen: " + sScreen);

                stateImages.Clear();
                propLabels.Clear();
                navImages.Clear();
                clickImages.Clear();
                cameraViewers.Clear();
                canGUI.Children.Clear();
                browserFrames.Clear();

                gCurrentScreen = sScreen;
                OSAEObjectPropertyManager.ObjectPropertySet(gAppName, "Current Screen", sScreen, "GUI");
                OSAE.OSAEImageManager imgMgr = new OSAE.OSAEImageManager();
                string         imgID         = OSAEObjectPropertyManager.GetObjectPropertyValue(sScreen, "Background Image").Value;
                OSAE.OSAEImage img           = imgMgr.GetImage(imgID);

                //sPath = OSAEApi.APIpath + OSAEApi.GetObjectPropertyValue(sScreen, "Background Image").Value;
                //byte[] byteArray = File.ReadAllBytes(sPath);

                if (img.Data != null)
                {
                    var imageStream = new MemoryStream(img.Data);
                    var bitmapImage = new BitmapImage();

                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = imageStream;
                    bitmapImage.EndInit();
                    canGUI.Background = new ImageBrush(bitmapImage);
                    canGUI.Height     = bitmapImage.Height;
                    canGUI.Width      = bitmapImage.Width;
                }

                //Thread threadLoad = new Thread(() => Load_Objects(sScreen));
                //threadLoad.Start();

                Load_Objects(sScreen);
                loadingScreen = false;

                //this.Log.Debug("Loading screen complete: " + sScreen);
            }
            catch (Exception ex)
            {
                this.Log.Error("Failed to load screen: " + sScreen, ex);
            }
        }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (fileUpload.HasFile)
        {
            try
            {
                if (System.IO.Path.GetExtension(fileUpload.FileName).ToLower() != ".jpg" && System.IO.Path.GetExtension(fileUpload.FileName).ToLower() != ".png" && System.IO.Path.GetExtension(fileUpload.FileName).ToLower() != ".jpeg")
                {
                    // wrong file type
                    return;
                }
                else
                {
                    if (fileUpload.PostedFile.ContentLength < 102400)
                    {

                        OSAEImage img = new OSAEImage();
                        img.Data = fileUpload.FileBytes;
                        img.Name = txtName.Text;
                        img.Type = System.IO.Path.GetExtension(fileUpload.FileName).ToLower().Substring(1);

                        var imageManager = new OSAE.OSAEImageManager();
                        imageManager.AddImage(img);
                        loadImages();
                    }
                    else
                    {
                        // file to big
                        return;
                    }

                }
            }
            catch (Exception ex)
            {

            }
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (fileUpload.HasFile)
        {
            try
            {
                if (System.IO.Path.GetExtension(fileUpload.FileName).ToLower() != ".jpg" && System.IO.Path.GetExtension(fileUpload.FileName).ToLower() != ".png" && System.IO.Path.GetExtension(fileUpload.FileName).ToLower() != ".jpeg" && System.IO.Path.GetExtension(fileUpload.FileName).ToLower() != ".gif")
                {
                    Master.Log.Error("Image not added, Wrong file type");
                    return; // wrong file type
                }
                else
                {
                    if (fileUpload.PostedFile.ContentLength < 2502400) //202400
                    {
                        OSAEImage img = new OSAEImage();
                        img.Data = fileUpload.FileBytes;
                        img.Name = txtName.Text;
                        img.Type = System.IO.Path.GetExtension(fileUpload.FileName).ToLower().Substring(1);

                        var imageManager = new OSAE.OSAEImageManager();
                        imageManager.AddImage(img);

                        loadImages();
                    }
                    else
                    {
                        Master.Log.Error("Image not added, file is to large.");
                        return; //file to big
                    }
                }
            }
            catch (Exception ex)
            { }
        }
    }
 /// <summary>
 /// Adds an image to the DB
 /// </summary>
 /// <param name="osaeImage">The image information to add</param>
 public int AddImage(OSAEImage osaeImage)
 {
     return(AddImage(osaeImage.Name, osaeImage.Type, osaeImage.Data));
 }
        /// <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: " + imageId.ToString(), true);
                    }
                }
            }

            return osaeImage;
        }
 /// <summary>
 /// Adds an image to the DB
 /// </summary>
 /// <param name="osaeImage">The image information to add</param>
 public int AddImage(OSAEImage osaeImage)
 {
     return 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;
        }
        /// <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>();

            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)
                {
                    // Exceptions should be caught by calling application
                    throw new Exception("API - GetImages - Failed: " + e.Message, e);
                }
            }

            return imageList;
        }