Example #1
0
        /// <summary>
        /// Gets the media.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="cacheConnector">The cache connector.</param>
        /// <returns>A memory stream for the media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public System.IO.Stream GetMediaStream(int id, IDbMediaConnector cacheConnector)
        {
            MemoryStream stream = null;
            SqlCeCommand cmd    = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=@id;";
            cmd.Parameters.Add("@id", id);
            byte[] media = (byte[])MSSQLCEConn.ExecuteScalar(cmd);
            if (media != null)
            {
                stream = new MemoryStream(media);
                stream.Seek(0, SeekOrigin.Begin);
            }
            return(stream);
        }
Example #2
0
        /// <summary>
        /// Gets the media.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="cacheConnector">The cache connector.</param>
        /// <returns>A memory stream for the media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public Stream GetMediaStream(int id, IDbMediaConnector cacheConnector)
        {
            CachingStream stream = null;

            using (NpgsqlConnection conn = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                int noid = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=:id;";
                    cmd.Parameters.Add("id", id);
                    noid = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }

                NpgsqlTransaction  tran        = conn.BeginTransaction();
                LargeObjectManager lbm         = new LargeObjectManager(conn);
                LargeObject        largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[]             buffer      = LargeObjectToBuffer(largeObject);
                stream = new CachingStream(buffer, id, cacheConnector);
                largeObject.Close();
                tran.Commit();
            }
            return(stream);
        }
        /// <summary>
        /// Gets the media.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="cacheConnector">The cache connector.</param>
        /// <returns>A memory stream for the media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public Stream GetMediaStream(int id, IDbMediaConnector cacheConnector)
        {
            CachingStream stream = null;
            using (NpgsqlConnection conn = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                int noid = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=:id;";
                    cmd.Parameters.Add("id", id);
                    noid = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }

                NpgsqlTransaction tran = conn.BeginTransaction();
                LargeObjectManager lbm = new LargeObjectManager(conn);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[] buffer = LargeObjectToBuffer(largeObject);
                stream = new CachingStream(buffer, id, cacheConnector);
                largeObject.Close();
                tran.Commit();
            }
            return stream;
        }
Example #4
0
 /// <summary>
 /// Gets the media.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="cacheConnector">The cache connector.</param>
 /// <returns>A memory stream for the media object.</returns>
 /// <remarks>Documented by Dev03, 2008-08-05</remarks>
 /// <remarks>Documented by Dev03, 2009-01-13</remarks>
 public System.IO.Stream GetMediaStream(int id, IDbMediaConnector cacheConnector)
 {
     MemoryStream stream = null;
     SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
     cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=@id;";
     cmd.Parameters.Add("@id", id);
     byte[] media = (byte[])MSSQLCEConn.ExecuteScalar(cmd);
     if (media != null)
     {
         stream = new MemoryStream(media);
         stream.Seek(0, SeekOrigin.Begin);
     }
     return stream;
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CachingStream"/> class.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="id">The id.</param>
 /// <param name="connector">The media connector.</param>
 /// <remarks>
 /// Documented by CFI, 2009-03-30
 /// </remarks>
 public CachingStream(byte[] buffer, int id, IDbMediaConnector connector)
     : base(buffer)
 {
     MediaId = id;
     MediaConnector = connector;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CachingStream"/> class.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="id">The id.</param>
 /// <param name="connector">The media connector.</param>
 /// <remarks>
 /// Documented by CFI, 2009-03-30
 /// </remarks>
 public CachingStream(byte[] buffer, int id, IDbMediaConnector connector)
     : base(buffer)
 {
     MediaId        = id;
     MediaConnector = connector;
 }