예제 #1
0
        /// <summary>
        /// Loads the parts for the specfied media item
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="mediaItemId">Unique identifier of the media item</param>
        /// <param name="mediaItemType">Type of the media item</param>
        /// <returns>Collection of parts belonging to the specified media item, sorted ascendingly</returns>
        public static Business.MediaItemPartCollection GetMediaItemPartsById(SqlConnection conn, Int64 mediaItemId, Business.MediaItemTypeEnum mediaItemType)
        {
            try
            {
                List <sp.Parameter> parameters = new List <sp.Parameter>();
                parameters.Add(new sp.Parameter("MediaItemId", DbType.Int64, mediaItemId));
                parameters.Add(new sp.Parameter("MediaItemType", DbType.Int16, Convert.ToInt16(mediaItemType)));

                sp.DataTable table = SqlDbObject.ExecuteReader("GetMediaItemPartsById", CommandType.StoredProcedure, parameters.ToArray(), conn);
                Business.MediaItemPartCollection parts = new Business.MediaItemPartCollection();

                foreach (sp.DataRow row in table)
                {
                    IntelligentString location     = (String)row["Location"];
                    Int64             size         = (Int64)row["Size"];
                    Int32             milliseconds = (Int32)row["Duration"];
                    Int16             index        = (Int16)row["Index"];

                    parts.Add(location, size, milliseconds, index);
                }

                parts.Sort();
                return(parts);
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load play history for media item", e);
            }
        }
예제 #2
0
        /// <summary>
        /// Executes a command and maps each row to an object
        /// </summary>
        /// <typeparam name="T">Type of object to map the data to</typeparam>
        /// <typeparam name="TIdType">Type of the unique identifier of the object</typeparam>
        /// <returns>Each row selected by the command, mapped to an object</returns>
        public T[] ExecuteMappedReader <T, TIdType>() where T : DbObject <TIdType>
        {
            sp.DataTable table = ExecuteReader();

            return(ExecuteMappedReader <T>(table, row =>
            {
                return ExecuteMappedSingleReader <T, TIdType>(connection, row);
            }));
        }
예제 #3
0
        /// <summary>
        /// Executes a command and returns the only row selected
        /// </summary>
        /// <returns>The only row selected by the command</returns>
        public sp.DataRow ExecuteSingleReader()
        {
            sp.DataTable dt = ExecuteReader();

            if (dt.RowCount != 1)
            {
                throw new Exception.SpecifiedSqlDbObjectNotFoundException(String.Format("{0} rows found in the database", dt.RowCount));
            }

            return(dt[0]);
        }
예제 #4
0
        /// <summary>
        /// Maps each row in a data table to an object
        /// </summary>
        /// <typeparam name="T">Type of object to map the data to</typeparam>
        /// <param name="table">Data table containing the rows being mapped</param>
        /// <param name="mapper">Mapper used to map the data to an object</param>
        /// <returns>Each row in the data table, mapped to an object</returns>
        private static T[] ExecuteMappedReader <T>(sp.DataTable table, Func <sp.DataRow, T> mapper)
        {
            List <T> items = new List <T>();

            foreach (sp.DataRow dr in table)
            {
                items.Add(mapper(dr));
            }

            if ((typeof(IComparable).IsAssignableFrom(typeof(T))) || (typeof(IComparable <T>).IsAssignableFrom(typeof(T))))
            {
                items.Sort();
            }

            return(items.ToArray());
        }
예제 #5
0
        /// <summary>
        /// Executes a command and maps each row to an object
        /// </summary>
        /// <typeparam name="T">Type of object to map the data to</typeparam>
        /// <typeparam name="TIdType">Type of the unique identifier of the object</typeparam>
        /// <param name="mapper">Mapper used to map the data to an object</param>
        /// <returns>Each row selected by the command, mapped to an object</returns>
        public T[] ExecuteMappedReader <T, TIdType>(Func <sp.DataRow, T> mapper)
        {
            sp.DataTable dt = ExecuteReader();

            return(ExecuteMappedReader <T>(dt, row =>
            {
                T item = mapper(row);

                DbObject <TIdType> dbObject = item as DbObject <TIdType>;

                if (dbObject != null)
                {
                    dbObject.SetIsInDatabase(true);
                }

                return item;
            }));
        }
