public static void smethod_11(string string0, List <string> list0, List <string> list1, string string1) { Stream stream = File.OpenRead(string0); var stream2 = new ZipCompressor(stream); if (string1 != null) { stream2.method_3(string1); } var array = new byte[2048]; Class193 @class; while ((@class = stream2.method_5()) != null) { if (list1.Contains(@class.method_20())) { var index = list1.IndexOf(@class.method_20()); using (Stream stream3 = File.Create(list0[index])) { if (stream3.CanWrite) { int num; do { num = stream2.Read(array, 0, array.Length); stream3.Write(array, 0, num); } while (num > 0); } } } } stream2.Close(); stream.Close(); }
public bool LoadSourceDataFromFile( SourceDataFileDescriptor sdFileDescriptor, bool needVerify, out SourceData sd) { needVerify = !QuietMode && needVerify; try { using (var stream = new FileStream(sdFileDescriptor.FilePath, FileMode.Open, FileAccess.Read)) { var uncompressedStream = ZipCompressor.Uncompress(stream); sd = DeserializeSourceData(uncompressedStream); uncompressedStream.Close(); if (sd.Id == Guid.Empty) { if (_votingResultManager.PackResultsEnabled) { throw new SourceDataVerifierException( "Исходные данные не содержат уникального идентификатора"); } sd.Id = GenerateSourceDataId(sd); } } sd.Init(sdFileDescriptor.Uik); var verifier = new SourceDataVerifier(sd, _config.DefaultVotingModeTimes); Logger.LogVerbose(Message.Election_SourceDataRepairing); verifier.Repair(); if (needVerify) { Logger.LogVerbose(Message.Election_SourceDataVerifying); verifier.Verify(); } } catch (SourceDataVerifierException ex) { sd = null; Logger.LogWarning(Message.Election_SourceDataIncorrect, sdFileDescriptor.FilePath, ex.Message); return(false); } catch (Exception ex) { sd = null; Logger.LogWarning(Message.Election_SourceDataLoadFromFileFailed, ex, sdFileDescriptor.FilePath); return(false); } if (needVerify) { try { Logger.LogVerbose(Message.Election_CheckCreateModel); _recognitionManager.CheckCreateModel(sd); } catch (Exception ex) { sd = null; Logger.LogWarning(Message.Election_SourceDataIncorrect, sdFileDescriptor.FilePath, ex.Message); return(false); } } Logger.LogVerbose(Message.Election_SourceDataSuccessfullyLoadedFromFile, sdFileDescriptor.FilePath); return(true); }
public void Compress(Byte[] b) { File.WriteAllBytes(INPUT_FILE, b); var zipOperation = new ZipCompressor(); var readerQueue = new SynchronizedQueue <Chunk>(4); var writerQueue = new SynchronizedQueue <Chunk>(4); zipOperation.Cancel += readerQueue.Close; zipOperation.Cancel += writerQueue.Close; var reader = new Thread(() => zipOperation.Reader(INPUT_FILE, ref readerQueue)); var proces = new Thread(() => zipOperation.Process(ref readerQueue, ref writerQueue)); var writer = new Thread(() => zipOperation.Writer(MID_OUTPUT_FILE, ref writerQueue)); reader.Start(); proces.Start(); writer.Start(); reader.Join(); proces.Join(); writer.Join(); zipOperation.Cancel -= readerQueue.Close; zipOperation.Cancel -= writerQueue.Close; }
public static void smethod_10(Stream zipFile, Stream memoryStream, string fileName, string password) { var zipManager = new ZipCompressor(zipFile); if (password != null) { zipManager.method_3(password); } var buffer = new byte[2048]; Class193 @class; while ((@class = zipManager.method_5()) != null) { if (@class.method_20() == fileName) { int num; do { num = zipManager.Read(buffer, 0, buffer.Length); memoryStream.Write(buffer, 0, num); } while (num > 0); zipManager.Close(); memoryStream.Close(); zipFile.Close(); return; } } }
public void TestSerializeDeserialize() { var doc = TestHelpers.CreateStarDocument(); byte[] packed = ZipCompressor.Compress(doc); // tricky casting through dynamic StarDocument unpacked = (StarDocument)(dynamic)ZipCompressor.Uncompress <Document>(packed); TestHelpers.AssertEqualStars(doc, unpacked); }
public static T Unpack <T>(byte[] packed, IGatewayBlobStore gatewayBlobStore) where T : IGatewayMessage { Guard.NotNull(packed, "packed"); Guard.NotNull(gatewayBlobStore, "gatewayBlobStore"); GatewayPacket packet = ZipCompressor.Uncompress <GatewayPacket>(packed); if (packet.MessageSerialized == null) { return(Unpack <T>(gatewayBlobStore.Read(packet.Packet), gatewayBlobStore)); } return(JsonCustomConvert.DeserializeObject <T>(packet.MessageSerialized)); }
public static byte[] Pack(IGatewayMessage message, IGatewayBlobStore gatewayBlobStore) { Guard.NotNull(message, "message"); Guard.NotNull(gatewayBlobStore, "gatewayBlobStore"); GatewayPacket packet = new GatewayPacket(message); byte[] packed = ZipCompressor.Compress(packet); if (packed.Length <= CloudQueueMessage.MaxMessageSize) { return(packed); } return(ZipCompressor.Compress(new GatewayPacket(gatewayBlobStore.Write(packed)))); }
public void Load() { if (!File.Exists(filename)) { throw new SceneFileNotFoundException(filename); } string content = ZipCompressor.Unzip(File.ReadAllBytes(filename)); using (StringReader stream = new StringReader(content)) { using (XmlReader reader = XmlReader.Create(stream)) { LoadTextures(reader); LoadAudio(reader); LoadEntities(reader); } } }
//void ModifyEndPoint(OlapWebService.OlapWebServiceSoapClient service) //{ // if (service != null) // { // if (!String.IsNullOrEmpty(URL)) // { // service.Endpoint.Address = new System.ServiceModel.EndpointAddress(new Uri(URL)); // } // else // { // service.Endpoint.Address = new System.ServiceModel.EndpointAddress(new Uri(Application.Current.Host.Source, "/OlapWebService.asmx")); // } // } //} #region IStorageManager Members void service_PerformStorageActionCompleted(object sender, Ranet.AgOlap.OlapWebService.PerformOlapServiceActionCompletedEventArgs e) { InvokeResultDescriptor result = null; if (e.Error == null) { result = InvokeResultDescriptor.Deserialize(e.Result); } if (result != null) { if (result.IsArchive) { result.Content = ZipCompressor.DecompressFromBase64String(result.Content); result.IsArchive = false; } Raise_InvokeCompleted(new DataLoaderEventArgs(result, e.Error, e.UserState)); } }
public void Save() { if (File.Exists(filename)) { File.Delete(filename); } string content = string.Empty; using (StringWriter stream = new StringWriter()) { using (XmlWriter writer = XmlWriter.Create(stream)) { SaveTextures(writer); SaveAudio(writer); SaveEntities(writer); } content = stream.ToString(); } File.WriteAllBytes(filename, ZipCompressor.Zip(content)); }
/// <summary> /// Method reads setting as set by the user and assigns them to proper private fields. /// </summary> private void ReadSettings() { string algorythmValue = algorythmDropDownList.Value; if (algorythmValue == _plainText) { _compressor = null; } else { CompressorType compressorType = (CompressorType)Enum.Parse(typeof(CompressorType), algorythmValue, true); _compressor = CompressorFactory.GetCompressor(compressorType); if (compressorType == CompressorType.Zip) { _zipCompressor = (ZipCompressor)_compressor; } } _compressionLevel = int.Parse(compressionLevelDropDownList.Items[compressionLevelDropDownList.SelectedIndex].Value); _conversionType = (ConversionType)Enum.Parse(typeof(ConversionType), dataTypeDropDownList.Value, true); _inputText = inputArea.Value; _password = passwordTextBox.Value; }
private String ExportToExcel(String schema) { InvokeResultDescriptor result = new InvokeResultDescriptor(); String res = String.Empty; try { String sessionId = String.Empty; String connection = String.Empty; try { MdxQueryArgs args = XmlSerializationUtility.XmlStr2Obj <MdxQueryArgs>(schema); if (args != null) { sessionId = args.SessionId; connection = args.Connection; DefaultQueryExecuter queryExecuter = new DefaultQueryExecuter(GetConnection(args.Connection)); if (args.Queries.Count > 0) { res = queryExecuter.GetCellSetDescription(args.Queries[0], ref sessionId); } } } catch (AdomdConnectionException connection_ex) { result.Content = connection_ex.Message; result.ContentType = InvokeContentType.Error; } catch (AdomdErrorResponseException response_ex) { result.Content = response_ex.Message; result.ContentType = InvokeContentType.Error; } catch (AdomdUnknownResponseException unknown_ex) { result.Content = unknown_ex.Message; result.ContentType = InvokeContentType.Error; } catch (InvalidOperationException invalid_ex) { result.Content = invalid_ex.Message; result.ContentType = InvokeContentType.Error; } if (!String.IsNullOrEmpty(res)) { CellSetData cs = CellSetData.Deserialize(res); PivotDataProvider pivotProvider = new PivotDataProvider(new CellSetDataProvider(cs)); res = ExportHelper.ExportToExcel(pivotProvider); } result.Content = res; if (UseCompress) { // Архивация строки String compesed = ZipCompressor.CompressAndConvertToBase64String(res); result.Content = compesed; result.IsArchive = true; } result.ContentType = InvokeContentType.MultidimData; result.Headers.Add(new Header(InvokeResultDescriptor.SESSION_ID, sessionId)); result.Headers.Add(new Header(InvokeResultDescriptor.CONNECTION_ID, connection)); } catch (Exception) { throw; } return(InvokeResultDescriptor.Serialize(result)); }
String ExecuteQuery(String schema) { InvokeResultDescriptor result = new InvokeResultDescriptor(); String res = String.Empty; try { String sessionId = String.Empty; MdxQueryArgs args = XmlSerializationUtility.XmlStr2Obj <MdxQueryArgs>(schema); if (args != null) { sessionId = args.SessionId; DefaultQueryExecuter queryExecuter = new DefaultQueryExecuter(GetConnection(args.Connection)); if (args.Queries.Count > 0) { result.ContentType = InvokeContentType.MultidimData; switch (args.Type) { case QueryTypes.Update: case QueryTypes.CommitTransaction: case QueryTypes.RollbackTransaction: List <String> results = new List <String>(); result.ContentType = InvokeContentType.UpdateResult; foreach (var query in args.Queries) { try { // Method return a value of one (1). queryExecuter.ExecuteNonQuery(query, ref sessionId); results.Add(String.Empty); } catch (AdomdConnectionException connection_ex) { results.Add(connection_ex.Message); } catch (AdomdErrorResponseException response_ex) { results.Add(response_ex.Message); } catch (AdomdUnknownResponseException unknown_ex) { results.Add(unknown_ex.Message); } catch (InvalidOperationException invalid_ex) { results.Add(invalid_ex.Message); } } res = XmlSerializationUtility.Obj2XmlStr(results, Common.Namespace); break; case QueryTypes.Select: try { res = queryExecuter.GetCellSetDescription(args.Queries[0], ref sessionId); } catch (AdomdConnectionException connection_ex) { res = connection_ex.Message; result.ContentType = InvokeContentType.Error; } catch (AdomdErrorResponseException response_ex) { res = response_ex.Message; result.ContentType = InvokeContentType.Error; } catch (AdomdUnknownResponseException unknown_ex) { res = unknown_ex.Message; result.ContentType = InvokeContentType.Error; } catch (InvalidOperationException invalid_ex) { res = invalid_ex.Message; result.ContentType = InvokeContentType.Error; } break; case QueryTypes.DrillThrough: try { var table = queryExecuter.ExecuteReader(args.Queries[0], ref sessionId); if (table != null) { res = XmlSerializationUtility.Obj2XmlStr(DataTableHelper.Create(table)); } } catch (AdomdConnectionException connection_ex) { res = connection_ex.Message; result.ContentType = InvokeContentType.Error; } catch (AdomdErrorResponseException response_ex) { res = response_ex.Message; result.ContentType = InvokeContentType.Error; } catch (AdomdUnknownResponseException unknown_ex) { res = unknown_ex.Message; result.ContentType = InvokeContentType.Error; } catch (InvalidOperationException invalid_ex) { res = invalid_ex.Message; result.ContentType = InvokeContentType.Error; } break; } } } result.Content = res; System.Diagnostics.Debug.WriteLine("CellSetData size: " + res.Length); if (UseCompress) { DateTime start = DateTime.Now; // Архивация строки String compesed = ZipCompressor.CompressAndConvertToBase64String(res); System.Diagnostics.Debug.WriteLine("CellSetData compression time: " + (DateTime.Now - start).ToString()); System.Diagnostics.Debug.WriteLine("CellSetData compressed size: " + compesed.Length); result.Content = compesed; result.IsArchive = true; } result.Headers.Add(new Header(InvokeResultDescriptor.SESSION_ID, sessionId)); result.Headers.Add(new Header(InvokeResultDescriptor.CONNECTION_ID, args.Connection)); } catch (Exception ex) { throw; } return(InvokeResultDescriptor.Serialize(result)); }
String GetMetaData(String schema) { InvokeResultDescriptor result = new InvokeResultDescriptor(); String res = null; try { MetadataQuery args = XmlSerializationUtility.XmlStr2Obj <MetadataQuery>(schema); if (args != null) { switch (args.QueryType) { case MetadataQueryType.GetCubes: res = GetCubes(args); break; case MetadataQueryType.GetMeasures: res = GetMeasures(args); break; case MetadataQueryType.GetKPIs: res = GetKPIs(args); break; case MetadataQueryType.GetLevels: res = GetLevels(args); break; case MetadataQueryType.GetDimensions: res = GetDimensions(args); break; case MetadataQueryType.GetHierarchies: res = GetHierarchies(args); break; case MetadataQueryType.GetDimension: res = GetDimension(args); break; case MetadataQueryType.GetHierarchy: res = GetHierarchy(args); break; case MetadataQueryType.GetMeasureGroups: res = GetMeasureGroups(args); break; case MetadataQueryType.GetLevelProperties: res = GetLevelProperties(args); break; case MetadataQueryType.GetCubeMetadata: case MetadataQueryType.GetCubeMetadata_AllMembers: res = GetCubeMetadata(args); break; } } result.Content = res; if (UseCompress) { // Архивация строки String compesed = ZipCompressor.CompressAndConvertToBase64String(res); result.Content = compesed; result.IsArchive = true; } result.ContentType = InvokeContentType.MultidimData; } catch (AdomdConnectionException connection_ex) { result.Content = connection_ex.Message; result.ContentType = InvokeContentType.Error; } catch (AdomdErrorResponseException response_ex) { result.Content = response_ex.Message; result.ContentType = InvokeContentType.Error; } catch (OlapMetadataResponseException metadata_ex) { result.Content = metadata_ex.Message; result.ContentType = InvokeContentType.Error; } catch (Exception) { throw; } return(InvokeResultDescriptor.Serialize(result)); }
public bool SaveVotingResultProtocol() { var filePath = _votingResultProtocolFilePath; try { if (string.IsNullOrEmpty(_votingResultProtocolFilePath) || string.IsNullOrEmpty(_votingResultProtocolData)) { throw new InvalidOperationException( "Путь к файлу для сохранения протокола и/или данные протокола не определены"); } if (PackResults) { filePath = Path.ChangeExtension(_votingResultProtocolFilePath, "bin"); var arr = ZipCompressor.Compress( _votingResultProtocolData, _votingResultProtocolFileName, ZipCompressor.DEFAULT_COMPRESS_LEVEL, _electionManager.SourceData.Id.ToString("N")); if (!_fileSystemManager.SafeSerialization( arr, new BinaryFormatter(), filePath, false, false)) { throw new Exception("Ошибка записи: " + filePath); } } else { if (!_fileSystemManager.WriteTextToFile( filePath, FileMode.Create, _votingResultProtocolData, false)) { throw new Exception("Ошибка записи: " + filePath); } SystemHelper.SyncFileSystem(); } } catch (Exception ex) { Logger.LogError(Message.VotingResult_SaveVotingResultToFlashFailed, ex); return(false); } if (_config.ResultsReserveCopyCount.Value > 0) { try { for (var i = 0; i < _config.ResultsReserveCopyCount.Value; ++i) { File.Copy(filePath, filePath + i, true); } } catch (Exception ex) { Logger.LogWarning(Message.VotingResult_SaveVotingResultReserveCopiesToFlashFailed, ex); } SystemHelper.SyncFileSystem(); } return(true); }