/*
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.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Everest.Library.ExtensionMethod;
using Everest.Library.Web;
namespace Everest.CmsServices.Models{
public class FolderFile
{
private const string ImageFolder = "Styles/Images/FileTypes/";
static HashSet<string> SupportedExtentsions;
static FolderFile()
{
SupportedExtentsions = new HashSet<string>()
{
"directory",
"notype",
"upwards"
};
DirectoryInfo dir = new DirectoryInfo(Path.Combine(CmsGlobal.BaseDirPath, ImageFolder));
if (dir.Exists)
{
FileInfo[] files = dir.GetFiles();
foreach (var f in files)
{
SupportedExtentsions.Add(Path.GetFileNameWithoutExtension(f.Name));
}
}
}
public string FileName { get; set; }
public string FilePath { get; set; }
public long FileSize { get; set; }
public string Body { get; set; }
public string Application { get; set; }
public DateTime CreationDate { get; set; }
public string Url
{
get
{
if (this.IsDirectory)
return string.Empty;
return UrlConvertor.ResolveUrl(this.FilePath);
}
}
public bool IsDirectory
{
get;
set;
}
private bool _isUpwards;
public bool IsUpwards
{
get
{
return _isUpwards;
}
set
{
_isUpwards = value;
if (_isUpwards == true)
this.IsDirectory = true;
}
}
public string FileExtentsion
{
get
{
if (this.IsUpwards && this.IsDirectory)
return "upwards";
if (this.IsDirectory)
return "directory";
string extension = Path.GetExtension(this.FileName);
if (StringExtensions.IsNullOrEmptyTrim(extension) || extension.Length < 1)
return "notype";
return extension.Substring(1).ToLower();
}
}
public string FileType
{
get
{
string extentsion = this.FileExtentsion;
if (!SupportedExtentsions.Contains(extentsion))
extentsion = "unknow";
return string.Format("{0}{1}.gif", ImageFolder, extentsion);
}
}
}
}
|