Exemple #1
0
 public static void Delete(CMSImageDataContext db, int?id)
 {
     if (id.HasValue)
     {
         db.ExecuteCommand("DELETE dbo.Image WHERE Id = {0}", id);
     }
 }
Exemple #2
0
        public static Image NewImageFromBits(byte[] bits, int w, int h, CMSImageDataContext db)
        {
            var i = new Image();

            i.LoadResizeFromBits(bits, w, h);
            InsertImage(db, i);
            return(i);
        }
Exemple #3
0
        public Image CreateNewTinyImage(CMSImageDataContext db)
        {
            var i = new Image();

            i.LoadResizeFromBits(Bits, 50, 50);
            InsertImage(db, i);
            return(i);
        }
Exemple #4
0
        public static Image CreateImageFromType(byte[] bits, string type, CMSImageDataContext db)
        {
            var i = new Image();

            i.LoadFromBits(bits, type);
            InsertImage(db, i);
            return(i);
        }
Exemple #5
0
 public static void DbDispose()
 {
     if (InternalDb != null)
     {
         InternalDb.Dispose();
         InternalDb = null;
     }
 }
Exemple #6
0
        public static Image NewImageFromBits(byte[] bits, CMSImageDataContext db, bool isPublic = false)
        {
            var i = new Image();

            i.LoadImageFromBits(bits);
            i.IsPublic = isPublic;
            InsertImage(db, i);
            return(i);
        }
Exemple #7
0
        public static Image NewTextFromString(string s, CMSImageDataContext db)
        {
            var i = new Image();

            i.Mimetype = "text/plain";
            i.Bits     = Encoding.ASCII.GetBytes(s);
            i.Length   = i.Bits.Length;
            InsertImage(db, i);
            return(i);
        }
Exemple #8
0
        public static CMSImageDataContext Create(HttpContextBase currentHttpContext)
        {
            var host = currentHttpContext.Request.Url.Authority.Split('.', ':')[0];
            var cs   = ConfigurationManager.ConnectionStrings["CMS"];
            var cb   = new SqlConnectionStringBuilder(cs.ConnectionString);

            cb.InitialCatalog      = $"CMSi_{host}";
            cb.PersistSecurityInfo = true;
            var connectionString = cb.ConnectionString;

            return(CMSImageDataContext.Create(connectionString));
        }
Exemple #9
0
        private static Image GetImageFromFile(CMSImageDataContext db, HttpPostedFileBase file)
        {
            byte[] data;
            using (Stream inputStream = file.InputStream)
            {
                MemoryStream memoryStream = inputStream as MemoryStream;
                if (memoryStream == null)
                {
                    memoryStream = new MemoryStream();
                    inputStream.CopyTo(memoryStream);
                }
                data = memoryStream.ToArray();
            }
            var mimetype = UtilityExtensions.MimeTypes.ShortTypeFromMimeType(MimeMapping.GetMimeMapping(file.FileName));

            return(Image.CreateImageFromType(data, mimetype, db));
        }
Exemple #10
0
        public static CMSImageDataContext Create(HttpContextBase currentHttpContext)
        {
            var host = UtilityExtensions.Util.PickFirst(ConfigurationManager.AppSettings["host"], currentHttpContext.Request.Url.Authority.Split('.', ':')[0]);

            return(CMSImageDataContext.Create(host));
        }
Exemple #11
0
        public static int StoreImageFromDocument(CMSImageDataContext db, HttpPostedFileBase file)
        {
            Image i = GetImageFromFile(db, file);

            return(i.Id);
        }
Exemple #12
0
 public static Image ImageFromId(CMSImageDataContext db, int?id)
 {
     return(db.Images.SingleOrDefault(ii => ii.Id == id));
 }
Exemple #13
0
 private static void InsertImage(CMSImageDataContext db, Image i)
 {
     db.Images.InsertOnSubmit(i);
     db.SubmitChanges();
 }
Exemple #14
0
        public static Image NewImageFromBits(byte[] bits, string type, CMSImageDataContext db)
        {
            var image = CreateImageFromType(bits, type, db);

            return(image);
        }
Exemple #15
0
        public static CMSImageDataContext Create(HttpContextBase currentHttpContext)
        {
            var host = ConfigurationManager.AppSettings["host"] ?? currentHttpContext.Request.Url.Authority.Split('.', ':')[0];

            return(CMSImageDataContext.Create(host));
        }