/// <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. 不小心删除了sysWOW64下的webio.dll

    weibo的桌面客户端留了一个服务,在syswow64目录下留了个exe文件,看着旁边好像还有个weibo.dll,就把试着也删除了,但是删除不掉,我就进安全模式删除了(f8在Windows的启动界面 ...

  2. PBOC2.0中消费交易流程

    消费交易允许持卡人使用电子存折或电子钱包的余额进行购物或获取服务.此交易可以在销售点终端(POS)上脱机进行.使用电子存折进行的消费交易必须提交个人识别码(PIN),使用电子钱包则不需要. 1.1 终 ...

  3. C++ 从一组数据中按概率选择一个

    #include <stdio.h> #include <stdint.h> #include <ctime> #include <vector> #i ...

  4. Yii2 关闭和打开csrf 验证 防止表单多次重复提交

    原文地址:http://blog.csdn.net/terry_water/article/details/52221007 1.在Yii2配置中配置所有:所有的controller都将关闭csrf验 ...

  5. Java 静态变量,常量和方法

    static 关键字 例如:在球类中使用PI这个常量,可能除了本类需要这个常量之外,在另外一个圆类中也需要使用这个常量.这时没有必要 在两个类中同时创建PI这个常量,因为这样系统会将这两个不在同一个类 ...

  6. ipad互动教学

  7. string模块

    string模块 string模块包括了一些字符串常量, 并且有str对象的功能,主要用来生成一些字符串.字符串格式化等 参考: http://python.usyiyi.cn/python_278/ ...

  8. 修复Magento SQLSTATE[23000]: Integrity constraint

    magneto在意外情况下报错Magento SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry,出现这个问题最 ...

  9. Python程序的首行

    >问题 >>在一些python程序中的首行往往能够看见下面这两行语句中的一句 >>>#!/usr/bin/Python >>>#!/usr/bin ...

  10. css ul li 横向排列

    因为li是块级元素,默认占一行的,要想实现横向排列,一般通过以下两个方法:float:left这样设置有一个问题,li浮动以后则脱离了文本流,即不占位置,如果它的父级元素有具体的样式且没有固定宽高,建 ...