Пример #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
 /// <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);
                }
            }
        }
Пример #10
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;
        }