Пример #1
0
 /// <summary>
 /// 恢复默认设置
 /// </summary>
 public void RestoreDefaultSettings()
 {
     GetIni.INIWriteValue(file, "path", "LogPath", "E:\\WorkSapce\\WorkTimeRecord\\setting_and_log    //路径");
     GetIni.INIWriteItems(file, "get_time", "TimeObtain = 1    //1、本机时间  2、局域网时间  3、外网时间\0LocalIP = \\10.8.1.196   //可以是局域网内某IP地址或局域网内计算机名,也可以为net_time\0Website = https://www.baidu.com    //获取时间的网站");
     GetIni.INIWriteItems(file, "location", "MainLocationX = 1200 //屏幕左上角为原点,主窗体左上顶点的横轴坐标\0MainLocationY = 0  //屏幕左上角为原点,主窗体左上顶点的纵轴坐标");
     GetIni.INIWriteValue(file, "trigger_method", "TriggerMethod", "1    //1、通过系统锁屏与解锁触发 2、通过系统一段时间有无操作触发");
 }
Пример #2
0
        /// <summary>
        /// 读取并解析ini设置文件
        /// </summary>
        public void RemoveComments()
        {
            GlobalVariables.LogPath = GetIni.INIGetStringValue(file, "path", "LogPath", null);
            //去掉注释
            GlobalVariables.LogPath = GlobalVariables.LogPath.Split(new char[] { '/', ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];

            GlobalVariables.TimeObtain = GetIni.INIGetStringValue(file, "get_time", "TimeObtain", null);
            GlobalVariables.TimeObtain = GlobalVariables.TimeObtain.Split(new char[] { '/', ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];

            GlobalVariables.LocalIP = GetIni.INIGetStringValue(file, "get_time", "LocalIP ", null);
            GlobalVariables.LocalIP = GlobalVariables.LocalIP.Split(new char[] { '/', ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];

            GlobalVariables.Website = GetIni.INIGetStringValue(file, "get_time", "Website", null);
            string[] Websites = GlobalVariables.Website.Split(new char[] { '/', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            //本身带有”//“,需要注意
            GlobalVariables.Website = Websites[0] + "//" + Websites[1];

            GlobalVariables.MainLocationX = GetIni.INIGetStringValue(file, "location", "MainLocationX", null);
            GlobalVariables.MainLocationX = GlobalVariables.MainLocationX.Split(new char[] { '/', ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];

            GlobalVariables.MainLocationY = GetIni.INIGetStringValue(file, "location", "MainLocationY", null);
            GlobalVariables.MainLocationY = GlobalVariables.MainLocationY.Split(new char[] { '/', ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];

            GlobalVariables.TriggerMethod = GetIni.INIGetStringValue(file, "trigger_method", "TriggerMethod", null);
            GlobalVariables.TriggerMethod = GlobalVariables.TriggerMethod.Split(new char[] { '/', ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];
        }
Пример #3
0
        public static void StaticHandler(HttpResponse response, HttpRequest request)
        {
            //解析请求资源Uri
            string resourceUri = ParseUri(request.Uri);
            string filename    = Path.GetFileName(resourceUri);

            //检查文件访问控制属性
            List <string> allowedmethod = GetIni.GetList(Path.GetDirectoryName(resourceUri) + @"\.access.ini", filename);

            //如果请求的方法不在文件的支持方法列表中,则触发405异常
            if (allowedmethod.Contains(request.Method) == false)
            {
                throw new HttpException.HttpException("405 method not allowed", 405);
            }

            //读取文件数据
            byte[] buffer = File.ReadAllBytes(resourceUri);

            //解析文件媒体类型
            string pattern   = @".[^.\/:*?<>|]*$";
            string extension = Regex.Match(filename, pattern).Value;

            response.Header.Add("Content-Type", QuickMimeTypeMapper.GetMimeType(extension));

            string encoding = "identity";   //默认使用identity编码

            if (response.Header.ContainsKey("Content-Encoding"))
            {
                //使用请求指定的编码
                encoding = response.Header["Content-Encoding"];
            }

            //对文件数据进行编码
            switch (encoding)
            {
            case "gzip":
                MemoryStream ms   = new MemoryStream();
                GZipStream   gzip = new GZipStream(ms, CompressionMode.Compress);
                gzip.Write(buffer, 0, buffer.Length);
                gzip.Close();
                response.Content = ms.ToArray();
                break;

            case "compress":
                break;

            case "deflate":
                MemoryStream  ms2     = new MemoryStream();
                DeflateStream deflate = new DeflateStream(ms2, CompressionMode.Compress);
                deflate.Write(buffer, 0, buffer.Length);
                deflate.Close();
                response.Content = ms2.ToArray();
                break;

            case "identity":
                response.Content = buffer;
                break;

            default:
                response.Content = buffer;
                break;
            }
        }