Esempio n. 1
0
        /// <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();
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a single property value for a media object.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="property">The property.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev02, 2008-08-07</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public string GetPropertyValue(int id, MLifter.DAL.Interfaces.MediaProperty property)
        {
            Dictionary <MediaProperty, string> properties = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.MediaProperties, id)] as Dictionary <MediaProperty, string>;

            if (properties != null && properties.ContainsKey(property))
            {
                return(properties[property]);
            }

            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "SELECT property, value FROM MediaProperties WHERE media_id=@id";
            cmd.Parameters.Add("@id", id);
            SqlCeDataReader reader = MSSQLCEConn.ExecuteReader(cmd);

            properties = new Dictionary <MediaProperty, string>();
            while (reader.Read())
            {
                properties[(MediaProperty)Enum.Parse(typeof(MediaProperty), reader["property"].ToString())] = reader["value"].ToString();
            }

            reader.Close();
            Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.MediaProperties, id, new TimeSpan(1, 0, 0))] = properties;

            if (properties.ContainsKey(property))
            {
                return(properties[property]);
            }
            else
            {
                return(null);
            }
        }