示例#1
0
        /// <summary>
        /// Serializes a data reference composed of raw bytes.
        /// </summary>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="data">The data.</param>
        /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
        private static void SerializeDataReference(MemoryStream tagStream, IDataBlock block, byte[] data, TagFieldAttribute valueInfo)
        {
            var writer = block.Writer;
            uint offset = 0;
            uint size = 0;
            if (data != null && data.Length > 0)
            {
                // Ensure the block is aligned correctly
                var align = Math.Max(DefaultBlockAlign, (valueInfo != null) ? valueInfo.DataAlign : 0);
                StreamUtil.Align(tagStream, (int)align);

                // Write its data
                offset = (uint)tagStream.Position;
                size = (uint)data.Length;
                tagStream.Write(data, 0, data.Length);
                StreamUtil.Align(tagStream, DefaultBlockAlign);
            }

            // Write the reference data
            writer.Write(size);
            writer.Write(0);
            writer.Write(0);
            if (size > 0)
                block.WritePointer(offset, typeof(byte[]));
            else
                writer.Write(0);
            writer.Write(0);
        }
示例#2
0
 public void Add(IDataBlock data)
 {
     if (saveData.ContainsKey(data.DataId)) {
         // Override if exists
         saveData[data.DataId] = new SaveFileEntry(data);
     }
     else {
         // new one otherwise
         saveData.Add(data.DataId, new SaveFileEntry(data));
     }
 }
示例#3
0
    /// <summary>
    /// Creates an independent <see cref="DataBlockInfo"/> instance
    /// base on another one.
    /// </summary>
    /// <param name="other">The object to copy.</param>
    /// <returns>Independent <see cref="DataBlockInfo"/> whose
    /// properties match the submitted instance.</returns>
    /// <exception cref="ArgumentNullException">If <paramref name="other"/>
    /// is a null reference.</exception>
    public static DataBlockInfo FromDataBlock(IDataBlock other)
    {
      Ensure.ArgumentNotNull(other, "other");

      return new DataBlockInfo
               {
                 TransferTokenId = other.TransferTokenId,
                 BlockNumber = other.BlockNumber,
                 BlockLength = other.BlockLength,
                 Offset = other.Offset,
                 IsLastBlock = other.IsLastBlock
               };
    }
示例#4
0
 public static void SerializeMatrix(IDataBlock block, Matrix4x3 mat)
 {
     block.Writer.Write(mat.m11);
     block.Writer.Write(mat.m12);
     block.Writer.Write(mat.m13);
     block.Writer.Write(mat.m21);
     block.Writer.Write(mat.m22);
     block.Writer.Write(mat.m23);
     block.Writer.Write(mat.m31);
     block.Writer.Write(mat.m32);
     block.Writer.Write(mat.m33);
     block.Writer.Write(mat.m41);
     block.Writer.Write(mat.m42);
     block.Writer.Write(mat.m43);
 }
        /// <summary>
        /// Serializes a structure into a temporary memory block.
        /// </summary>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="info">Information about the tag structure type.</param>
        /// <param name="structure">The structure to serialize.</param>
        /// <exception cref="System.InvalidOperationException">Structure type must have TagStructureAttribute</exception>
        private void SerializeStruct(ISerializationContext context, MemoryStream tagStream, IDataBlock block, TagStructureInfo info, object structure)
        {
            var baseOffset = block.Stream.Position;
            var enumerator = new TagFieldEnumerator(info);
            while (enumerator.Next())
                SerializeProperty(context, tagStream, block, structure, enumerator, baseOffset);

            // Honor the struct size if it's defined
            if (info.TotalSize > 0)
            {
                block.Stream.Position = baseOffset + info.TotalSize;
                if (block.Stream.Position > block.Stream.Length)
                    block.Stream.SetLength(block.Stream.Position);
            }

            // Honor alignment
            if (info.Structure.Align > 0)
                block.SuggestAlignment(info.Structure.Align);
        }
示例#6
0
 private void SerializeEulerAngles(IDataBlock block, RealEulerAngles2d angles)
 {
     block.Writer.Write(angles.Yaw.Radians);
     block.Writer.Write(angles.Pitch.Radians);
 }
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            if (lstListBox.SelectedItem == null)
                return;

            viewBlockList.Visible = false;

            if (lstListBox.SelectedItem is ProjectBlockInfo)
            {
                viewBlockList.Visible = false;

                lblStatus.Text = ((ProjectBlockInfo) lstListBox.SelectedItem).ToString();

                Block tmp;
                if (blkFld is BlocksOfflineFolder)
                    tmp = ((BlocksOfflineFolder) blkFld).GetBlock((ProjectBlockInfo) lstListBox.SelectedItem,
                        new S7ConvertingOptions(MnemonicLanguage.German)
                        {
                            GenerateCallsfromUCs = convertCallsToolStripMenuItem.Checked
                        });
                else tmp = blkFld.GetBlock((ProjectBlockInfo) lstListBox.SelectedItem);

                if (tmp != null)
                {
                    if (tmp.BlockType == PLCBlockType.UDT || tmp.BlockType == PLCBlockType.DB ||
                        tmp.BlockType == PLCBlockType.S5_DV || tmp.BlockType == PLCBlockType.S5_DB)
                    {
                        //dataBlockViewControl.DataBlockRows = ((PLCDataBlock) tmp).Structure;
                        myBlk = (IDataBlock) tmp;
                        //expRow = myBlk.Structure;
                        //if (mnuExpandDatablockArrays.Checked)
                        //    expRow = myBlk.GetArrayExpandedStructure(new S7DataBlockExpandOptions() { ExpandCharArrays = false });

                        dataBlockViewControl.ExpandDataBlockArrays = mnuExpandDatablockArrays.Checked;
                        dataBlockViewControl.DataBlock = myBlk;

                        datablockView.Visible = true;

                    }
                    else
                    {
                        txtTextBox.Text = tmp.ToString();
                        txtTextBox.Visible = true;
                    }
                }

            }
            else if (lstListBox.SelectedItem.GetType() == typeof (S7ProjectSourceInfo))
            {
                var tmp = (S7ProjectSourceInfo) lstListBox.SelectedItem;

                if (tmp != null)
                {
                    string fnm = tmp.Filename;

                    if (fnm != null && fnm != "")
                        if (System.IO.File.Exists(fnm))
                            txtTextBox.Text = new System.IO.StreamReader(tmp.Filename).ReadToEnd();
                }

                txtTextBox.Visible = true;
                //lstListBox.Visible = false;
            }

        }
