示例#1
0
        /// <summary>
        /// Creates a new media object.
        /// </summary>
        /// <param name="media">The memory stream containing the media.</param>
        /// <param name="type">The media type.</param>
        /// <param name="rpu">A delegate of type <see cref="StatusMessageReportProgress"/> used to send messages back to the calling object.</param>
        /// <param name="caller">The calling object.</param>
        /// <returns>The id for the new media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public int CreateMedia(Stream media, EMedia type, StatusMessageReportProgress rpu, object caller)
        {
            using (NpgsqlConnection conn = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                NpgsqlTransaction tran = conn.BeginTransaction();

                LargeObjectManager lbm  = new LargeObjectManager(conn);
                int         noid        = lbm.Create(LargeObjectManager.READWRITE);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[]      buffer      = new byte[media.Length];
                media.Read(buffer, 0, (int)media.Length);
                BufferToLargeObject(buffer, largeObject, rpu, caller);
                largeObject.Close();

                int newId = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"MediaContent\" (data, media_type) VALUES (:data, :type) RETURNING id;";
                    cmd.Parameters.Add("data", noid);
                    cmd.Parameters.Add("type", type.ToString());
                    newId = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }
                tran.Commit();

                return(newId);
            }
        }
示例#2
0
        public void ClearCardMedia(int cardid, Side side, WordType type, EMedia mediatype)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                cmd.CommandText = "DELETE FROM \"Cards_MediaContent\" WHERE cards_id=@cardid AND side=@side AND type=@type " +
                                  "AND media_id IN (SELECT id FROM \"MediaContent\" WHERE media_type=@mediatype);";
                cmd.Parameters.Add("@cardid", cardid);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@mediatype", mediatype.ToString());
                cmd.ExecuteNonQuery();
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }
        public void ClearCardMedia(int cardid, Side side, WordType type, EMedia mediatype)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "DELETE FROM \"Cards_MediaContent\" WHERE cards_id=:cardid AND side=:side AND type=:type " +
                                      "AND media_id IN (SELECT id FROM \"MediaContent\" WHERE media_type=:mediatype);";
                    cmd.Parameters.Add("cardid", cardid);
                    cmd.Parameters.Add("side", side.ToString());
                    cmd.Parameters.Add("type", type.ToString());
                    cmd.Parameters.Add("mediatype", mediatype.ToString());
                    cmd.ExecuteNonQuery();
                }
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }
        /// <summary>
        /// Creates a new media object.
        /// </summary>
        /// <param name="media">The memory stream containing the media.</param>
        /// <param name="type">The media type.</param>
        /// <param name="rpu">A delegate of type <see cref="StatusMessageReportProgress"/> used to send messages back to the calling object.</param>
        /// <param name="caller">The calling object.</param>
        /// <returns>The id for the new media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public int CreateMedia(Stream media, EMedia type, StatusMessageReportProgress rpu, object caller)
        {
            using (NpgsqlConnection conn = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                NpgsqlTransaction tran = conn.BeginTransaction();

                LargeObjectManager lbm = new LargeObjectManager(conn);
                int noid = lbm.Create(LargeObjectManager.READWRITE);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[] buffer = new byte[media.Length];
                media.Read(buffer, 0, (int)media.Length);
                BufferToLargeObject(buffer, largeObject, rpu, caller);
                largeObject.Close();

                int newId = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"MediaContent\" (data, media_type) VALUES (:data, :type) RETURNING id;";
                    cmd.Parameters.Add("data", noid);
                    cmd.Parameters.Add("type", type.ToString());
                    newId = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }
                tran.Commit();

                return newId;
            }
        }
        public void ClearCardMedia(int cardid, Side side, WordType type, EMedia mediatype)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "DELETE FROM \"Cards_MediaContent\" WHERE cards_id=:cardid AND side=:side AND type=:type " +
                        "AND media_id IN (SELECT id FROM \"MediaContent\" WHERE media_type=:mediatype);";
                    cmd.Parameters.Add("cardid", cardid);
                    cmd.Parameters.Add("side", side.ToString());
                    cmd.Parameters.Add("type", type.ToString());
                    cmd.Parameters.Add("mediatype", mediatype.ToString());
                    cmd.ExecuteNonQuery();
                }
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }
        public void ClearCardMedia(int cardid, Side side, WordType type, EMedia mediatype)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                cmd.CommandText = "DELETE FROM \"Cards_MediaContent\" WHERE cards_id=@cardid AND side=@side AND type=@type " +
                    "AND media_id IN (SELECT id FROM \"MediaContent\" WHERE media_type=@mediatype);";
                cmd.Parameters.Add("@cardid", cardid);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@mediatype", mediatype.ToString());
                cmd.ExecuteNonQuery();
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }