示例#1
0
        public void MoveTo(ISupportsMediaMoving target, MediaMoverContext context, MediaFile mediaFile)
        {
            Guard.NotNull(target, nameof(target));
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(mediaFile, nameof(mediaFile));

            if (mediaFile.MediaStorageId != null)
            {
                // Let target store data (into a file for example)
                target.Receive(context, mediaFile, OpenRead(mediaFile));

                // Remove picture binary from DB
                try
                {
                    _mediaStorageRepo.Delete(mediaFile.MediaStorageId.Value);
                    //mediaFile.MediaStorageId = null;
                    //mediaFile.MediaStorage = null;

                    _mediaFileRepo.Update(mediaFile);
                }
                catch { }

                context.ShrinkDatabase = true;
            }
        }
        public void MoveTo(ISupportsMediaMoving target, MediaMoverContext context, MediaFile mediaFile)
        {
            Guard.NotNull(target, nameof(target));
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(mediaFile, nameof(mediaFile));

            var filePath = GetPath(mediaFile);

            try
            {
                // Let target store data (into database for example)
                target.Receive(context, mediaFile, OpenRead(mediaFile));

                // Remember file path: we must be able to rollback IO operations on transaction failure
                context.AffectedFiles.Add(filePath);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }
        }
        public void MoveTo(ISupportsMediaMoving target, MediaMoverContext context, MediaItem media)
        {
            Guard.NotNull(target, nameof(target));
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(media, nameof(media));

            if (media.Entity.MediaStorage != null)
            {
                // let target store data (into a file for example)
                target.Receive(context, media, media.Entity.MediaStorage.Data);

                // remove picture binary from DB
                try
                {
                    _mediaStorageRepository.Delete(media.Entity.MediaStorage);
                }
                catch { }

                media.Entity.MediaStorageId = null;

                context.ShrinkDatabase = true;
            }
        }
示例#4
0
        public void MoveTo(ISupportsMediaMoving target, MediaMoverContext context, MediaItem media)
        {
            Guard.NotNull(target, nameof(target));
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(media, nameof(media));

            var filePath = GetPicturePath(media);

            try
            {
                // read data from file
                var data = _fileSystem.ReadAllBytes(filePath);

                // let target store data (into database for example)
                target.Receive(context, media, data);

                // remember file path: we must be able to rollback IO operations on transaction failure
                context.AffectedFiles.Add(filePath);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }
        }