示例#8
0
        /// <summary>
        /// Serializes a value.
        /// </summary>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="val">The value.</param>
        /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
        /// <param name="valueType">Type of the value.</param>
        private void SerializeValue(ISerializationContext context, MemoryStream tagStream, IDataBlock block, object val, TagFieldAttribute valueInfo, Type valueType)
        {
            // Call the data block's PreSerialize callback to determine if the value should be mutated
            val = block.PreSerialize(valueInfo, val);
            if (val != null)
                valueType = val.GetType(); // TODO: Fix hax

            if (valueType.IsPrimitive)
                SerializePrimitiveValue(block.Writer, val, valueType);
            else
                SerializeComplexValue(context, tagStream, block, val, valueInfo, valueType);
        }
示例#9
0
        private void SerializeIndirectValue(CacheVersion version, ISerializationContext context, MemoryStream tagStream, IDataBlock block, object val, Type valueType)
        {
            var writer = block.Writer;

            if (val == null)
            {
                writer.Write(0);
                return;
            }

            // Serialize the value to a temporary block
            var valueBlock = context.CreateBlock();

            SerializeValue(version, context, tagStream, valueBlock, val, null, valueType);

            // Finalize the block and write the pointer
            block.WritePointer(valueBlock.Finalize(tagStream), valueType);
        }
示例#10
0
 private static void SerializeTag(IDataBlock block, Tag tag)
 {
     block.Writer.Write(tag.Value);
 }
示例#11
0
        /// <summary>
        /// Serializes an inline array.
        /// </summary>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="data">The array.</param>
        /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
        private void SerializeInlineArray(ISerializationContext context, MemoryStream tagStream, IDataBlock block, Array data, TagFieldAttribute valueInfo)
        {
            if (valueInfo == null || valueInfo.Count == 0)
                throw new ArgumentException("Cannot serialize an inline array with no count set");
            if (data == null || data.Length != valueInfo.Count)
                throw new ArgumentException("Array length does not match the fixed count of " + valueInfo.Count);

            // Serialize each element into the current block
            var elementType = data.GetType().GetElementType();
            foreach (var elem in data)
                SerializeValue(context, tagStream, block, elem, null, elementType);
        }
示例#12
0
        public void Visit(IDataBlock dataBlock)
        {
            var data = dataBlock.Data;

            _callback(data);
        }
示例#13
0
        /// <inheritdoc/>
        public void SetBlock(int x, int y, int z, IDataBlock block)
        {
            cache = GetChunk(x, y, z);
            if (cache == null || !Check(x, y, z)) {
                return;
            }

            cache.Blocks.SetBlock(x, y, z, block);
        }
 public DataBlockStatistics(IDataBlock dataBlock)
 {
     _dataBlock = dataBlock;
 }
示例#15
0
        private bool GetNextDataBlock(IInputFile file, IDataReader dataReader, IScanContext scanContext, out IDataBlock volBlock, out IDataBlockBuilder volBuilder)
        {
            IDataBlock        volBlockAttempt        = null;
            IDataBlockBuilder volBlockAttemptBuilder = null;

            while (volBlockAttempt == null && dataReader.State == DataReaderState.Ready)
            {
                volBlockAttemptBuilder = CreateBuilder(file);
                scanContext.Detectors  = new[] { _detector };
                volBlockAttempt        = _detector.DetectData(dataReader, volBlockAttemptBuilder, scanContext);
            }
            volBlock   = volBlockAttempt;
            volBuilder = volBlockAttemptBuilder;
            return(volBlock != null);
        }
示例#16
0
 /// <inheritdoc/>
 public void SetBlock(int x, int y, int z, IDataBlock block)
 {
     SetID(x, y, z, block.ID);
     SetData(x, y, z, block.Data);
 }
示例#17
0
 public void Visit(IDataBlock dataBlock)
 {
     dataBlock.Data = _data;
     _observers.ForEach(o => o.OnNext(true));
 }
示例#18
0
        public void Visit(IDataBlock dataBlock)
        {
            var data = dataBlock.Data;

            _observers.ForEach(o => o.OnNext(data));
        }
示例#19
0
 /// <inheritdoc/>
 public void SetBlock(int x, int y, int z, IDataBlock block)
 {
     cache.Blocks.SetBlock(x, y, z, block);
 }
