/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Everest.Library.ExtensionMethod;
using Everest.CmsServices.Models;
using Everest.Library.Web;
namespace Everest.CmsServices.Services{
public class SitePackageManager
{
/// <summary>
///
/// </summary>
const string SitePackageDirName = "SitePackage";
/// <summary>
/// Gets the site packag path.
/// </summary>
/// <returns></returns>
public virtual string BasePath
{
get
{
string path = Path.Combine(CmsGlobal.BaseDirPath, SitePackageDirName);
FileExtensions.EnsureDirtectoryExists(path);
return path;
}
}
/// <summary>
/// Gets the site packages.
/// </summary>
/// <returns></returns>
public virtual IEnumerable<FolderFile> GetList()
{
string sitePackagePath = BasePath;
List<FolderFile> folderFiles = new List<FolderFile>();
if (Directory.Exists(sitePackagePath))
{
DirectoryInfo directoryInfo = new DirectoryInfo(sitePackagePath);
var files = directoryInfo.GetFiles();
foreach (var file in files)
{
folderFiles.Add(new FolderFile()
{
Application = CmsGlobal.RootApplicationName,
FileName = file.Name,
CreationDate = file.CreationTime,
FilePath = UrlConvertor.AbsolutePathToRelativeUrl(file.FullName),
IsDirectory = false,
FileSize = file.Length
});
}
}
return folderFiles;
}
/// <summary>
/// Deletes the specified file name.
/// </summary>
/// <param name="fileName">Name of the file.</param>
public virtual void Delete(string fileName)
{
string fullPath = Path.Combine(BasePath, fileName);
if (File.Exists(fullPath))
{
File.Delete(fullPath);
}
}
/// <summary>
/// Saves the site package.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <param name="stream">The stream.</param>
public virtual void Save(string fileName, Stream stream)
{
string fullPath = Path.Combine(BasePath, fileName);
stream.SaveAs(fullPath, true);
}
}
public class TemplatePackageManager : SitePackageManager
{
const string TemplatePackageDirName = "TemplatePackage";
public override string BasePath
{
get
{
var path = Path.Combine(base.BasePath, TemplatePackageDirName);
FileExtensions.EnsureDirtectoryExists(path);
return path;
}
}
}
}
|