internal static ISerializer GetSerializer(bool? compress, bool? security) { ISerializer result = new CloneSerializer(); if(compress.GetValueOrDefault(false)) result = new CompressSerializer(result); if(security.GetValueOrDefault(false)) result = new EncryptSerializer(result); return result; }
public void Serialize_By_SymmetricEncryptor() { var user = UserInfo.GetSample(); foreach(var encryptor in symmetricEncryptors) { var serializer = new EncryptSerializer<UserInfo>(new BinarySerializer<UserInfo>(), encryptor); var data = serializer.Serialize(user); var user2 = serializer.Deserialize(data); Assert.AreEqual(user.FirstName, user2.FirstName); Assert.AreEqual(user.FavoriteMovies.Count, user.FavoriteMovies.Count); } }
/// <summary> /// 원하는 <see cref="ISerializer"/>를 빌드합니다. /// </summary> /// <param name="compress">압축할 것인가?</param> /// <param name="security">보안을 적용할 것인가?</param> /// <returns></returns> public static ISerializer GetSerializer(bool compress, bool security) { if(IsDebugEnabled) log.Debug("Create Serializer. compress=[{0}], security=[{1}]", compress, security); // ISerializer serializer = new BinarySerializer(); ISerializer serializer = new CloneSerializer(); if(compress) serializer = new CompressSerializer(serializer); if(security) serializer = new EncryptSerializer(serializer); return serializer; }
public void XmlSerialize_With_Compress_Encryption([Values(typeof(SharpBZip2Compressor), typeof(GZipCompressor), typeof(DeflateCompressor), typeof(SevenZipCompressor))] Type compressorType, [Values(typeof(AriaSymmetricEncryptor), typeof(RC2SymmetricEncryptor), typeof(TripleDESSymmetricEncryptor))] Type encryptorType) { var xmlSerializer = XmlSerializer<List<User>>.Instance; var compressor = (ICompressor)ActivatorTool.CreateInstance(compressorType); var encryptor = (ISymmetricEncryptor)ActivatorTool.CreateInstance(encryptorType); var serializer = new EncryptSerializer<List<User>>(new CompressSerializer<List<User>>(xmlSerializer, compressor), encryptor); var users = GetSampleUsers(10); var usersData = serializer.Serialize(users); var deserializedUsers = serializer.Deserialize(usersData); CollectionAssert.AreEqual(users, deserializedUsers); }