public PackagingEditorController(IBackOfficeRequestContext requestContext)
     : base(requestContext)
 {
     _hive = BackOfficeRequestContext.Application.Hive.GetWriter <IFileStore>(new Uri("storage://created-packages"));
     _packageInstallUtility = new PackageInstallUtility(requestContext);
 }
예제 #2
0
        internal static IDictionary<string, object> WriteUploadedFile(Guid mediaId, bool removeExistingFile, HttpPostedFileBase httpFile, IGroupUnitFactory<IFileStore> groupUnitFactory, HiveId existingFileId = default(HiveId), string thumbSizes = null)
        {
            var val = new Dictionary<string, object>();

            //add the media id to be saved
            val.Add("MediaId", mediaId.ToString("N"));

            // Check to see if we should delete the current file
            // either becuase remove file is checked, or we have a replacement file
            if (existingFileId != HiveId.Empty && (removeExistingFile || HasFile(httpFile)))
            {
                if (!existingFileId.IsNullValueOrEmpty())
                {
                    // delete entire property folder (deletes image and any thumbnails stored)
                    //var folderHiveId = HiveId.Parse("storage://file-uploader/string/" + MediaId.ToString("N"));
                    var folderHiveId = new HiveId("storage", "file-uploader", new HiveIdValue(mediaId.ToString("N")));

                    using (var uow = groupUnitFactory.Create())
                    {
                        try
                        {
                            uow.Repositories.Delete<File>(existingFileId); // Must delete file entity so that relations are deleted
                            uow.Repositories.Delete<File>(folderHiveId);
                            uow.Complete();
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Warn(typeof(ContentExtensions), "Could not delete previous file and/or container", ex);
                        }
                    }
                }
            }

            // If we've received a File from the binding, we need to save it
            if (HasFile(httpFile))
            {
                // Open a new unit of work to write the file
                using (var uow = groupUnitFactory.Create())
                {
                    // Create main file
                    var file = new File
                                   {
                                       RootedPath =
                                           mediaId.ToString("N") + "/" + Path.GetFileName(httpFile.FileName)
                                                .Replace(" ", "").Replace(",", "")
                                   };

                    var stream = httpFile.InputStream;
                    if (stream.CanRead && stream.CanSeek)
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        using (var mem = new MemoryStream())
                        {
                            stream.CopyTo(mem);
                            file.ContentBytes = mem.ToArray();
                        }
                    }

                    uow.Repositories.AddOrUpdate(file);

                    // Create thumbnails (TODO: Need to encapsulate this so it can be reused in other places?)
                    CreateThumbnails(uow, file, mediaId.ToString("N"), thumbSizes);

                    uow.Complete();

                    val.Add("Value", file.Id);
                }
            }
            else if (!existingFileId.IsNullValueOrEmpty() && !removeExistingFile)
            {
                val.Add("Value", existingFileId);
            }
            else
            {
                val.Add("Value", HiveId.Empty);
            }

            return val;
        }
 public PackagingEditorController(IBackOfficeRequestContext requestContext)
     : base(requestContext)
 {
     _hive = BackOfficeRequestContext.Application.Hive.GetWriter<IFileStore>(new Uri("storage://created-packages"));
     _packageInstallUtility = new PackageInstallUtility(requestContext);
 }
 public CreateSnapshotDashboardController(IBackOfficeRequestContext requestContext) : base(requestContext)
 {
     _requestContext = requestContext;
     _hive = requestContext.Application.Hive.GetWriter<IFileStore>(new Uri("storage://snapshots"));
 }
예제 #5
0
        internal static IDictionary <string, object> WriteUploadedFile(Guid mediaId, bool removeExistingFile, HttpPostedFileBase httpFile, IGroupUnitFactory <IFileStore> groupUnitFactory, HiveId existingFileId = default(HiveId), string thumbSizes = null)
        {
            var val = new Dictionary <string, object>();

            //add the media id to be saved
            val.Add("MediaId", mediaId.ToString("N"));

            // Check to see if we should delete the current file
            // either becuase remove file is checked, or we have a replacement file
            if (existingFileId != HiveId.Empty && (removeExistingFile || HasFile(httpFile)))
            {
                if (!existingFileId.IsNullValueOrEmpty())
                {
                    // delete entire property folder (deletes image and any thumbnails stored)
                    //var folderHiveId = HiveId.Parse("storage://file-uploader/string/" + MediaId.ToString("N"));
                    var folderHiveId = new HiveId("storage", "file-uploader", new HiveIdValue(mediaId.ToString("N")));

                    using (var uow = groupUnitFactory.Create())
                    {
                        try
                        {
                            uow.Repositories.Delete <File>(existingFileId); // Must delete file entity so that relations are deleted
                            uow.Repositories.Delete <File>(folderHiveId);
                            uow.Complete();
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Warn(typeof(ContentExtensions), "Could not delete previous file and/or container", ex);
                        }
                    }
                }
            }

            // If we've received a File from the binding, we need to save it
            if (HasFile(httpFile))
            {
                // Open a new unit of work to write the file
                using (var uow = groupUnitFactory.Create())
                {
                    // Create main file
                    var file = new File
                    {
                        RootedPath =
                            mediaId.ToString("N") + "/" + Path.GetFileName(httpFile.FileName)
                            .Replace(" ", "").Replace(",", "")
                    };

                    var stream = httpFile.InputStream;
                    if (stream.CanRead && stream.CanSeek)
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        using (var mem = new MemoryStream())
                        {
                            stream.CopyTo(mem);
                            file.ContentBytes = mem.ToArray();
                        }
                    }

                    uow.Repositories.AddOrUpdate(file);

                    // Create thumbnails (TODO: Need to encapsulate this so it can be reused in other places?)
                    CreateThumbnails(uow, file, mediaId.ToString("N"), thumbSizes);

                    uow.Complete();

                    val.Add("Value", file.Id);
                }
            }
            else if (!existingFileId.IsNullValueOrEmpty() && !removeExistingFile)
            {
                val.Add("Value", existingFileId);
            }
            else
            {
                val.Add("Value", HiveId.Empty);
            }

            return(val);
        }
예제 #6
0
 public CreateSnapshotDashboardController(IBackOfficeRequestContext requestContext) : base(requestContext)
 {
     _requestContext = requestContext;
     _hive           = requestContext.Application.Hive.GetWriter <IFileStore>(new Uri("storage://snapshots"));
 }