Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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);
                            }
                        }
                    }
                }
            }
        }