private async Task LoadFolder(StorageFolder folder, DateTime lastSync)
        {
            if (isCanceled)
            {
                return;
            }

            IReadOnlyList <IStorageItem> fileList = await folder.GetItemsAsync();

            foreach (IStorageItem storageItem in fileList)
            {
                if (storageItem.IsOfType(StorageItemTypes.File))
                {
                    StorageFile storageFile = DebugHelper.CastAndAssert <StorageFile>(storageItem);

                    await LoadFile(storageFile);
                }
                else if (storageItem.IsOfType(StorageItemTypes.Folder))
                {
                    StorageFolder storageFolder = DebugHelper.CastAndAssert <StorageFolder>(storageItem);

                    BasicProperties basicProperties = await storageFolder.GetBasicPropertiesAsync();

                    DateTime candidateTime = basicProperties.DateModified.UtcDateTime;

                    if (candidateTime > lastSync)
                    {
                        await LoadFolder(storageFolder, lastSync);
                    }
                }
            }
        }
示例#2
0
        public void Connect()
        {
            sqlConnection = new SQLiteConnection(DB_PATH);

            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey(DB_VERSION_KEY))
            {
                ApplicationData.Current.LocalSettings.Values.Add(DB_VERSION_KEY, 0);
            }

            int currentDatabaseVersion = DebugHelper.CastAndAssert <int>(ApplicationData.Current.LocalSettings.Values[DB_VERSION_KEY]);

            if (currentDatabaseVersion < 1)
            {
                sqlConnection.CreateTable <ArtistTable>();
                sqlConnection.CreateTable <AlbumTable>();
                sqlConnection.CreateTable <SongTable>();
                sqlConnection.CreateTable <PlayQueueEntryTable>();
                sqlConnection.CreateTable <PlaylistTable>();
                sqlConnection.CreateTable <PlaylistEntryTable>();
                sqlConnection.CreateTable <HistoryTable>();
                sqlConnection.CreateTable <MixTable>();
                sqlConnection.CreateTable <MixEntryTable>();
            }

            if (currentDatabaseVersion < DB_VERSION)
            {
                ApplicationData.Current.LocalSettings.Values[DB_VERSION_KEY] = DB_VERSION;
            }
        }
示例#3
0
        public bool Eval(SongViewModel song)
        {
            T targetValue = DebugHelper.CastAndAssert <T>(TargetProperty.GetValue(song));

            switch (EvalType)
            {
            case NumericEvalType.StrictLess:
                return(targetValue.CompareTo(Target) < 0);

            case NumericEvalType.Less:
                return(targetValue.CompareTo(Target) <= 0);

            case NumericEvalType.Equal:
                return(targetValue.CompareTo(Target) == 0);

            case NumericEvalType.More:
                return(targetValue.CompareTo(Target) >= 0);

            case NumericEvalType.StrictMore:
                return(targetValue.CompareTo(Target) > 0);

            default:
                DebugHelper.Alert(new CallerInfo(), "Unexpected NumericEvalType: {0}", EvalType);
                return(false);
            }
        }
        private async Task LoadFile(StorageFile file)
        {
            if (isCanceled)
            {
                return;
            }

            if (Utilities.IsSupportedFileType(file.FileType))
            {
                StorageItemContentProperties fileProperties = file.Properties;

                MusicProperties musicProperties = await fileProperties.GetMusicPropertiesAsync();

                IDictionary <string, object> artistProperties = await fileProperties.RetrievePropertiesAsync(RealMusicProperties);

                object artists = null;
                artistProperties.TryGetValue("System.Music.Artist", out artists);

                string[] artistsAsArray = DebugHelper.CastAndAssert <string[]>(artists);

                string artistName = string.Empty;

                if (artistsAsArray != null && artistsAsArray.Length > 0)
                {
                    artistName = artistsAsArray[0];
                }

                if (this.TrackScanned != null)
                {
                    this.TrackScanned(this, new TrackScannedEventArgs(new StorageProviderSong(file.Path, musicProperties, artistName)));
                }
            }
        }
