コード例 #1
0
ファイル: Serializer.cs プロジェクト: tobeyun/MyPresenter
        public static New.song DeserializeFromXML <song>(string filePath)
        {
            New.song retVal = default(New.song);

            try
            {
                XmlSerializer deserializer = new XmlSerializer(typeof(New.song));

                using (TextReader textReader = new StreamReader(filePath))
                {
                    retVal = (New.song)deserializer.Deserialize(textReader);

                    foreach (New.songVerse v in retVal.lyrics)
                    {
                        retVal.lyrics[v.name].name  = v.name.ToUpper();
                        retVal.lyrics[v.name].lyric = v.lyric.Replace("_", "\r\n");
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Error loading  '" + System.IO.Path.GetFileNameWithoutExtension(filePath.Replace("MISSING PAD: ", "")) + "'.\n\n" + ex.InnerException.Message, "Song Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);

                //Console.Write(ex.Message);
            }

            return(retVal);
        }
コード例 #2
0
ファイル: Serializer.cs プロジェクト: tobeyun/MyPresenter
        public static void SerializeToXML <song>(New.song t)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(t.GetType());

                using (TextWriter textWriter = new StreamWriter(Properties.Resources.SongPath + "\\" + t.title + ".xml"))
                {
                    foreach (New.songVerse v in t.lyrics)
                    {
                        t.lyrics[v.name].name  = v.name.ToUpper();
                        t.lyrics[v.name].lyric = v.lyric.Replace("\r\n", "_");
                    }

                    serializer.Serialize(textWriter, t);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Error: " + ex.Message);

                // HACK: Pull our assembly base file name from exception message
                Regex regex = new Regex(@"File or assembly name (?<baseFileName>.*).dll");
                Match match = regex.Match(ex.Message);

                string baseFileName = match.Groups["baseFileName"].Value;

                if (baseFileName == string.Empty)
                {
                    return;
                }

                string outputPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), baseFileName + ".out");
                System.Diagnostics.Debug.WriteLine((new StreamReader(outputPath)).ReadToEnd());

                string csPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), baseFileName + ".0.cs");
                System.Diagnostics.Debug.WriteLine("XmlSerializer-produced source:\n" + csPath);

                return;
            }
        }
コード例 #3
0
        private void serviceListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            New.song _currentSong = new New.song();

            if (serviceListBox.SelectedIndex < 0) ScriptListView.Items.Clear();
            if (serviceListBox.SelectedIndex < 0) return;

            _liveOutputWindow.DisplayText("");

            // get song selection
            ServiceItem _song = (ServiceItem)serviceListBox.SelectedItem;

            try
            {
                // create song object
                _currentSong = Serializer.DeserializeFromXML<New.song>(Properties.Resources.SongPath + _song.Title + ".xml");
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Error loading '" + _song.Title + "'.", "XML Error");

                System.Diagnostics.EventLog.WriteEntry("Application", ex.Message);
            }

            if (PresentationSource.FromVisual(_liveOutputWindow) != null)
            {
                var rand = new Random();
                var files = Directory.GetFiles(Properties.Resources.LoopPath, "background*.mp*"); // filter for auto-selecting bg loops
                string _loop = _currentSong.loop;

                // select random loop if none specified in XML file
                if (_loop == "") _loop = System.IO.Path.GetFileName(files[rand.Next(files.Length)]);

                setLoop(_loop); //getLoopSelection(serviceListBox.SelectedItem));
                startPad(_currentSong.key); //getPadSelection(serviceListBox.SelectedItem));

                MuteAudio = false;
            }

            setSong(_song.Title);

            double _count = ScriptListView.Items.Count;
            double _progress = (((ServiceItem)_serviceItemList[serviceListBox.SelectedIndex]).Progress / 100.0);
            double _index = _count * _progress;

            ScriptListView.SelectedIndex = (int)_index;
            ScriptListView.Focus();
            ScriptListView.ScrollIntoView(ScriptListView.SelectedItem);

            if (ScriptListView.SelectedItem != null)
                ((ListBoxItem)ScriptListView.SelectedItem).Focus();

            //if (serviceListBox.SelectedItem.ToString().Contains("Break"))
            //    gotoBreak(new Uri(Properties.Resources.ImagePath + "\\LivingRoomLive.jpg", UriKind.Absolute));

            // update HTML for remote control
            generateHtml();

            //killSpotify();
        }