示例#20
0
        /// <summary>
        /// Serializes a property.
        /// </summary>
        /// <param name="version"></param>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="instance">The object that the property belongs to.</param>
        /// <param name="tagFieldInfo">The field enumerator.</param>
        /// <param name="baseOffset">The base offset of the structure from the start of its block.</param>
        /// <exception cref="System.InvalidOperationException">Offset for property \ + property.Name + \ is outside of its structure</exception>
        private void SerializeProperty(CacheVersion version, ISerializationContext context, MemoryStream tagStream, IDataBlock block, object instance, TagFieldInfo tagFieldInfo, long baseOffset)
        {
            if (tagFieldInfo.Attribute.Flags.HasFlag(Runtime))
            {
                return;
            }

            object objectValue = tagFieldInfo.GetValue(instance);

            // second condition is a hack to prevent exceptions when encountering cached tags
            if (objectValue != null)
            {
                if (objectValue.GetType() == tagFieldInfo.FieldType || tagFieldInfo.FieldType == typeof(CachedTag))
                {
                    SerializeValue(version, context, tagStream, block,
                                   objectValue, tagFieldInfo.Attribute, tagFieldInfo.FieldType);
                }
                else
                {
                    throw new Exception($"TagFieldInfo.GetValue return type {objectValue.GetType().ToString()} is not the same as the FieldInfo Type {tagFieldInfo.FieldType.ToString()}!");
                }
            }
            else
            {
                SerializeValue(version, context, tagStream, block,
                               objectValue, tagFieldInfo.Attribute, tagFieldInfo.FieldType);
            }
        }
示例#21
0
 public SaveFileEntry(IDataBlock dblock)
 {
     this.typeName = dblock.GetType().AssemblyQualifiedName;
     this.rawData = DataSerializer.SerializeProtoObject(dblock);
 }
示例#22
0
        public virtual void SerializeTagData(ISerializationContext context, MemoryStream tagStream, IDataBlock block, TagData tagData, TagFieldAttribute valueInfo)
        {
            var  writer = block.Writer;
            uint offset = 0;
            uint size   = 0;
            var  data   = tagData.Data;

            if (data != null && data.Length > 0)
            {
                // Ensure the block is aligned correctly
                var align = Math.Max(DefaultBlockAlign, (valueInfo != null) ? valueInfo.Align : 0);
                StreamUtil.Align(tagStream, (int)align);

                // Write its data
                offset = (uint)tagStream.Position;
                size   = (uint)data.Length;
                tagStream.Write(data, 0, data.Length);
                StreamUtil.Align(tagStream, DefaultBlockAlign);
            }

            // Write the reference data
            writer.Write(size);
            writer.Write(0);
            writer.Write(0);
            if (size > 0)
            {
                block.WritePointer(offset, typeof(byte[]));
            }
            else
            {
                writer.Write(0);
            }
            writer.Write(0);
        }
示例#23
0
 private static void SerializeRange(IDataBlock block, object val)
 {
     var type = val.GetType();
     var boundsType = type.GenericTypeArguments[0];
     var min = type.GetField("Min").GetValue(val);
     var max = type.GetField("Max").GetValue(val);
     SerializePrimitiveValue(block.Writer, min, boundsType);
     SerializePrimitiveValue(block.Writer, max, boundsType);
 }
示例#24
0
        /// <summary>
        /// Serializes a structure into a temporary memory block.
        /// </summary>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="info">Information about the tag structure type.</param>
        /// <param name="structure">The structure to serialize.</param>
        /// <exception cref="System.InvalidOperationException">Structure type must have TagStructureAttribute</exception>
        public void SerializeStruct(ISerializationContext context, MemoryStream tagStream, IDataBlock block, TagStructureInfo info, object structure)
        {
            var baseOffset = block.Stream.Position;

            foreach (var tagFieldInfo in TagStructure.GetTagFieldEnumerable(info))
            {
                SerializeProperty(info.Version, context, tagStream, block, structure, tagFieldInfo, baseOffset);
            }

            // Honor the struct size if it's defined
            if (info.TotalSize > 0)
            {
                block.Stream.Position = baseOffset + info.TotalSize;
                if (block.Stream.Position > block.Stream.Length)
                {
                    block.Stream.SetLength(block.Stream.Position);
                }
            }

            // Honor alignment
            if (info.Structure.Align > 0)
            {
                block.SuggestAlignment(info.Structure.Align);
            }
        }
