using System;
using System.Collections.Generic;
using System.Text;
using Feeboo.SearchLIB.DataBase;
using Feeboo.SearchLIB.DataBase.SearchDataSetTableAdapters;
using Feeboo.Library;
namespace Feeboo.SearchLIB
{
public class Search
{
private Regulation regu;
private readonly string rootPath = AppDomain.CurrentDomain.BaseDirectory;
private bool isDownloadFile = false;
public event DelegateSearchInfo GetTotal;
public event DelegateSearchInfo GetCount;
private EnumSearchType searchType;
public EnumSearchType SearchType
{
get { return searchType; }
set { searchType = value; }
}
private int typeID = 999;
public int TypeId
{
get { return typeID; }
set { typeID = value; }
}
public bool IsDownloadFile
{
set { isDownloadFile = value; }
}
public Search(string id)
{
regu = new Regulation();
regu.Info = RegulationInfoFactory.GetRegulationInfoByID(id);
}
public void RunSearch()
{
if (isDownloadFile)
{
regu.GetFile += new DelegateGetFile(regu_GetFile);
}
SearchDataSet.ArticleDataTable table = new SearchDataSet.ArticleDataTable();
List<string> urlList = regu.UrlList;
OnGetTotal(urlList.Count);
int i = 0;
foreach (string url in urlList)
{
SearchDataSet.ArticleRow row = table.NewArticleRow();
if (searchType == EnumSearchType.SaveToAccess)
{
ArticleTableAdapter adapter = new ArticleTableAdapter();
try
{
adapter.InsertURL(url);
regu.GetRow(url, ref row);
adapter.UpdateRow(typeID, row.IsCommend, row.SmallImage,
row.BigImage, row.Title, row.ContentType, row.Summary,
row.Content, row.ClickCount, row.Author, row.Source,
row.PostDate, row.Operator, row.ModifyDate, row.OtherA,
row.OtherB, url);
}
catch { }
}
if (searchType == EnumSearchType.SaveToXML)
{
regu.GetRow(url, ref row);
table.AddArticleRow(row);
}
i++;
OnGetCount(i);
}
if (searchType == EnumSearchType.SaveToXML)
table.WriteXml(rootPath + "Data/" +
DateTime.Now.ToString("yyyyMMdd_") +
new Random().Next(10000, 99999) + ".xml");
}
private void OnGetCount(int i)
{
if (GetCount != null)
GetCount(i);
}
private void OnGetTotal(int count)
{
if (GetTotal != null)
GetTotal(count);
}
void regu_GetFile(string value)
{
DownLoad download = new DownLoad(rootPath + "Data/files");
List<string> _list = DownLoad.GetDownloadFileList(value, regu.Info.InfoURL);
download.DownloadFileList(_list);
}
public enum EnumSearchType
{
SaveToXML,
SaveToAccess
}
}
public delegate void DelegateSearchInfo(int count);
}
Search
最新推荐文章于 2025-01-10 00:15:00 发布
本文介绍了一个搜索应用程序的实现细节,包括不同类型的搜索(如保存到XML或Access数据库),以及如何通过事件委托来跟踪搜索进度。此外,还展示了如何处理下载文件的情况,并提供了具体的代码示例。
1万+

被折叠的 条评论
为什么被折叠?



