예제 #1
0
        /// <summary>
        /// Gets a Media Player.
        /// </summary>
        /// <param name="playerID">The ID of the Media Player.</param>
        /// <returns>The Media Player object.</returns>
        public static MediaPlayer Get(int playerId)
        {
            //Get the player for the provided PlayerID.
            List <MediaPlayer> playerList = LoadListFromReader(DBMediaPlayer.Select(playerId));


            //Make sure there was data found for the provided PlayerID.
            if (playerList.Count > 0)
            {
                MediaPlayer player = playerList[0];
                //There was data found, so populate the Media Tracks for the Player.
                player.MediaTracks = MediaTrack.GetForPlayer(player.PlayerId);

                return(player);
            }
            //else
            //{
            //    //The instance of the player was not located, present an exception.
            //    throw new ArgumentException("The Player ID of '" + playerID.ToString() + "' was not found.");
            //}

            //return thePlayer;

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Moves an AudioTrack up in the play order for the module
        /// </summary>
        /// <param name="playerID">The ModuleID of the Audio Player</param>
        /// <param name="trackOrder">The TrackOrder of the AudioTrack to be moved up</param>
        public static void MoveTrackDown(int playerId, int trackOrder)
        {
            if (trackOrder < GetCountForPlayer(playerId))
            {
                List <MediaTrack> tracks = GetForPlayer(playerId);

                //Find the MediaTrack to be moved up
                MediaTrack downTrack = new MediaTrack();
                foreach (MediaTrack mt in tracks)
                {
                    if (mt.TrackOrder == trackOrder)
                    {
                        downTrack = mt;
                    }
                }

                //Find the MediaTrack that is to be moved down
                MediaTrack upTrack = new MediaTrack();
                foreach (MediaTrack mt in tracks)
                {
                    if (mt.TrackOrder == downTrack.TrackOrder + 1)
                    {
                        upTrack = mt;
                    }
                }

                //Decrease the value to move the track up in the order, and increase the value to move the track up in the order.
                upTrack.TrackOrder--;
                downTrack.TrackOrder++;

                Update(upTrack);
                Update(downTrack);
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a list of MediaTracks from an IDataReader populated with Media Track data.
        /// </summary>
        /// <param name="reader">The IDataReader.</param>
        /// <returns>A List of MediaTracks.</returns>
        private static List <MediaTrack> LoadListFromReader(IDataReader reader)
        {
            List <MediaTrack> mediaTrackList = new List <MediaTrack>();

            try
            {
                while (reader.Read())
                {
                    MediaTrack mediaTrack = new MediaTrack();
                    mediaTrack.TrackId     = Convert.ToInt32(reader["TrackID"]);
                    mediaTrack.PlayerId    = Convert.ToInt32(reader["PlayerID"]);
                    mediaTrack.TrackType   = (MediaType)Enum.Parse(typeof(MediaType), reader["TrackType"].ToString());
                    mediaTrack.TrackOrder  = Convert.ToInt32(reader["TrackOrder"]);
                    mediaTrack.Name        = reader["Name"].ToString();
                    mediaTrack.Artist      = reader["Artist"].ToString();
                    mediaTrack.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]);
                    mediaTrack.UserGuid    = new Guid(reader["UserGuid"].ToString());
                    mediaTrackList.Add(mediaTrack);
                }
            }
            finally
            {
                reader.Close();
            }

            return(mediaTrackList);
        }
예제 #4
0
        /// <summary>
        /// Removes a MediaTrack
        /// </summary>
        /// <param name="mediaTrack">The MediaTrack.</param>
        /// <returns>True if the MediaTrack was successfully removed.</returns>
        public static bool Remove(MediaTrack mediaTrack)
        {
            //Delete the track from the database.
            bool successfulRemove = DBMediaTrack.Delete(mediaTrack.TrackId);

            //Adjust the TrackOrder values if the track delete was a success.
            if (successfulRemove)
            {
                DBMediaTrack.AdjustTrackOrdersForDelete(mediaTrack.PlayerId, mediaTrack.TrackOrder);
            }

            return(successfulRemove);
        }
예제 #5
0
        /// <summary>
        /// Updates a MediaTrack
        /// </summary>
        /// <param name="mediaTrack">The MediaTrack.</param>
        /// <returns>True if the the update is successful.</returns>
        public static bool Update(MediaTrack mediaTrack)
        {
            //Get the current persisted MediaTrack
            MediaTrack currentTrack = Get(mediaTrack.TrackId);

            //Update the MediaTrack
            bool isUpdated = DBMediaTrack.Update(
                mediaTrack.TrackId,
                mediaTrack.PlayerId,
                mediaTrack.TrackType.ToString(),
                mediaTrack.TrackOrder,
                mediaTrack.Name,
                mediaTrack.Artist,
                mediaTrack.UserGuid);

            //If the MediaTrack successfully updated, update the associated MediaFiles.
            if (isUpdated)
            {
                //Remove any MediaFiles that no longer exist.
                foreach (MediaFile currentFile in currentTrack.MediaFiles)
                {
                    bool matchFound = false;
                    foreach (MediaFile updatedFile in mediaTrack.MediaFiles)
                    {
                        if (currentFile.FileId == updatedFile.FileId)
                        {
                            matchFound = true;
                            break;
                        }
                    }

                    if (!matchFound)
                    {
                        MediaFile.Remove(currentFile);
                    }
                }

                //Add any MediaFiles that have not been persisted yet.
                foreach (MediaFile updatedFile in mediaTrack.MediaFiles)
                {
                    if (updatedFile.FileId <= 0)
                    {
                        updatedFile.FileId = MediaFile.Add(updatedFile);
                    }
                }
            }

            return(isUpdated);
        }
예제 #6
0
        public static bool Update(MediaPlayer mediaPlayer)
        {
            //Get the current persisted MediaPlayer
            MediaPlayer currentPlayer = Get(mediaPlayer.PlayerId);

            //Update the MediaPlayer
            bool isUpdated = DBMediaPlayer.Update(
                mediaPlayer.PlayerId,
                mediaPlayer.ModuleId,
                mediaPlayer.PlayerType.ToString(),
                mediaPlayer.SkinName,
                mediaPlayer.UserGuid,
                mediaPlayer.ModuleGuid);

            //If the MediaPlayer is successfully updated, update the associated MediaTracks.
            if (isUpdated)
            {
                //Remove any MediaTracks that no longer exist.
                foreach (MediaTrack currentTrack in currentPlayer.MediaTracks)
                {
                    bool matchFound = false;
                    foreach (MediaTrack updatedTrack in mediaPlayer.MediaTracks)
                    {
                        if (currentTrack.TrackId == updatedTrack.TrackId)
                        {
                            matchFound = true;
                            break;
                        }
                    }

                    if (!matchFound)
                    {
                        MediaTrack.Remove(currentTrack);
                    }
                }

                //Add any MediaTracks that have not been persisted yet.
                foreach (MediaTrack updatedTrack in mediaPlayer.MediaTracks)
                {
                    if (updatedTrack.TrackId <= 0)
                    {
                        updatedTrack.TrackId = MediaTrack.Add(updatedTrack);
                    }
                }
            }

            return(isUpdated);
        }
예제 #7
0
        /// <summary>
        /// Gets a Media Player associated to a Module.
        /// </summary>
        /// <param name="moduleID">The ID of the Module.</param>
        /// <returns>The MediaPlayer object.</returns>
        public static MediaPlayer GetForModule(int moduleId)
        {
            //Gets the player for the provided ModuleID
            List <MediaPlayer> playerList = LoadListFromReader(DBMediaPlayer.SelectByModule(moduleId));

            //Make sure there was data found for the provided ModuleID
            if (playerList.Count > 0)
            {
                MediaPlayer mediaPlayer = playerList[0];
                //The Player exists, so populate the Media Tracks for the Player.
                mediaPlayer.MediaTracks = MediaTrack.GetForPlayer(mediaPlayer.PlayerId);
                return(mediaPlayer);
            }

            return(null);
        }
예제 #8
0
        /// <summary>
        /// Gets a MediaTrack.
        /// </summary>
        /// <param name="trackID">The ID of the MediaTrack.</param>
        /// <returns>The MediaTrack object.</returns>
        public static MediaTrack Get(int trackId)
        {
            //Get the track for the provided trackID.
            List <MediaTrack> trackList  = LoadListFromReader(DBMediaTrack.Select(trackId));
            MediaTrack        mediaTrack = new MediaTrack();

            //Make sure there was data found
            if (trackList.Count > 0)
            {
                mediaTrack = trackList[0];
                //There was data found, so populate the Media Files for the Track.
                mediaTrack.MediaFiles = MediaFile.GetForTrack(trackId);
                return(mediaTrack);
            }


            return(null);
        }
예제 #9
0
        /// <summary>
        /// Adds a Media Player.
        /// </summary>
        /// <param name="mediaPlayer">The MediaPlayer.</param>
        /// <returns>The ID of the MediaPlayer.</returns>
        public static int Add(MediaPlayer mediaPlayer)
        {
            //Insert the MediaPlayer.
            int playerId = DBMediaPlayer.Insert(
                mediaPlayer.ModuleId,
                mediaPlayer.PlayerType.ToString(),
                mediaPlayer.SkinName,
                mediaPlayer.UserGuid,
                mediaPlayer.ModuleGuid);

            mediaPlayer.playerId = playerId;

            //Insert each of the MediaPlayer's MediaTracks.
            foreach (MediaTrack track in mediaPlayer.MediaTracks)
            {
                track.PlayerId = playerId;
                MediaTrack.Add(track);
            }

            return(playerId);
        }
예제 #10
0
        /// <summary>
        /// Adds a MediaTrack.
        /// </summary>
        /// <param name="mediaTrack">The MediaTrack.</param>
        /// <returns>The ID of the MediaTrack.</returns>
        public static int Add(MediaTrack mediaTrack)
        {
            //Insert the MediaTrack.
            int trackId = DBMediaTrack.Insert(
                mediaTrack.PlayerId,
                mediaTrack.TrackType.ToString(),
                mediaTrack.TrackOrder,
                mediaTrack.Name,
                mediaTrack.Artist,
                mediaTrack.UserGuid
                );

            mediaTrack.trackId = trackId;

            //Insert each of MediaTrack's MediaFiles.
            foreach (MediaFile file in mediaTrack.MediaFiles)
            {
                file.TrackId = trackId;
                MediaFile.Add(file);
            }

            return(trackId);
        }
예제 #11
0
        /// <summary>
        /// Updates a MediaTrack
        /// </summary>
        /// <param name="mediaTrack">The MediaTrack.</param>
        /// <returns>True if the the update is successful.</returns>
        public static bool Update(MediaTrack mediaTrack)
        {
            //Get the current persisted MediaTrack
            MediaTrack currentTrack = Get(mediaTrack.TrackId);

            //Update the MediaTrack
            bool isUpdated = DBMediaTrack.Update(
                mediaTrack.TrackId,
                mediaTrack.PlayerId,
                mediaTrack.TrackType.ToString(),
                mediaTrack.TrackOrder,
                mediaTrack.Name,
                mediaTrack.Artist,
                mediaTrack.UserGuid);

            //If the MediaTrack successfully updated, update the associated MediaFiles.
            if (isUpdated)
            {
                //Remove any MediaFiles that no longer exist.
                foreach (MediaFile currentFile in currentTrack.MediaFiles)
                {
                    bool matchFound = false;
                    foreach (MediaFile updatedFile in mediaTrack.MediaFiles)
                    {
                        if (currentFile.FileId == updatedFile.FileId)
                        {
                            matchFound = true;
                            break;
                        }
                    }

                    if (!matchFound)
                    {
                        MediaFile.Remove(currentFile);
                    }
                }

                //Add any MediaFiles that have not been persisted yet.
                foreach (MediaFile updatedFile in mediaTrack.MediaFiles)
                {
                    if (updatedFile.FileId <= 0)
                    {
                        updatedFile.FileId = MediaFile.Add(updatedFile);
                    }
                }
            }

            return isUpdated;
        }
예제 #12
0
        /// <summary>
        /// Removes a MediaTrack
        /// </summary>
        /// <param name="mediaTrack">The MediaTrack.</param>
        /// <returns>True if the MediaTrack was successfully removed.</returns>
        public static bool Remove(MediaTrack mediaTrack)
        {
            //Delete the track from the database.
            bool successfulRemove = DBMediaTrack.Delete(mediaTrack.TrackId);

            //Adjust the TrackOrder values if the track delete was a success.
            if (successfulRemove)
            {
                DBMediaTrack.AdjustTrackOrdersForDelete(mediaTrack.PlayerId, mediaTrack.TrackOrder);
            }

            return successfulRemove;
        }
예제 #13
0
        /// <summary>
        /// Moves an AudioTrack up in the play order for the module
        /// </summary>
        /// <param name="playerID">The ModuleID of the Audio Player</param>
        /// <param name="trackOrder">The TrackOrder of the AudioTrack to be moved up</param>
        public static void MoveTrackUp(int playerId, int trackOrder)
        {
            if (trackOrder > 1)
            {
                List<MediaTrack> tracks = GetForPlayer(playerId);

                //Find the MediaTrack to be moved up
                MediaTrack upTrack = new MediaTrack();
                foreach (MediaTrack mt in tracks)
                {
                    if (mt.TrackOrder == trackOrder)
                    {
                        upTrack = mt;
                    }
                }

                //Find the AudioTrack that is to be moved down
                MediaTrack downTrack = new MediaTrack();
                foreach (MediaTrack mt in tracks)
                {
                    if (mt.TrackOrder == upTrack.TrackOrder - 1)
                    {
                        downTrack = mt;
                    }
                }

                //Decrease the value to move the track up in the order, and increase the value to move the track up in the order.
                upTrack.TrackOrder--;
                downTrack.TrackOrder++;

                Update(upTrack);
                Update(downTrack);
            }
        }
예제 #14
0
        /// <summary>
        /// Gets a MediaTrack.
        /// </summary>
        /// <param name="trackID">The ID of the MediaTrack.</param>
        /// <returns>The MediaTrack object.</returns>
        public static MediaTrack Get(int trackId)
        {
            //Get the track for the provided trackID.
            List<MediaTrack> trackList = LoadListFromReader(DBMediaTrack.Select(trackId));
            MediaTrack mediaTrack = new MediaTrack();

            //Make sure there was data found
            if (trackList.Count > 0)
            {
                mediaTrack = trackList[0];
                //There was data found, so populate the Media Files for the Track.
                mediaTrack.MediaFiles = MediaFile.GetForTrack(trackId);
                return mediaTrack;
            }

            return null;
        }
예제 #15
0
        /// <summary>
        /// Adds a MediaTrack.
        /// </summary>
        /// <param name="mediaTrack">The MediaTrack.</param>
        /// <returns>The ID of the MediaTrack.</returns>
        public static int Add(MediaTrack mediaTrack)
        {
            //Insert the MediaTrack.
            int trackId = DBMediaTrack.Insert(
                mediaTrack.PlayerId,
                mediaTrack.TrackType.ToString(),
                mediaTrack.TrackOrder,
                mediaTrack.Name,
                mediaTrack.Artist,
                mediaTrack.UserGuid
                );

            mediaTrack.trackId = trackId;

            //Insert each of MediaTrack's MediaFiles.
            foreach (MediaFile file in mediaTrack.MediaFiles)
            {
                file.TrackId = trackId;
                MediaFile.Add(file);
            }

            return trackId;
        }
예제 #16
0
        void AddTrackButton_Click(object sender, EventArgs e)
        {
            if (SelectedFilesListBox.Items.Count > 0)
            {
                MediaTrack mt = new MediaTrack();

                //Populate the MediaTrack object.
                mt.PlayerId = thePlayer.PlayerId;
                mt.TrackType = thePlayer.PlayerType;
                mt.UserGuid = SiteUtils.GetCurrentSiteUser().UserGuid;
                mt.Name = TrackNameTextBox.Text;
                mt.Artist = ArtistTextBox.Text;
                mt.TrackOrder = TracksGridView.Rows.Count + 1;

                try
                {
                    //Add the MediaTrack
                    mt.TrackId = MediaTrack.Add(mt);

                    //Add the MediaFiles
                    foreach (ListItem filePath in SelectedFilesListBox.Items)
                    {
                        MediaFile mf = new MediaFile();
                        mf.TrackId = mt.TrackId;
                        if (filePath.Text.StartsWith("http"))
                            mf.FilePath = filePath.Text;
                        else
                            mf.FilePath = "~" + filePath.Text;
                        mf.UserGuid = mt.UserGuid;
                        MediaFile.Add(mf);
                    }

                    RedirectToThisPage();
                }
                catch (Exception ex)
                {
                    //Perform backout actions of anything already saved
                    //The Forgien key of the MediaFiles table is set up with a Cascading delete, so
                    //the deleting of the MediaTracks will also delete any related MediaFiles.
                    MediaTrack.RemoveForPlayer(thePlayer.PlayerId);
                    //Display error to user
                    AddTrackErrorLabel.Text = ex.Message;
                }
            }
            else
            {
                AtLeastOneFileSelectedValidator.IsValid = false;
                AddTrackErrorLabel.Text = MediaPlayerResources.AtLeastOneFileSelectedValidatorErrorMessage;
            }
        }
예제 #17
0
        /// <summary>
        /// Creates a list of MediaTracks from an IDataReader populated with Media Track data.
        /// </summary>
        /// <param name="reader">The IDataReader.</param>
        /// <returns>A List of MediaTracks.</returns>
        private static List<MediaTrack> LoadListFromReader(IDataReader reader)
        {
            List<MediaTrack> mediaTrackList = new List<MediaTrack>();

            try
            {
                while (reader.Read())
                {
                    MediaTrack mediaTrack = new MediaTrack();
                    mediaTrack.TrackId = Convert.ToInt32(reader["TrackID"]);
                    mediaTrack.PlayerId = Convert.ToInt32(reader["PlayerID"]);
                    mediaTrack.TrackType = (MediaType)Enum.Parse(typeof(MediaType), reader["TrackType"].ToString());
                    mediaTrack.TrackOrder = Convert.ToInt32(reader["TrackOrder"]);
                    mediaTrack.Name = reader["Name"].ToString();
                    mediaTrack.Artist = reader["Artist"].ToString();
                    mediaTrack.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]);
                    mediaTrack.UserGuid = new Guid(reader["UserGuid"].ToString());
                    mediaTrackList.Add(mediaTrack);
                }
            }
            finally
            {
                reader.Close();
            }

            return mediaTrackList;
        }
