Esempio n. 1
0
        protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count)
        {
            lock (this.ThisLock)
            {
                for (; ;)
                {
                    byte id;
                    {
                        byte[] idBuffer = new byte[1];
                        if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length)
                        {
                            return;
                        }
                        id = idBuffer[0];
                    }

                    int length;
                    {
                        byte[] lengthBuffer = new byte[4];
                        if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length)
                        {
                            return;
                        }
                        length = NetworkConverter.ToInt32(lengthBuffer);
                    }

                    using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true))
                    {
                        if (id == (byte)SerializeId.Group)
                        {
                            this.Groups.Add(Group.Import(rangeStream, bufferManager));
                        }

                        else if (id == (byte)SerializeId.CompressionAlgorithm)
                        {
                            this.CompressionAlgorithm = (CompressionAlgorithm)Enum.Parse(typeof(CompressionAlgorithm), ItemUtilities.GetString(rangeStream));
                        }

                        else if (id == (byte)SerializeId.CryptoAlgorithm)
                        {
                            this.CryptoAlgorithm = (CryptoAlgorithm)Enum.Parse(typeof(CryptoAlgorithm), ItemUtilities.GetString(rangeStream));
                        }
                        else if (id == (byte)SerializeId.CryptoKey)
                        {
                            this.CryptoKey = ItemUtilities.GetByteArray(rangeStream);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count)
        {
            for (; ;)
            {
                byte id;
                {
                    byte[] idBuffer = new byte[1];
                    if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length)
                    {
                        return;
                    }
                    id = idBuffer[0];
                }

                int length;
                {
                    byte[] lengthBuffer = new byte[4];
                    if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length)
                    {
                        return;
                    }
                    length = NetworkConverter.ToInt32(lengthBuffer);
                }

                using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true))
                {
                    if (id == (byte)SerializeId.Id)
                    {
                        this.Id = ItemUtilities.GetByteArray(rangeStream);
                    }

                    else if (id == (byte)SerializeId.Uri)
                    {
                        this.ProtectedUris.Add(ItemUtilities.GetString(rangeStream));
                    }
                }
            }
        }
Esempio n. 3
0
        protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count)
        {
            lock (this.ThisLock)
            {
                for (; ;)
                {
                    byte id;
                    {
                        byte[] idBuffer = new byte[1];
                        if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length)
                        {
                            return;
                        }
                        id = idBuffer[0];
                    }

                    int length;
                    {
                        byte[] lengthBuffer = new byte[4];
                        if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length)
                        {
                            return;
                        }
                        length = NetworkConverter.ToInt32(lengthBuffer);
                    }

                    using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true))
                    {
                        if (id == (byte)SerializeId.Name)
                        {
                            this.Name = ItemUtilities.GetString(rangeStream);
                        }
                        else if (id == (byte)SerializeId.Length)
                        {
                            this.Length = ItemUtilities.GetLong(rangeStream);
                        }
                        else if (id == (byte)SerializeId.CreationTime)
                        {
                            this.CreationTime = DateTime.ParseExact(ItemUtilities.GetString(rangeStream), "yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo).ToUniversalTime();
                        }
                        else if (id == (byte)SerializeId.Comment)
                        {
                            this.Comment = ItemUtilities.GetString(rangeStream);
                        }
                        else if (id == (byte)SerializeId.Rank)
                        {
                            this.Rank = ItemUtilities.GetInt(rangeStream);
                        }
                        else if (id == (byte)SerializeId.Key)
                        {
                            this.Key = Key.Import(rangeStream, bufferManager);
                        }

                        else if (id == (byte)SerializeId.Keyword)
                        {
                            this.Keywords.Add(ItemUtilities.GetString(rangeStream));
                        }

                        else if (id == (byte)SerializeId.CompressionAlgorithm)
                        {
                            this.CompressionAlgorithm = (CompressionAlgorithm)Enum.Parse(typeof(CompressionAlgorithm), ItemUtilities.GetString(rangeStream));
                        }

                        else if (id == (byte)SerializeId.CryptoAlgorithm)
                        {
                            this.CryptoAlgorithm = (CryptoAlgorithm)Enum.Parse(typeof(CryptoAlgorithm), ItemUtilities.GetString(rangeStream));
                        }
                        else if (id == (byte)SerializeId.CryptoKey)
                        {
                            this.CryptoKey = ItemUtilities.GetByteArray(rangeStream);
                        }

                        else if (id == (byte)SerializeId.Certificate)
                        {
                            this.Certificate = Certificate.Import(rangeStream, bufferManager);
                        }
                    }
                }
            }
        }