示例#5
0
        private void HandleMixLimitTextBoxGotFocus(object sender, RoutedEventArgs e)
        {
            Transform stackPanelRestore = DebugHelper.CastAndAssert <Transform>(((TextBox)sender).TransformToVisual(rootGrid));

            double shift = 0;

            if (stackPanelRestore is MatrixTransform)
            {
                shift = (stackPanelRestore as MatrixTransform).Matrix.OffsetY;
            }
            else if (stackPanelRestore is TranslateTransform)
            {
                shift = (stackPanelRestore as TranslateTransform).Y;
            }
            else
            {
                DebugHelper.Alert(new CallerInfo(), "Unexpected transform type {0}", stackPanelRestore.GetType());
            }

            TranslateTransform shiftDown = new TranslateTransform();

            shiftDown.Y = 90 - shift;

            TransformGroup group = new TransformGroup();

            group.Children.Add(shiftDown);

            rootGrid.RenderTransform = group;

            RootScrollViewer.VerticalScrollMode = ScrollMode.Disabled;
        }
示例#6
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            double valueAsDouble = DebugHelper.CastAndAssert <double>(value);

            System.Diagnostics.Debug.WriteLine("Input " + valueAsDouble + " output " + ((valueAsDouble) / Sections - Margin));

            return((valueAsDouble) / Sections - Margin);
        }
示例#7
0
        async void HandleBackgroundMediaPlayerMessageReceivedFromBackground(object sender, MediaPlayerDataReceivedEventArgs e)
        {
            foreach (string key in e.Data.Keys)
            {
                switch (key)
                {
                case PlayQueueMessageHelper.BackgroundStarted:
                    BackgroundInitialized.Set();
                    break;

                case PlayQueueMessageHelper.SeekComplete:
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        isScrubInProgress = false;
                        CurrentTime       = BackgroundMediaPlayer.Current.Position;
                    });

                    break;

                case PlayQueueMessageHelper.TrackChanged:
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        if (!isScrubInProgress)
                        {
                            CurrentTime = BackgroundMediaPlayer.Current.Position;
                        }
                        else
                        {
                            CurrentTime = TimeSpan.Zero;
                        }
                        FullTime = BackgroundMediaPlayer.Current.NaturalDuration;

                        CurrentPlaybackQueueEntryId = DebugHelper.CastAndAssert <int>(e.Data[key]);
                    });

                    break;

                case PlayQueueMessageHelper.TrackPlayed:
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        UpdateHistory();
                    });

                    break;

                case PlayQueueMessageHelper.PlayQueueFinished:
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        ResetPlayerToStart();
                        IsActive    = false;
                        IsPlaying   = false;
                        CurrentTime = TimeSpan.Zero;
                    });

                    break;
                }
            }
        }
示例#8
0
        private void ExecuteNavigate(object parameter)
        {
            string             parameterAsString = DebugHelper.CastAndAssert <string>(parameter);
            NavigationLocation target            = NavigationLocation.Home;

            DebugHelper.Assert(new CallerInfo(), Enum.TryParse <NavigationLocation>(parameterAsString, out target), "Couldn't find location named {0}", parameterAsString);

            NavigationManager.Current.Navigate(target);
        }
示例#9
0
        internal void LoadState(Dictionary <string, object> pageState)
        {
            object lastIndex;

            if (pageState != null && pageState.TryGetValue(LAST_INDEX_KEY, out lastIndex))
            {
                lastFrameInViewIndex = DebugHelper.CastAndAssert <int>(lastIndex);
            }
        }
示例#10
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            SolidColorBrush valueAsBrush = DebugHelper.CastAndAssert <SolidColorBrush>(value);

            if (valueAsBrush == TargetBrush)
            {
                return(TargetStyle);
            }

            return(null);
        }
示例#11
0
        protected override Style SelectStyleCore(object item, DependencyObject container)
        {
            MixViewModel itemAsMixViewModel = DebugHelper.CastAndAssert <MixViewModel>(item);

            if (itemAsMixViewModel.IsHidden)
            {
                return(EmptyStyle);
            }

            return(null);
        }
示例#12
0
        public static T GetSettingsValue <T>(string key, T defaultValue)
        {
            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey(key))
            {
                ApplicationData.Current.LocalSettings.Values.Add(key, defaultValue);

                Logger.Current.Log(new CallerInfo(), LogLevel.Warning, "Setting {0} does not exist, defaulting to {1}", key, defaultValue);
            }

            return(DebugHelper.CastAndAssert <T>(ApplicationData.Current.LocalSettings.Values[key]));
        }
示例#13
0
        private void UpdateTheme()
        {
            SolidColorBrush brush = DebugHelper.CastAndAssert <SolidColorBrush>(App.Current.Resources["PhoneAccentBrush"]);

            Color c = brush.Color;

            c.R = (byte)(byte.MaxValue - c.R * 0.2);
            c.G = (byte)(byte.MaxValue - c.G * 0.2);
            c.B = (byte)(byte.MaxValue - c.B * 0.2);

            ((SolidColorBrush)App.Current.Resources["PlayerControlBackgroundColor"]).Color = c;
        }