示例#25
0
 /// <summary>
 /// Serializes a complex value.
 /// </summary>
 /// <param name="context">The serialization context to use.</param>
 /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
 /// <param name="block">The temporary block to write incomplete tag data to.</param>
 /// <param name="val">The value.</param>
 /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
 /// <param name="valueType">Type of the value.</param>
 private void SerializeComplexValue(ISerializationContext context, MemoryStream tagStream, IDataBlock block, object val, TagFieldAttribute valueInfo, Type valueType)
 {
     if (valueInfo != null && ((valueInfo.Flags & TagFieldFlags.Indirect) != 0 || valueType == typeof(ResourceReference)))
         SerializeIndirectValue(context, tagStream, block, val, valueType);
     else if (valueType.IsEnum)
         SerializePrimitiveValue(block.Writer, val, valueType.GetEnumUnderlyingType());
     else if (valueType == typeof(string))
         SerializeString(block.Writer, (string)val, valueInfo);
     else if (valueType == typeof(Tag))
         SerializeTag(block, (Tag)val);
     else if (valueType == typeof(TagInstance))
         SerializeTagReference(block.Writer, (TagInstance)val, valueInfo);
     else if (valueType == typeof(ResourceAddress))
         block.Writer.Write(((ResourceAddress)val).Value);
     else if (valueType == typeof(byte[]))
         SerializeDataReference(tagStream, block, (byte[])val, valueInfo);
     else if (valueType == typeof(Euler2))
         SerializeEulerAngles(block, (Euler2)val);
     else if (valueType == typeof(Euler3))
         SerializeEulerAngles(block, (Euler3)val);
     else if (valueType == typeof(Vector2))
         SerializeVector(block, (Vector2)val);
     else if (valueType == typeof(Vector3))
         SerializeVector(block, (Vector3)val);
     else if (valueType == typeof(Vector4))
         SerializeVector(block, (Vector4)val);
     else if (valueType == typeof(RealQuaternion))
         SerializeRealQuaternion(block, (RealQuaternion)val);
     else if (valueType == typeof(Matrix4x3))
         SerializeMatrix(block, (Matrix4x3)val);
     else if (valueType == typeof(StringID))
         block.Writer.Write(((StringID)val).Value);
     else if (valueType == typeof(Angle))
         block.Writer.Write(((Angle)val).Radians);
     else if (valueType.IsArray)
         SerializeInlineArray(context, tagStream, block, (Array)val, valueInfo);
     else if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(List<>))
         SerializeTagBlock(context, tagStream, block, val, valueType, valueInfo);
     else if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(Range<>))
         SerializeRange(block, val);
     else
         SerializeStruct(context, tagStream, block, new TagStructureInfo(val.GetType(), _version), val);
 }
示例#26
0
 private void SerializePoint(IDataBlock block, Point2d point)
 {
     block.Writer.Write(point.X);
     block.Writer.Write(point.Y);
 }
        /// <summary>
        /// Checks whether the <paramref name="newDataBlock"/> are not different from
        /// the initially detected <paramref name="initialDataBlock"/>.
        /// </summary>
        /// <param name="initialDataBlock">the initially detected data block</param>
        /// <param name="newDataBlock">the new data block to compare</param>
        /// <returns>whether the data block is correct</returns>
        private static bool IsDataBlockCorrect(IDataBlock initialDataBlock, IDataBlock newDataBlock)
        {
            if (newDataBlock == null)
            {
                return(false);
            }
            if (newDataBlock.InputFile != initialDataBlock.InputFile)
            {
                return(false);
            }
            if (newDataBlock.StartOffset != 0L)
            {
                return(false);
            }
            if (newDataBlock.Length != initialDataBlock.Length)
            {
                return(false);                  // Size of data block differs
            }
            if (newDataBlock.IsFullFile != initialDataBlock.IsFullFile)
            {
                return(false);                  // IsFullFile property differs
            }
            if (newDataBlock.CodecStreams == null)
            {
                return(initialDataBlock.CodecStreams.Count == 0);
            }

            // Codec streams can be divided into fragments when a maximum header count is reached
            // The data block object contains the fragmented codec streams,
            // the newDataBlock object contains the unfragmented codec streams.
            // This is handled by the 'Where' clause.

            // Also, codec streams that are split into multiple parts in the data block
            // are represented by a single codec stream in the 'newDataBlock' object.
            // This is handled by the 'GroupBy' clause.
            int initialCodecStreamCount = initialDataBlock.CodecStreams.Where(c => (c.FragmentIndex == 0)).GroupBy(c => c.StreamNumber).Count();

            if (initialCodecStreamCount != newDataBlock.CodecStreams.Count)
            {
                return(false);                // Codec stream count differs
            }

            // Check the codec and container stream detectors used
            foreach (ICodecStream initialCodecStream in initialDataBlock.CodecStreams)
            {
                if (initialCodecStream.FragmentIndex == 0)
                {
                    int          streamNumber   = initialCodecStream.StreamNumber;
                    ICodecStream newCodecStream = newDataBlock.CodecStreams.Where(c => c.StreamNumber == streamNumber).FirstOrDefault();
                    if (newCodecStream == null)
                    {
                        return(false);                        // Codec stream not found in rescanned data block
                    }

                    IDetector initialDetector = initialCodecStream.Detectors.FirstOrDefault();
                    if (!IsCompatibleCodec(initialDetector, newCodecStream.DataFormat))
                    {
                        //It is possible that the container reports an incorrect format of the datastream
                        //Therefore disabled:
                        //return false;
                    }
                }
            }
            return(true);
        }
示例#28
0
 private void SerializePoint(IDataBlock block, RealPoint3d point)
 {
     block.Writer.Write(point.X);
     block.Writer.Write(point.Y);
     block.Writer.Write(point.Z);
 }
 public DataBlockVerification(IDataBlock block, IResultNode resultNode, String description)
 {
     _dataBlock   = block;
     _resultNode  = resultNode;
     _description = description;
 }
示例#30
0
 private void SerializeVector(IDataBlock block, RealVector3d vec)
 {
     block.Writer.Write(vec.I);
     block.Writer.Write(vec.J);
     block.Writer.Write(vec.K);
 }
示例#31
0
 private void SerializeColor(IDataBlock block, RealRgbColor color)
 {
     block.Writer.Write(color.Red);
     block.Writer.Write(color.Green);
     block.Writer.Write(color.Blue);
 }
示例#32
0
 private void SerializePlane(IDataBlock block, RealPlane2d plane)
 {
     block.Writer.Write(plane.I);
     block.Writer.Write(plane.J);
     block.Writer.Write(plane.D);
 }
