Exemplo n.º 1
0
        protected override Frame ParseFrame(byte[] data)
        {
            int place=0;

            SingleByteField encodingField=new SingleByteField();
            place+=encodingField.Parse(data, place);

            TextField imageFormatField=TextField.CreateTextField(true,EncodingScheme.Ascii);
            place+=imageFormatField.Parse(data, place);

            SingleByteField pictureTypeField=new SingleByteField();
            place+=pictureTypeField.Parse(data, place);

            TextField descriptionField=TextField.CreateTextField(true,(EncodingScheme)encodingField.Value);
            place+=descriptionField.Parse(data, place);

            BinaryField dataField=new BinaryField();
            place+=dataField.Parse(data, place);

            System.IO.MemoryStream memoryImageBuffer=new System.IO.MemoryStream(dataField.Data);
            try
            {
                System.Drawing.Image image=System.Drawing.Image.FromStream(memoryImageBuffer);
                return new PictureFrame(dataField.Data, image, descriptionField.Text, (PictureType)pictureTypeField.Value);
            }
            catch(ArgumentException)
            {
                throw new FrameParsingException("Unrecognized picture format found in Picture frame.");
            }
        }
        protected override Frame ParseFrame(byte[] data)
        {
            //Text encoding          $xx
            //MIME type              <text string> $00
            //Filename               <text string according to encoding> $00 (00)
            //Content description    <text string according to encóding> $00 (00)
            //Encapsulated object    <binary data>

            int place=0;

            SingleByteField encodingField=new SingleByteField();
            place+=encodingField.Parse(data, place);

            TextField mimeTypeField=TextField.CreateTextField(true,EncodingScheme.Ascii);
            place+=mimeTypeField.Parse(data, place);

            TextField fileNameField=TextField.CreateTextField(true,(EncodingScheme)encodingField.Value);
            place+=fileNameField.Parse(data, place);

            TextField contentDescriptionField=TextField.CreateTextField(true, (EncodingScheme)encodingField.Value);
            place+=contentDescriptionField.Parse(data, place);

            BinaryField dataField=new BinaryField();
            place+=dataField.Parse(data, place);

            return new GeneralEncapsulatedObjectFrame(
                fileNameField.Text,
                contentDescriptionField.Text,
                mimeTypeField.Text,
                dataField.Data);
        }
Exemplo n.º 3
0
 public void TestRead()
 {
     for(int testCase=0;testCase<100;testCase++)
     {
         byte[] randomData=new byte[_randomNumberGenerator.Next(1, 50000)];
         int offset=_randomNumberGenerator.Next(0, randomData.Length-1);
         _randomNumberGenerator.NextBytes(randomData);
         SingleByteField field=new SingleByteField();
         field.Parse(randomData, offset);
         Assert.AreEqual(randomData[offset], field.Value);
     }
 }
Exemplo n.º 4
0
 public void TestWrite()
 {
     for(int testCase=0;testCase<100;testCase++)
     {
         byte[] randomData=new byte[1];
         _randomNumberGenerator.NextBytes(randomData);
         SingleByteField field=new SingleByteField(randomData[0]);
         MemoryStream stream=new MemoryStream();
         field.WriteToStream(stream);
         Assert.AreEqual(stream.Length, 1);
         Assert.AreEqual(randomData[0], stream.GetBuffer()[0]);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the text encoded in a text frame.
        /// </summary>
        /// <param name="data">Byte array to parse the text frame out of.</param>
        /// <returns>The string encoded in the text frame.</returns>
        protected static string ParseTextFrame(byte[] data)
        {
            //Text encoding                $xx
            //Information                  <text string according to encoding>
            int place=0;

            SingleByteField encodingField=new SingleByteField();
            place+=encodingField.Parse(data, place);

            TextField textField=TextField.CreateTextField(false, (EncodingScheme)encodingField.Value);
            place+=textField.Parse(data, place);

            return textField.Text;
        }
Exemplo n.º 6
0
        protected static string ParseExtendedTextFrame(byte[] data, out string description, out LanguageCode language)
        {
            int place=0;

            SingleByteField encodingField=new SingleByteField();
            place+=encodingField.Parse(data, place);

            FixedLengthAsciiTextField langField=new FixedLengthAsciiTextField(3);
            place+=langField.Parse(data, place);

            TextField descriptinoField=TextField.CreateTextField(true,(EncodingScheme)encodingField.Value);
            place+=descriptinoField.Parse(data, place);

            TextField textField=TextField.CreateTextField(false,(EncodingScheme)encodingField.Value);
            place+=textField.Parse(data, place);

            if(!Enum.IsDefined(typeof(LanguageCode), langField.Text))
            {
                langField.Text="Unknown";
            }
            language=(LanguageCode)Enum.Parse(typeof(LanguageCode), langField.Text);
            description=descriptinoField.Text;
            return textField.Text;
        }
Exemplo n.º 7
0
        protected override Frame ParseFrame(byte[] data)
        {
            int place=0;

            SingleByteField encodingField=new SingleByteField();
            place+=encodingField.Parse(data, place);

            TextField lastPlayedOnField=TextField.CreateTextField(true, EncodingScheme.Ascii);
            place+=lastPlayedOnField.Parse(data, place);

            TextField playCountField=TextField.CreateTextField(true, EncodingScheme.Ascii);
            place+=playCountField.Parse(data, place);

            TextField memoField=TextField.CreateTextField(true, EncodingScheme.Ascii);
            place+=memoField.Parse(data, place);

            DateTime lastPlayed;
            if(!DateTime.TryParse(lastPlayedOnField.Text, out lastPlayed))
            {
                throw new FrameParsingException("Invalid value in date field of LastPlayedOn frame.");
            }
            int playCount;
            if(!int.TryParse(playCountField.Text, out playCount))
            {
                throw new FrameParsingException("Invalid value in play count field of LastPlayedOn frame.");
            }

            return new LastPlayedOnFrame(lastPlayed, playCount, memoField.Text);
        }