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);
        }
Esempio n. 2
0
        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))));
        }
Esempio n. 3
0
        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);
        }