示例#33
0
        public void OnMessage(IDataBlock message)
        {
            // Handle incorrect protocol version.
            if (message is ProtocolInitiation)
            {
                string error = String.Format("Protocol mismatch - {0}", message.ToString());
                AMQException e = new AMQProtocolHeaderException(error);
                _log.Error("Closing connection because of protocol mismatch", e);
                //_protocolSession.CloseProtocolSession();
                _stateManager.Error(e);
                return;
            }

            AMQFrame frame = (AMQFrame)message;
            // Console.WriteLine(">>> AMQFrame frame received: " + frame); //KHC

            if (frame.BodyFrame is AMQMethodBody)
            {
                if (_log.IsDebugEnabled)
                {
                    _log.Debug("Method frame received: " + frame);
                }
                AMQMethodEvent evt = new AMQMethodEvent(frame.Channel, (AMQMethodBody)frame.BodyFrame, _protocolSession);
                try
                {
                    bool wasAnyoneInterested = false;
                    lock (_frameListeners.SyncRoot)
                    {
                        foreach (IAMQMethodListener listener in _frameListeners)
                        {
                            wasAnyoneInterested = listener.MethodReceived(evt) || wasAnyoneInterested;
                        }
                    }
                    if (!wasAnyoneInterested)
                    {
                        throw new AMQException("AMQMethodEvent " + evt + " was not processed by any listener.");
                    }
                }
                catch (Exception e)
                {
                    foreach (IAMQMethodListener listener in _frameListeners)
                    {
                        listener.Error(e);
                    }
                }
            }
            else if (frame.BodyFrame is ContentHeaderBody)
            {
                _protocolSession.MessageContentHeaderReceived(frame.Channel,
                                                              (ContentHeaderBody)frame.BodyFrame);
            }
            else if (frame.BodyFrame is ContentBody)
            {
                _protocolSession.MessageContentBodyReceived(frame.Channel,
                                                            (ContentBody)frame.BodyFrame);
            }
            else if (frame.BodyFrame is HeartbeatBody)
            {
                _log.Debug("HeartBeat received");
            }
            else
            {
                Console.WriteLine("***** UNHANDLED FRAME ******");
            }
        }
示例#34
0
        private void SerializeRange(CacheVersion version, ISerializationContext context, MemoryStream tagStream, IDataBlock block, object val)
        {
            var type       = val.GetType();
            var boundsType = type.GenericTypeArguments[0];
            var lower      = type.GetProperty("Lower").GetValue(val);
            var upper      = type.GetProperty("Upper").GetValue(val);

            SerializeValue(version, context, tagStream, block, lower, null, boundsType);
            SerializeValue(version, context, tagStream, block, upper, null, boundsType);
        }
 public CompositeAMQDataBlock(IDataBlock[] blocks)
 {
     _blocks = blocks;
 }
 private void ResetFixAndReportDataBlock(long startOffset)
 {
     _fixedDataBlockStartOffset = startOffset;
     _fixedDataBlock            = null;
 }
示例#37
0
        public static void CompaireActivityPeriod(IDataTree dataTree, IDataBlock activityPeriodDataBlock, IDataBlock activityPeriodDataBlock2)
        {
            IDsnNode current = dataTree.DsnTree.Find(ActivityPeriod.KeyActivityPeriodBlock);

            Stack <IDsnNode> stack = new Stack <IDsnNode>();

            stack.Push(current);
            while (stack.Count > 0)
            {
                current = stack.Pop();
                for (var i = current.Children.Count - 1; i >= 0; i--)
                {
                    stack.Push(current.Children[i]);
                }
            }
        }
        private void ScanCodecStreams(DataBlockDetectedEventArgs e, IDataBlock dataBlock)
        {
            IProgressReporter dataBlockProgressReporter = _createSubProgressReporter(_codecProgressReporter, dataBlock.StartOffset, dataBlock.Length, dataBlock.InputFile.Length);
            long      totalStreamBytes       = dataBlock.CodecStreams.Sum(x => x.Length);
            long      streamBytesScanned     = 0L;
            bool      hasCompleteCodecStream = false;
            IDetector detector = null;

            IDataBlockBuilder dataBlockBuilder = _createDataBlockBuilder();

            dataBlockBuilder.DataFormat            = dataBlock.DataFormat;
            dataBlockBuilder.Detectors             = dataBlock.Detectors;
            dataBlockBuilder.InputFile             = dataBlock.InputFile;
            dataBlockBuilder.IsFullFile            = dataBlock.IsFullFile;
            dataBlockBuilder.IsFragmented          = dataBlock.IsFragmented;
            dataBlockBuilder.PreviousFragment      = LastDataBlock;
            dataBlockBuilder.StartOffset           = dataBlock.StartOffset;
            dataBlockBuilder.EndOffset             = dataBlock.EndOffset;
            dataBlockBuilder.ReferenceHeaderOffset = dataBlock.ReferenceHeaderOffset;
            dataBlockBuilder.ReferenceHeader       = dataBlock.ReferenceHeader;

            foreach (ICodecStream completeCodecStream in dataBlock.CodecStreams)
            {
                IProgressReporter codecStreamProgressReporter = _createSubProgressReporter(dataBlockProgressReporter, streamBytesScanned, completeCodecStream.Length, totalStreamBytes);
                var completeCodecStreamScanner = new CompleteCodecStreamScanner(_codecStreamDataScanner, dataBlockBuilder, completeCodecStream, codecStreamProgressReporter);

                // Note: The container detector that was used is not available to the codec detector!

                // NOTE: We assume that a file never uses multiple codec formats that are supported by Defraser.
                //       So, if at any time for example audio codecs will be supported, this code should be revised!
                using (IDataReader dataReader = _dataReaderPool.CreateDataReader(completeCodecStream, completeCodecStreamScanner))
                {
                    if (detector != null)
                    {
                        // Only scan other streams with the detector that already produced a valid and complete result
                        if (!completeCodecStreamScanner.ScanForNearlyCompleteCodecStream(dataReader))
                        {
                            AddUnknownCodecStream(dataBlockBuilder, completeCodecStream);
                        }
                    }
                    else
                    {
                        detector = completeCodecStreamScanner.ScanDetectForNearlyCompleteCodecStream(dataReader, CodecDetectors);

                        if (detector == null)
                        {
                            AddUnknownCodecStream(dataBlockBuilder, completeCodecStream);
                        }
                    }

                    hasCompleteCodecStream |= completeCodecStreamScanner.HasCompleteCodecStream;
                }

                streamBytesScanned += completeCodecStream.Length;
            }

            if (!hasCompleteCodecStream)
            {
                e.DoubleScanPayload = true;
            }

            LastDataBlock = dataBlockBuilder.Build();

            ReportDataBlock(LastDataBlock);
        }
