当前位置: 首页>>代码示例>>C#>>正文


C# Stream.GetMemoryStream方法代码示例

本文整理汇总了C#中Stream.GetMemoryStream方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.GetMemoryStream方法的具体用法?C# Stream.GetMemoryStream怎么用?C# Stream.GetMemoryStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream的用法示例。


在下文中一共展示了Stream.GetMemoryStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessVariableData

        static Collection<Exception> ProcessVariableData(PropertyInfo[] propertyList, object obj, Stream sourceData, int index, bool[] IncludedFields)
        {
            int position = index;
            Collection<Exception> errors = new Collection<Exception>();
            if (propertyList != null && obj != null && sourceData != null && IncludedFields != null)
            {

                using (MemoryStream dataStream = sourceData.GetMemoryStream(index))
                {
                    dataStream.Position = 0;

                    for (int i = 0; i < IncludedFields.Length; i++)
                    {

                        if (IncludedFields[i])
                        {
                            try
                            {
                                

                                position += Utility.LoadProperty(obj, dataStream, propertyList[i], errors);

                                
                            }
                            catch (Exception ex)
                            {
                                errors.Add(ex);
                            }
                        }

                    }
                }
            }
            return errors;
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:35,代码来源:VariablePackage.cs

示例2: RaiseBytesReceived

 void RaiseBytesReceived(Stream buffer)
 {
     if (BytesReceived != null)
     {
         BytesReceived(this, new BytesReceivedEventArgs(buffer.GetMemoryStream(0), this.ID));
     }
 }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:7,代码来源:Connector.cs

示例3: ShipAction2Packet

        public ShipAction2Packet(Stream stream, int index) : base()
        {
            try
            {
                if (stream != null)
                {
                    if (stream.CanSeek)
                    {
                        stream.Position = index;
                    }
                    if (index < stream.Length - 3)
                    {
                        SubPacketType = (ShipAction2SubPacketType)stream.ToInt32();
                    }
                    if (index < stream.Length - 4)
                    {
                        SubPacketData = stream.GetMemoryStream(index + 4);

                        _subPacket = GetSubPacket(SubPacketData);
                    }
                    else
                    {
                        _subPacket = null;
                        SubPacketData = null;
                    }
                }
            }
            catch (Exception ex)
            {
                AddError(ex);
            }
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:32,代码来源:ShipAction2Packet.cs

示例4: ShipActionPacket

        public ShipActionPacket(Stream stream, int index)
            : base()
        {

            if (stream != null)
            {
                if (stream.CanSeek)
                {
                    stream.Position = index;
                }
                if (index < stream.Length - 3)
                {
                    SubPacketType = (ShipActionSubPackets.ShipActionSubPacketType)stream.ToInt32();
                }
                if (index < stream.Length - 4)
                {
                    SubPacketData = stream.GetMemoryStream(index + 4);
                    _subPacket = GetSubPacket(SubPacketData);
                }
                else
                {
                    _subPacket = null;
                    SubPacketData = null;
                }
            }
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:26,代码来源:ShipActionPacket.cs

示例5: LoadData

        void LoadData(Stream stream, int index)
        {
            if (stream != null)
            {
                try
                {
                    List<PlayerShip> ships = new List<PlayerShip>();
                    using (MemoryStream dataStream = stream.GetMemoryStream(index))
                    {
                        int position = 0;
                        do
                        {
                            PlayerShip p = new PlayerShip(dataStream, position);
                            ships.Add(p);
                            position += p.Length;

                        } while (position < dataStream.Length);
                    }
                    Ships = new ReadOnlyCollection<PlayerShip>(ships);
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                }
            }
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:26,代码来源:AllShipSettingsSubPacket.cs

示例6: AllShipSettingsSubPacket

        //**CONFIRMED

     

        public AllShipSettingsSubPacket(Stream stream, int index)
        {

            RawData = stream.GetMemoryStream(index);
            LoadData(RawData, 0);

        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:11,代码来源:AllShipSettingsSubPacket.cs

示例7: GameMessagePacket

        // GameStartSubPacket = 0,
        //GameOverSubPacket = 6,
        //Unknown1SubPacket = 8,
        //Unknown2SubPacket = 9,
        //GameTextMessageSubPacket = 10,
        //JumpStartSubPacket = 12,
        //JumpCompleteSubPacket = 13,
        //AllShipSettingsSubPacket = 15,
        public GameMessagePacket(Stream stream, int index)
        {
            try
            {
                if (stream != null)
                {
                    if (stream.CanSeek)
                    {
                        stream.Position = index;
                    }
                    if (stream.Length > 3)
                    {
                        SubPacketType = (GameMessageSubPacketType)stream.ToInt32();
                       
                    }
                    if (stream.Length >= 4)
                    {
                        SubPacketData = stream.GetMemoryStream(index + 4);

                     
                        _subPacket = GetSubPacket(stream, index + 4);
                    }
                    else
                    {
                        _subPacket = null;
                        SubPacketData = null;
                    }
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex);
            }
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:42,代码来源:GameMessagePacket.cs

示例8: LoadProperties

        private void LoadProperties(Stream stream, int index)
        {

            _rawData = stream.GetMemoryStream(index);

            Length = Utility.LoadProperties(this, _rawData, 0, errors);
        
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:8,代码来源:ParentPacket.cs

示例9: ObjectStatusUpdatePacket

        public ObjectStatusUpdatePacket(Stream stream, int index) : base()
        {
            if (stream != null)
            {
                try
                {
                    if (stream.Length > index + 1)
                    {
                        SubPacketType = (ObjectStatusUpdateSubPacketType)Convert.ToByte(stream.ReadByte());
                    }
                    SubPacketData = stream.GetMemoryStream(index + 1);

                    if (SubPacketData != null)
                    {
                        _subPacket = GetSubPacket(SubPacketData);
                    }
                }
                catch (Exception ex)
                {
                    AddError(ex);
                }
            }
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:23,代码来源:ObjectStatusUpdatePacket.cs

示例10: Packet

        public Packet(Stream stream)
        {
            if (stream != null)
            {
                if (stream.CanSeek)
                {
                    stream.Position = 0;
                }
#if DEBUG
                HexFormattedData = FormatIt(stream.GetMemoryStream(0).ToArray());
                if (stream.CanSeek)
                {
                    stream.Position = 0;
                }
#endif
                _rawData = stream.GetMemoryStream(0);

                if (ThrowWhenInvalid && _rawData.Length < HeaderLength)
                {
                    throw new InvalidPacketException();
                }
                else
                {
                    if (_rawData.Length > 3) ID = _rawData.ToInt32();
                    if (ThrowWhenInvalid && ID != Connector.StandardID)
                    {
                        throw new InvalidPacketException();
                    }
                    else
                    {
                        if (_rawData.Length > 7) Length = _rawData.ToInt32();
                        if (_rawData.Length > 11) Origin = (OriginType)_rawData.ToInt32();
                        if (_rawData.Length > 15) Padding = _rawData.ToInt32();
                        if (_rawData.Length > 19) PayloadLength = _rawData.ToInt32();
                        if (_rawData.Length > 23) PacketType = (PacketType)_rawData.ToInt32();


                        int ln = Convert.ToInt32(_rawData.Length);
                        if (ln > Length)
                        {
                            ln = Length;
                        }

                        Payload = _rawData.GetMemoryStream(HeaderLength);

                        _package = BuildPackage(_rawData, HeaderLength, Type.GetType(typeof(Packet).Namespace + "." + this.PacketType.ToString()));
                                //GetPackage(byteArray);
                        int packetLength = 0;
                        if (_package != null)
                        {
                            if (_package.GetErrors().Count > 0)
                            {
                                ConversionFailed = true;
                                
                            }
                            packetLength = Convert.ToInt32(Payload.Length);
                            if (Length - HeaderLength != packetLength)
                            {
                                if (ThrowWhenInvalid)
                                {
                                    throw new InvalidPacketException();
                                }
                                else
                                {
                                    ConversionException = new InvalidPacketException();
                                    ConversionFailed = true;
                                }
                            }
                        }
                        else
                        {
                            //Unknown package found!!
                        }
                    }
                }
            }

        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:78,代码来源:Packet.cs

示例11: Initialize

        void Initialize(Stream stream, int index)
        {
            if (stream != null)
            {
                if (stream.CanRead)
                {
                    stream.Position = index;
                }
                _rawData = stream.GetMemoryStream(index);
                if (stream.CanRead)
                {
                    stream.Position = index;
                }
                _rawData.Position = 0;
                ID = _rawData.ToInt32();
                

                List<PropertyInfo> propertyList = new List<PropertyInfo>();

                Type t = this.GetType();
                PropertyInfo[] properties = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                foreach (PropertyInfo prop in properties)
                {
                    bool skip = false;
                    foreach (System.Attribute attrib in prop.GetCustomAttributes(true))
                    {
                        if (attrib is ArtemisExcludedAttribute)
                        {
                            skip = true;
                            break;
                        }
                    }
                    if (!skip)
                    {
                        if (prop.Name != "ID" && prop.Name != "IncludedFields")
                        {
                            propertyList.Add(prop);
                        }
                    }
                }

                IncludedFields = new ReadOnlyCollection<bool>(ProcessBitFlags(propertyList.Count, _rawData, 4));
                int flagsize = (propertyList.Count - 1)/ 8 + 1;

                int position = 4 + flagsize;

                errors = ProcessVariableData(propertyList.ToArray(), this, _rawData, position, IncludedFields.ToArray<bool>());
                
            }
            
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:51,代码来源:VariablePackage.cs

示例12: BytesReceivedEventArgs

 //public BytesReceivedEventArgs(byte[] byteArray, Guid connectionID) : base(connectionID)
 //{
     
 //    Buffer = byteArray;
 //    DataStream = new MemoryStream(Buffer);
 //}
 public BytesReceivedEventArgs(Stream stream, Guid connectionID)
     : base(connectionID)
 {
     DataStream = stream.GetMemoryStream(0);
     //Buffer = DataStream.GetBuffer();
 }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:12,代码来源:BytesReceivedEventArgs.cs

示例13: Initialize

        void Initialize(Stream stream, int index)
        {

            
            if (stream != null && index < stream.Length)
            {
                if (stream.CanSeek)
                {
                    stream.Position = index;
                }
                _rawData = stream.GetMemoryStream(index);
                if (Convert.ToByte(_rawData.ReadByte()) < 0x0a)
                {

                }
                try
                {
                    _rawData.Position = index;

                    TeamNumber = Convert.ToByte(_rawData.ReadByte() - 0x0a);

                 
                    if (_rawData.Position < _rawData.Length - 3)
                    {
                        
                        GoalX = _rawData.ToInt32();
                    }
                    if (_rawData.Position < _rawData.Length - 3)
                    {

                        CurrentX = _rawData.ToInt32();
                    }
                    if (_rawData.Position < _rawData.Length - 3)
                    {

                        GoalY = _rawData.ToInt32();
                    }
                    if (_rawData.Position < _rawData.Length - 3)
                    {
                        CurrentY = _rawData.ToInt32();
                    }
                    if (_rawData.Position < _rawData.Length - 3)
                    {
                        GoalZ = _rawData.ToInt32();
                    }
                    if (_rawData.Position < _rawData.Length - 3)
                    {
                        CurrentZ = _rawData.ToInt32();
                    }
                    if (_rawData.Position < _rawData.Length - 3)
                    {
                        Progress = _rawData.ToSingle();
                    }
                    if (_rawData.Position < _rawData.Length - 3)
                    {

                        NumberOfTeamMembers = _rawData.ToInt32();
                    }
                    _rawData.Position = 0;
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                }


            }
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:68,代码来源:DamComStatus.cs

示例14: LoadProperties

        public static int LoadProperties(object baseObject, Stream stream, int index, Collection<Exception> errors)
        {

            int retVal = 0;
            if (baseObject == null || stream == null || errors == null)
            {

            }
            else
            {
                if (index < stream.Length)
                {

                    using (MemoryStream RawData = stream.GetMemoryStream(index))
                    {

                        RawData.Position = 0;
                        foreach (PropertyInfo prop in baseObject.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
                        {
                            //@@@@@@@
                            bool exclude = false;
                            foreach (object a in prop.GetCustomAttributes(false))
                            {
                                if (a.GetType() == typeof(ArtemisExcludedAttribute))
                                {
                                    exclude = true;
                                    break;
                                }
                               

                            }
                            if (!exclude)
                            {
                                retVal += LoadProperty(baseObject, RawData, prop, errors);
                            }
                            long i = RawData.Position;
                        }
                        if (stream.CanSeek)
                        {
                            stream.Position = retVal + index;
                        }
                    }

                }
            }
            return retVal;
        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:47,代码来源:Utility.cs

示例15: ArtemisString

        public ArtemisString(Stream stream, int index)
        {
            
            if (stream != null && index < stream.Length - 3)
            {
                using (MemoryStream Data = stream.GetMemoryStream(index))
                {
                    Data.Position = 0;

                    Length = Data.ToInt32();
                    if (Length <= LongestAllowedLength)
                    {

                        //Only last character should be a null character (two zeroes together).  If there are two null characters together elsewhere--the parsing is WRONG and needs fixed.
                        bool badString = false;
                        for (int i = index; i < (Length * 2) - 2; i += 2)
                        {
                            byte[] buffer = new byte[2];
                            Data.Read(buffer, 0, 2);
                            if (BitConverter.ToInt16(buffer, 0) == 0)
                            {
                                badString = true;
                                break;
                            }
                        }
                        if (badString)
                        {
                            throw new ParseException("Stream for ArtemisString not correct.");
                        }
                        else
                        {
                            Data.Position = 0;
                            Value = System.Text.ASCIIEncoding.Unicode.GetString(Data.GetBuffer(), 4, Length * 2 - 2);
                            if (Value != "Artemis" && Value != "Intrepid")
                            {

                            }
                            else
                            {

                            }
                        }
                    }
                    else
                    {
                        throw new ParseException("Stream for ArtemisString not correct: Length too long.");
                    }
                }
                if (stream.CanSeek)
                {
                    stream.Position = index;
                }

                byte[] buff = new byte[Length * 2 + 4];
                stream.Read(buff, 0, buff.Length);
                _rawData = new MemoryStream(buff);
                if (stream.CanSeek)
                {
                    stream.Position += Length * 2 + 4;
                }
            }

        }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:63,代码来源:ArtemisString.cs


注:本文中的Stream.GetMemoryStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。