예제 #6
0
        /// <summary>
        /// Gets all file types in the system
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <returns>All file types in the system</returns>
        public static Business.FileType[] GetFileTypes(SqlConnection conn)
        {
            try
            {
                sp.DataTable             dt        = SqlDbObject.ExecuteReader("GetFileTypes", CommandType.StoredProcedure, conn);
                List <Business.FileType> fileTypes = new List <Business.FileType>();

                foreach (sp.DataRow dr in dt)
                {
                    fileTypes.Add(Business.FileType.FromDataRow(conn, dr));
                }

                fileTypes.Sort();
                return(fileTypes.ToArray());
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load file types", e);
            }
        }
예제 #7
0
        /// <summary>
        /// Gets the extensions in the database for the specified file type
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="fileType">File type who's extensions are being loaded</param>
        /// <returns>Extensions in the database for the specified file type</returns>
        public static Business.FileExtensionCollection GetExtensionsByFileTypeId(SqlConnection conn, Int16 fileTypeId)
        {
            try
            {
                sp.DataTable dt = SqlDbObject.ExecuteReader("GetExtensionsByFileTypeId", CommandType.StoredProcedure, new sp.Parameter("FileTypeId", DbType.Int16, fileTypeId), conn);
                Business.FileExtensionCollection extensions = new Business.FileExtensionCollection();

                foreach (sp.DataRow dr in dt)
                {
                    extensions.extensions.Add((String)dr["Extension"]);
                }

                extensions.Sort();
                return(extensions);
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load extensions for file type", e);
            }
        }
예제 #8
0
        /// <summary>
        /// Loads a file type from the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="fileTypeId">Unique identifier of the file type being loaded</param>
        /// <returns>FileType object loaded from the database</returns>
        public static Business.FileType GetFileTypeById(SqlConnection conn, Int16 fileTypeId)
        {
            try
            {
                sp.DataTable dt = SqlDbObject.ExecuteReader("GetFileTypeById", CommandType.StoredProcedure, new sp.Parameter("FileTypeId", DbType.Int16, fileTypeId), conn);

                if (dt.RowCount == 1)
                {
                    return(Business.FileType.FromDataRow(conn, dt[0]));
                }
                else
                {
                    throw new SpecifiedSqlDbObjectNotFoundException("GetFileTypeById returned " + dt.RowCount.ToString() + " rows");
                }
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load specified file type", e);
            }
        }
예제 #9
0
        /// <summary>
        /// Gets all root folders in the system that are associated with the specified type
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="mediaItemType">Type associated with the desired root folders</param>
        /// <returns>All root folders in the system that are associated with the specified type</returns>
        public static Business.RootFolder[] GetRootFoldersByType(SqlConnection conn, Business.MediaItemTypeEnum mediaItemType)
        {
            try
            {
                sp.DataTable dt = SqlDbObject.ExecuteReader("GetRootFoldersByType", CommandType.StoredProcedure, new sp.Parameter("MediaItemType", DbType.Int16, Convert.ToInt16(mediaItemType)), conn);
                List <Business.RootFolder> rootFolders = new List <Business.RootFolder>();

                foreach (sp.DataRow row in dt)
                {
                    rootFolders.Add(Business.RootFolder.FromDataRow(conn, row));
                }

                rootFolders.Sort();
                return(rootFolders.ToArray());
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load root folders", e);
            }
        }
예제 #10
0
        /// <summary>
        /// Loads a song from the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="songId">Unique identifier of the song being loaded</param>
        /// <returns>Song object loaded from the database</returns>
        public static Business.Song GetSongById(SqlConnection conn, Int64 songId)
        {
            try
            {
                sp.DataTable dt = SqlDbObject.ExecuteReader("GetSongById", CommandType.StoredProcedure, new sp.Parameter("SongId", DbType.Int64, songId), conn);

                if (dt.RowCount == 1)
                {
                    return(Business.MediaItem.FromDataRow(conn, dt[0]) as Business.Song);
                }
                else
                {
                    throw new SpecifiedSqlDbObjectNotFoundException("GetSongById returned " + dt.RowCount.ToString() + " rows");
                }
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load specified song", e);
            }
        }
예제 #11
0
        /// <summary>
        /// Gets all media items in the system
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <returns>All media items in the system</returns>
        public static Business.MediaItem[] GetMediaItems(SqlConnection conn)
        {
            try
            {
                sp.DataTable dt = SqlDbObject.ExecuteReader("GetMediaItems", CommandType.StoredProcedure, conn);
                List <Business.MediaItem> mediaItems = new List <Business.MediaItem>();

                foreach (sp.DataRow dr in dt)
                {
                    mediaItems.Add(Business.MediaItem.FromDataRow(conn, dr));
                }

                mediaItems.Sort();

                return(mediaItems.ToArray());
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load media items", e);
            }
        }
