• 代码


    using System;
    using System.Collections;
    using System.Security.Cryptography;
    using System.Text;
    using System.Web;
    using System.IO;

    using System.Collections.Specialized;

    using System.Web.Caching;
    using System.Xml;
    using System.Configuration;
    using System.Xml.Serialization;


    namespace Utility
    {
     /// <summary>
     /// Common 的摘要说明。
     /// </summary>
     public class Common
     {
      #region 成员字段
      public static readonly string CacheKey = "ForumsConfiguration";
      private Hashtable providers = new Hashtable();
      private Hashtable extensions = new Hashtable();
      private static readonly Cache cache = HttpRuntime.Cache;
      private string defaultProvider;
      private string defaultLanguage;
      private string forumFilesPath;
      private bool disableBackgroundThreads = false;
      private bool disableIndexing = false;
      private bool disableEmail = false;
      private string passwordEncodingFormat = "unicode";
      private int threadIntervalEmail = 15;
      private int threadIntervalStats = 15;
      //private SystemType systemType = SystemType.Self;
      private short smtpServerConnectionLimit = -1;
      private bool enableLatestVersionCheck = true;
      private string uploadFilesPath = "/Upload/";
      private XmlDocument XmlDoc = null;
      #endregion
      public Common()
      {
       //
       // TODO: 在此处添加构造函数逻辑
       //
      }
      public enum UserPasswordFormat
      {
       ClearText = 0,
       MD5Hash = 1,
       Sha1Hash = 2,
       Encyrpted = 3
      }
      public string PasswordEncodingFormat
      {
       get { return passwordEncodingFormat; }
      }
      public static string Encrypt(UserPasswordFormat format, string cleanString, string salt)
      {
       Byte[] clearBytes;
       Byte[] hashedBytes;
       Encoding encoding = Encoding.GetEncoding("unicode");
       clearBytes = encoding.GetBytes(salt.ToLower().Trim() + cleanString.Trim());

       hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);

         return BitConverter.ToString(hashedBytes);
         ;                     
       
      }
      public static Common GetConfig()
      {
       Common config = cache.Get(CacheKey) as Common;
       if(config == null)
       {
        string path;
        if(HttpContext.Current != null)
         path = HttpContext.Current.Server.MapPath("~/Forums.config");
        else
         path = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Forums.config";

        XmlDocument doc = new XmlDocument();
        doc.Load(path);
        config = new Common(doc);
        cache.Insert(CacheKey,config,new CacheDependency(path),DateTime.MaxValue,TimeSpan.Zero,CacheItemPriority.AboveNormal,null);

        //cache.ReSetFactor(config.CacheFactor);
       }
       return config;
               
      }
     }
    }

  • 相关阅读:
    吉他 摄影
    前端思考独处时间自我成长
    约束力
    js算法
    旅行计划
    生产者消费者问题
    Lock锁
    线程和进程
    什么是JUC
    GC日志分析和垃圾回收器的新展望
  • 原文地址:https://www.cnblogs.com/sujingnan/p/963743.html
Copyright © 2020-2023  润新知