Created
December 9, 2013 13:24
-
-
Save mikaelbr/7872176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using EPiServer.Web.Hosting; | |
using MoreLinq; | |
namespace Business.ImageHandling | |
{ | |
public class MediaMigration | |
{ | |
public void MigrateAutogenererteFiler() | |
{ | |
var parent = Konfigurasjon.VppAutogenererteFilerRootDirectory; | |
if (parent == null) return; | |
var newParent = GetSubFolder(parent); | |
if (newParent == null) return; | |
MoveAllFiles(parent, newParent); | |
} | |
public void MigrateProfileImages() | |
{ | |
var parent = Konfigurasjon.VppProfilbilderRootDirectory; | |
if (parent == null) return; | |
var newParent = GetSubFolder(parent); | |
if (newParent == null) return; | |
MoveAllFiles(parent, newParent); | |
} | |
public void MoveAllFiles(VersioningDirectory parent, VersioningDirectory newParent) | |
{ | |
parent | |
.GetFiles() | |
.Where(x => !x.IsDirectory) | |
.ForEach(x => x.MoveTo(newParent.VirtualPath + "/" + x.Name)); | |
} | |
public VersioningDirectory GetSubFolder(VersioningDirectory dir) | |
{ | |
var newParent = dir.GetDirectories().FirstOrDefault(x => x.Name == dir.Name); | |
if (newParent != null) return newParent as VersioningDirectory; | |
return dir.CreateSubdirectory(dir.Name) as VersioningDirectory; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment