/// <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(System.IO.Stream media, MLifter.DAL.Interfaces.EMedia type, MLifter.DAL.Tools.StatusMessageReportProgress rpu, object caller) { int newId; SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser); cmd.CommandText = "INSERT INTO MediaContent (data, media_type) VALUES (@data, @type); SELECT @@IDENTITY;"; cmd.Parameters.Add("@data", SqlDbType.Image); cmd.Parameters.Add("@type", SqlDbType.NVarChar, 100); cmd.Parameters["@data"].Value = GetByteArrayFromStream(media, rpu, caller); cmd.Parameters["@type"].Value = type.ToString(); newId = Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)); return newId; }
/// <summary> /// Sets a single property value for a media object. /// </summary> /// <param name="id">The id.</param> /// <param name="property">The property.</param> /// <param name="value">The value.</param> /// <remarks>Documented by Dev02, 2008-08-07</remarks> /// <remarks>Documented by Dev03, 2009-01-13</remarks> public void SetPropertyValue(int id, MLifter.DAL.Interfaces.MediaProperty property, string value) { SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser); SqlCeTransaction tran = cmd.Connection.BeginTransaction(); if (GetPropertyValue(id, property) == null) cmd.CommandText = "INSERT INTO MediaProperties (media_id, property, value) VALUES (@media_id, @property, @value);"; else cmd.CommandText = "UPDATE MediaProperties SET value=@value WHERE media_id=@media_id AND property=@property;"; Dictionary<MediaProperty, string> properties = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.MediaProperties, id)] as Dictionary<MediaProperty, string>; if (properties == null) properties = new Dictionary<MediaProperty, string>(); properties[property] = value; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.MediaProperties, id, new TimeSpan(1, 0, 0))] = properties; cmd.Parameters.Add("@media_id", id); cmd.Parameters.Add("@property", property.ToString()); cmd.Parameters.Add("@value", value); MSSQLCEConn.ExecuteNonQuery(cmd); tran.Commit(); }
public void SetCardMedia(int id, int cardid, MLifter.DAL.Interfaces.Side side, MLifter.DAL.Interfaces.WordType type, bool isDefault, MLifter.DAL.Interfaces.EMedia mediatype) { using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser)) { SqlCeTransaction tran = cmd.Connection.BeginTransaction(); ClearCardMedia(cardid, side, type, mediatype); cmd.CommandText = "INSERT INTO \"Cards_MediaContent\" (media_id, cards_id, side, type, is_default) " + "VALUES (@mediaid, @cardid, @side, @type, @isdefault);"; cmd.Parameters.Add("@mediaid", id); cmd.Parameters.Add("@cardid", cardid); cmd.Parameters.Add("@side", side.ToString()); cmd.Parameters.Add("@type", type.ToString()); cmd.Parameters.Add("@isdefault", isDefault); MSSQLCEConn.ExecuteNonQuery(cmd); tran.Commit(); } Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid)); }