Dispose() приватный Метод

private Dispose ( bool disposing ) : void
disposing bool
Результат void
        /// <summary>
        /// A portion of the file contents have been received. This method will
        /// be called multiple times until the download is complete. Return
        /// |true| to continue receiving data and |false| to cancel.
        /// </summary>
        private int received_data(cef_download_handler_t* self, void* data, int data_size)
        {
            ThrowIfObjectDisposed();

            var m_stream = new UnmanagedMemoryStream((byte*)data, data_size, data_size, FileAccess.Read);

            var handled = this.ReceivedData(m_stream);

            m_stream.Dispose();

            return handled ? 1 : 0;
        }
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing)
             _unmanagedStream.Dispose();
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
        /// <summary>
        /// Set |substitute_data| to the replacement for the data in |data| if
        /// data should be modified.
        /// </summary>
        private void process_data(cef_content_filter_t* self, /*const*/ void* data, int data_size, cef_stream_reader_t** substitute_data)
        {
            ThrowIfObjectDisposed();

            var m_stream = new UnmanagedMemoryStream((byte*)data, data_size, data_size, FileAccess.Read);
            CefStreamReader m_substitute_data;

            this.ProcessData(m_stream, out m_substitute_data);

            if (m_substitute_data != null)
            {
                *substitute_data = m_substitute_data.GetNativePointerAndAddRef();
            }

            m_stream.Dispose();
        }