예제 #12
0
        /// <summary>
        /// Gets all deleted song iTunes IDs from the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <returns>All deleted song iTunes IDs from the database</returns>
        public static Int16[] GetDeletedSongITunesIds(SqlConnection conn)
        {
            try
            {
                sp.DataTable table = SqlDbObject.ExecuteReader("GetDeletedSongITunesIds", CommandType.StoredProcedure, conn);

                List <Int16> deletedSongITunesIds = new List <Int16>();

                foreach (sp.DataRow row in table)
                {
                    deletedSongITunesIds.Add((Int16)row["iTunesId"]);
                }

                deletedSongITunesIds.Sort();
                return(deletedSongITunesIds.ToArray());
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not get deleted song iTunes IDs", e);
            }
        }
예제 #13
0
        /// <summary>
        /// Loads the tags for the specfied root folder
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="mediaItemType">Type associated with the root folder the tags are being loaded for</param>
        /// <param name="rootFolderPriority">Priority of the root folder the tags are being loaded for</param>
        /// <returns>Collection of tags assigned to the specified root folder, sorted ascendingly</returns>
        public static IntelligentString[] GetRootFolderTagsByPriority(SqlConnection conn, Business.MediaItemTypeEnum mediaItemType, Int16 rootFolderPriority)
        {
            try
            {
                List <sp.Parameter> parameters = new List <sp.Parameter>();
                parameters.Add(new sp.Parameter("RootFolderPriority", DbType.Int16, rootFolderPriority));
                parameters.Add(new sp.Parameter("MediaItemType", DbType.Int16, Convert.ToInt16(mediaItemType)));

                sp.DataTable             table = SqlDbObject.ExecuteReader("GetRootFolderTagsByPriority", CommandType.StoredProcedure, parameters.ToArray(), conn);
                List <IntelligentString> tags  = new List <IntelligentString>();

                foreach (sp.DataRow row in table)
                {
                    tags.Add((String)row["Tag"]);
                }

                tags.Sort();
                return(tags.ToArray());
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load tags for root folder", e);
            }
        }
예제 #14
0
        /// <summary>
        /// Gets the root folder from the database with the specified priority
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="mediaItemType">Type of media item the desired root folder is associated with</param>
        /// <param name="priority">Priority of the desired root folder</param>
        /// <returns>Root folder in the database with the specified priority</returns>
        public static Business.RootFolder GetRootFolderByPriority(SqlConnection conn, Business.MediaItemTypeEnum mediaItemType, Int16 priority)
        {
            try
            {
                List <sp.Parameter> parameters = new List <sp.Parameter>();
                parameters.Add(new sp.Parameter("MediaItemType", DbType.Int16, Convert.ToInt16(mediaItemType)));
                parameters.Add(new sp.Parameter("Priority", DbType.Int16, priority));

                sp.DataTable dt = SqlDbObject.ExecuteReader("GetRootFolderByPriority", CommandType.StoredProcedure, parameters.ToArray(), conn);

                if (dt.RowCount == 1)
                {
                    return(Business.RootFolder.FromDataRow(conn, dt[0]));
                }
                else
                {
                    throw new SpecifiedSqlDbObjectNotFoundException("GetRootFolderByPriority returned " + dt.RowCount.ToString() + " rows");
                }
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load specified root folder", e);
            }
        }
예제 #15
0
        /// <summary>
        /// Loads the play history for the specfied media item
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="mediaItemId">Unique identifier of the media item having it's play history loaded</param>
        /// <param name="mediaItemType">Type of media item having it's play history loaded</param>
        /// <returns>Collection of dates and times the specified media item has been played, sorted ascendingly</returns>
        public static DateTime[] GetMediaItemPlayHistoryById(SqlConnection conn, Int64 mediaItemId, Business.MediaItemTypeEnum mediaItemType)
        {
            try
            {
                List <sp.Parameter> parameters = new List <sp.Parameter>();
                parameters.Add(new sp.Parameter("MediaItemId", DbType.Int64, mediaItemId));
                parameters.Add(new sp.Parameter("MediaItemType", DbType.Int16, Convert.ToInt16(mediaItemType)));

                sp.DataTable    table       = SqlDbObject.ExecuteReader("GetMediaItemPlayHistoryById", CommandType.StoredProcedure, parameters.ToArray(), conn);
                List <DateTime> playHistory = new List <DateTime>();

                foreach (sp.DataRow row in table)
                {
                    playHistory.Add((DateTime)row["DatePlayed"]);
                }

                playHistory.Sort();
                return(playHistory.ToArray());
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load play history for media item", e);
            }
        }