public bool SendByteResult(byte[] bytResult) { byte[] temp = CompressHelper.DeCompress(EnumCompressType.MemCompress, bytResult); string result = ConvertUtility.CodingToString(temp, 2); //result = result.Replace("\n", "\r\n"); if (string.IsNullOrEmpty(result)) { return(false); } ServiceCommand command = new ServiceCommand(); command.CommandStringToClass(result, false); if (command == null || string.IsNullOrEmpty(command.Guid)) { return(false); } return (Singleton <ResultCacheManager <string> > .Instance.AddResult(command.Guid, command.EntityXmlContent)); }
public static void AllXlsToConfig(string path, string outPath) { //把文件夹下所有的xls转成一个总配置文件 string[] paths = Directory.GetFiles(path, "*.xl*", SearchOption.AllDirectories); ByteArray ba = new ByteArray(); for (int i = 0; i < paths.Length; i++) { byte[] data = XlsToConfig(paths[i]); if (data != null && data.LongLength > 0) { ba.Write(data); } } Directory.CreateDirectory(outPath); string cfgPath = outPath + Path.DirectorySeparatorChar + "cfg.bytes"; if (File.Exists(cfgPath)) { File.Delete(cfgPath); } //Console.WriteLine("压前 \n"+ba.GetBuffer().ToString()); //Console.WriteLine("压后 \n" + CompressHelper.Compress(ba.GetBuffer())); File.WriteAllBytes(cfgPath, CompressHelper.Compress(ba.GetBuffer())); ba.Close(); Console.WriteLine("配置数据导出成功"); }
public TranMsg[] NextPackages(out int len) { if (this._indexFiles.Length > 0) { FileInfo fi = this._indexFiles[0]; int flen = fi.FullName.Length; FileInfo fd = new FileInfo(fi.FullName.Substring(0, flen - 4) + ".odb"); this._lastSynchronized = new FileInfo[] { fi, fd }; byte[] buff1 = CompressHelper.Compress(fi.FullName); byte[] buff2 = CompressHelper.Compress(fd.FullName); len = buff1.Length + buff2.Length + 4; byte[] bb = new byte[len]; ValueHelper.WriteShort(bb, 0, (short)buff1.Length); Array.Copy(buff1, 0, bb, 2, buff1.Length); ValueHelper.WriteShort(bb, buff1.Length + 2, (short)buff2.Length); Array.Copy(buff2, 0, bb, buff1.Length + 4, buff2.Length); return(this.Splite(bb, len)); } else { len = 0; return(null); } }
private async void BackgroundUploader_DoWork(object sender, DoWorkEventArgs e) { try { Invoke(new Action(() => { ProgressUpload.MarqueeAnimationSpeed = 100; MainGroupBox.Enabled = false; })); _FileToSave = await _DBProvider.GetFile(_FileToSave.Id); if (_FileToSave.Compressed) { _FileToSave.ByteArray = CompressHelper.Decompress(_FileToSave.ByteArray); } using (var fs = new FileStream(Path.Combine(PathTextBox.Text, NameTextBox.Text + _FileToSave.Extension), FileMode.Create, FileAccess.Write)) { fs.Write(_FileToSave.ByteArray, 0, _FileToSave.ByteArray.Length); } } finally { Invoke(new Action(() => { ProgressUpload.MarqueeAnimationSpeed = 0; MainGroupBox.Enabled = true; this.DialogResult = DialogResult.OK; this.Close(); })); } }
public void ImportBack(StringRequestInfo requestInfo, AppSession app_session) { var data = requestInfo.Parameters[0]; var decompress_data = CompressHelper.Decompress(data); ThreadPool.QueueUserWorkItem(SetBackSessions, decompress_data); }
private IActionResult ShowFileText(string file) { string fileName = null; try { fileName = CompressHelper.GzipDecompress(file); } catch { /* 防止人为修改URL,造成解压缩失败 */ } if (string.IsNullOrEmpty(fileName)) { return(new TextResult("parameter error.")); } string logpath = ClientLogController.GetClientLogPath(); string text = null; string filePath = Path.Combine(logpath, fileName); if (File.Exists(filePath)) { text = File.ReadAllText(filePath, Encoding.UTF8); } else { text = "parameter error."; } return(new TextResult(text)); }
public static Map LoadLvlMap(string mapname) { var mappath = Path.Combine(CONTENT_MANAGER.LocalRootPath, "map", mapname + ".lvl"); if (!File.Exists(mappath)) { return(null); } var mapdata = File.ReadAllText(mappath).Split('|'); mappath = Path.Combine(CONTENT_MANAGER.LocalRootPath, "map", mapname + ".tmx"); if (File.Exists(mappath)) { var checksum = Convert.ToBase64String(HelperMethod.GetMD5CheckSum(mappath)); if (string.Compare(checksum, mapdata[0]) != 0) { return(LoadTmxMap(mapname)); } } var map = JsonConvert.DeserializeObject <Map>(CompressHelper.UnZip(mapdata[1])); var interactableObj = from obj in map.Objects where !string.IsNullOrEmpty(obj.Value.OnActivate) || !string.IsNullOrEmpty(obj.Value.OnDeactivate) select obj.Value; map.InteractLink = ProcessInteractableObject(ref map, interactableObj); return(map); }
public ActionResult Read(int Id, string code) { ContentViewModel c = UIHelper.GetContentView(Id, code); ContentViewModel prev = UIHelper.GetPrevContent(c); ContentViewModel next = UIHelper.GetNextContent(c); ViewBag.NextContent = next; ViewBag.PrevContent = prev; ViewBag.BookCSS = c.Book.CSSURL; ViewBag.BookCustomCss = c.Book.CustomCSS; ViewBag.BookId = c.BookId; c.HTML = CompressHelper.DecompressString(c.HTML); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(c.HTML); var ps = doc.DocumentNode.Descendants("p").Where(x => x.Id.Contains("|")); foreach (var p in ps.ToList()) { string pCode = p.Id.Split('|')[0]; int pPos = int.Parse(p.Id.Split('|')[1]); TranslatedContent translated = DBHelper.GetTranslatedContent(c.BookId, pCode, pPos); if (translated != null) { p.ParentNode.ReplaceChild(HtmlNode.CreateNode(translated.Data), p); } } c.HTML = Regex.Replace(doc.DocumentNode.OuterHtml, "href=\"(.+?)\\.(xhtml|html|htm)(#.+?)?\"", "href=\"" + Id + "?code=$1$3\""); return(View(c)); }
public void ProcessDepartments(JobAudit job) { try { _job = job; _job.JobStatus = BOFileStatus.Processing; JobAuditDAL.UpdateJobAudit(_job); DateTime start = DateTime.Now; List <byte[]> files = CompressHelper.DeCompress(_job.FilePath); int totalItems = 0; List <Department> fromClient = ProcessDepartmentsFile(job.RetailerId, files.FirstOrDefault(), out totalItems); List <Department> fromDB = DeptDAL.GetAllDepartments(job.RetailerId); UpdateDB(fromClient, fromDB); _job.ItemsProcessed = totalItems; _job.ProcessTime = (int)DateTime.Now.Subtract(start).TotalSeconds; _job.JobStatus = BOFileStatus.Done; JobAuditDAL.UpdateJobAudit(_job); } catch (Exception ex) { Logger.LogException(ex); } }
/// <summary> /// 应用程序的主入口点。 /// </summary> //[STAThread] static void Main(string[] args) { // // TODO: 在此处添加代码以启动应用程序 // Console.WriteLine("Hello World"); //Console.WriteLine(Environment.Version.ToString()); string s = "阿斯个贷哈根室电话个撒谎干大事个贷伽师将阿斯个贷哈根室电话个撒谎干大事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将"; byte[] buffer = Encoding.UTF8.GetBytes(s); byte[] bytes; bytes = CompressHelper.GZipCompress ( buffer ); Console.WriteLine ( "{0},GZip: {1}; {2}" , buffer.Length , bytes.Length , s.Length ); //bytes = CompressHelper.ReadStreamToBytes(ms); //string ss = Encoding.UTF8.GetString(bytes); Stream ms = new MemoryStream(bytes); //ms.Write(bytes, 0, bytes.Length); ms.Position = 0; ms = CompressHelper.GZipDecompress ( ms ); bytes = StreamDataHelper.ReadDataToBytes(ms); string ss = Encoding.UTF8.GetString(bytes); Console.WriteLine(ss); bytes = CompressHelper.DeflateCompress ( buffer ); Console.WriteLine ( "{0},Deflate: {1}; {2}" , buffer.Length , bytes.Length , s.Length ); //Console.WriteLine("{0},Deflate: {1}", buffer.Length, bytes.Length); ss = Encoding.UTF8.GetString ( ( CompressHelper.DeflateDecompress ( bytes ) ) ); Console.WriteLine(ss); }
public IEnumerator StartDown() { if (File.Exists(savePath)) { File.Delete(savePath); } if (!Directory.Exists(AppConst.AppExternalDataPath)) { Directory.CreateDirectory(AppConst.AppExternalDataPath); } WWW www = new WWW(HotUpdateRessMgr.Instance.downLoadInfo.ResUrl + "/" + downInfo.fileName); yield return(www); if (!string.IsNullOrEmpty(www.error)) { IsFailure = true; Debug.LogErrorFormat("下载文件 {0} 出错:{1}", downInfo.fileName, www.error); } else { byte[] bytes = www.bytes; CompressHelper.DecompressBytesLZMA(bytes, savePath); IsFinished = true; } www.Dispose(); }
public override void SendAsync(byte[] data, int offset, int length) { if (this._disposable == 1) { return; } byte[] bytes = CompressHelper.Compress(data, offset, length); if ((SessionWorkType)_session.AppTokens[0] == SessionWorkType.ManagerSession) { byte[] body = new byte[sizeof(Int64) + sizeof(Int32) + bytes.Length]; BitConverter.GetBytes(this.RemoteId).CopyTo(body, 0); BitConverter.GetBytes(bytes.Length).CopyTo(body, 8); bytes.CopyTo(body, 12); SendMessageHelper.SendMessage(_session, MsgCommand.Msg_MessageData, body); } else { byte[] body = new byte[bytes.Length + sizeof(Int32)]; BitConverter.GetBytes(bytes.Length).CopyTo(body, 0); bytes.CopyTo(body, 4); _session.SendAsync(body, 0, body.Length); } }
public void TestNextPackageData() { int len; provider.HasMoreData(); TranMsg[] msgs = provider.NextPackages(out len); Assert.AreEqual(5, msgs.Length); TranMsg msg1 = TranMsg.Combine(msgs); byte[] buff = msg1.Data; short fiLen = ValueHelper.GetShort(buff, 0); short fdLen = ValueHelper.GetShort(buff, 0 + 2 + fiLen); Assert.AreEqual(55, fiLen); Assert.AreEqual(4670, fdLen); byte[] fib = CompressHelper.Decompress(buff, 2, fiLen); byte[] fdb = CompressHelper.Decompress(buff, 4 + fiLen, fdLen); using (FileStream writer = new FileStream("vibi.data", FileMode.Create, FileAccess.Write)) { writer.Write(fib, 0, fib.Length); } using (FileStream writer = new FileStream("vibd.data", FileMode.Create, FileAccess.Write)) { writer.Write(fdb, 0, fdb.Length); } provider.OnPackageSent(); Assert.AreEqual(1, provider.Remainder); }
public void Decompress2() { FileInfo file = new FileInfo(@"D:\123.sql.gz"); FileInfo file2 = new FileInfo(@"D:\456.sql"); CompressHelper.Decompress(file, file2); }
public byte[] DealClientRequestByte(string condition) { string result = DealRequest(condition); byte[] bytResult = ConvertUtility.CodingToByte(result, 2); byte[] returnResult = null; // 长度大于2048,要进行压缩。 if (bytResult != null || bytResult.Length > WebServiceConst.Need_Compress_MinLength) { byte[] temp = CompressHelper.Compress(EnumCompressType.MemCompress, bytResult); returnResult = new byte[temp.Length + 1]; returnResult[0] = 1; Array.Copy(temp, 0, returnResult, 1, temp.Length); temp = null; } else { returnResult = new byte[bytResult.Length + 1]; returnResult[0] = 0; Array.Copy(bytResult, 0, returnResult, 1, bytResult.Length); } bytResult = null; // 处理客户端请求 return(returnResult); }
public void Decompress3() { DirectoryInfo dir = new DirectoryInfo(@"D:\123\"); DirectoryInfo dest = new DirectoryInfo(@"D:\456\"); CompressHelper.Compress(dir, dest); }
public override void Add(DataTable data) { if ((data != null) && (data.Rows.Count > 0)) { GpsDataTable table = new GpsDataTable(UpdataStruct.ColNameList); try { int num = 1; for (int i = 0; i <= (data.Rows.Count - 1); i++) { table.InsertRows(data.Rows[i].ItemArray); if ((num >= base._Size) || (i == (data.Rows.Count - 1))) { lock (base._PosList.SyncRoot) { base._PosList.Add(CompressHelper.CompressToSelf(table)); } table.Rows.Clear(); num = 0; } num++; } } catch (Exception exception) { ErrorMsg msg = new ErrorMsg("RemotingDataBS", "Add", exception.Message + exception.StackTrace); new LogHelper().WriteError(msg); base._PosList = new ArrayList(100); } } }
public void SendCompressedCommand(RemoteCommand command, object obj, AppSession session) { LogHelper.WriteLog(typeof(RemoteCommand), "发送消息:" + command.ToString()); var type = ((int)command).ToString().PadLeft(2, '0'); byte[] typeByte = Encoding.UTF8.GetBytes(type); var str = JsonConvert.SerializeObject(obj); var comp_str = CompressHelper.Compress(str); byte[] byteBuffer = Encoding.UTF8.GetBytes(comp_str); int len = byteBuffer.Length; byte[] length = BitConverter.GetBytes(len); var data = typeByte.Concat(length).Concat(byteBuffer).ToArray(); if (type.Length != 2) { return; } try { session.Send(data, 0, data.Length); } catch (Exception) { } }
public override FileChunk ConvertReadToWriteModel(ChunkForDecompressModel readChunk) { var position = BitConverter.ToInt64(readChunk.PositionBuffer, 0); var decompressed = CompressHelper.Decompress(readChunk.DataBuffer); return(new FileChunk(position, decompressed)); }
public bool LoadSkin(String skinFilePath) { //如果皮肤文件不存在 if (!System.IO.File.Exists(skinFilePath)) { return(false); } var zipDllBytes = CompressHelper.DecompressBytes(Properties.Resources.Ionic_Zip_dll); var ass = System.Reflection.Assembly.Load(zipDllBytes); var ZipFileType = ass.GetType("Ionic.Zip.ZipFile"); var constructorInfo = ZipFileType.GetConstructor(new Type[] { typeof(String) }); var ZipFileObject = constructorInfo.Invoke(new object[] { skinFilePath }); var ExtractAllMethod = ZipFileType.GetMethod("ExtractAll", new Type[] { typeof(String) }); //临时皮肤目录 String skinDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString()); //解压皮肤文件包中的所有文件 ExtractAllMethod.Invoke(ZipFileObject, new object[] { skinDir }); //加载皮肤 bool rtnBool = LoadSkin(new System.IO.DirectoryInfo(skinDir)); //删除临时目录及其中的文件 System.IO.Directory.Delete(skinDir, true); //释放ZipFile对象 var DisposeMethod = ZipFileType.GetMethod("Dispose"); DisposeMethod.Invoke(ZipFileObject, new object[] { }); return(rtnBool); }
public override void SendAsync(byte[] data, int offset, int length) { if (this._socket == null) { return; } byte[] buffer = this._iscompress ? this.BuilderPack(CompressHelper.Compress(data, offset, length)) : this.BuilderPack(data, offset, length); var awaiter = _handlerSaeaPool.Take(); awaiter.Saea.SetBuffer(buffer, 0, buffer.Length); Interlocked.Increment(ref _isuchannel); SaeaExHelper.SendAsync(this._socket, awaiter, (a, e) => { Interlocked.Decrement(ref _isuchannel); this._handlerSaeaPool.Return(awaiter); this.SendTransferredBytes = a.Saea.Buffer.Length; this._notifyEventHandler?.Invoke(TcpSocketCompletionNotify.OnSend, this); if (e != SocketError.Success) { _logger.WriteLog(string.Format("SendAsync--exception:{0}", e.ToString())); } }); }
public override int Send(byte[] data, int offset, int length) { int count = 0; if (this._socket == null) { return(count); } byte[] buffer = this._iscompress ? this.BuilderPack(CompressHelper.Compress(data, offset, length)) : this.BuilderPack(data, offset, length); Interlocked.Increment(ref _isuchannel); try { count = this._socket.Send(buffer); } catch { } finally { this.SendTransferredBytes = count; this._notifyEventHandler?.Invoke(TcpSocketCompletionNotify.OnSend, this); Interlocked.Decrement(ref _isuchannel); } return(count); }
public IEnumerator Start() { Debug.Log("开始下载 " + mFileName); WWW www = new WWW(AppConst.SourceResPathUrl + "/" + mFileName); yield return(www); if (www.error != null) { Debug.Log("下载文件失败 " + www.error); IsFailure = true; } else { if (!Directory.Exists(AppConst.AppExternalDataPath)) { Directory.CreateDirectory(AppConst.AppExternalDataPath); } CompressHelper.DecompressBytesLZMA(www.bytes, AppConst.AppExternalDataPath + "/" + mFileName); Debug.LogWarning("解压完成" + mFileName); yield return(10); IsFinished = true; } www.Dispose(); }
public void SendImageFile(Bitmap desktopImage, Graphics g) { using (MemoryStream ms = ImageHelper.GetLossyCompression(desktopImage, 15, "W", Screen.PrimaryScreen.Bounds.Width)) { if (desktopImage != null) { try { ms.Position = 0; _mCleint.SendFile(_remote, CompressHelper.Compress(ms.GetBuffer())); isBigChnage = true; //if (_fps > 0) // sec = 1000 / _fps; //else // sec = 2000; //Thread.Sleep(sec); } catch { } finally { ms.Dispose(); g.Dispose(); desktopImage.Dispose(); } } } }
public void Compress5() { FileInfo file = new FileInfo(@"D:\锋利的SQL.sql"); FileInfo file_dest = new FileInfo(@"D:\123.sql"); CompressHelper.Compress(file, file_dest); }
public void Compress() { var num = CompressHelper.Compress("1234567890"); var result = CompressHelper.Decompress(num); Assert.AreEqual("1234567890", result); }
public override ByteChunkModel ConvertReadToWriteModel(FileChunk readChunk) { var position = BitConverter.GetBytes(readChunk.Position); var compressed = CompressHelper.Compress(readChunk.DataBuffer); var length = BitConverter.GetBytes(compressed.Length); return(new ByteChunkModel(length, position, compressed)); }
private void GameClient_PacketReceived(BinaryReader reader) { PacketType packetType = (PacketType)reader.ReadInt16(); int size = reader.ReadInt32(); string packet = CompressHelper.Unzip(reader.ReadBytes(size)); logger.Trace("PACKET RECEIVED - {0} : {1}", packetType, packet); try { switch (packetType) { case PacketType.ChatMessage: OnChatMessage(JsonConvert.DeserializeObject <StandardServerChatMessage>(packet)); break; case PacketType.PrivateMessage: OnPrivateChatMessage(JsonConvert.DeserializeObject <StandardServerPrivateMessage>(packet)); break; case PacketType.Login: OnLogin(JsonConvert.DeserializeObject <StandardServerLogin>(packet)); break; case PacketType.AddHubPlayer: OnAddHubPlayer(JsonConvert.DeserializeObject <StandardServerAddHubPlayer>(packet)); break; case PacketType.RemoveHubPlayer: OnRemoveHubPlayer(JsonConvert.DeserializeObject <StandardServerRemoveHubPlayer>(packet)); break; case PacketType.UpdateHubPlayer: OnUpdateHubPlayer(JsonConvert.DeserializeObject <StandardServerUpdateHubPlayer>(packet)); break; case PacketType.PlayerList: OnUpdateHubPlayerList(JsonConvert.DeserializeObject <StandardServerPlayerlist>(packet)); break; case PacketType.Ping: OnPing(JsonConvert.DeserializeObject <StandardServerPing>(packet)); break; case PacketType.AskAnimations: OnGetAnimations(JsonConvert.DeserializeObject <StandardServerGetAnimations>(packet)); break; case PacketType.GetRanking: OnGetRanking(JsonConvert.DeserializeObject <StandardServerGetRanking>(packet)); break; } } catch (Exception ex) { logger.Error(ex.ToString()); } }
public static void ExportSDKToPackage() { if (File.Exists(PathConfig.SDKPathInPackage)) { File.Delete(PathConfig.SDKPathInPackage); } CompressHelper.CompressDirectory(PathConfig.SDKBackupPath, PathConfig.SDKPathInPackage); Debug.logger.Log("Compress To " + PathConfig.SDKBackupPath); }
public static void Configure( DbContextOptionsBuilder <ABPBlogDbContext> dbContextOptions, string connectionString ) { /* This is the single point to configure DbContextOptions for ABPBlogDbContext */ // dbContextOptions.UseSqlServer(connectionString);dbContextOptions dbContextOptions.UseMySQL(CompressHelper.AES_Decrypt(connectionString, "qwertyuiop", "1234567891234567")); }