示例#39
0
 /// <inheritdoc/>
 public void SetBlock(int x, int y, int z, IDataBlock block)
 {
     SetID(x, y, z, block.ID);
     SetData(x, y, z, block.Data);
 }
示例#40
0
        internal static IDataBlock CreateDataBlock(IDetector detector, IDataPacket data, bool isFullFile, IDataBlock lastDataBlock)
        {
            IDataBlockBuilder dataBlockBuilder = CreateDataBlockBuilder();

            dataBlockBuilder.DataFormat   = CodecID.Unknown;
            dataBlockBuilder.Detectors    = new[] { detector };
            dataBlockBuilder.InputFile    = data.InputFile;
            dataBlockBuilder.StartOffset  = data.StartOffset;
            dataBlockBuilder.EndOffset    = data.EndOffset;
            dataBlockBuilder.IsFullFile   = isFullFile;
            dataBlockBuilder.IsFragmented = false;
            return(dataBlockBuilder.Build());
        }
示例#41
0
 private static void SerializeEulerAngles(IDataBlock block, Euler3 angles)
 {
     block.Writer.Write(angles.Yaw.Radians);
     block.Writer.Write(angles.Pitch.Radians);
     block.Writer.Write(angles.Roll.Radians);
 }
示例#42
0
        /// <summary>
        /// Serializes a property.
        /// </summary>
        /// <param name="version"></param>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="instance">The object that the property belongs to.</param>
        /// <param name="tagFieldInfo">The field enumerator.</param>
        /// <param name="baseOffset">The base offset of the structure from the start of its block.</param>
        /// <exception cref="System.InvalidOperationException">Offset for property \ + property.Name + \ is outside of its structure</exception>
        private void SerializeProperty(CacheVersion version, ISerializationContext context, MemoryStream tagStream, IDataBlock block, object instance, TagFieldInfo tagFieldInfo, long baseOffset)
        {
            if (tagFieldInfo.Attribute.Flags.HasFlag(TagFieldFlags.Runtime))
            {
                return;
            }

            SerializeValue(version, context, tagStream, block,
                           tagFieldInfo.GetValue(instance), tagFieldInfo.Attribute, tagFieldInfo.FieldType);
        }
示例#43
0
 private static void SerializeRealQuaternion(IDataBlock block, RealQuaternion quat)
 {
     block.Writer.Write(quat.I);
     block.Writer.Write(quat.J);
     block.Writer.Write(quat.K);
     block.Writer.Write(quat.W);
 }
示例#44
0
 /// <summary>
 /// Serializes a value.
 /// </summary>
 /// <param name="version"></param>
 /// <param name="context">The serialization context to use.</param>
 /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
 /// <param name="block">The temporary block to write incomplete tag data to.</param>
 /// <param name="val">The value.</param>
 /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
 /// <param name="valueType">Type of the value.</param>
 private void SerializeValue(CacheVersion version, ISerializationContext context, MemoryStream tagStream, IDataBlock block, object val, TagFieldAttribute valueInfo, Type valueType)
 {
     // Call the data block's PreSerialize callback to determine if the value should be mutated
     val = block.PreSerialize(valueInfo, val);
     if (val != null)
     {
         valueType = val.GetType(); // TODO: Fix hax
     }
     if (valueType.IsPrimitive)
     {
         SerializePrimitiveValue(block.Writer, val, valueType);
     }
     else
     {
         SerializeComplexValue(version, context, tagStream, block, val, valueInfo, valueType);
     }
 }
示例#45
0
 private static void SerializeVector(IDataBlock block, Vector4 vec)
 {
     block.Writer.Write(vec.X);
     block.Writer.Write(vec.Y);
     block.Writer.Write(vec.Z);
     block.Writer.Write(vec.W);
 }