Пример #4
0
        protected unsafe void InitDna(byte[] bdnaOrg)
        {
            if (_dna != IntPtr.Zero)
            {
                return;
            }

            _dnaLength = bdnaOrg.Length;
            _dna = Marshal.AllocHGlobal(bdnaOrg.Length);
            Marshal.Copy(bdnaOrg, 0, _dna, _dnaLength);

            Stream stream = new UnmanagedMemoryStream((byte*)_dna.ToPointer(), _dnaLength);
            BinaryReader reader = new BinaryReader(stream);

            // SDNA
            byte[] code = reader.ReadBytes(8);
            string codes = ASCIIEncoding.ASCII.GetString(code);

            // NAME
            if (!codes.Equals("SDNANAME"))
            {
                throw new InvalidDataException();
            }
            int dataLen = reader.ReadInt32();
            _names = new Dna.NameInfo[dataLen];
            for (int i = 0; i < dataLen; i++)
            {
                List<byte> name = new List<byte>();
                byte ch = reader.ReadByte();
                while (ch != 0)
                {
                    name.Add(ch);
                    ch = reader.ReadByte();
                }

                _names[i] = new Dna.NameInfo(ASCIIEncoding.ASCII.GetString(name.ToArray()));
            }
            stream.Position = (stream.Position + 3) & ~3;

            // TYPE
            code = reader.ReadBytes(4);
            codes = ASCIIEncoding.ASCII.GetString(code);
            if (!codes.Equals("TYPE"))
            {
                throw new InvalidDataException();
            }
            dataLen = reader.ReadInt32();
            _types = new Dna.TypeDecl[dataLen];
            for (int i = 0; i < dataLen; i++)
            {
                List<byte> name = new List<byte>();
                byte ch = reader.ReadByte();
                while (ch != 0)
                {
                    name.Add(ch);
                    ch = reader.ReadByte();
                }
                string type = ASCIIEncoding.ASCII.GetString(name.ToArray());
                _types[i] = new Dna.TypeDecl(type);
            }
            stream.Position = (stream.Position + 3) & ~3;

            // TLEN
            code = reader.ReadBytes(4);
            codes = ASCIIEncoding.ASCII.GetString(code);
            if (!codes.Equals("TLEN"))
            {
                throw new InvalidDataException();
            }
            for (int i = 0; i < _types.Length; i++)
            {
                _types[i].Length = reader.ReadInt16();
            }
            stream.Position = (stream.Position + 3) & ~3;

            // STRC
            code = reader.ReadBytes(4);
            codes = ASCIIEncoding.ASCII.GetString(code);
            if (!codes.Equals("STRC"))
            {
                throw new InvalidDataException();
            }
            dataLen = reader.ReadInt32();
            _structs = new Dna.StructDecl[dataLen];
            long shtPtr = stream.Position;
            for (int i = 0; i < dataLen; i++)
            {
                Dna.StructDecl structDecl = new Dna.StructDecl();
                _structs[i] = structDecl;
                if (!BitConverter.IsLittleEndian)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    short typeNr = reader.ReadInt16();
                    structDecl.Type = _types[typeNr];
                    structDecl.Type.Struct = structDecl;
                    int numElements = reader.ReadInt16();
                    structDecl.Elements = new Dna.ElementDecl[numElements];
                    for (int j = 0; j < numElements; j++)
                    {
                        typeNr = reader.ReadInt16();
                        short nameNr = reader.ReadInt16();
                        structDecl.Elements[j] = new Dna.ElementDecl(_types[typeNr], _names[nameNr]);
                    }
                }
            }

            reader.Dispose();
            stream.Dispose();

            // build reverse lookups
            _structReverse = new Dictionary<string, Dna.StructDecl>(_structs.Length);
            foreach (Dna.StructDecl s in _structs)
            {
                _structReverse.Add(s.Type.Name, s);
            }
        }
        public override void Open(string filePath)
        {
            _content = File.ReadAllText(filePath);

            int i = _content.IndexOf("%!");

            if (i > 0)
            {
                _content = _content.Substring(i, _content.Length - i - 1);
            }

            i = _content.IndexOf("%%EOF");

            if (i > -1)
            {
                _content = _content.Substring(0, i + 5);
            }

            if (this.Viewer.EPSClip)
            {
                unsafe
                {
                    fixed (char* p = _content)
                    {
                        UnmanagedMemoryStream ums = new UnmanagedMemoryStream((byte*)p, _content.Length);
                        DSCTokenizer tokenizer = new DSCTokenizer(ums, true, BitConverter.IsLittleEndian);

                        DSCToken token = null;

                        while ((token = tokenizer.GetNextDSCKeywordToken()) != null)
                        {
                            if (token.Text == "%%BoundingBox:")
                            {
                                try
                                {
                                    DSCToken v1 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);
                                    DSCToken v2 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);
                                    DSCToken v3 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);
                                    DSCToken v4 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);

                                    this.BoundingBox = new GhostscriptRectangle(
                                            float.Parse(v1.Text, System.Globalization.CultureInfo.InvariantCulture),
                                            float.Parse(v2.Text, System.Globalization.CultureInfo.InvariantCulture),
                                            float.Parse(v3.Text, System.Globalization.CultureInfo.InvariantCulture),
                                            float.Parse(v4.Text, System.Globalization.CultureInfo.InvariantCulture));
                                }
                                catch { }

                                break;
                            }
                        }

                        tokenizer.Dispose(); tokenizer = null;
                        ums.Close(); ums.Dispose(); ums = null;
                    }
                }
            }

            this.FirstPageNumber = 1;
            this.LastPageNumber = 1;
        }
        //returns bitmap image converted from the PANGU stream
        public Bitmap getImage(float x, float y, float z, float yaw, float pitch, float roll , float fov)
        {
            try
            {
                unsafe
                {
                    pan_protocol_set_aspect_ratio(sock, 1);     //sets aspect ratio
                    pan_protocol_set_boulder_view(sock, 1, 0);  //view boulders
                    pan_protocol_set_field_of_view(sock, fov);  //set field of view

                    ulong t = 1024;
                    char* img;
                    img = pan_protocol_get_viewpoint_by_angle(sock, x, y, z, yaw, pitch, roll, &t); //gets the image
                    UnmanagedMemoryStream readStream = new UnmanagedMemoryStream((byte*)img, (long)t);

                    Bitmap bitmap = fetchImage(readStream);
                    readStream.Close();
                    readStream.Dispose();
                    return bitmap;
                }
            }
            catch
            {
                return null; //Error at PANGU end.
            }
        }