Пример #1
0
        public void WriteRead(int cnt)
        {
            ////var ms = new FileStream("c:\\azos\\archive.lar", FileMode.Create);//  new MemoryStream();
            var ms = new MemoryStream();

            var meta = VolumeMetadataBuilder.Make("Log archive", LogMessageArchiveAppender.CONTENT_TYPE_LOG)
                       .SetVersion(1, 0)
                       .SetDescription("Testing log messages")
                       .SetChannel(Atom.Encode("dvop"));

            var volume = new DefaultVolume(CryptoMan, meta, ms);

            using (var appender = new LogMessageArchiveAppender(volume,
                                                                NOPApplication.Instance.TimeSource,
                                                                NOPApplication.Instance.AppId, "dima@zhaba"))
            {
                for (var i = 0; i < cnt; i++)
                {
                    var msg = new Message()
                    {
                        Text = "Message#" + i.ToString()
                    }.InitDefaultFields();

                    appender.Append(msg);
                }
            }


            var reader = new LogMessageArchiveReader(volume);

            Aver.AreEqual(cnt, reader.All.Count());
            Aver.AreEqual(cnt, reader.GetEntriesStartingAt(new Bookmark()).Count());
            Aver.AreEqual(cnt, reader.GetBookmarkedEntriesStartingAt(new Bookmark()).Count());
            Aver.AreEqual(cnt, reader.GetEntriesAsObjectsStartingAt(new Bookmark()).Count());
            Aver.AreEqual(cnt, reader.GetBookmarkedEntriesAsObjectsStartingAt(new Bookmark()).Count());

            reader.All.ForEach((m, i) => Aver.AreEqual("Message#" + i.ToString(), m.Text));

            reader.GetBookmarkedEntriesStartingAt(new Bookmark()).ForEach((t, i) =>
            {
                var pointed = reader.GetEntriesStartingAt(t.bm).First();
                Aver.AreEqual("Message#" + i.ToString(), pointed.Text);
                Aver.AreEqual(t.entry.Text, pointed.Text);
            });

            volume.Dispose();
        }