示例#46
0
        /// <summary>
        /// Serializes a complex value.
        /// </summary>
        /// <param name="version"></param>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="value">The value.</param>
        /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
        /// <param name="valueType">Type of the value.</param>
        private void SerializeComplexValue(CacheVersion version, ISerializationContext context, MemoryStream tagStream, IDataBlock block, object value, TagFieldAttribute valueInfo, Type valueType)
        {
            if (valueInfo != null && valueInfo.Flags.HasFlag(TagFieldFlags.Pointer))
            {
                SerializeIndirectValue(version, context, tagStream, block, value, valueType);
            }
            else if (valueType.IsEnum)
            {
                SerializePrimitiveValue(block.Writer, value, valueType.GetEnumUnderlyingType());
            }
            else if (valueType == typeof(string))
            {
                SerializeString(block.Writer, (string)value, valueInfo);
            }
            else if (valueType == typeof(Tag))
            {
                SerializeTag(block, (Tag)value);
            }
            else if (valueType == typeof(CachedTagInstance))
            {
                SerializeTagReference(context, block.Writer, (CachedTagInstance)value, valueInfo);
            }
            else if (valueType == typeof(CacheAddress))
            {
                block.Writer.Write(((CacheAddress)value).Value);
            }
            else if (valueType == typeof(byte[]))
            {
                if (valueInfo.Flags.HasFlag(TagFieldFlags.Padding) || (value == null && valueInfo.Length > 0))
                {
                    block.Writer.Write(new byte[valueInfo.Length]);
                }
                else if (valueInfo.Length > 0)
                {
                    block.Writer.Write((byte[])value);
                }
                else
                {
                    SerializeDataReference(tagStream, block, (byte[])value, valueInfo);
                }
            }
            else if (valueType == typeof(RealRgbColor))
            {
                SerializeColor(block, (RealRgbColor)value);
            }
            else if (valueType == typeof(RealArgbColor))
            {
                SerializeColor(block, (RealArgbColor)value);
            }
            else if (valueType == typeof(ArgbColor))
            {
                SerializeColor(block, (ArgbColor)value);
            }
            else if (valueType == typeof(ArgbColor))
            {
                SerializeColor(block, (ArgbColor)value);
            }
            else if (valueType == typeof(RealEulerAngles2d))
            {
                SerializeEulerAngles(block, (RealEulerAngles2d)value);
            }
            else if (valueType == typeof(RealEulerAngles3d))
            {
                SerializeEulerAngles(block, (RealEulerAngles3d)value);
            }
            else if (valueType == typeof(Point2d))
            {
                SerializePoint(block, (Point2d)value);
            }
            else if (valueType == typeof(Rectangle2d))
            {
                SerializeRectangle(block, (Rectangle2d)value);
            }
            else if (valueType == typeof(RealPoint2d))
            {
                SerializePoint(block, (RealPoint2d)value);
            }
            else if (valueType == typeof(RealPoint3d))
            {
                SerializePoint(block, (RealPoint3d)value);
            }
            else if (valueType == typeof(RealVector2d))
            {
                SerializeVector(block, (RealVector2d)value);
            }
            else if (valueType == typeof(RealVector3d))
            {
                SerializeVector(block, (RealVector3d)value);
            }
            else if (valueType == typeof(RealQuaternion))
            {
                SerializeVector(block, (RealQuaternion)value);
            }
            else if (valueType == typeof(RealPlane2d))
            {
                SerializePlane(block, (RealPlane2d)value);
            }
            else if (valueType == typeof(RealPlane3d))
            {
                SerializePlane(block, (RealPlane3d)value);
            }
            else if (valueType == typeof(RealMatrix4x3))
            {
                SerializeMatrix(block, (RealMatrix4x3)value);
            }
            else if (valueType == typeof(StringId))
            {
                block.Writer.Write(((StringId)value).Value);
            }
            else if (valueType == typeof(Angle))
            {
                block.Writer.Write(((Angle)value).Radians);
            }
            else if (valueType == typeof(DatumIndex))
            {
                block.Writer.Write(((DatumIndex)value).Value);
            }
            else if (valueType == typeof(VertexShaderReference))
            {
                block.Writer.Write(0); // TODO: fix  (not used in halo online)
            }
            else if (valueType == typeof(PixelShaderReference))
            {
                block.Writer.Write(0); // TODO: fix  (not used in halo online)
            }
            else if (valueType.IsArray)
            {
                SerializeInlineArray(version, context, tagStream, block, (Array)value, valueInfo, valueType);
            }
            else if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(List <>))
            {
                SerializeTagBlock(version, context, tagStream, block, value, valueType, valueInfo);
            }
            else if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(Bounds <>))
            {
                SerializeRange(version, context, tagStream, block, value);
            }
            else
            {
                if (value == null)
                {
                    value = Activator.CreateInstance(valueType);
                }

                SerializeStruct(context, tagStream, block, TagStructure.GetTagStructureInfo(valueType, version), value);
            }
        }
示例#47
0
        private void SerializeIndirectValue(ISerializationContext context, MemoryStream tagStream, IDataBlock block, object val, Type valueType)
        {
            var writer = block.Writer;
            if (val == null)
            {
                writer.Write(0);
                return;
            }

            // Serialize the value to a temporary block
            var valueBlock = context.CreateBlock();
            SerializeValue(context, tagStream, valueBlock, val, null, valueType);

            // Finalize the block and write the pointer
            block.WritePointer(valueBlock.Finalize(tagStream), valueType);
        }
示例#48
0
 public void WriteFrame(IDataBlock frame)
 {
     _protocolWriter.Write(frame);
 }