示例#14
0
        protected U GetTableField <U>(string tableProperty)
        {
            PropertyInfo propertyInfo = typeof(T).GetRuntimeProperty(tableProperty);

            if (propertyInfo != null)
            {
                return(DebugHelper.CastAndAssert <U>(propertyInfo.GetValue(rootTable)));
            }
            else
            {
                return(default(U));
            }
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            double valueAsDouble = DebugHelper.CastAndAssert <double>(value);

            double LeftBase = 20;

            double RightBase = 20;

            if (BaseShape == null)
            {
                BaseShape = new Polygon();

                BaseShape.Points.Add(new Point(-20, 25));
                BaseShape.Points.Add(new Point(-20, 20));
                BaseShape.Points.Add(new Point(0, 0));
                BaseShape.Points.Add(new Point(20, 20));
                BaseShape.Points.Add(new Point(20, 25));
            }

            PointCollection newShape = new PointCollection();

            double maxValue = Windows.UI.Xaml.Window.Current.Bounds.Width;

            if (BaseShape != null)
            {
                foreach (Point j in BaseShape.Points)
                {
                    double shiftX = j.X;

                    if (valueAsDouble < LeftBase)
                    {
                        if (j.X < 0)
                        {
                            shiftX = j.X * valueAsDouble / LeftBase;
                        }
                    }
                    if ((maxValue - valueAsDouble) < RightBase)
                    {
                        if (j.X > 0)
                        {
                            shiftX = j.X * (maxValue - valueAsDouble) / RightBase;
                        }
                    }

                    newShape.Add(new Point(shiftX, j.Y));
                }
            }

            return(newShape);
        }
示例#16
0
        protected override void HandleNavigationHelperLoadState(object sender, LoadStateEventArgs e)
        {
            base.HandleNavigationHelperLoadState(sender, e);

            object lastIndex;

            if (e.PageState != null && e.PageState.TryGetValue("LIBRARY_PIVOT_INDEX", out lastIndex))
            {
                RootPivot.SelectedIndex = DebugHelper.CastAndAssert <int>(lastIndex);
            }

            songListRestoreHelper.LoadState(e.PageState);
            albumListRestoreHelper.LoadState(e.PageState);
            artistListRestoreHelper.LoadState(e.PageState);
        }
示例#17
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            double valueAsDouble = DebugHelper.CastAndAssert <double>(value);

            if (valueAsDouble < 0)
            {
                return(0);
            }
            if (valueAsDouble > FullTarget)
            {
                return(FullTarget);
            }

            return(FullTarget * valueAsDouble);
        }
示例#18
0
        protected U GetModelField <U>(string modelProperty)
        {
            PropertyInfo propertyInfo = typeof(T).GetRuntimeProperty(modelProperty);

            DebugHelper.Assert(new CallerInfo(), propertyInfo != null, "Model {0} does not contain property {1}", typeof(T), modelProperty);

            if (propertyInfo != null)
            {
                return(DebugHelper.CastAndAssert <U>(propertyInfo.GetValue(rootModel)));
            }
            else
            {
                return(default(U));
            }
        }
示例#19
0
        private void HandleLowerTextBoxGotFocus(object sender, RoutedEventArgs e)
        {
            Transform stackPanelRestore = DebugHelper.CastAndAssert <Transform>(((TextBox)sender).TransformToVisual(rootStackPanel));

            TranslateTransform shiftDown = new TranslateTransform();

            shiftDown.Y = 90;

            TransformGroup group = new TransformGroup();

            group.Children.Add(DebugHelper.CastAndAssert <Transform>(stackPanelRestore.Inverse));
            group.Children.Add(shiftDown);

            rootStackPanel.RenderTransform = group;
        }
示例#20
0
        private void HandleContentDialogPrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var selectedItem = AddComboBox.SelectedItem;

            if (selectedItem == null)
            {
                return;
            }

            PlaylistViewModel selectedPlaylist = DebugHelper.CastAndAssert <PlaylistViewModel>(selectedItem);

            selectedPlaylistId = selectedPlaylist.PlaylistId;

            selectedPlaylist.AddSong(Song);
        }