예제 #18
0
        private void LoadSettings()
        {
            thePlayer = MediaPlayer.GetForModule(moduleId);
            theTrack = MediaTrack.Get(trackId);

            // need to enforce that the track is connected to the player that is connected to the module instance
            if ((theTrack == null) || (thePlayer == null) || (theTrack.PlayerId != thePlayer.PlayerId))
            {
                // url manipulation hard redirect to current page
                Response.Redirect(SiteUtils.GetCurrentPageUrl(), true);
            }

            FilesObjectDataSource.SelectParameters.Add("trackID", TypeCode.Int32, theTrack.TrackId.ToInvariantString());

            if (thePlayer.PlayerType == MediaType.Audio)
            {
                MediaFileBrowser.BrowserType = "audio";
            }

            if (thePlayer.PlayerType == MediaType.Video)
            {
                MediaFileBrowser.BrowserType = "video";
            }
        }
예제 #19
0
        public void InstallContent(Module module, string configInfo)
        {
            if (string.IsNullOrEmpty(configInfo)) { return; }

            SiteSettings siteSettings = new SiteSettings(module.SiteId);
            SiteUser admin = SiteUser.GetNewestUser(siteSettings);

            XmlDocument xml = new XmlDocument();

            using (StreamReader stream = File.OpenText(HostingEnvironment.MapPath(configInfo)))
            {
                xml.LoadXml(stream.ReadToEnd());
            }

            MediaPlayer player = new MediaPlayer();
            player.ModuleGuid = module.ModuleGuid;
            player.ModuleId = module.ModuleId;
            player.PlayerType = MediaType.Audio;

            if ((xml.DocumentElement.Attributes["type"] != null) && (xml.DocumentElement.Attributes["type"].Value.Length > 0))
            {
                player.PlayerType = (MediaType)Enum.Parse(typeof(MediaType), xml.DocumentElement.Attributes["type"].Value);
            }

            MediaPlayer.Add(player);

            XmlNode tracksNode = null;
            foreach (XmlNode n in xml.DocumentElement.ChildNodes)
            {
                if (n.Name == "tracks")
                {
                    tracksNode = n;
                    break;
                }
            }

            if (tracksNode == null) { return; }

            foreach (XmlNode node in xml.DocumentElement.ChildNodes)
            {
                if (node.Name == "moduleSetting")
                {
                    XmlAttributeCollection settingAttributes = node.Attributes;

                    if ((settingAttributes["settingKey"] != null) && (settingAttributes["settingKey"].Value.Length > 0))
                    {
                        string key = settingAttributes["settingKey"].Value;
                        string val = string.Empty;
                        if (settingAttributes["settingValue"] != null)
                        {
                            val = settingAttributes["settingValue"].Value;
                            if ((key == "HeaderContent") || (key == "FooterContent"))
                            {
                                val = System.Web.HttpUtility.HtmlDecode(val);
                            }
                        }

                        ModuleSettings.UpdateModuleSetting(module.ModuleGuid, module.ModuleId, key, val);
                    }
                }
            }

            foreach (XmlNode trackNode in tracksNode.ChildNodes)
            {
                if (trackNode.Name == "track")
                {
                    XmlAttributeCollection trackAttrributes = trackNode.Attributes;

                    MediaTrack track = new MediaTrack();
                    track.PlayerId = player.PlayerId;
                    track.TrackType = player.PlayerType;

                    if ((trackAttrributes["name"] != null) && (trackAttrributes["name"].Value.Length > 0))
                    {
                        track.Name = trackAttrributes["name"].Value;
                    }

                    if ((trackAttrributes["artist"] != null) && (trackAttrributes["artist"].Value.Length > 0))
                    {
                        track.Artist = trackAttrributes["artist"].Value;
                    }

                    MediaTrack.Add(track);

                    XmlNode filesNode = null;
                    foreach (XmlNode n in trackNode.ChildNodes)
                    {
                        if (n.Name == "files")
                        {
                            filesNode = n;
                            break;
                        }
                    }

                    if (filesNode == null) { return; }

                    foreach (XmlNode fileNode in filesNode.ChildNodes)
                    {
                        if (fileNode.Name == "file")
                        {
                            MediaFile mediaFile = new MediaFile();
                            mediaFile.TrackId = track.TrackId;

                            XmlAttributeCollection fileAttrributes = fileNode.Attributes;

                            string targetFormat = string.Empty;
                            string sourcePath = string.Empty;

                            if ((fileAttrributes["targetPathFormat"] != null) && (fileAttrributes["targetPathFormat"].Value.Length > 0))
                            {
                                targetFormat = fileAttrributes["targetPathFormat"].Value;
                            }

                            if ((fileAttrributes["sourcePath"] != null) && (fileAttrributes["sourcePath"].Value.Length > 0))
                            {
                                sourcePath = HostingEnvironment.MapPath(fileAttrributes["sourcePath"].Value);
                            }

                            if (targetFormat != string.Empty)
                            {
                                mediaFile.FilePath = string.Format(CultureInfo.InvariantCulture, targetFormat, module.SiteId.ToInvariantString());

                                string directory = Path.GetDirectoryName(HostingEnvironment.MapPath(mediaFile.FilePath));
                                if (!Directory.Exists(directory))
                                {
                                    Directory.CreateDirectory(directory);
                                }

                                File.Copy(sourcePath, HostingEnvironment.MapPath(mediaFile.FilePath));

                                MediaFile.Add(mediaFile);
                            }
                            else //targetPathFormat is not defined so we don't need to move the file
                            {
                                mediaFile.FilePath = fileAttrributes["sourcePath"].Value;
                                MediaFile.Add(mediaFile);
                            }

                        }
                    }
                }
            }
        }