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 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)); }