Пример #1
0
        public IList<CmsImage> GetImages(int startRowIndex, int maximumRows)
        {
            int start = startRowIndex;
            int end = start + maximumRows;

            end = end - 1; //0-based

            CmsImageDao dao = new CmsImageDao();
            return dao.FindBySiteWithPaging(CurrentSite.Guid, start, end);
        }
Пример #2
0
        public IList<CmsImage> GetThemeImages(int startRowIndex, int maximumRows)
        {
            int start = startRowIndex;
            int end = start + maximumRows;

            end = end - 1; //0-based

            String themeId = WebRequestContext.Instance.Request.QueryString["tid"];

            CmsImageDao dao = new CmsImageDao();
            return dao.FindBySiteWithPagingAndDirectory(CurrentSite.Guid, themeId, start, end);
        }
Пример #3
0
        public static void SaveImagesToDatabase(Data.Guid siteGuid, IStorageClient client, String container, String folder, IList<StorageFile> images, IList<StorageFile> results)
        {
            CmsImageDao dao = new CmsImageDao();
            using (Transaction tx = new Transaction())
            {
                foreach (StorageFile file in images)
                {
                    StorageFile actualFile;

                    if (results != null)
                        actualFile = client.GetInfo(container, folder, file.Filename);
                    else
                        actualFile = file;

                    if (actualFile.Exists())
                    {
                        CmsImage temp = dao.FindByUrl(actualFile.Url);
                        if (temp == null)
                        {
                            FileInfo info = new FileInfo(actualFile.Filename);

                            String mimetype = "image/png";
                            if (ImageMimeTypes.ContainsKey(info.Extension))
                                mimetype = ImageMimeTypes[info.Extension];

                            temp = new CmsImage();
                            temp.CloudUrl = actualFile.Url;
                            temp.ContentType = mimetype;
                            temp.Created = UtcDateTime.Now;
                            temp.Directory = folder;
                            temp.Filename = actualFile.Filename;
                            temp.Guid = System.Guid.NewGuid().ToString();
                            temp.SubscriptionId = siteGuid.Value;
                            temp.Length = actualFile.Size;

                            dao.Save<CmsImage>(temp);
                        }

                        if (results != null)
                            results.Add(actualFile);
                    }
                }
                tx.Commit();
            }
        }
Пример #4
0
        public CmsImage GetImageByNameAndDirectory(Data.Guid siteGuid, String filename, String directory, Boolean includeData)
        {
            CmsImageDao dao = new CmsImageDao();
            CmsImage image = dao.FindByNameAndDirectory(siteGuid, filename, directory);

            if ((image != null) && (includeData))
                SetImageData(siteGuid, image);

            return image;
        }
Пример #5
0
        public CmsImage GetImageByGuid(Data.Guid siteGuid, Data.Guid guid, bool loadImageData)
        {
            CmsImageDao dao = new CmsImageDao();
            CmsImage image = dao.FindBySiteAndGuid(siteGuid, guid);

            if (image != null)
                SetImageData(siteGuid, image);

            return image;
        }
Пример #6
0
        public void DeleteImage(Data.Guid siteGuid, Data.Guid imageGuid)
        {
            //Find the image based upon the guid
            CmsImageDao dao = new CmsImageDao();
            CmsImage image = dao.FindBySiteAndGuid(siteGuid, imageGuid);
            if (image != null)
            {
                String container = SiteHelper.GetStorageKey(SiteHelper.ImagesContainerKey, siteGuid.Value);

                //Attempt to delete from cloud storage first
                IStorageClient client = StorageHelper.GetStorageClient();
                if (client.ContainsSnapshots(container, image.Directory, image.Filename))
                    throw new ArgumentException("Unable to delete the image because it is currently being used by a site package");

                try
                {
                    client.Delete(container, image.Directory, image.Filename);
                    using (Transaction tx = new Transaction())
                    {
                        dao.Delete<CmsImage>(image);
                        tx.Commit();
                    }
                }
                catch (Exception e)
                {
                    throw new ArgumentException("There was a problem deleting the image: " + e.Message);
                }
            }
        }
Пример #7
0
 public int GetImageCount()
 {
     CmsImageDao dao = new CmsImageDao();
     return dao.FindImageCount(CurrentSite.Guid);
 }