Beispiel #1
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();
            }
        }
Beispiel #2
0
        private void SetImageData(Data.Guid siteGuid, CmsImage image)
        {
            String container = SiteHelper.GetStorageKey(SiteHelper.ImagesContainerKey, siteGuid.Value);

            IStorageClient client = StorageHelper.GetStorageClient();
            byte[] data = client.Open(container, image.Directory, image.Filename);
            image.Data = data;
        }