示例#1
0
        // Reads a collection element from the PQDIF file.
        private CollectionElement ReadCollection(BinaryReader recordBodyReader)
        {
            int size = recordBodyReader.ReadInt32();
            CollectionElement collection = new CollectionElement();

            for (int i = 0; i < size; i++)
            {
                collection.AddElement(ReadElement(recordBodyReader));
            }

            return(collection);
        }
示例#2
0
        private int GetByteSize(CollectionElement collection)
        {
            int sum;

            if ((object)collection == null)
            {
                return(0);
            }

            sum = collection.Elements
                  .Where(element => !IsEmbedded(element))
                  .Sum(GetPaddedByteSize);

            return(4 + (28 * collection.Size) + sum);
        }
示例#3
0
        // Reads a collection element from the PQDIF file.
        private CollectionElement ReadCollection(BinaryReader recordBodyReader)
        {
            int size = recordBodyReader.ReadInt32();
            CollectionElement collection = new CollectionElement();

            collection.ReadSize = size;

            for (int i = 0; i < size; i++)
            {
                collection.AddElement(ReadElement(recordBodyReader));

                if (recordBodyReader.BaseStream.Position >= recordBodyReader.BaseStream.Length || MaximumExceptionsReached)
                {
                    break;
                }
            }

            return(collection);
        }
示例#4
0
文件: RecordBody.cs 项目: sotaria/gsf
 /// <summary>
 /// Creates a new instance of the <see cref="RecordBody"/> class.
 /// </summary>
 /// <param name="rootTag">Tag of the collection root element of the record.</param>
 public RecordBody(Guid rootTag)
 {
     m_collection = new CollectionElement();
     m_collection.TagOfElement = rootTag;
 }
示例#5
0
        private int GetByteSize(CollectionElement collection)
        {
            int sum;

            if ((object)collection == null)
                return 0;

            sum = collection.Elements
                .Where(element => !IsEmbedded(element))
                .Sum(element => GetByteSize(element));

            return 4 + (28 * collection.Size) + sum;
        }
示例#6
0
        private void WriteCollection(BinaryWriter writer, CollectionElement collection)
        {
            int linkPosition = (int)writer.BaseStream.Position + 4 + (28 * collection.Size);

            writer.Write(collection.Size);

            foreach (Element element in collection.Elements)
            {
                bool isEmbedded = IsEmbedded(element);

                writer.Write(element.TagOfElement.ToByteArray());
                writer.Write((byte)element.TypeOfElement);
                writer.Write((byte)element.TypeOfValue);
                writer.Write(isEmbedded ? (byte)1 : (byte)0);
                writer.Write((byte)0);

                if (!isEmbedded)
                {
                    int size = GetByteSize(element);
                    writer.Write(linkPosition);
                    writer.Write(size);
                    linkPosition += size;
                }
                else
                {
                    WriteScalar(writer, element as ScalarElement);

                    for (int i = element.TypeOfValue.GetByteSize(); i < 8; i++)
                        writer.Write((byte)0);
                }
            }

            foreach (Element element in collection.Elements)
            {
                switch (element.TypeOfElement)
                {
                    case ElementType.Collection:
                        WriteCollection(writer, element as CollectionElement);
                        break;

                    case ElementType.Scalar:
                        if (!IsEmbedded(element))
                            WriteScalar(writer, element as ScalarElement);

                        break;

                    case ElementType.Vector:
                        WriteVector(writer, element as VectorElement);
                        break;
                }
            }
        }
示例#7
0
        // Reads a collection element from the PQDIF file.
        private CollectionElement ReadCollection(BinaryReader recordBodyReader)
        {
            int size = recordBodyReader.ReadInt32();
            CollectionElement collection = new CollectionElement();

            for (int i = 0; i < size; i++)
                collection.AddElement(ReadElement(recordBodyReader));

            return collection;
        }
示例#8
0
        /// <summary>
        /// Adds a new channel setting to the collection
        /// of channel settings in this monitor settings record.
        /// </summary>
        public ChannelSetting AddNewChannelSetting()
        {
            CollectionElement channelSettingsElement = m_physicalRecord.Body.Collection.GetCollectionByTag(ChannelSettingsArrayTag);
            CollectionElement channelSettingElement = new CollectionElement() { TagOfElement = OneChannelSettingTag };
            ChannelSetting channelSetting = new ChannelSetting(channelSettingElement, this);

            if ((object)channelSettingsElement == null)
            {
                channelSettingsElement = new CollectionElement()
                {
                    TagOfElement = OneChannelSettingTag
                };

                m_physicalRecord.Body.Collection.AddElement(channelSettingsElement);
            }

            channelSettingsElement.AddElement(channelSettingElement);

            return channelSetting;
        }
