C#:复杂条件判断类型(练习)
/// <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#:复杂条件判断类型(练习)的更多相关文章
- 值类型之间的相互转化,运算符,if条件判断,循环,函数
值类型之间的相互转化 number | string | boolean 一.转换为boolean=>Boolean(a); var num = 10; var s = '123'; var b ...
- Python:Base2(List和Tuple类型, 条件判断和循环,Dict和Set类型)
1.Python创建list: Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 比如,列出班里所有同学的名字,就可以用一个list表示: &g ...
- 5-3 bash脚本编程之二 条件判断
1. 条件测试的表达式 1. [ expression ] :注意这个中括号的前后都有一个空格 2. [[ expression ]] 3. test expression 2.条件判断的类型 1. ...
- 第10章 Shell编程(3)_字符处理命令和条件判断
3. 字符处理命令 3.1 排序命令:sort (1)sort命令:#sort [选项] 文件名 选项 作用 -f 忽略大小写 -n 以数值型进行排序,默认使用字符串型排序 -r 反向排序 -t 指定 ...
- shell条件判断与流程控制
一 条件判断式语句 1.按文件类型进行判断 测试类型 作用 -b 文件 判断文件是否存在,并且是否为块设备文件(是块设备文件为真) -c 文件 判断文件是否存在,并且是否为字符设备文件(是字符设备设备 ...
- wordpress 函数、条件判断以及文件的总结
WordPress基本模板文件 一套完整的WordPress模板应至少具有如下文件: style.css : CSS(样式表)文件 index.php : 主页模板 archive.php : Arc ...
- Bash条件判断
bash编程之:条件判断,判定后续操作的前提条件是否满足, bash编程之: 条件判断常用类型: 整数测试:比较两个整数谁大谁小,是否相等: 二元测试: num1 操作符 num2 -eq: 等于 - ...
- Linux 条件判断
1. 按照文件类型判断 -b 文件 #判断文件是否存在,并且是设备文件 -c 文件 #判断文件是否存在,并且是字符设备文件 -d 目录 #判断目录是否存在,并且是否为目录(是目录返回真) -e 文件 ...
- 一行代码调用实现带字段选取+条件判断+排序+分页功能的增强ORM框架
问题:3行代码 PDF.NET是一个开源的数据开发框架,它的特点是简单.轻量.快速,易上手,而且是一个注释完善的国产开发框架,受到不少朋友的欢迎,也在我们公司的项目中多次使用.但是,PDF.NET比起 ...
随机推荐
- Apache Spark技术实战之9 -- 日志级别修改
摘要 在学习使用Spark的过程中,总是想对内部运行过程作深入的了解,其中DEBUG和TRACE级别的日志可以为我们提供详细和有用的信息,那么如何进行合理设置呢,不复杂但也绝不是将一个INFO换为TR ...
- Mysql中字段类型不一致导致索引无效
修改后 详细见楼下链接 http://ustb80.blog.51cto.com/6139482/1287847
- linux-shell笔记
1.当从windows拖到shell中无法传递文件时,多半可能没有权限,可用sudo rz来进行手动选择传递 2.连接虚拟机时,ssh 用户名@ip地址,然后会提示输入该虚拟机密码,输入密码即可连接 ...
- 点击input时,里面默认字体消失显示
点击input时,点击input里面默认字体消失显示: <input type="" name="" id="" value=&quo ...
- ssh 使用密钥与登录进行远程cp
scp -P 50000 -i abc.pem ubuntu@10.223.191.105://srv/log/webserver/main/nginx.access.2015-08-07.log ...
- (转载)在Visual Studio 2015中使用Git
原文:http://blog.csdn.net/damon316/article/details/51885802 1. VS2015在对Git的支持 VS2015是微软IDE集成开发环境的重量级升级 ...
- 使用udev实现显示器的热插拔和usb的自动挂载
udev:用来监听硬件设备是否发生改变,并可以给硬件设备命名 ,也可以在硬件发生改变之后执行脚本 使用udev检测显示器是否发生变化,然后执行脚本,解决linux显示器热插拔问题 先补充一点: [ro ...
- 移动BI来袭我们要做哪些准备?
(了解更多商业智能行业资讯.商业智能BI解决方案.商业智能客户案例,请访问:http://www.powerbi.com.cn/service) 随着智能手机的发展,商业智能(BI)基础架构也扩展到移 ...
- pycharm licenseserver 注册方法
pycharm5.0之后,以前的很多注册码都无法使用,可以选择使用license server 方式进行注册,方法如下: 注册方法: 在 注册时选择 License server ,填 http ...
- SpringMVC之控制器的单例和多例管理
版权声明:本文为博主原创文章,未经博主允许不得转载. 在使用Spring3对控制器Controller进行bean管理时,如果要对控制器是否单例进行管理. 有两种方式配置多例模式: 1.springX ...