Example #1
0
        /// <summary>
        /// Saves image data to image data folder file.
        /// </summary>
        /// <param name="ImageGuid">Image GUID.</param>
        /// <param name="Data">Binary image data to save.</param>
        /// <returns>true if the function succeeds, false otherwise.</returns>
        public static async Task <bool> SaveImageDataAsync(Guid ImageGuid, byte[] Data)
        {
            log.Trace("(ImageGuid:'{0}',Data.Length:{1})", ImageGuid, Data != null ? Data.Length.ToString() : "n/a");

            bool res = false;

            if ((Data != null) && (Data.Length > 0))
            {
                try
                {
                    string fileName = GetImageFileName(ImageGuid);
                    string path     = Path.GetDirectoryName(fileName);
                    Directory.CreateDirectory(path);
                    await FileAsync.WriteAllBytesAsync(fileName, Data);

                    res = true;
                }
                catch (Exception e)
                {
                    log.Error("Exception occurred: {0}", e.ToString());
                }
            }

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #2
0
        /// <summary>
        /// Loads image data from a file.
        /// </summary>
        /// <param name="ImageGuid">Image GUID.</param>
        /// <returns>Binary image data if the function succeeds, null in case of error.</returns>
        public static async Task <byte[]> GetImageDataAsync(Guid ImageGuid)
        {
            log.Trace("(ImageGuid:'{0}')", ImageGuid);

            byte[] res      = null;
            string fileName = GetImageFileName(ImageGuid);

            if (fileName != null)
            {
                try
                {
                    res = await FileAsync.ReadAllBytesAsync(fileName);
                }
                catch (Exception e)
                {
                    log.Error("Exception occurred: {0}", e.ToString());
                }
            }

            log.Trace("(-):*.Lenght={0}", res != null ? res.Length.ToString() : "n/a");
            return(res);
        }