linearSearch.cs
资源名称:08.zip [点击查看]
上传用户:ynjin1970
上传日期:2014-10-13
资源大小:6438k
文件大小:3k
源码类别:
中间件编程
开发平台:
Visual C++
- using System;
- using System.Threading ;
- using System.Collections ;
- namespace WebApplication1
- {
- /// <summary>
- ///
- /// </summary>
- public class linearSearch
- {
- private ArrayList _results= null;
- private string _keyword;
- private DateTime _started;
- private DateTime _end;
- private void addResult(result thisResult)
- {
- _results.Add(thisResult);
- }
- public TimeSpan totalTime
- {
- get { return _end.Subtract(_started); }
- }
- public linearSearch(){}
- public ArrayList search(string keyword)
- {
- if (keyword==null && keyword=="")
- return null;
- _started=DateTime.Now;
- _keyword=keyword;
- _results=new ArrayList();
- searchWebSites();
- searchDatabases();
- searchDirectoryServers();
- _end=DateTime.Now;
- return _results;
- }
- private void searchDatabases()
- {
- result r = new result("符合查询关键字的记录:""+_keyword+""来自数据库服务器中");
- try
- {
- Thread.Sleep(1000);
- r.links.Add( new link("书名- 《你今天心情不好吗?》","HHFDESKTOP"));
- Thread.Sleep(1000);
- r.links.Add( new link("书名 - 《中国机械设计大典》","HHFDESKTOP"));
- Thread.Sleep(1000);
- r.links.Add( new link("书名 - 《甲骨文献集成》","HHFDESKTOP"));
- r.message="查询结果:" + r.links.Count+ "项";
- r.isCompleted =true;
- }
- catch(Exception e)
- {
- r.isCompleted=false;
- r.message ="查询结果:" + r.links.Count+ "项"+"在操作出错之前";
- }
- finally
- {
- addResult(r);
- }
- }
- private void searchDirectoryServers()
- {
- result r = new result("符合查询关键字的记录:""+_keyword+""来自目录服务器中");
- try
- {
- Thread.Sleep(1000);
- r.links.Add( new link("员工 -书名 张大宝","/"));
- r.links.Add( new link("员工 - 书名 刘爱山","/"));
- r.message="查询结果::" + r.links.Count+ "项";
- r.isCompleted =true;
- }
- catch(Exception e)
- {
- r.isCompleted=false;
- r.message ="查询结果:" + r.links.Count+ "项"+"在操作出错之前";
- }
- finally
- {
- addResult(r);
- }
- }
- private void searchWebSites()
- {
- result r = new result("符合查询关键字的记录:""+_keyword+""来自WEB服务器中");
- try
- {
- Thread.Sleep(2000);
- r.links.Add( new link("简体中文网页-书名 《国王和国后》","HTTP://WWW.163.COM"));
- Thread.Sleep(1000);
- r.links.Add( new link("简体中文网页 -书名 《坐井之小青蛙》","HTTP://WWW.163.COM"));
- Thread.Sleep(1000);
- r.links.Add( new link("简体中文网页 -书名 《激情燃烧的岁月》","HTTP://WWW.163.COM"));
- Thread.Sleep(1000);
- r.links.Add( new link("简体中文网页 -书名《 林海雪原》","HTTP://WWW.163.COM"));
- r.message="查询结果:" + r.links.Count+ "项";
- r.isCompleted =true;
- }
- catch(Exception e)
- {
- r.isCompleted=false;
- r.message ="查询结果:" + r.links.Count+ "项"+"在操作出错之前";
- }
- finally
- {
- addResult(r);
- }
- }
- }
- }