示例#21
0
        public bool Eval(SongViewModel song)
        {
            DateTime targetValue = DebugHelper.CastAndAssert <DateTime>(TargetProperty.GetValue(song));

            switch (EvalType)
            {
            case RangeEvalType.Days:
                DateTime target = DateTime.Now - TimeSpan.FromDays(Target);

                return(target < targetValue);

            default:
                DebugHelper.Alert(new CallerInfo(), "Unexpected MemberEvalType: {0}", EvalType);
                return(false);
            }
        }
示例#22
0
        protected void SetModelField <U>(string modelProperty, U value, string property)
        {
            PropertyInfo propertyInfo = typeof(T).GetRuntimeProperty(modelProperty);

            DebugHelper.Assert(new CallerInfo(), propertyInfo != null, "Model {0} does not contain property {1}", typeof(T), modelProperty);

            if (propertyInfo != null)
            {
                U field = DebugHelper.CastAndAssert <U>(propertyInfo.GetValue(rootModel));

                if (!EqualityComparer <U> .Default.Equals(field, value))
                {
                    propertyInfo.SetValue(rootModel, value);
                    NotifyPropertyChanged(property);
                }
            }
        }
示例#23
0
        protected void SetTableField <U>(string tableProperty, U value, string property)
        {
            PropertyInfo propertyInfo = typeof(T).GetRuntimeProperty(tableProperty);

            DebugHelper.Assert(new CallerInfo(), propertyInfo != null, "Table {0} does not contain property {1}", typeof(T), tableProperty);

            if (propertyInfo != null)
            {
                U field = DebugHelper.CastAndAssert <U>(propertyInfo.GetValue(rootTable));

                if (!EqualityComparer <U> .Default.Equals(field, value))
                {
                    propertyInfo.SetValue(rootTable, value);
                    DatabaseManager.Current.Update(rootTable);
                    NotifyPropertyChanged(property);
                }
            }
        }
示例#24
0
        private void MixEntryType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MixEntryType.SelectedItem == null)
            {
                return;
            }

            SelectableOption <MixType> selectedType = DebugHelper.CastAndAssert <SelectableOption <MixType> >(MixEntryType.SelectedItem);

            switch (selectedType.Type & MixType.TYPE_MASK)
            {
            case MixType.NUMBER_TYPE:
                VisualStateManager.GoToState(this, "NumberSelected", false);

                UpdateNumericState(selectedType.Type);
                return;

            case MixType.STRING_TYPE:
                VisualStateManager.GoToState(this, "StringSelected", false);
                return;

            case MixType.NESTED_TYPE:
                VisualStateManager.GoToState(this, "NestedSelected", false);
                return;

            case MixType.RANGE_TYPE:
                VisualStateManager.GoToState(this, "RangeSelected", false);
                return;

            case MixType.MEMBER_TYPE:
                VisualStateManager.GoToState(this, "MemberSelected", false);

                UpdateMemberState(selectedType.Type);
                return;

            default:
                DebugHelper.Assert(new CallerInfo(), selectedType.Type == MixType.None, "Unexpected mix type: {0}", selectedType.Type);
                VisualStateManager.GoToState(this, "UnknownSelected", false);
                return;
            }
        }
示例#25
0
        private void UpdateMargins()
        {
            double h = this.ActualHeight == 0 ? this.Height : this.ActualHeight;
            double w = this.ActualWidth == 0 ? this.Width : this.ActualWidth;

            double desiredHeight = h - 2 * InnerMargin;
            double desiredWidth  = w - 2 * InnerMargin;

            SymbolTileScaleTransform.ScaleX = desiredHeight / 30.0;
            SymbolTileScaleTransform.ScaleY = desiredWidth / 30.0;

            // For some reason the visual states don't work... so giving up and doing this instead
            if (w < 160)
            {
                CaptionTextBlock.Style = DebugHelper.CastAndAssert <Style>(Resources["TileTextStyleSmall"]);
            }
            else
            {
                CaptionTextBlock.Style = DebugHelper.CastAndAssert <Style>(Resources["TileTextStyle"]);
            }
        }
示例#26
0
        private void UpdateNumericStartingValue(MixType type, IComparable target)
        {
            switch (type & MixType.SUBTYPE_MASK)
            {
            case MixType.LENGTH_SUBTYPE:
                NumericValue.Text = target.ToString();
                break;

            case MixType.RATING_SUBTYPE:
                NumericStarRater.Rating = DebugHelper.CastAndAssert <uint>(target);
                break;

            case MixType.PLAYCOUNT_SUBTYPE:
                NumericValue.Text = target.ToString();
                break;

            default:
                DebugHelper.Alert(new CallerInfo(), "Unexpected numeric mix type: {0}", type);
                NumericValue.Text = "0";
                return;
            }
        }
