private void StatusChange() { StatusInfo.Clear(); if (_isStart) { try { _timer.Stop(); var connectResult = _ap.getStatus(); StartChange(connectResult.IsActive); foreach (var item in connectResult.Peers) { StatusInfo.Add(new WlanStatusInfo() { Authenticated = item.Authenticated, HostName = item.HostName, IpAddress = item.IpAddress, MAC = item.MAC }); } if (_isFirst && !String.IsNullOrEmpty(connectResult.MAC)) { //DevicePacp.Instance.StartPacp(connectResult.MAC); _isFirst = false; } _timer.Start(); } catch (Exception ex) { // LogHelper.ShowErrorMessage(ex); _timer.Start(); } } }
/// <summary> /// 设置是否启动 /// </summary> /// <param name="isStart"></param> private void StartChange(bool isStart) { _isStart = isStart; if (_isStart) { StartAndStopContent = "停止"; } else { StatusInfo.Clear(); StartAndStopContent = "启动"; } }
/// <summary> /// 点击压缩 /// </summary> private void Compress_Click(object sender, EventArgs e) { FileStream fs = File.OpenRead(InputFile.Text); try { StatusInfo.Clear(); Compress.Enabled = false; StatusText = "分析文件......"; StatusText = "加载哈夫曼编码编码......"; Codex.Analyzer a = new Codex.Analyzer(fs); Codex.HuffmanCodex h = new Codex.HuffmanCodex(a); StatusText = "写入哈夫曼编码......"; fs.Position = 0; Codex.HuffmanEncoder en = new Codex.HuffmanEncoder(h, fs); FileStream target = File.OpenWrite(OutputFile.Text); target.SetLength(0); target.WriteByte((Byte)Codex.Block.BlockSize); //文件第一位写块大小 en.WriteCodexToStream(target); StatusText = "写入压缩文件......"; var buffer = en.ReadToEnd(); target.Write(buffer, 0, buffer.Length); StatusText = "写入完成."; StatusText = "压缩率:" + (100.0 * target.Length / fs.Length) + '%'; StatusText = "平均编码长度:" + Codex.Debug.AverageCodeLength(a, h) + "位"; StatusText = "字典大小:" + Codex.Block.BlockSize + "字节"; StatusText = "压缩文件头长度:" + h.Length + "字节"; target.Close(); } catch (DataMisalignedException) { MessageBox.Show("文件长度不能够均分到每个块中", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } fs.Close(); Compress.Enabled = true; }