/// <summary> /// 全同步单个表 /// </summary> /// <param name="buyerId"></param> public int AllSyncOneData(LogedInUser CurrentUser, string tableName) { int count = 0; try { ProxyFactory.SyncDataProxy.RefreshUserData(); byte[] data = ProxyFactory.SyncDataProxy.GetSyncTableEx(tableName, CurrentUser); DataTable dt = (DataTable)CompressUtil.Decompression(data); //DataTable dt = ProxyFactory.SyncDataProxy.GetSyncTable(tableName,CurrentUser); //count = dt.Rows.Count; count = AllSyncTable1(dt); //AllSyncTable1(dt); } catch (Exception e) { count = -1; //CloseConntion(); } //CloseConntion(); return(count); /*改之前 备份 * DataSet ds = DataSerialization.UnSerializeData(ProxyFactory.SyncDataProxy.GetSyncData(buyerId)); * foreach (DataTable dt in ds.Tables) * { * * AllSyncTable(dt); * * } * CloseConntion(); * */ }
public void HeightMapCompression() { int width = 256; int height = 256; float[] heightmap = new float[width * height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { heightmap[x + y * width] = -x + y; } } byte[] compressedBytes = CompressUtil.CompressHeightMap(heightmap, 0, 10); float[] decompressedHeightMap = CompressUtil.DecompressHeightMap(compressedBytes, 0, 10); LogUtil.Debug("Original byte size: " + heightmap.Length * 4); LogUtil.Debug("Compressed byte size: " + compressedBytes.Length); LogUtil.Debug("Compression ratio: " + (compressedBytes.Length * 100 / (heightmap.Length * 4)) + "%"); Assert.AreEqual(heightmap.Length, decompressedHeightMap.Length); for (int i = 0; i < heightmap.Length; i++) { Assert.AreEqual(heightmap[i], decompressedHeightMap[i]); } }
static void Main(string[] args) { try { var path = ConfigurationManager.AppSettings["dirPath"] ?? "C:\\1.0.1"; var loop = Convert.ToInt32(ConfigurationManager.AppSettings["loop"] ?? "0"); Console.WriteLine("path=>" + path); Console.WriteLine("loop=>" + loop); for (int i = 0; i < loop; i++) { var temp = path + "\\" + i; CompressUtil.DecompressFile($"{path}.zip", temp); var stopiis = @"get-website 'Default Web Site' | where-object { if ($_.Name -ne ''){stop-website $_.Name; get-website $_.Name;}};"; var script = $"Copy-Item -Path \"{temp + "\\1.0.1"}\" -Destination \"{temp + "\\copy"}\" -Recurse -Force"; PowerShellUtil.RunScript(new List <string> { "Get-ExecutionPolicy | Where-Object { if ($_ -nq 'Unrestricted') { set-executionpolicy Unrestricted -confirm:$false -force } };", stopiis, script }); } Console.WriteLine("执行完毕。"); } catch (Exception ex) { Logger.Error(ex.Message, ex); Console.WriteLine(ex.ToString()); } Console.ReadKey(); }
/// <summary> /// get mz values only for aird file /// 默认从Aird文件中读取,编码Order为LITTLE_ENDIAN /// </summary> /// <param name="value"> 加密的数组 </param> /// <returns> 解压缩后的数组 </returns> public int[] getMzValuesAsInteger(byte[] value) { var intValues = CompressUtil.zlibDecoderToInt(value); intValues = CompressUtil.fastPforDecoder(intValues); return(intValues); }
private void button1_Click(object sender, EventArgs e) { if (!File.Exists(txtFileName.Text)) { MessageBox.Show("檔案不存在", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string content; try { if (checkBox1.Checked) { content = CompressUtil.DecompressStringFromFile(txtFileName.Text, txtPassword.Text); } else { content = CompressUtil.DecompressStringFromFile(txtFileName.Text); } } catch (Exception ex) { MessageBox.Show("檔案還原失敗 ! " + ex.Message, "失敗", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Completed != null) { Completed.Invoke(this, new ExportEventArgs(content)); } this.Close(); }
public void compress(List <Spectrum> spectrumGroup, TempScanSZDPD ts) { List <int[]> mzListGroup = new List <int[]>(); //Intensity数组会直接合并为一个数组 List <float> intListAllGroup = new List <float>(); for (int i = 0; i < spectrumGroup.Count; i++) { BinaryDataDouble mzData = spectrumGroup[i].getMZArray().data; BinaryDataDouble intData = spectrumGroup[i].getIntensityArray().data; List <int> mzList = new List <int>(); List <float> intensityList = new List <float>(); var dataCount = mzData.Count; int[] mzArray = new int[dataCount]; int j = 0; for (int t = 0; t < mzData.Count; t++) { if (jobInfo.jobParams.ignoreZeroIntensity && intData[t] == 0) { continue; } int mz = Convert.ToInt32(mzData[t] * mzPrecision); mzArray[j] = mz; if (jobInfo.jobParams.log2) { intensityList.Add(Convert.ToSingle(Math.Round(Math.Log(intData[t]) / log2, 3))); //取log10并且精确到小数点后3位 } else { intensityList.Add(Convert.ToSingle(Math.Round(intData[t], 1))); //精确到小数点后一位 } j++; } //空光谱的情况下会填充一个mz=0,intensity=0的点 if (j == 0) { mzListGroup.Add(new int[] { 0 }); intensityList.Add(0); } else { int[] mzSubArray = new int[j]; Array.Copy(mzArray, mzSubArray, j); mzListGroup.Add(mzSubArray); } //说明是一帧空光谱,那么直接在Aird文件中抹除这一帧的信息 intListAllGroup.AddRange(intensityList); } Layers layers = StackCompressUtil.stackEncode(mzListGroup, mzListGroup.Count == Math.Pow(2, jobInfo.jobParams.digit)); // List<int[]> temp = StackCompressUtil.stackDecode(layers); //使用SZDPD对mz进行压缩 ts.mzArrayBytes = layers.mzArray; ts.tagArrayBytes = layers.tagArray; ts.intArrayBytes = CompressUtil.zlibEncoder(intListAllGroup.ToArray()); }
public void CompressFolder() { CompressUtil.CompressFolder(@"E:\\PublishOutput", @"E:\\PublishOutput.zip"); var path = "E:\\PublishOutput.zip"; var flag = File.Exists(path); Assert.AreEqual(flag, true); }
public void Crypt(string data, string password, string salt, int iterations) { var bytesSalt = Encoding.UTF8.GetBytes(salt); var encData = TSKT.CryptUtil.Encrypt(CompressUtil.Compress(Encoding.UTF8.GetBytes(data)), password, bytesSalt, iterations); var decData = CompressUtil.Decompress(TSKT.CryptUtil.Decrypt(encData, password, bytesSalt, iterations)); Assert.AreEqual(data, decData); }
public void UnZipFolder() { var path = "E:\\4.6.0.70708"; CompressUtil.DecompressFile(@"E:\\4.6.0.70708.zip"); var flag = Directory.Exists(path); Assert.AreEqual(flag, true); }
/// <summary> /// 解压Z文件 /// </summary> /// <param name="ObsDataSource"></param> /// <param name="destDir"></param> /// <param name="delSourse"></param> private void DecomressZFile(string source, string destDir, bool delSourse) { if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } string[] files = Directory.GetFiles(source); if (this.ProgressBar != null) { this.ProgressBar.InitProcess(files.Length); } foreach (var item in files) { if (IsCancelProcessing) { break; } try { CompressUtil.Decompres(item, destDir); } catch (Exception ex) { string msg = "解压 Z 文件出错了:" + ex.Message + "\r\n"; ShowInfo(msg); if (!ignoreError) { if (FormUtil.ShowYesNoMessageBox(msg + "是否继续?") == System.Windows.Forms.DialogResult.No) { break; } } } //try{ // if (delSourse) { System.Threading.Thread.Sleep(100); File.Delete(key); } //} //catch (Exception ex) //{ // string msg = "删除 Z文件出错了:" + ex.Message + key+ "\r\n"; // ShowInfo(msg); // if (!ignoreError) // if (FormUtil.ShowYesNoMessageBox(msg + "是否继续?") // == System.Windows.Forms.DialogResult.No) // break; //} string info = "解压Z文件 " + item; ShowInfo("总进度 " + (allCountProcess) + "/" + allCount + " " + info); PerformStep(); } }
private void button_decompress_Click(object sender, EventArgs e) { string compressedFilePath = this.textBox_sourseZip.Text; string destDir = this.textBox_destDir.Text; string pass = GetPassword(); CompressUtil.Decompres(compressedFilePath, destDir, pass); FormUtil.ShowIfOpenDirMessageBox(destDir); }
protected override void OnStart(string[] args) { #if DEBUG Thread.Sleep(30000); #endif string backupFolder = ConfigurationManager.AppSettings["BackupFolder"]; CompressUtil dir = new CompressUtil(backupFolder); var mainThread = new Thread(new ThreadStart(() => Main(dir))); mainThread.Start(); }
/// <summary> /// get intensity values only for aird file /// </summary> /// <param name="value"> 压缩的数组 </param> /// <returns> 解压缩后的数组 </returns> public float[] getLogedIntValues(byte[] value) { var intValues = CompressUtil.zlibDecoderToFloat(value); float[] intensityValues = new float[intValues.Length]; for (int index = 0; index < intValues.Length; index++) { intensityValues[index] = (float)Math.Pow(10, intValues[index]); } return(intensityValues); }
/// <summary> /// get intensity values only for aird file /// </summary> /// <param name="value"> 压缩的数组 </param> /// <param name="start"> 起始位置 </param> /// <param name="length"> 读取长度 </param> /// <returns> 解压缩后的数组 </returns> public float[] getLogedIntValues(byte[] value, int start, int length) { var intValues = CompressUtil.zlibDecoderToFloat(value.Skip(start).Take(length).ToArray()); float[] intensityValues = new float[intValues.Length]; for (int index = 0; index < intValues.Length; index++) { intensityValues[index] = (float)Math.Pow(10, intValues[index]); } return(intensityValues); }
/// <summary> /// get mz values only for aird file /// 默认从Aird文件中读取,编码Order为LITTLE_ENDIAN,精度为小数点后三位 /// </summary> /// <param name="value"> 压缩后的数组 </param> /// <param name="start"> 起始位置 </param> /// <param name="length"> 读取长度 </param> /// <returns> 解压缩后的数组 </returns> public float[] getMzValues(byte[] value, int start, int length) { var Values = CompressUtil.zlibDecoderToInt(value.Skip(start).Take(length).ToArray()); var intValues = CompressUtil.fastPforDecoder(Values); float[] floatValues = new float[intValues.Length]; for (int index = 0; index < intValues.Length; index++) { floatValues[index] = (float)intValues[index] / mzPrecision; } return(floatValues); }
public void CopyItem_Test() { var path = "E:\\1.0.1"; for (int i = 0; i < 2; i++) { var temp = path + "\\" + i; CompressUtil.DecompressFile(@"E:\\1.0.1.zip", temp); var script = $"Copy-Item -Path \"{temp + "\\1.0.1"}\" -Destination \"{temp + "\\copy"}\" -Recurse -Force"; PowerShellUtil.RunScript(script); } }
/// <summary> /// get mz values only for aird file /// 默认从Aird文件中读取,编码Order为LITTLE_ENDIAN,精度为小数点后三位 /// </summary> /// <param name="value"> 压缩后的数组 </param> /// <returns> 解压缩后的数组 </returns> public float[] getMzValues(byte[] value) { var Values = CompressUtil.zlibDecoderToInt(value); var intValues = CompressUtil.fastPforDecoder(Values); float[] floatValues = new float[intValues.Length]; for (int index = 0; index < intValues.Length; index++) { floatValues[index] = (float)intValues[index] / mzPrecision; } return(floatValues); }
public static void DecompressFile(string inputfilename, string outputFilename) { Console.WriteLine("Decompressing file {0} to {1}", inputfilename, outputFilename); HuffmanTree <char> huffmanTree; var encodedStream = new List <byte>(); using (var fs = new FileStream(inputfilename, FileMode.Open, FileAccess.Read)) { var keyLengthArray = new byte[4]; var valueLengthArray = new byte[4]; fs.Read(keyLengthArray, 0, 4); fs.Read(valueLengthArray, 0, 4); var keyLength = BitConverter.ToInt32(keyLengthArray, 0); var valueLength = BitConverter.ToInt32(valueLengthArray, 0); var keyArray = new byte[keyLength]; var valueArray = new byte[valueLength]; fs.Read(keyArray, 0, keyLength); fs.Read(valueArray, 0, valueLength); var compressedLengthArray = new byte[4]; fs.Read(compressedLengthArray, 0, 4); var compressedLength = BitConverter.ToInt32(compressedLengthArray, 0); var dict = CharacterFrequencyDictionary.CreateDictionary(keyArray, valueArray); huffmanTree = new HuffmanTree <char>(dict); int record; while ((record = fs.ReadByte()) != -1) { encodedStream.AddRange(CompressUtil.ConvertToBitArray((byte)record)); } if (encodedStream.Count() > compressedLength) { encodedStream.RemoveRange(compressedLength, encodedStream.Count() - compressedLength); } } using (var fsw = new FileStream(outputFilename, FileMode.Create, FileAccess.Write)) using (var sr = new StreamWriter(fsw)) sr.Write(huffmanTree.Decode(encodedStream)); Console.WriteLine("Compression complete."); }
public T Deserialize <T>(byte[] bytes) { if (ShouldCrypt) { bytes = CryptUtil.Decrypt(bytes, password, salt, iterations); } if (compress) { bytes = CompressUtil.Decompress(bytes); } var json = System.Text.Encoding.UTF8.GetString(bytes); return(JsonUtility.FromJson <T>(json)); }
public byte[] Serialize <T>(T obj) { var json = JsonUtility.ToJson(obj, prettyPrint: !compress && !ShouldCrypt); var bytes = System.Text.Encoding.UTF8.GetBytes(json); if (compress) { bytes = CompressUtil.Compress(bytes); } if (ShouldCrypt) { bytes = CryptUtil.Encrypt(bytes, password, salt, iterations); } return(bytes); }
private static void CompressFile(string inputFile, string outputFilename) { Console.WriteLine("Compressing file {0} to {1}", inputFile, outputFilename); var input = String.Join(Environment.NewLine, File.ReadAllText(inputFile, Encoding)); var dict = CharacterFrequencyDictionary.CreateDictionary(input); var fileHeader = CharacterFrequencyDictionary.GetHeaderByteArray(dict); var compressed = new HuffmanTree <char>(dict).Encode(input); var fileByteArray = CompressUtil.GetFileByteArray(fileHeader, compressed); using (var fs = new FileStream(outputFilename, FileMode.Create, FileAccess.Write)) fs.Write(fileByteArray, 0, fileByteArray.Length); Console.WriteLine("Compression complete."); }
private static void Main(CompressUtil dir) { BackupClass backup = dir.GetLatestBackup(); if ((DateTime.Now - backup.CreatedOn).TotalDays > 7) { backup = dir.CreateBackup(); } List <string> dirsToBackup = new List <string>(ConfigurationManager.AppSettings["DirectoriesToBackup"].Split(';')); foreach (var dirPath in dirsToBackup) { DirToBackup dirToBackup = new DirToBackup(dirPath, DirectoryUtil.GetFolderName(dirPath), backup); dirToBackup.StartBackup(); dirToBackup.DoneBackup(); } }
/// <summary> /// 取得单表数据(压缩) /// </summary> /// <param name="tableName"></param> /// <returns></returns> public byte[] GetDataByCsvStream(string tableName, LogedInUser CurrentUser) { //DateTime dt = DateTime.Now; IDataReader dataReader; StringBuilder csvStr = new StringBuilder(); byte[] data; try { dataReader = GetSyncTableReader(tableName, CurrentUser); data = (byte[])CompressUtil.CompressData(CSVUtils.ToCSV(dataReader, true)); } catch (Exception e) { throw e; } return(data); }
public void TestCompress() { var checkValue = generateData(checkCount); var compressSize = CompressUtil.CompressSize(checkValue); var compressbuffer = BufferManager.Take(compressSize); var ret = CompressUtil.Compress(checkValue, compressbuffer, checkCount); var decompressSize = CompressUtil.DecompressSize(compressbuffer); Assert.AreEqual(decompressSize, checkCount); byte[] decompressBuffer = new byte[decompressSize]; ret = CompressUtil.Decompress(compressbuffer, decompressBuffer); Assert.AreEqual(ret, checkCount); checkData(checkValue, decompressBuffer); }
public void DecompressFileLZMA(string inFile, string outFile, Action <UInt64, UInt64> progress = null, Action <bool> finish = null) { if (outFile == null) { outFile = CompressUtil.GetDefaultFileName(inFile); } decompressFileLZMAFinish = false; deCoder = null; deInFile = inFile; deOutFile = outFile; Thread decompressThread = new Thread(new ThreadStart(DoDecompressFileLZMA)); decompressThread.Start(); if (progress != null || finish != null) { this.StartCoroutine(IE_WaitDecompressFileLZMA(progress, finish)); } }
/// <summary> /// 压缩文件 /// </summary> public void CompressFile(string in_file, string out_file = null, Action <Int64, Int64> progress = null, Action <bool> finish = null) { if (out_file == null) { out_file = CompressUtil.GetCompressFileName(in_file); } compressFileLZMAFinish = false; coder = null; inFile = in_file; outFile = out_file; Thread decompressThread = new Thread(new ThreadStart(DoCompressFileLZMA)); decompressThread.Start(); if (progress != null || finish != null) { this.StartCoroutine(IE_WaitCompressFileLZMA(progress, finish)); } }
/// <summary> /// 取得单表数据,生产csv文件 /// </summary> /// <param name="tableName"></param> /// <returns></returns> public byte[] DataToFile(string tableName, LogedInUser CurrentUser) { //DateTime dt = DateTime.Now; IDataReader dataReader; StringBuilder csvStr = new StringBuilder(); byte[] data; try { dataReader = GetSyncTableReader(tableName, CurrentUser); string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, tableName + CurrentUser.UserOrg.Reg_org_id + ".csv"); ////写表头 //File.WriteAllText(file, CSVUtils.CreateCSVHeader(dataReader, csvStr), Encoding.GetEncoding(936)); ////写数据 //while (dataReader.Read()) //{ // //using (StreamWriter sw = File.AppendText(file)) // //{ // // sw.Write(CSVUtils.CreateCSVContextLine(dataReader, csvStr)); // //} // File.AppendAllText(file, CSVUtils.CreateCSVContextLine(dataReader, csvStr), Encoding.GetEncoding(936)); //} File.WriteAllText(file, CSVUtils.ToCSV(dataReader, true), Encoding.GetEncoding(936)); //TimeSpan t = DateTime.Now.Subtract(dt); //MessageBox.Show(t.TotalSeconds.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Information); CompressUtil.CompressFile(file); data = File.ReadAllBytes(file + ".cps"); File.Delete(file); File.Delete(file + ".cps"); } catch (Exception e) { throw e; } return(data); }
void eh_Completed(object sender, ExportEventArgs e) { this.Text = "匯出壓縮檔"; string content = e.Result; if (checkBox1.Checked) { CompressUtil.CompressStringToFile(txtFileName.Text, e.Result, txtPassword.Text); } else { CompressUtil.CompressStringToFile(txtFileName.Text, e.Result); } if (Completed != null) { Completed.Invoke(this, EventArgs.Empty); } this.Close(); }
public void compress(Spectrum spectrum, TempScan ts) { BinaryDataDouble mzData = spectrum.getMZArray().data; BinaryDataDouble intData = spectrum.getIntensityArray().data; var dataCount = mzData.Count; int[] mzArray = new int[dataCount]; float[] intensityArray = new float[dataCount]; int j = 0; for (int t = 0; t < dataCount; t++) { if (jobInfo.jobParams.ignoreZeroIntensity && intData[t] == 0) { continue; } int mz = Convert.ToInt32(mzData[t] * mzPrecision); mzArray[j] = mz; if (jobInfo.jobParams.log2) { intensityArray[j] = Convert.ToSingle(Math.Round(Math.Log(intData[t]) / log2, 3)); //取log10并且精确到小数点后3位 } else { intensityArray[j] = Convert.ToSingle(Math.Round(intData[t], 1)); //精确到小数点后一位 } j++; } int[] mzSubArray = new int[j]; Array.Copy(mzArray, mzSubArray, j); float[] intensitySubArray = new float[j]; Array.Copy(intensityArray, intensitySubArray, j); int[] compressedMzArray = CompressUtil.fastPforEncoder(mzSubArray); ts.mzArrayBytes = CompressUtil.zlibEncoder(compressedMzArray); ts.intArrayBytes = CompressUtil.zlibEncoder(intensitySubArray); }
public BaseParser(string indexPath) { airdInfo = AirdScanUtil.loadAirdInfo(indexPath); if (airdInfo == null) { throw new Exception(ResultCodeEnum.AIRD_INDEX_FILE_PARSE_ERROR.Message); } try { airdFile = File.OpenRead(FileNameUtil.getAirdPathByIndexPath(indexPath)); } catch (FileNotFoundException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); throw new Exception(ResultCodeEnum.AIRD_FILE_PARSE_ERROR.Message); } mzCompressor = CompressUtil.getMzCompressor(airdInfo.compressors); intCompressor = CompressUtil.getIntCompressor(airdInfo.compressors); mzPrecision = mzCompressor.precision; type = airdInfo.type; }