public void Save(long ghLocationId, HttpPostedFileBase image, string caption, string userName)
        {
            try
            {
                var temp = System.Drawing.Image.FromStream(image.InputStream);
                var ms   = new MemoryStream();
                temp.Save(ms, ImageFormat.Png);
                var data = ms.ToArray();

                var i = new Models.Image();
                i.Caption      = caption;
                i.UserName     = userName;
                i.GHLocationID = ghLocationId;

                ms.Dispose();
                ms = new MemoryStream();
                var myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                var thumbNail  = temp.GetThumbnailImage(32, 32, myCallback, IntPtr.Zero);
                thumbNail.Save(ms, ImageFormat.Png);
                i.Thumbnail = ms.ToArray();

                _ir.Insert(i);

                var ri = new RawImage();
                ri.FileName   = image.FileName;
                ri.MIMEType   = "image/png";
                ri.Data       = data;
                ri.RawImageID = i.ImageID;

                _rir.Insert(ri);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
            }
        }
Example #2
0
        public ActionResult ImageTests()
        {
            try
            {
                var ctm = new CacheTestModel();

                var c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1");

                if (c == null)
                {
                    ctm.Message = "Initial Get Failed";
                    return(View(ctm));
                }

                var dt = DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal);

                var rawSound = new RawImage();
                rawSound.Data     = new byte[1];
                rawSound.FileName = "LocationControllerTest";
                rawSound.MIMEType = "image/png";

                var s = new Image();
                s.GHLocationID = 1;
                s.Caption      = "Location Controller Test";
                s.UserName     = UserHelper.Instance.CurrentUserName;
                _ir.Insert(s);

                rawSound.RawImageID = s.ImageID;
                _rir.Insert(rawSound);

                c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1");

                if (DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal) == dt)
                {
                    ctm.Message = "Update Date Last Modified On Sound Insert Failed";
                    return(View(ctm));
                }
                dt = DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal);

                s.Caption = "Cache Update Test";
                _ir.Update(s);

                c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1");

                if (DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal) == dt)
                {
                    ctm.Message = "Update Date Last Modified On Sound Update Failed";
                    return(View(ctm));
                }
                dt = DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal);

                _ir.Delete(s);
                _rir.Delete(rawSound);

                c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1");

                if (DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal) == dt)
                {
                    ctm.Message = "Update Date Last Modified On Sound Delete Failed";
                    return(View(ctm));
                }

                c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1");

                ctm.Message = "Success";

                return(View(ctm));
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                return(new HttpStatusCodeResult(500));
            }
        }