Exemplo n.º 1
0
        public MigrateMediaResult MigratAzureBlobStorageToFileSystem(string connectionString, bool isOverwrite)
        {
            var mediaItems = _mediaLibraryService.GetMediaContentItems()
                             .List();

            var result          = new MigrateMediaResult();
            var azureFileSystem = InitializeAzureFileSystem(connectionString);

            foreach (var mediaItem in mediaItems)
            {
                var path = Path.Combine(mediaItem.FolderPath, mediaItem.FileName);

                if (!azureFileSystem.FileExists(path) || (!isOverwrite && _storageProvider.FileExists(path)))
                {
                    result.IgnoredCount++;
                    continue;
                }

                try
                {
                    if (isOverwrite && _storageProvider.FileExists(path))
                    {
                        _storageProvider.DeleteFile(path);
                    }

                    var file      = _storageProvider.CreateFile(path);
                    var azureFile = azureFileSystem.GetFile(path);

                    using (var inputStream = azureFile.OpenRead())
                    {
                        using (var outputStream = file.OpenWrite())
                        {
                            var buffer = new byte[8192];
                            while (true)
                            {
                                var length = inputStream.Read(buffer, 0, buffer.Length);

                                if (length <= 0)
                                {
                                    break;
                                }

                                outputStream.Write(buffer, 0, length);
                            }
                        }
                    }

                    result.SuccessfulTransferCount++;
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, string.Format("Failed to transfer media {0}.", path));
                    result.UnsuccessfulTransferCount++;

                    _storageProvider.DeleteFile(path);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public ActionResult MediaItems(string folderPath, int skip = 0, int count = 0, string order = "created", string mediaType = "")
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia, T("Cannot view media")))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission.var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder();
            if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                var model = new MediaManagerMediaItemsViewModel {
                    MediaItems      = new List <MediaManagerMediaItemViewModel>(),
                    MediaItemsCount = 0,
                    FolderPath      = folderPath
                };

                return(View(model));
            }

            var mediaParts      = _mediaLibraryService.GetMediaContentItems(folderPath, skip, count, order, mediaType, VersionOptions.Latest);
            var mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(folderPath, mediaType, VersionOptions.Latest);

            var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
                MediaPart = x,
                Shape     = Services.ContentManager.BuildDisplay(x.ContentItem, "Thumbnail")
            }).ToList();

            var viewModel = new MediaManagerMediaItemsViewModel {
                MediaItems      = mediaItems,
                MediaItemsCount = mediaPartsCount,
                FolderPath      = folderPath
            };

            return(View(viewModel));
        }
        public ActionResult Index(string mediaPath)
        {
            mediaPath = _storageProvider.GetStoragePath(mediaPath);
            if (mediaPath == null)
            {
                return(HttpNotFound());
            }
            var fileName  = Path.GetFileName(mediaPath);
            var directory = mediaPath.Substring(0, mediaPath.IndexOf(fileName));

            directory = directory.TrimEnd('/');
            var medias = _mediaLibraryService
                         .GetMediaContentItems(VersionOptions.Published)
                         .Where(x => x.FolderPath == directory && x.FileName == fileName)
                         .List();
            var isSecure = medias.All(x => x.As <SecureMediaPart>()?.IsSecure ?? true);

            if ((isSecure && !_authorizer.Authorize(Permissions.ViewSecureMedia)) || !_storageProvider.FileExists(mediaPath))
            {
                return(HttpNotFound());
            }
            var file   = _storageProvider.GetFile(mediaPath);
            var stream = file.OpenRead();

            return(File(stream, file.GetFileType()));
        }
