Exemplo n.º 1
0
        private static List <CurdayChannel> Deserialize(JArray array)
        {
            List <CurdayChannel> result = new List <CurdayChannel>();

            foreach (var token in array)
            {
                CurdayChannel channel = new CurdayChannel();

                channel.ChannelNumber   = (string)token["number"];
                channel.SourceID        = (string)token["sourceID"];
                channel.CallLetters     = (string)token["callLetters"];
                channel.Flags1          = (ChannelFlags1)Enum.Parse(typeof(ChannelFlags1), (string)token["flags1"]);
                channel.TimeslotMask    = SixByteMask.Parse((string)token["timeslotMask"]);
                channel.BlackoutMask    = SixByteMask.Parse((string)token["blackoutMask"]);
                channel.Flags2          = (byte)token["flags2"];
                channel.BackgroundColor = Convert.ToUInt16(((string)token["backgroundColor"]).Substring(2, 4), 16);
                channel.BrushID         = Convert.ToUInt16(((string)token["brushID"]).Substring(2, 4), 16);
                channel.Flags3          = (ChannelsFlags3)Enum.Parse(typeof(ChannelsFlags3), (string)token["flags3"]);

                var programs = (JArray)token["programs"];
                channel.Programs = DeserializePrograms(programs);

                result.Add(channel);
            }

            return(result);
        }
Exemplo n.º 2
0
        private static object GetSerializableObjects(CurdayChannel channel)
        {
            List <object> programObjects = new List <object>(channel.Programs.Count);

            foreach (var program in channel.Programs)
            {
                programObjects.Add(GetSerializableObjects(program));
            }

            return(new
            {
                number = channel.ChannelNumber,
                sourceID = channel.SourceID,
                callLetters = channel.CallLetters,
                flags1 = channel.Flags1.ToString(),
                timeslotMask = channel.TimeslotMask.ToString(),
                blackoutMask = channel.BlackoutMask.ToString(),
                flags2 = channel.Flags2,
                backgroundColor = $"0x{channel.BackgroundColor:X4}",
                brushID = $"0x{channel.BrushID:X4}",
                flags3 = channel.Flags3.ToString(),
                programs = programObjects
            });
        }
Exemplo n.º 3
0
        private static CurdayChannel ReadChannel(BinaryReader reader, out bool lastChannel)
        {
            CurdayChannel result = new CurdayChannel();

            // Skip the channel separator (ASCII '[')
            reader.BaseStream.Position += 1;

            // Read the channel number (5 ASCII characters)
            result.ChannelNumber = new string(reader.ReadChars(5));

            // Skip six null bytes
            reader.BaseStream.Position += 6;

            // Read the source ID (6 ASCII characters, padded with NULs)
            result.SourceID = new string(reader.ReadChars(6)).Replace("\0", "");

            // Skip the null byte
            reader.BaseStream.Position += 1;

            // Read the call letters (6 ASCII characters, padded with NULs)
            result.CallLetters = new string(reader.ReadChars(6)).Replace("\0", "");

            // Skip two null bytes
            reader.BaseStream.Position += 2;

            // Read flags 1 (1 byte)
            result.Flags1 = (ChannelFlags1)reader.ReadByte();

            // Read timeslot mask (6 bytes)
            result.TimeslotMask = new SixByteMask(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());

            // Read blackout mask (6 bytes)
            result.BlackoutMask = new SixByteMask(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());

            // Read flags 2 (1 byte)
            result.Flags2 = reader.ReadByte();

            // Read background color (2 bytes)
            result.BackgroundColor = reader.ReadUInt16();

            // Read brush ID (2 bytes)
            result.BrushID = reader.ReadUInt16();

            // Skip two null bytes
            reader.BaseStream.Position += 2;

            // Read flags 3 (1 byte)
            result.Flags3 = (ChannelsFlags3)reader.ReadByte();

            // Skip the duplicate source ID.
            string duplicateSourceID = new string(reader.ReadChars(6)).Replace("\0", "");

            // Read programs
            result.Programs = new List <CurdayProgram>();
            bool lastProgram = false;

            while (!lastProgram)
            {
                result.Programs.Add(ReadProgram(reader, out lastProgram));
            }

            lastChannel = (reader.PeekChar() == -1);

            return(result);
        }
Exemplo n.º 4
0
        private static void WriteChannel(CurdayChannel channel, BinaryWriter file)
        {
            // Write the channel separator (ASCII '[')
            file.Write('[');

            // Write the channel number (5 ASCII characters)
            for (int i = 0; i < 5; i++)
            {
                file.Write(channel.ChannelNumber[i]);
            }

            // Write six null bytes
            for (int i = 0; i < 6; i++)
            {
                file.Write((byte)0x00);
            }

            // Write the source ID (6 ASCII characters, padded with NULs)
            for (int i = 0; i < 6; i++)
            {
                if (i < channel.SourceID.Length)
                {
                    file.Write(channel.SourceID[i]);
                }
                else
                {
                    file.Write((byte)0x00);
                }
            }

            // Write a null byte
            file.Write((byte)0x00);

            // Write the call letters (6 ASCII characters, padded with NULs)
            for (int i = 0; i < 6; i++)
            {
                if (i < channel.CallLetters.Length)
                {
                    file.Write(channel.CallLetters[i]);
                }
                else
                {
                    file.Write((byte)0x00);
                }
            }

            // Write two null bytes
            file.Write((byte)0x00);
            file.Write((byte)0x00);

            // Write flags 1 (1 byte)
            file.Write((byte)channel.Flags1);

            // Write timeslot mask (6 bytes)
            for (int i = 0; i < 6; i++)
            {
                file.Write(channel.TimeslotMask[i]);
            }

            // Write blackout mask (6 bytes)
            for (int i = 0; i < 6; i++)
            {
                file.Write(channel.BlackoutMask[i]);
            }

            // Write flags 2 (1 byte)
            file.Write(channel.Flags2);

            // Write background color (2 bytes)
            // === ENDIAN MIGHT BE WRONG ===
            file.Write(channel.BackgroundColor);

            // Write brush color (2 bytes)
            // === ENDIAN MIGHT BE WRONG ===
            file.Write(channel.BrushID);

            // Write two null bytes
            file.Write((byte)0x00);
            file.Write((byte)0x00);

            // Write flags 3 (1 byte)
            file.Write((byte)channel.Flags3);

            // Write the source ID again
            for (int i = 0; i < 6; i++)
            {
                if (i < channel.SourceID.Length)
                {
                    file.Write(channel.SourceID[i]);
                }
                else
                {
                    file.Write((byte)0x00);
                }
            }

            // Write programs
        }