ClassNHT.cs
上传用户:zhangkuixh
上传日期:2013-09-30
资源大小:5473k
文件大小:5k
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Text;
- using System.Collections;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- /*
- ' 迅龙中文分类搜索引擎 v0.6
- '
- ' LGPL 许可发行
- '
- ' 宁夏大学 张冬 康彩 zd4004@163.com
- '
- ' 官网 http://blog.163.com/zd4004/
- */
- namespace NetHashTableAPI
- {
- public class ClassNHT
- {
-
- /// <summary>
- /// 存储器是否锁定 锁定状态下不能进行写入和读出 需要持续等待
- /// </summary>
- public bool lockIt = false;
- /// <summary>
- /// 本地模式下设定数据保存的路径 目录
- /// </summary>
- private string DBPATH = "";
- /// <summary>
- /// 直接存储操作类
- /// </summary>
- private ClassFilesDataBase nDBs = new ClassFilesDataBase();
- /// <summary>
- /// 得到一个数据的值
- /// </summary>
- /// <param name="KeyVal"></param>
- /// <returns></returns>
- public string Value(string KeyVal)
- {
- try
- {
- string a = nDBs.Value(KeyVal);
-
- return a;
- }
- catch
- {
- return "";
- }
-
- }
- /// <summary>
- /// 系统设定
- /// </summary>
- public void SetClassNHT(string nPath, int nM, string k_c_path)
- {
- //读取配置
- XunLong.CongifData.Config.InitConfigData(k_c_path);
- DBPATH = nPath;
- //设定存储器
- nDBs.SetClassFilesDataBase(nPath, nM);
- }
- /// <summary>
- /// 压入一个数据的值
- /// </summary>
- /// <param name="KeyVal"></param>
- /// <param name="DataVal"></param>
- /// <param name="bendi">是否是本地模式 本地模式为直接硬盘存取</param>
- /// <returns></returns>
- public bool add(string Key, string Val,bool bendi)
- {
- //加锁
- lockIt = true ;
- if (bendi == true)
- {
- //得到名称
- //string newname = DBPATH + "\" + getMD5name(Key);
- lockIt = true;
- //保存数据
- nDBs.add(Key, Val);
-
- }
- //解锁
- lockIt = false;
- return true;
- }
- /// <summary>
- /// 判断是否包含特定键
- /// </summary>
- /// <param name="Key"></param>
- /// <returns></returns>
- public bool Contains(string Key)
- {
- return true;
- }
- /// <summary>
- /// 系统内键/值对的数目
- /// </summary>
- /// <returns></returns>
- public long Count()
- {
- return 0;
- }
- /// <summary>
- /// 移除指定的键
- /// </summary>
- /// <param name="Key"></param>
- /// <returns></returns>
- public bool Remove(string Key)
- {
- return true;
- }
- /// <summary>
- /// 得到特定的键列表
- /// </summary>
- /// <param name="xmlTxt">XML格式 负责在键描述中查找</param>
- /// <returns>键列表</returns>
- public ArrayList SearchOneList(string xmlTxt)
- {
- ArrayList n = new ArrayList();
- n.Clear();
- n = nDBs.SearchOneList(xmlTxt);
- return n;
- }
- /// <summary>
- /// 得到URL的MD5名
- /// </summary>
- /// <param name="url"></param>
- /// <returns></returns>
- private string getMD5name(string url)
- {
- string strMd5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(url, "md5");
- return strMd5;
- }
- /// <summary>
- /// 写文件
- /// </summary>
- /// <param name="filename"></param>
- /// <param name="data"></param>
- private void putFileData(string filename, string data)
- {
- StreamWriter writer = null;
- try
- {
- writer = new StreamWriter(filename, false, System.Text.Encoding.GetEncoding("gb2312"));
- writer.Write(data);
- writer.Close();
- }
- catch (IOException e)
- {
- Console.WriteLine(e.Message);
- }
- finally
- {
- if (writer != null)
- writer.Close();
- }
- }
- }
- }