Example #1
0
        /// <summary>
        /// Save all currently registered hot key sequences and their associated actions
        /// to the user's local application data directory.
        /// </summary>

        public void Save()
        {
            var dirPath = Path.GetDirectoryName(dataPath);

            if (dirPath == null)
            {
                MessageWindow.Show($"Cannot find save path: {dataPath}");
                return;
            }

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            var map      = new HotKeyCollection(keys.Values);
            var settings = new XmlWriterSettings {
                Indent = true
            };

            try
            {
                using (XmlWriter writer = XmlWriter.Create(dataPath, settings))
                {
                    var serializer = new DataContractSerializer(typeof(HotKeyCollection));
                    serializer.WriteObject(writer, map);

                    writer.Flush();
                    writer.Close();
                }
            }
            catch (Exception exc)
            {
                MessageWindow.Show(string.Format(Resx.HotKeysNotSaved, exc.Message));
            }
        }
Example #2
0
        //----------------------------------------------------------------------------------------

        /// <summary>
        /// Invoked when the Sync button is pressed, starts the synchronization process.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void DoSync(object sender, RoutedEventArgs e)
        {
            string text = String.Format(Resx.SyncWarningText, selector.Location);

            MessageBoxResult result = MessageWindow.Show(
                null, text, Resx.SyncWarningCaption,
                MessageBoxButton.OKCancel, MessageWindowImage.Warning, MessageBoxResult.Cancel);

            if (result != MessageBoxResult.OK)
            {
                e.Handled = true;
                return;
            }

            countBox.Visibility      = Visibility.Hidden;
            playlistBox.IsEnabled    = false;
            selector.IsEnabled       = false;
            syncButton.Visibility    = Visibility.Collapsed;
            progressPanel.Visibility = Visibility.Visible;

            string format       = PathHelper.GetPathFormat(selector.FormatTag);
            bool   withPlaylist = format.Contains("playlist");

            var list = new PersistentIDCollection();

            using (var selectedPlaylists = new PlaylistCollection())
            {
                selectedPlaylists.AddRange(playlists.FindAll(p => p.IsSelected == true));

                foreach (Playlist playlist in selectedPlaylists.Values)
                {
                    if (playlist != null)
                    {
                        PersistentID pid = playlist.PersistentID;

                        PersistentIDCollection tracks =
                            controller.Librarian.Catalog.FindTracksByPlaylist(pid);

                        if (withPlaylist)
                        {
                            // Cannot modify a value type (PersistentID) from within a foreach loop
                            // or the .ForEach extension method, so we need to recreate each pid
                            // to set the playlist name.  Unfortunate design consequence...
                            foreach (PersistentID track in tracks)
                            {
                                PersistentID tid = track;
                                tid.PlaylistName = playlist.Name;
                                list.Add(tid);
                            }
                        }
                        else
                        {
                            list.AddRange(tracks);
                        }
                    }
                }
            }

            // show iTunes incase a protection fault occurs; otherwise you cannot see the
            // dialog if iTunes is minimized as a Taskbar toolbar
            controller.ShowiTunes();

            controller.Librarian.ProgressChanged += new ProgressChangedEventHandler(DoProgressChanged);
            controller.Librarian.Export(list, selector.Location, format);
        }