示例#9
0
        private void WriteCollection(BinaryWriter writer, CollectionElement collection)
        {
            int linkPosition = (int)writer.BaseStream.Position + 4 + (28 * collection.Size);

            writer.Write(collection.Size);

            foreach (Element element in collection.Elements)
            {
                bool isEmbedded = IsEmbedded(element);

                writer.Write(element.TagOfElement.ToByteArray());
                writer.Write((byte)element.TypeOfElement);
                writer.Write((byte)element.TypeOfValue);
                writer.Write(isEmbedded ? (byte)1 : (byte)0);
                writer.Write((byte)0);

                if (!isEmbedded)
                {
                    int padSize = GetPaddedByteSize(element);
                    writer.Write(linkPosition);
                    writer.Write(padSize);
                    linkPosition += padSize;
                }
                else
                {
                    WriteScalar(writer, element as ScalarElement);

                    for (int i = element.TypeOfValue.GetByteSize(); i < 8; i++)
                    {
                        writer.Write((byte)0);
                    }
                }
            }

            foreach (Element element in collection.Elements)
            {
                if (IsEmbedded(element))
                {
                    continue;
                }

                switch (element.TypeOfElement)
                {
                case ElementType.Collection:
                    WriteCollection(writer, element as CollectionElement);
                    break;

                case ElementType.Scalar:
                    WriteScalar(writer, element as ScalarElement);
                    break;

                case ElementType.Vector:
                    WriteVector(writer, element as VectorElement);
                    break;
                }

                int byteSize = GetByteSize(element);
                int padSize  = GetPaddedByteSize(element);

                for (int i = 0; i < padSize - byteSize; i++)
                {
                    writer.Write((byte)0);
                }
            }
        }
        /// <summary>
        /// Adds a new channel definition to the collection
        /// of channel definitions in this data source record.
        /// </summary>
        public ChannelDefinition AddNewChannelDefinition()
        {
            CollectionElement channelDefinitionsElement = m_physicalRecord.Body.Collection.GetCollectionByTag(ChannelDefinitionsTag);
            CollectionElement channelDefinitionElement = new CollectionElement() { TagOfElement = OneChannelDefinitionTag };
            ChannelDefinition channelDefinition = new ChannelDefinition(channelDefinitionElement, this);

            if ((object)channelDefinitionsElement == null)
            {
                channelDefinitionsElement = new CollectionElement()
                {
                    TagOfElement = ChannelDefinitionsTag
                };

                m_physicalRecord.Body.Collection.AddElement(channelDefinitionsElement);
            }

            channelDefinitionsElement.AddElement(channelDefinitionElement);

            return channelDefinition;
        }
示例#11
0
        // Reads a collection element from the PQDIF file.
        private CollectionElement ReadCollection(BinaryReader recordBodyReader)
        {
            int size = recordBodyReader.ReadInt32();
            CollectionElement collection = new CollectionElement();
            collection.ReadSize = size;
            
            for (int i = 0; i < size; i++)
            {
                collection.AddElement(ReadElement(recordBodyReader));

                if (recordBodyReader.BaseStream.Position >= recordBodyReader.BaseStream.Length || MaximumExceptionsReached)
                    break;
            }

            return collection;
        }
示例#12
0
 /// <summary>
 /// Creates a new instance of the <see cref="ChannelSetting"/> class.
 /// </summary>
 /// <param name="physicalStructure">The collection element which is the physical structure of the channel setting.</param>
 /// <param name="monitorSettingsRecord">The monitor settings record in which the channel setting resides.</param>
 public ChannelSetting(CollectionElement physicalStructure, MonitorSettingsRecord monitorSettingsRecord)
 {
     m_physicalStructure = physicalStructure;
     m_monitorSettingsRecord = monitorSettingsRecord;
 }
示例#13
0
        /// <summary>
        /// Adds a new channel instance to the collection
        /// of channel instances in this observation record.
        /// </summary>
        public ChannelInstance AddNewChannelInstance()
        {
            CollectionElement channelInstancesElement = m_physicalRecord.Body.Collection.GetCollectionByTag(ChannelInstancesTag);
            CollectionElement channelInstanceElement = new CollectionElement() { TagOfElement = OneChannelInstanceTag };
            ChannelInstance channelInstance = new ChannelInstance(channelInstanceElement, this);

            if ((object)channelInstancesElement == null)
            {
                channelInstancesElement = new CollectionElement()
                {
                    TagOfElement = OneChannelInstanceTag
                };

                m_physicalRecord.Body.Collection.AddElement(channelInstancesElement);
            }

            channelInstancesElement.AddElement(channelInstanceElement);

            return channelInstance;
        }