示例#49
0
 /// <summary>
 /// Serializes a property.
 /// </summary>
 /// <param name="context">The serialization context to use.</param>
 /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
 /// <param name="block">The temporary block to write incomplete tag data to.</param>
 /// <param name="instance">The object that the property belongs to.</param>
 /// <param name="structInfo">The structure information.</param>
 /// <param name="property">The property.</param>
 /// <param name="baseOffset">The base offset of the structure from the start of its block.</param>
 /// <exception cref="System.InvalidOperationException">Offset for property \ + property.Name + \ is outside of its structure</exception>
 private void SerializeProperty(ISerializationContext context, MemoryStream tagStream, IDataBlock block, object instance, TagFieldEnumerator enumerator, long baseOffset)
 {
     // Seek to the value if it has an offset specified and write it
     var valueInfo = enumerator.Attribute;
     if (enumerator.Attribute.Offset >= 0)
         block.Stream.Position = baseOffset + valueInfo.Offset;
     var startOffset = block.Stream.Position;
     var val = enumerator.Field.GetValue(instance);
     SerializeValue(context, tagStream, block, val, valueInfo, enumerator.Field.FieldType);
     if (valueInfo.Size > 0)
         block.Stream.Position = startOffset + valueInfo.Size;
 }
示例#50
0
        /// <summary>
        /// Serializes an inline array.
        /// </summary>
        /// <param name="version"></param>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="data">The array.</param>
        /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
        /// <param name="valueType">The type of the value.</param>
        private void SerializeInlineArray(CacheVersion version, ISerializationContext context, MemoryStream tagStream, IDataBlock block, Array data, TagFieldAttribute valueInfo, Type valueType)
        {
            if (valueInfo == null || valueInfo.Length == 0)
            {
                throw new ArgumentException("Cannot serialize an inline array with no count set");
            }

            var elementType = valueType.GetElementType();

            if (data == null)
            {
                data = Array.CreateInstance(elementType, valueInfo.Length);
            }

            if (data == null || data.Length != valueInfo.Length)
            {
                throw new ArgumentException("Array length does not match the fixed count of " + valueInfo.Length);
            }

            // Serialize each element into the current block
            foreach (var element in data)
            {
                SerializeValue(version, context, tagStream, block, element, null, elementType);
            }
        }
示例#51
0
        /// <summary>
        /// Serializes a tag block.
        /// </summary>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="list">The list of values in the tag block.</param>
        /// <param name="listType">Type of the list.</param>
        /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
        private void SerializeTagBlock(ISerializationContext context, MemoryStream tagStream, IDataBlock block, object list, Type listType, TagFieldAttribute valueInfo)
        {
            var writer = block.Writer;
            var listCount = 0;
            if (list != null)
            {
                // Use reflection to get the number of elements in the list
                var countProperty = listType.GetProperty("Count");
                listCount = (int)countProperty.GetValue(list);
            }
            if (listCount == 0)
            {
                writer.Write(0);
                writer.Write(0);
                writer.Write(0);
                return;
            }

            // Serialize each value in the list to a data block
            var tagBlock = context.CreateBlock();
            var enumerableList = (System.Collections.IEnumerable)list;
            var valueType = listType.GenericTypeArguments[0];
            foreach (var val in enumerableList)
                SerializeValue(context, tagStream, tagBlock, val, null, valueType);

            // Ensure the block is aligned correctly
            var align = Math.Max(DefaultBlockAlign, (valueInfo != null) ? valueInfo.DataAlign : 0);
            StreamUtil.Align(tagStream, (int)align);

            // Finalize the block and write the tag block reference
            writer.Write(listCount);
            block.WritePointer(tagBlock.Finalize(tagStream), listType);
            writer.Write(0);
        }
示例#52
0
        /// <summary>
        /// Serializes a tag block.
        /// </summary>
        /// <param name="version"></param>
        /// <param name="context">The serialization context to use.</param>
        /// <param name="tagStream">The stream to write completed blocks of tag data to.</param>
        /// <param name="block">The temporary block to write incomplete tag data to.</param>
        /// <param name="list">The list of values in the tag block.</param>
        /// <param name="listType">Type of the list.</param>
        /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
        private void SerializeTagBlock(CacheVersion version, ISerializationContext context, MemoryStream tagStream, IDataBlock block, object list, Type listType, TagFieldAttribute valueInfo)
        {
            var writer = block.Writer;
            var count  = 0;

            if (list != null)
            {
                // Use reflection to get the number of elements in the list
                var countProperty = listType.GetProperty("Count");
                count = (int)countProperty.GetValue(list);
            }
            if (count == 0)
            {
                writer.Write(0);
                writer.Write(0);
                writer.Write(0);
                return;
            }

            var elementType = listType.GenericTypeArguments[0];
            TagStructureAttribute structure;

            try
            {
                structure = TagStructure.GetTagStructureInfo(elementType, Version).Structure;
            }
            catch
            {
                structure = null;
            }

            // Serialize each value in the list to a data block
            var tagBlock       = context.CreateBlock();
            var enumerableList = (System.Collections.IEnumerable)list;

            foreach (var val in enumerableList)
            {
                SerializeValue(version, context, tagStream, tagBlock, val, null, elementType);
            }

            // Ensure the block is aligned correctly
            var align = Math.Max(DefaultBlockAlign, (valueInfo != null) ? valueInfo.Align : 0);

            StreamUtil.Align(tagStream, (int)align);

            // Finalize the block and write the tag block reference
            writer.Write(count);
            block.WritePointer(tagBlock.Finalize(tagStream), listType);
            writer.Write(0);
        }
示例#53
0
 private void SerializeTag(IDataBlock block, Tag tag)
 {
     block.Writer.Write(tag.Value);
 }
 /// <summary>
 /// Convenience method that writes a frame to the protocol session. Equivalent
 /// to calling getProtocolSession().write().
 /// </summary>
 /// <param name="frame">the frame to write</param>
 public void WriteFrame(IDataBlock frame)
 {
     _protocolWriter.Write(frame);
 }