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比起 ...
随机推荐
- 2016.10.14,英语,《American Accent Training》
这本书是讲述美语发音训练的.已经看了一段时间了,决定向周叶学习,记录读书笔记.计划每天花半个小时,学习3节左右的音频(按照CD TRACK),并完成训练. CD1 Track1 What is Acc ...
- MVC中的一些坑
1.@字符在.cshtml文件中不能启用 经过2个小时求解,发现是配置文件web.config中引用的namespace少了System.Web.Optimization,所以不能启用,因为创建的空的 ...
- poj2488骑士马走
#include<stdio.h> #include<stdlib.h> int data[100][100] = {0}; int Dx[8] = {-1,1,-2,2,-2 ...
- 使用JSON.Net(Newtonsoft.Json)作为ASP.Net MVC的json序列化和反序列化工具
ASP.Net MVC默认的JSON序列化使用的是微软自己的JavaScriptSerializer.性能低不说,最让人受不了的是Dictionary<,>和Hashtable类型居然对应 ...
- 过滤关键字防止XSS攻击
public static string ClearXSS(string str) { string returnValue = str; if (string.IsNullOrEmpty(retur ...
- POST流方式接受数据方法
/** * 流方式接收数据 * @param $url * @param $jsonFile * @return bool */private static function sendStreamJs ...
- java 默认修饰符
public的类.类属变量及方法,包内及包外的任何类均可以访问:protected的类.类属变量及方法,包内的任何类,及包外的那些继承了此类的子类才能访问:private的类.类属变量及方法,包内包外 ...
- Python开发程序:生产环境下实时统计网站访问日志信息
日志实时分析系统 生产环境下有需求:要每搁五分钟统计下这段时间内的网站访问量.UV.独立IP等信息,用直观的数据表格表现出来 环境描述: 网站为Nginx服务,系统每日凌晨会对日志进行分割,拷贝到其他 ...
- [SharePoint 2010] Modify lookup mapping with PowerShell
SharePoint支持将列表保存成列表模板,但当列表包含Lookup字段时,通过模板创建的列表会丢失Lookup字段的信息. 通过PowerShell,可以修改Lookup字段的xml内容. Fun ...
- ubuntu安装node.js+express+mongodb
输入以下命令安装: sudo apt-get install nodejs 安装完成后,终端输入nodejs,就能进入node命令啦: 但是正常下应该是输入node进入命令而不是nodejs: 在Ub ...