Ejemplo n.º 1
0
 public ListTransform(BObjectTransform objectTransform)
 {
     if (objectTransform == null)
     {
         throw new ArgumentNullException("objectTransform");
     }
     this.objectTransform = objectTransform;
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length == 1)
            {
                var inFileStream = new FileStream(args[0], FileMode.Open);

                //BEncoding
                var transform = new BObjectTransform();
                IBObject bObject = transform.DecodeNext(inFileStream);

                var textOutput = new TextOutput(4);
                textOutput.WriteObject(0, bObject);
            }
            else
            {
                Console.WriteLine("\nSyntax is:\nOSS.SampleApp.exe <torrent file path>");
            }
        }
Ejemplo n.º 3
0
        public void DecodeNext_EmptyStringFollowingEmptyString_Positive()
        {
            string str3 = "hello";      // third example string in test data list

            var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("l0:0:5:" + str3 + "e"), false);      // list with two empty string, followed by "hello"

            var bot = new BObjectTransform();
            IBObject decodedList = bot.DecodeNext(dataStream);

            Assert.IsNotNull(decodedList);
            Assert.IsInstanceOfType(decodedList, typeof(BList));

            var castList = (BList)decodedList;

            Assert.AreEqual<int>(3, castList.Value.Length);
            Assert.IsInstanceOfType(castList.Value[0], typeof(BByteString));
            Assert.IsInstanceOfType(castList.Value[1], typeof(BByteString));
            Assert.IsInstanceOfType(castList.Value[2], typeof(BByteString));

            Assert.AreEqual<string>(string.Empty, ((BByteString)castList.Value[0]).ConvertToText(Encoding.UTF8));
            Assert.AreEqual<string>(string.Empty, ((BByteString)castList.Value[1]).ConvertToText(Encoding.UTF8));
            Assert.AreEqual<string>(str3, ((BByteString)castList.Value[2]).ConvertToText(Encoding.UTF8));
        }
Ejemplo n.º 4
0
        public void DecodeNext_NineLetterString_Positive()
        {
            string testWord = "debugging";
            var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("9:" + testWord), false);

            var bot = new BObjectTransform();
            IBObject decodedString = bot.DecodeNext(dataStream);

            Assert.IsNotNull(decodedString);
            Assert.IsInstanceOfType(decodedString, typeof(BByteString));
            var castDecodedString = (BByteString)decodedString;
            Assert.AreEqual<string>(testWord, castDecodedString.ConvertToText(Encoding.UTF8));
        }
Ejemplo n.º 5
0
        public void DecodeNext_EmptyString_Positive()
        {
            var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("0:"), false);

            var bot = new BObjectTransform();
            IBObject decodedString = bot.DecodeNext(dataStream);

            Assert.IsNotNull(decodedString);
            Assert.IsInstanceOfType(decodedString, typeof(BByteString));
            var castDecodedString = (BByteString)decodedString;
            Assert.AreEqual<string>(string.Empty, castDecodedString.ConvertToText(Encoding.UTF8));
        }
Ejemplo n.º 6
0
 public void BObjectTransform_DefaultCtor_Positive()
 {
     var bObjectTransform = new BObjectTransform();      // just make sure no exceptions are thrown
     Assert.IsNotNull(bObjectTransform);
 }
Ejemplo n.º 7
0
        public void EncodeObject_BDictionary_Positive()
        {
            string expectedOutput = "d3:one9:value_one3:twoi1ee";
            MemoryStream outputBuffer = new MemoryStream(64);

            // Create input test data
            BDictionary data = new BDictionary();
            data.Value.Add(new BByteString("one"), new BByteString("value_one"));
            data.Value.Add(new BByteString("two"), new BInteger(1));

            // Test
            var bot = new BObjectTransform();
            bot.EncodeObject(data, outputBuffer);

            // Get result and check it
            int length = (int) outputBuffer.Position;
            string actualOutput = Encoding.UTF8.GetString(outputBuffer.ToArray(), 0, length);

            Assert.AreEqual<string>(expectedOutput, actualOutput);
        }
Ejemplo n.º 8
0
        public void SaveTorrentFile()
        {
            if (!TorrentPrepared) { return; }

            BDictionary torrent = new BDictionary();
            torrent.Value.Add(new BByteString("announce"), torrentSaved.GetAnnounce());
            torrent.Value.Add(new BByteString("info"), torrentSaved.GetInfo());
            torrent.Value.Add(new BByteString("creation date"), new BInteger(TimeUnix()));

            using (FileStream outputFileStream = new FileStream(torrentSaved.FileName, FileMode.Create, FileAccess.Write))
            {
                BObjectTransform objTransform = new BObjectTransform();
                objTransform.EncodeObject(torrent, outputFileStream);
            }
            Console.WriteLine("\n{0} [{1}]\n", messages.GetMessage("TorrentCreated"), torrentSaved.FileName);
        }