Inheritance: IValueWriter
Esempio n. 1
0
        public void SerializeDeserialize()
        {
            const string logo = "logo";
            const string name = "name";
            const string desc = "description";

            ServerInfo info = new ServerInfo (new ServerSettings
            {
                ServerLogo = logo,
                Name = name,
                Description = desc,
                ServerPassword = "******"
            }, new GuestUserProvider());

            var stream = new MemoryStream (new byte[20480], true);
            var writer = new StreamValueWriter (stream);
            var reader = new StreamValueReader (stream);

            info.Serialize (null, writer);
            long length = stream.Position;
            stream.Position = 0;

            info = new ServerInfo (null, reader);
            Assert.AreEqual (length, stream.Position);
            Assert.AreEqual (logo, info.Logo);
            Assert.AreEqual (name, info.Name);
            Assert.AreEqual (desc, info.Description);
            Assert.AreEqual (true, info.Passworded);
            Assert.AreEqual (UserRegistrationMode.None, info.RegistrationMode);
            Assert.IsNull (info.RegistrationContent);
        }
Esempio n. 2
0
        public static Task<IAsymmetricKey> LoadKey(string path)
        {
            if (path == null)
                throw new ArgumentNullException ("path");

            return Task<IAsymmetricKey>.Factory.StartNew (() =>
            {
                if (!File.Exists (path) || new FileInfo (path).Length == 0)
                {
                    var crypto = new RSACrypto();
                    var key = crypto.ExportKey (includePrivate: true);

                    Directory.CreateDirectory (Path.GetDirectoryName (path));
                    using (var fstream = File.OpenWrite (path))
                    {
                        var writer = new StreamValueWriter (fstream);
                        key.Serialize (null, writer);
                    }

                    return key;
                }

                var reader = new BufferValueReader (File.ReadAllBytes (path));
                return new RSAAsymmetricKey (null, reader);
            });
        }
Esempio n. 3
0
        public void SerializeDeserialize()
        {
            var stream = new MemoryStream (new byte[20480], true);
            var writer = new StreamValueWriter (stream);
            var reader = new StreamValueReader (stream);

            var source = GetTestSource();
            source.Serialize (null, writer);
            long length = stream.Position;
            stream.Position = 0;

            source = new AudioSource (null, reader);
            AssertSourcesMatch (GetTestSource(), source);
            Assert.AreEqual (length, stream.Position);
        }
Esempio n. 4
0
        public void SerializeDeserialize()
        {
            var stream = new MemoryStream(new byte[20480], true);
            var writer = new StreamValueWriter (stream);
            var reader = new StreamValueReader (stream);

            var info = new UserInfo (Nickname, Phonetic, Username, UserId, ChanId, Muted, Comment, Status);

            info.Serialize (null, writer);
            long length = stream.Position;
            stream.Position = 0;

            info = new UserInfo (null, reader);
            Assert.AreEqual (length, stream.Position);
            Assert.AreEqual (UserId, info.UserId);
            Assert.AreEqual (ChanId, info.CurrentChannelId);
            Assert.AreEqual (Nickname, info.Nickname);
            Assert.AreEqual (Phonetic, info.Phonetic);
            Assert.AreEqual (Muted, info.IsMuted);
            Assert.AreEqual (Comment, info.Comment);
            Assert.AreEqual (Status, info.Status);
        }
Esempio n. 5
0
        public void SerializeDeserialize()
        {
            var stream = new MemoryStream (new byte[20480], true);
            var writer = new StreamValueWriter (stream);
            var reader = new StreamValueReader (stream);

            var channel = new ChannelInfo (1)
            {
                ParentChannelId = 2,
                Name = "Name",
                Description = "Description",
                ReadOnly = false,
                UserLimit = 2
            };

            channel.Serialize (null, writer);
            long length = stream.Position;
            stream.Position = 0;

            var deserializedChannel = new ChannelInfo();
            deserializedChannel.Deserialize (null, reader);

            Assert.AreEqual (length, stream.Position);
            AssertChanelsAreEqual (channel, deserializedChannel);
        }
Esempio n. 6
0
        public void SerializeDeserialize()
        {
            var stream = new MemoryStream(new byte[20480], true);
            var writer = new StreamValueWriter (stream);
            var reader = new StreamValueReader (stream);

            var args = new AudioCodecArgs (Format, Bitrate, FrameSize, Complexity);

            args.Serialize (null, writer);
            long length = stream.Position;
            stream.Position = 0;

            args = new AudioCodecArgs (null, reader);
            Assert.AreEqual (length, stream.Position);
            Assert.AreEqual (Format.WaveEncoding, args.WaveEncoding);
            Assert.AreEqual (Format.Channels, args.Channels);
            Assert.AreEqual (Format.BitsPerSample, args.BitsPerSample);
            Assert.AreEqual (Bitrate, args.Bitrate);
            Assert.AreEqual (Format.SampleRate, args.SampleRate);
            Assert.AreEqual (FrameSize, args.FrameSize);
            Assert.AreEqual (Complexity, args.Complexity);
        }