Exemplo n.º 4
0
        public ActionResult MediaItems(string folderPath, int skip = 0, int count = 0, string order = "created", string mediaType = "")
        {
            var mediaParts      = _mediaLibraryService.GetMediaContentItems(folderPath, skip, count, order, mediaType, Services.WorkContext.CurrentUser);
            var mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(folderPath, mediaType);

            var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
                MediaPart = x,
                Shape     = Services.ContentManager.BuildDisplay(x.ContentItem, "Thumbnail")
            }).ToList();

            var viewModel = new MediaManagerMediaItemsViewModel {
                MediaItems      = mediaItems,
                MediaItemsCount = mediaPartsCount
            };

            return(View(viewModel));
        }
        public ActionResult MediaItems(string folderPath, int skip = 0, int count = 0, string order = "created", string mediaType = "")
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Cannot view media")))
            {
                return(new HttpUnauthorizedResult());
            }

            var mediaParts      = _mediaLibraryService.GetMediaContentItems(folderPath, skip, count, order, mediaType);
            var mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(folderPath, mediaType);

            var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
                MediaPart = x,
                Shape     = Services.ContentManager.BuildDisplay(x.ContentItem, "Thumbnail")
            }).ToList();

            var viewModel = new MediaManagerMediaItemsViewModel {
                MediaItems      = mediaItems,
                MediaItemsCount = mediaPartsCount
            };

            return(View(viewModel));
        }
        public ActionResult MediaItems(string folderPath, int skip = 0, int count = 0, string order = "created", string mediaType = "")
        {
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath))
            {
                Services.Notifier.Add(UI.Notify.NotifyType.Error, T("Cannot select media"));
                var model = new MediaManagerMediaItemsViewModel {
                    MediaItems      = new List <MediaManagerMediaItemViewModel>(),
                    MediaItemsCount = 0,
                    FolderPath      = folderPath
                };

                return(View(model));
            }

            // Check permission
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath) && !_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                var model = new MediaManagerMediaItemsViewModel {
                    MediaItems      = new List <MediaManagerMediaItemViewModel>(),
                    MediaItemsCount = 0,
                    FolderPath      = folderPath
                };

                return(View(model));
            }

            var mediaParts      = _mediaLibraryService.GetMediaContentItems(folderPath, skip, count, order, mediaType, VersionOptions.Latest);
            var mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(folderPath, mediaType, VersionOptions.Latest);

            var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
                MediaPart = x,
                Shape     = Services.ContentManager.BuildDisplay(x.ContentItem, "Thumbnail")
            }).ToList();

            var viewModel = new MediaManagerMediaItemsViewModel {
                MediaItems      = mediaItems,
                MediaItemsCount = mediaPartsCount,
                FolderPath      = folderPath
            };

            return(View(viewModel));
        }
        public ActionResult MediaItems(string folderPath, int skip = 0, int count = 0, string order = "created", string mediaType = "", string culture = "")
        {
            if (String.IsNullOrWhiteSpace(folderPath))
            {
                folderPath = null;
            }
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath))
            {
                Services.Notifier.Add(UI.Notify.NotifyType.Error, T("Cannot select media"));
                var model = new MediaManagerMediaItemsViewModel {
                    MediaItems      = new List <MediaManagerMediaItemViewModel>(),
                    MediaItemsCount = 0,
                    FolderPath      = folderPath
                };

                return(View(model));
            }

            // Check permission
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath) && !_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                var model = new MediaManagerMediaItemsViewModel {
                    MediaItems      = new List <MediaManagerMediaItemViewModel>(),
                    MediaItemsCount = 0,
                    FolderPath      = folderPath
                };

                return(View(model));
            }

            IEnumerable <MediaPart> mediaParts;
            var mediaPartsCount = 0;

            if (culture == "")
            {
                mediaParts      = _mediaLibraryService.GetMediaContentItems(folderPath, skip, count, order, mediaType, VersionOptions.Latest);
                mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(folderPath, mediaType, VersionOptions.Latest);
            }
            else
            {
                var cultureId = _cultureManager.GetCultureByName(culture).Id;
                var query     = BuildGetMediaContentItemsQuery(Services.ContentManager, folderPath, order: order, mediaType: mediaType, versionOptions: VersionOptions.Latest)
                                .Join <LocalizationPartRecord>()
                                .Where(x => x.CultureId == cultureId)
                                .Join <MediaPartRecord>();
                mediaParts = query
                             .Slice(skip, count);
                mediaPartsCount = query.Count();
            }

            var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
                MediaPart = x,
                Shape     = Services.ContentManager.BuildDisplay(x.ContentItem, "Thumbnail")
            }).ToList();

            var viewModel = new MediaManagerMediaItemsViewModel {
                MediaItems      = mediaItems,
                MediaItemsCount = mediaPartsCount,
                FolderPath      = folderPath
            };

            return(View(viewModel));
        }
 private void SetDefaultModelProperties(MigrateMediaModel model)
 {
     model.ConfiguredAzureBlobStorage = RemoveSensitiveInfoFromConnectionString(ConfigurationManager.AppSettings[MediaStorageStorageConnectionStringSettingName]);
     model.MediaItemsCount            = _mediaLibraryService.GetMediaContentItems().Count();
 }