Esempio n. 1
0
        static private XElement _WriteDataNodes(SequenceBase sequence, Dictionary <Guid, int> effectTableIndex, Dictionary <Guid, int> channelIdTableIndex)
        {
            // Going to serialize data by channel.  Each channel will be represented.
            // Intervals will be referenced by the time of each command serialized
            // within a given channel.
            // Store all in a binary stream converted to base-64.
            string data = null;

            using (MemoryStream stream = new System.IO.MemoryStream()) {
                using (BinaryWriter dataWriter = new BinaryWriter(stream)) {
                    foreach (CommandNode commandNode in sequence.Data.GetCommands())
                    {
                        // Index of the command spec id from the command table (word).
                        dataWriter.Write((ushort)effectTableIndex[commandNode.Command.Effect.TypeId]);
                        // Referenced channel count (word).
                        dataWriter.Write((ushort)commandNode.TargetChannels.Length);
                        // Parameter count (byte)
                        dataWriter.Write((byte)commandNode.Command.ParameterValues.Length);

                        // Start time (dword).
                        dataWriter.Write(commandNode.StartTime);

                        // Time span (dword).
                        dataWriter.Write(commandNode.TimeSpan);

                        // Referenced channels (index into channel table, word).
                        foreach (Channel channel in commandNode.TargetChannels)
                        {
                            dataWriter.Write((ushort)channelIdTableIndex[channel.Id]);
                        }

                        dataWriter.Flush();

                        // Parameters (various)
                        foreach (object paramValue in commandNode.Command.ParameterValues)
                        {
                            ParameterValue.WriteToStream(stream, paramValue);
                        }
                    }
                    data = Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length);
                }
            }

            return(new XElement("Data", data));
        }