コード例 #1
0
        public Image getImagen(int id_voluntario)
        {
            Image   ret    = null;
            CnxBase myBase = new CnxBase();
            string  reqSQL = "SELECT foto FROM z_voluntarios WHERE id_voluntario=" + id_voluntario;

            try
            {
                NpgsqlConnection myConn    = myBase.OpenConnection(myBase.cnxString);
                NpgsqlCommand    myCommand = new NpgsqlCommand(reqSQL, myConn);
                NpgsqlDataReader myReader  = myCommand.ExecuteReader();
                if (myReader.Read() && myReader[0] != DBNull.Value)
                {
                    NpgsqlTransaction t = myConn.BeginTransaction();
                    NpgsqlTypes.LargeObjectManager lbm = new NpgsqlTypes.LargeObjectManager(myConn);
                    NpgsqlTypes.LargeObject        lo  = lbm.Open(Convert.ToInt32(myReader[0]), NpgsqlTypes.LargeObjectManager.READ);
                    byte[] buf = new byte[lo.Size()];
                    buf = lo.Read(lo.Size());
                    MemoryStream ms = new MemoryStream();
                    ms.Write(buf, 0, lo.Size());
                    lo.Close();
                    t.Commit();
                    ret = Image.FromStream(ms);
                }
                myConn.Close();
            }
            catch (Exception myErr)
            {
                throw (new Exception(myErr.ToString() + reqSQL));
            }
            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Gets the contents of a LargeObject into a buffer.
        /// </summary>
        /// <param name="largeObject">The large object.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev02, 2008-08-08</remarks>
        private byte[] LargeObjectToBuffer(LargeObject largeObject)
        {
            largeObject.Seek(0);
            int size = largeObject.Size();
            byte[] buffer = new byte[size];

            int offset = 0;
            while (offset < size)
            {
                largeObject.Read(buffer, offset, Math.Min(chunkSize, size - offset));
                offset += chunkSize;
            }

            return buffer;
        }
コード例 #3
0
        /// <summary>
        /// Writes the content of a buffer into a LargeObject.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="largeObject">The large object.</param>
        /// <param name="rpu">The rpu.</param>
        /// <param name="caller">The calling object.</param>
        /// <remarks>Documented by Dev02, 2008-08-08</remarks>
        private void BufferToLargeObject(byte[] buffer, LargeObject largeObject, StatusMessageReportProgress rpu, object caller)
        {
            largeObject.Seek(0);

            int offset = 0;
            int size = buffer.Length;
            StatusMessageEventArgs args = new StatusMessageEventArgs(StatusMessageType.CreateMediaProgress, buffer.Length);
            while (offset < size)
            {
                largeObject.Write(buffer, offset, Math.Min(chunkSize, size - offset));
                offset += chunkSize;
                args.Progress = offset;
                if (rpu != null)
                    rpu(args, caller);
            }
        }
コード例 #4
0
        /// <summary>
        /// Writes the content of a buffer into a LargeObject.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="largeObject">The large object.</param>
        /// <remarks>Documented by Dev02, 2008-08-08</remarks>
        private void BufferToLargeObject(byte[] buffer, LargeObject largeObject)
        {
            largeObject.Seek(0);

            int offset = 0;
            int size = buffer.Length;
            while (offset < size)
            {
                largeObject.Write(buffer, offset, Math.Min(chunkSize, size - offset));
                offset += chunkSize;
            }
        }
コード例 #5
0
ファイル: DB.cs プロジェクト: joewstroman/monkeywrench
			public DBFileStream (DBFile file, DB db)
			{
				try {
					transaction = db.dbcon.BeginTransaction ();
					obj = db.Manager.Open (file.file_id.Value);
				} catch {
					if (transaction != null) {
						transaction.Rollback ();
						transaction = null;
					}
				}
			}