/// <summary>
/// 文件类型
/// </summary>
public enum FileType
{
Courseware, //"课件"
Document, //"文档"
Picture, //"图片"
Audio, //"音频"
Video, //"视频"
Cartoon, //"动画"
Other //"其他"
} /// <summary>
/// 资源类型
/// </summary>
public enum ContentType
{
MaterialInterpretation, //"教材解读",
Writing, //"写作",
ExpandData, //"拓展资料",
CoursewareIllustrated, //"课件配图",
ReadText, //"课文朗读",
LearnCase, //"学案",
AudioVideo, //"音视频",
TeachingPlan, //"教案",
Courseware, //"课件",
TestQuestions, //"试题",
Other, //"其他"
} /// <summary>
/// 判断资源类型 (shenc 2016-7-11)
/// </summary>
public class JudgeContentType
{
LogService _logger = new LogService(); #region 文件格式类型 public List<string> _fileTypeName = new List<string>{"课件","文档","图片","音频","视频","动画","其他"};
public List<string> _coursewareFormatType = new List<string> { "ppt", "pptx"};
public List<string> _documentFormatType = new List<string> { "doc", "docx", "xls", "xlsx", "pdf", "vsd", "rtf", "txt", "xml", "xpt", "pps", "ppsx", "pdfx" };
public List<string> _pictureFormatType = new List<string> { "jpg", "jpeg", "gif", "bmp", "png", "tif" };
public List<string> _audioFormatType = new List<string> { "mp3", "mid", "wma", "wav", "flac", "m4a", "voc" };
public List<string> _videoFormatType = new List<string> { "flv", "avi", "mkv", "wmv", "mp4", "f4v", "mpg", "asf", "webm", "mov", "rmvb", "rm" };
public List<string> _cartoonFormatType = new List<string> { "swf" };
public List<string> _otherFormatType = new List<string> { "exe", "dbb" };
public Dictionary<FileType, List<string>> _dicFileType_Formats = new Dictionary<FileType, List<string>>();
//public Dictionary<string, List<string>> _dicFileTypeName_Formats = new Dictionary<string, List<string>>();
public Dictionary<FileType, string> _dicFileType_Name = new Dictionary<FileType, string>();
#endregion #region 资源格式 public List<string> _contentTypeName = new List<string> { "教材解读", "写作", "拓展资料", "课件配图", "课文朗读", "学案", "音视频", "教案", "课件", "试题", "其他" };
public Dictionary<ContentType, string> _dicContentType_Name = new Dictionary<ContentType, string>();
public List<string> _materialInterpretationFlags = new List<string> { "教材解读" };
public List<string> _writingFlags = new List<string> { "写作" };
public List<string> _expandDataFlags = new List<string> { "拓展资料", "专题资源"};
public List<string> _coursewareIllustratedFlags = new List<string> { };
public List<string> _readTextFlags = new List<string> { "课文朗读" };
public List<string> _learnCaseFlags = new List<string> { "学案" };
public List<string> _audioVideoFlags = new List<string> { };
public List<string> _teachingPlanFlags = new List<string> { "教案", "教学设计", "教学案例", "说课", "教学反思", "教学案", "课程设计", "教学方案" }; //教案、教学设计、教学案例、说课、教学反思,教学案,课程设计,教学方案
public List<string> _coursewareFlags = new List<string> { };
public List<string> _testQuestionsFlags = new List<string> { "试题", "习题", "练习" }; //试题、习题、练习
public List<string> _otherFlags = new List<string> { }; //以上不包含的文件,资源格式均列入“其他” #endregion public JudgeContentType()
{
InitFileType_Name();
InitFileTypeFormats();
//InitFileTypeNameFormats();
InitContentType_Name();
} private void InitFileType_Name()
{
_dicFileType_Name.Clear();
int i = ;
FileType type = FileType.Other;
foreach (string typeName in _contentTypeName)
{
type = (FileType)i++;
_dicFileType_Name.Add(type, typeName);
}
}
/*
private void InitFileTypeNameFormats()
{
_dicFileTypeName_Formats.Add("课件", _coursewareFormatType);
_dicFileTypeName_Formats.Add("文档", _documentFormatType);
_dicFileTypeName_Formats.Add("图片", _pictureFormatType);
_dicFileTypeName_Formats.Add("音频", _audioFormatType);
_dicFileTypeName_Formats.Add("视频", _videoFormatType);
_dicFileTypeName_Formats.Add("动画", _cartoonFormatType);
_dicFileTypeName_Formats.Add("其他", _otherFormatType);
}
*/
private void InitFileTypeFormats()
{
_dicFileType_Formats.Clear();
_dicFileType_Formats.Add(FileType.Courseware, _coursewareFormatType);
_dicFileType_Formats.Add(FileType.Document, _documentFormatType);
_dicFileType_Formats.Add(FileType.Picture, _pictureFormatType);
_dicFileType_Formats.Add(FileType.Audio, _audioFormatType);
_dicFileType_Formats.Add(FileType.Video, _videoFormatType);
_dicFileType_Formats.Add(FileType.Cartoon, _cartoonFormatType);
_dicFileType_Formats.Add(FileType.Other, _otherFormatType);
}
private void InitContentType_Name()
{
_dicContentType_Name.Clear();
int i = ;
ContentType contentType = ContentType.Other;
foreach (string typeName in _contentTypeName)
{
contentType = (ContentType) i++;
_dicContentType_Name.Add(contentType,typeName);
}
} #region 获取内容类型、名称 public string GetContentTypeName(string fileName)
{
string contentName = string.Empty;
ContentType contentType = GetContentType(fileName);
contentName = _dicContentType_Name[contentType];
return contentName;
} public ContentType GetContentType(string fileName)
{
ContentType contentType = ContentType.Other;
try
{
if (IsMaterialInterpretationType(fileName))
{
contentType = ContentType.MaterialInterpretation;
}
else if (IsWritingType(fileName))
{
contentType = ContentType.Writing;
}
else if (IsExpandDataType(fileName))
{
contentType = ContentType.ExpandData;
}
else if (IsCoursewareIllustratedType(fileName))
{
contentType = ContentType.CoursewareIllustrated;
}
else if (IsReadTextType(fileName))
{
contentType = ContentType.ReadText;
}
else if (IsLearnCaseType(fileName))
{
contentType = ContentType.LearnCase;
}
else if (IsAudioVideoType(fileName))
{
contentType = ContentType.AudioVideo;
}
else if (IsTeachingPlanType(fileName))
{
contentType = ContentType.TeachingPlan;
}
else if (IsCoursewareType(fileName))
{
contentType = ContentType.Courseware;
}
else if (IsTestQuestionsType(fileName))
{
contentType = ContentType.TestQuestions;
}
else
{
contentType = ContentType.Other;
}
}
catch(Exception ex)
{
contentType = ContentType.Other;
_logger.Error("获取教材解读内容类型出错:" + ex.Message);
}
return contentType;
} public bool IsMaterialInterpretationType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (isFileNameContainsFlags(fileName, _materialInterpretationFlags) && _documentFormatType.Contains(ext))
{
isRight = true;
}
}
catch (Exception ex)
{
isRight = false;
_logger.Error("获取内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsWritingType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (isFileNameContainsFlags(fileName,_writingFlags) && _documentFormatType.Contains(ext))
{
isRight = true;
}
}
catch (Exception ex)
{
isRight = false;
_logger.Error("获取写作内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsExpandDataType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (isFileNameContainsFlags(fileName, _expandDataFlags) && _documentFormatType.Contains(ext))
{
isRight = true;
}
}
catch (Exception ex)
{
isRight = false;
_logger.Error("获取拓展资料内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsCoursewareIllustratedType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (isFileNameContainsFlags(fileName, _coursewareIllustratedFlags) && _pictureFormatType.Contains(ext))
{
isRight = true;
}
}
catch (Exception ex)
{
isRight = false;
_logger.Error("获取课件配图内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsReadTextType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (isFileNameContainsFlags(fileName, _readTextFlags) && _audioFormatType.Contains(ext))
{
isRight = true;
}
}
catch (Exception ex)
{
isRight = false;
_logger.Error("获取课文朗读内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsLearnCaseType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (isFileNameContainsFlags(fileName, _learnCaseFlags) && _documentFormatType.Contains(ext))
{
isRight = true;
}
}
catch (Exception ex)
{
isRight = false;
_logger.Error("获取学案内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsAudioVideoType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (!IsReadTextType(fileName) && isFileNameContainsFlags(fileName, _audioVideoFlags) && (_audioFormatType.Contains(ext) || _videoFormatType.Contains(ext) || _cartoonFormatType.Contains(ext)))
{
isRight = true;
}
}
catch(Exception ex)
{
isRight = false;
_logger.Error("获取音视频内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsTeachingPlanType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (isFileNameContainsFlags(fileName, _teachingPlanFlags) && _documentFormatType.Contains(ext))
{
isRight = true;
}
}
catch(Exception ex)
{
isRight = false;
_logger.Error("获取教案内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsCoursewareType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (isFileNameContainsFlags(fileName, _coursewareFlags) && _coursewareFormatType.Contains(ext))
{
isRight = true;
}
}
catch(Exception ex)
{
isRight = false;
_logger.Error("获取课件内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsTestQuestionsType(string fileName)
{
bool isRight = false;
try
{
string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
if (isFileNameContainsFlags(fileName, _teachingPlanFlags) && _documentFormatType.Contains(ext))
{
isRight = true;
}
}
catch(Exception ex)
{
isRight = false;
_logger.Error("获取试题内容类型出错:" + ex.Message);
}
return isRight;
}
public bool IsOtherType(string fileName)
{
bool isRight = false;
try
{
//string ext = Path.GetExtension(fileName.Trim()).Replace(".",string.Empty);
//if (isFileNameContainsFlags(fileName, _otherFlags) && _otherFormatType.Contains(ext))
//{
// isRight = true;
//}
//else
if (!IsAudioVideoType(fileName) && !IsCoursewareIllustratedType(fileName) && !IsCoursewareType(fileName) && !IsExpandDataType(fileName) && IsLearnCaseType(fileName) && !IsMaterialInterpretationType(fileName) && !IsReadTextType(fileName) && !IsTeachingPlanType(fileName) && !IsTestQuestionsType(fileName) && !IsWritingType(fileName))
{
isRight = true;
}
}
catch (Exception ex)
{
isRight = false;
_logger.Error("获取其他内容类型出错:" + ex.Message);
}
return isRight;
} public bool isFileNameContainsFlags(string fileName,List<string> contentFlags)
{
bool isContain = false;
if (contentFlags == null || contentFlags.Count == )
{
isContain = true;
}
else
{
foreach (string flag in contentFlags)
{
if (fileName.Contains(flag.Trim()))
{
isContain = true;
break;
}
}
}
return isContain;
}
#endregion
}

C#:复杂条件判断类型(练习)的更多相关文章

  1. 值类型之间的相互转化,运算符,if条件判断,循环,函数

    值类型之间的相互转化 number | string | boolean 一.转换为boolean=>Boolean(a); var num = 10; var s = '123'; var b ...

  2. Python:Base2(List和Tuple类型, 条件判断和循环,Dict和Set类型)

    1.Python创建list: Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 比如,列出班里所有同学的名字,就可以用一个list表示: &g ...

  3. 5-3 bash脚本编程之二 条件判断

    1. 条件测试的表达式 1. [ expression ]  :注意这个中括号的前后都有一个空格 2. [[ expression ]] 3. test expression 2.条件判断的类型 1. ...

  4. 第10章 Shell编程(3)_字符处理命令和条件判断

    3. 字符处理命令 3.1 排序命令:sort (1)sort命令:#sort [选项] 文件名 选项 作用 -f 忽略大小写 -n 以数值型进行排序,默认使用字符串型排序 -r 反向排序 -t 指定 ...

  5. shell条件判断与流程控制

    一 条件判断式语句 1.按文件类型进行判断 测试类型 作用 -b 文件 判断文件是否存在,并且是否为块设备文件(是块设备文件为真) -c 文件 判断文件是否存在,并且是否为字符设备文件(是字符设备设备 ...

  6. wordpress 函数、条件判断以及文件的总结

    WordPress基本模板文件 一套完整的WordPress模板应至少具有如下文件: style.css : CSS(样式表)文件 index.php : 主页模板 archive.php : Arc ...

  7. Bash条件判断

    bash编程之:条件判断,判定后续操作的前提条件是否满足, bash编程之: 条件判断常用类型: 整数测试:比较两个整数谁大谁小,是否相等: 二元测试: num1 操作符 num2 -eq: 等于 - ...

  8. Linux 条件判断

    1. 按照文件类型判断 -b 文件 #判断文件是否存在,并且是设备文件 -c 文件 #判断文件是否存在,并且是字符设备文件 -d 目录 #判断目录是否存在,并且是否为目录(是目录返回真) -e 文件 ...

  9. 一行代码调用实现带字段选取+条件判断+排序+分页功能的增强ORM框架

    问题:3行代码 PDF.NET是一个开源的数据开发框架,它的特点是简单.轻量.快速,易上手,而且是一个注释完善的国产开发框架,受到不少朋友的欢迎,也在我们公司的项目中多次使用.但是,PDF.NET比起 ...

随机推荐

  1. 72. 求m到n之和

    求m到n之和 int sum(int m, int n) { int i, result = 0; for (i=m; i<=n; i++) result = result+i; return ...

  2. swift-重写方法和属性、禁止重写

    /*子类可以为继承来的实例方法,类方法,实例属性,或下标提供自己定制的实现.我们把这种行为叫重写. 如果要重写某个特性,你需要在重写定义的前面加上 关键字.这么做,你就表明了你是想提供一个重写 版本, ...

  3. Memcache,Redis,MongoDB(数据缓存系统)方案对比与分析

    mongodb和memcached不是一个范畴内的东西.mongodb是文档型的非关系型数据库,其优势在于查询功能比较强大,能存储海量数据.mongodb和memcached不存在谁替换谁的问题. 和 ...

  4. linux的sysctl基本配置

    # Controls the use of TCP syncookiesnet.ipv4.tcp_syncookies = 1 # me write paramnet.ipv4.tcp_timesta ...

  5. (。・・)ノ~java常见错误

    空指针错误 刚开始接触数组的时候,最容易出现的错误就是空指针错误.所谓空指针错误就是,一个引用指向了一个空的地址,而空的地址,没有地址,更没有数据,这时候用这引用去和别的数据对比,显然要出错.为了避免 ...

  6. iOS10 适配、Xcode8配置总结

    随着iOS10的推送更新到来,勤劳的程序员又在加班加点的搬砖了,为此收集了一些iOS10 更新的技能给大伙参考,不断更新喜欢就star 前沿 一.Xcode8 插件你去哪了 以为是和之前一样 Xcod ...

  7. Husky or C++ API - HDFS Short-Circuit Local Reads

    hdfs-site.xml added: <property> <name>dfs.client.read.shortcircuit</name> <valu ...

  8. tomcat404报错解决

    本地启动tomcat,不报错.也可正常打开http://localhost:8080 但是eclipse中启动tomcat不报错.但是打开http://localhost:8080时报404 思考,原 ...

  9. Python开发【第九章】:堡垒机实例

    一.堡垒机前戏 开发堡垒机之前,先来学习Python的paramiko模块,该模块基于SSH用于连接远程服务器并执行相关操作 模块安装 C:\Program Files\Python 3.5\Scri ...

  10. centos7 web服务器内核优化

    net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_keepalive_time = 600net.ipv4 ...