示例#27
0
        private void HandleContentDialogPrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if ((deleteMix.IsChecked.HasValue && deleteMix.IsChecked.Value) &&
                (deleteMixConfirm.IsChecked.HasValue && deleteMixConfirm.IsChecked.Value))
            {
                LibraryViewModel.Current.DeleteMix(Mix);
            }
            else
            {
                Mix.Name = editMixName.Text;

                if (mixLimitCheckBox.IsChecked.HasValue)
                {
                    Mix.HasLimit = mixLimitCheckBox.IsChecked.Value;
                }

                uint newMixLimit;

                if (uint.TryParse(mixLimitTextBox.Text, out newMixLimit))
                {
                    Mix.Limit = newMixLimit;
                }

                if (mixHiddenCheckBox.IsChecked.HasValue)
                {
                    Mix.IsHidden = mixHiddenCheckBox.IsChecked.Value;
                }

                SelectableOption <MixSortOrder> selectedType  = DebugHelper.CastAndAssert <SelectableOption <MixSortOrder> >(SortTypeComboBox.SelectedItem);
                SelectableOption <MixSortOrder> selectedOrder = DebugHelper.CastAndAssert <SelectableOption <MixSortOrder> >(SortOrderComboBox.SelectedItem);

                Mix.SortType = selectedType.Type | selectedOrder.Type;

                IMixEvaluator mixEval = RootMixEntry.ConvertToEvaluator();
                Mix.SetEvaluator(mixEval);

                Mix.Reset();
            }
        }
示例#28
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            double valueAsDouble = DebugHelper.CastAndAssert <double>(value);

            double target = FullTarget;

            if (FullMode)
            {
                target = Windows.UI.Xaml.Window.Current.Bounds.Width;
            }

            if (valueAsDouble < 0)
            {
                return(0);
            }
            if (valueAsDouble > target)
            {
                return(target);
            }

            return(target * valueAsDouble);
        }
示例#29
0
        internal void HandleContinuation(IContinuationActivatedEventArgs continuationEventArgs)
        {
            if (mainNavigationFrame != null && mainNavigationFrame.Content is AlbumPage)
            {
                if (continuationEventArgs is FileOpenPickerContinuationEventArgs)
                {
                    AlbumPage currentAlbumPage = DebugHelper.CastAndAssert <AlbumPage>(mainNavigationFrame.Content);
                    FileOpenPickerContinuationEventArgs filePickerOpenArgs = DebugHelper.CastAndAssert <FileOpenPickerContinuationEventArgs>(continuationEventArgs);

                    currentAlbumPage.HandleFilePickerLaunch(filePickerOpenArgs);
                }
            }
            else if (mainNavigationFrame != null && mainNavigationFrame.Content is ManageLibrary)
            {
                if (continuationEventArgs is FileOpenPickerContinuationEventArgs)
                {
                    FileOpenPickerContinuationEventArgs filePickerOpenArgs = DebugHelper.CastAndAssert <FileOpenPickerContinuationEventArgs>(continuationEventArgs);

                    if (filePickerOpenArgs.Files.Count > 0)
                    {
                        DebugHelper.Assert(new CallerInfo(), filePickerOpenArgs.Files.Count == 1);

                        IStorageFile pickedFile = filePickerOpenArgs.Files[0];

                        MediaImportManager.Current.HandleFilePickerLaunch(pickedFile);
                    }
                }
                else if (continuationEventArgs is FolderPickerContinuationEventArgs)
                {
                    FolderPickerContinuationEventArgs folderOpenArgs = DebugHelper.CastAndAssert <FolderPickerContinuationEventArgs>(continuationEventArgs);

                    if (folderOpenArgs.Folder != null)
                    {
                        MediaImportManager.Current.HandleSyncFolderLaunch(folderOpenArgs.Folder);
                    }
                }
            }
        }
示例#30
0
        public bool Eval(SongViewModel song)
        {
            string targetValue = DebugHelper.CastAndAssert <string>(TargetProperty.GetValue(song));

            switch (EvalType)
            {
            case StringEvalType.Equal:
                return(targetValue == Target);

            case StringEvalType.SubString:
                return(targetValue.Contains(Target));

            case StringEvalType.StartsWith:
                return(targetValue.StartsWith(Target));

            case StringEvalType.EndsWith:
                return(targetValue.EndsWith(Target));

            default:
                DebugHelper.Alert(new CallerInfo(), "Unexpected StringEvalType: {0}", EvalType);
                return(false);
            }
        }