Beispiel #1
0
        public void ClearData()
        {
            AllGroups.Clear();
            AllSeries.Clear();
            AllGroupsDictionary.Clear();
            AllSeriesDictionary.Clear();
            AllAnimeDictionary.Clear();

            ViewSeriesSearch.Refresh();
        }
Beispiel #2
0
        public void RefreshGroupsSeriesData()
        {
            //LoadTestData();
            //return;

            try
            {
                // set this to null so that it will be refreshed the next time it is needed
                AllAnimeDetailedDictionary = null;

                List <JMMServerBinary.Contract_AnimeGroup>  grpsRaw   = JMMServerVM.Instance.clientBinaryHTTP.GetAllGroups(JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
                List <JMMServerBinary.Contract_AnimeSeries> seriesRaw = JMMServerVM.Instance.clientBinaryHTTP.GetAllSeries(JMMServerVM.Instance.CurrentUser.JMMUserID.Value);

                if (grpsRaw.Count == 0 || seriesRaw.Count == 0)
                {
                    return;
                }

                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                {
                    AllGroups.Clear();
                    AllSeries.Clear();
                    AllGroupsDictionary.Clear();
                    AllSeriesDictionary.Clear();
                    AllAnimeDictionary.Clear();

                    // must series before groups the binding is based on the groups, and will refresh when that is changed
                    foreach (JMMServerBinary.Contract_AnimeSeries ser in seriesRaw)
                    {
                        AnimeSeriesVM serNew = new AnimeSeriesVM(ser);
                        AllSeries.Add(serNew);
                        AllSeriesDictionary[serNew.AnimeSeriesID.Value] = serNew;
                    }

                    ViewSeriesSearch.Refresh();

                    foreach (JMMServerBinary.Contract_AnimeGroup grp in grpsRaw)
                    {
                        AnimeGroupVM grpNew = new AnimeGroupVM(grp);
                        AllGroups.Add(grpNew);
                        AllGroupsDictionary[grpNew.AnimeGroupID.Value] = grpNew;
                    }
                });
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #3
0
        private async void GetAllGroups()
        {
            try
            {
                var groups = await remoteService.GetAllGroup();

                AllGroups.Clear();
                foreach (var item in groups)
                {
                    AllGroups.Add(item);
                }
            }
            catch
            {
            }
        }
Beispiel #4
0
        public void InitGroupsSeriesData()
        {
            //LoadTestData();
            //return;

            try
            {
                // set this to null so that it will be refreshed the next time it is needed
                AllAnimeDetailedDictionary = null;

                List <JMMServerBinary.Contract_AnimeGroup>  grpsRaw   = JMMServerVM.Instance.clientBinaryHTTP.GetAllGroups(JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
                List <JMMServerBinary.Contract_AnimeSeries> seriesRaw = JMMServerVM.Instance.clientBinaryHTTP.GetAllSeries(JMMServerVM.Instance.CurrentUser.JMMUserID.Value);

                if (grpsRaw.Count == 0 || seriesRaw.Count == 0)
                {
                    return;
                }


                AllGroups.Clear();
                AllSeries.Clear();
                AllGroupsDictionary.Clear();
                AllSeriesDictionary.Clear();
                AllAnimeDictionary.Clear();

                // must series before groups the binding is based on the groups, and will refresh when that is changed
                foreach (JMMServerBinary.Contract_AnimeSeries ser in seriesRaw)
                {
                    AnimeSeriesVM serNew = new AnimeSeriesVM(ser);
                    AllSeries.Add(serNew);
                    AllSeriesDictionary[serNew.AnimeSeriesID.Value] = serNew;
                }

                foreach (JMMServerBinary.Contract_AnimeGroup grp in grpsRaw)
                {
                    AnimeGroupVM grpNew = new AnimeGroupVM(grp);
                    AllGroups.Add(grpNew);
                    AllGroupsDictionary[grpNew.AnimeGroupID.Value] = grpNew;
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
        /// <summary>
        /// Update all groups
        /// </summary>
        public void UpdateGroups()
        {
            var mPath = Path.Combine(Properties.Settings.Default.SaveLocation);

            AllGroups.Clear();

            try
            {
                string[] subdirectoryEntries = Directory.GetDirectories(mPath);
                foreach (string subdirectory in subdirectoryEntries)
                {
                    string[] group = subdirectory.Split('\\');
                    AllGroups.Add(Group.CreateGroup(group[group.Length - 1]));
                }
            }
            catch
            {
            }
        }
Beispiel #6
0
        private void LoadTestData()
        {
            System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
            {
                AllGroups.Clear();
                AllSeries.Clear();

                AnimeGroupVM grpNew = new AnimeGroupVM();
                grpNew.GroupName    = grpNew.SortName = "Bleach";
                AllGroups.Add(grpNew);

                grpNew           = new AnimeGroupVM();
                grpNew.GroupName = grpNew.SortName = "Naruto";
                AllGroups.Add(grpNew);

                grpNew           = new AnimeGroupVM();
                grpNew.GroupName = grpNew.SortName = "High School of the Dead";
                AllGroups.Add(grpNew);

                grpNew           = new AnimeGroupVM();
                grpNew.GroupName = grpNew.SortName = "Gundam";
                AllGroups.Add(grpNew);
            });
        }
        public UserGroupsViewModel()
        {
            _allGroupsCollectionView = new ListCollectionView(_allGroups);
            _allGroupsCollectionView.SortDescriptions.Add(new SortDescription());
            _allGroupsCollectionView.Filter = TextFilter;

            OpenEditMemberOf = ReactiveCommand.CreateFromObservable(() => _dialogRequests.Handle(new DialogInfo(new EditMemberOfDialog(), _user.Principal.SamAccountName)));

            SaveDirectGroups = ReactiveCommand.CreateFromObservable(() =>
            {
                var saveFileDialog = new SaveFileDialog {
                    Filter = ExcelService.ExcelFileFilter, FileName = _user.CN
                };
                return(saveFileDialog.ShowDialog() ?? false ? ExcelService.SaveGroupsToExcelFile(_directGroups, saveFileDialog.FileName) : Observable.Return(Unit.Default));
            });

            SaveAllGroups = ReactiveCommand.CreateFromObservable(() =>
            {
                var saveFileDialog = new SaveFileDialog {
                    Filter = ExcelService.ExcelFileFilter, FileName = _user.CN
                };
                return(saveFileDialog.ShowDialog() ?? false ? ExcelService.SaveGroupsToExcelFile(_allGroups, saveFileDialog.FileName) : Observable.Return(Unit.Default));
            });

            GetAllGroups = ReactiveCommand.CreateFromObservable(
                () =>
            {
                AllGroups.Clear();
                return(User.Principal.GetAllGroups(TaskPoolScheduler.Default)
                       .TakeUntil(this.WhenAnyValue(vm => vm.IsShowingAllGroups).Where(false)));
            },
                this.WhenAnyValue(vm => vm.IsShowingAllGroups));
            GetAllGroups
            .Select(group => group.Properties.Get <string>("cn"))
            .ObserveOnDispatcher()
            .Subscribe(groupName => AllGroups.Add(groupName));

            _isLoadingGroups = GetAllGroups
                               .IsExecuting
                               .ToProperty(this, vm => vm.IsLoadingGroups);

            FindDirectGroup = ReactiveCommand.CreateFromTask(() => NavigationService.ShowWindow <GroupWindow>(_selectedDirectGroup));

            FindAllGroup = ReactiveCommand.CreateFromTask(() => NavigationService.ShowWindow <GroupWindow>(_selectedAllGroup));

            this.WhenActivated(disposables =>
            {
                this
                .WhenAnyValue(vm => vm.GroupFilter, vm => vm.UseFuzzy)
                .Subscribe(_ => AllGroupsCollectionView?.Refresh())
                .DisposeWith(disposables);

                GetAllGroups
                .ThrownExceptions
                .SelectMany(ex => _messages.Handle(new MessageInfo(MessageType.Error, ex.Message, "Couldn't get groups")))
                .Subscribe()
                .DisposeWith(disposables);

                Observable.Merge(
                    this.WhenAnyValue(vm => vm.User).WhereNotNull(),
                    OpenEditMemberOf.Select(_ => User))
                .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
                .Do(_ => _directGroups.Clear())
                .SelectMany(user => GetDirectGroups(user.Principal.SamAccountName, TaskPoolScheduler.Default))
                .Select(group => group.Properties.Get <string>("cn"))
                .ObserveOnDispatcher()
                .Subscribe(groupCn => _directGroups.Add(groupCn))
                .DisposeWith(disposables);

                this
                .WhenAnyValue(vm => vm.IsShowingDirectGroups)
                .Where(true)
                .Subscribe(_ => IsShowingAllGroups = false)
                .DisposeWith(disposables);

                this
                .WhenAnyValue(vm => vm.IsShowingAllGroups)
                .Where(true)
                .Subscribe(_ => IsShowingDirectGroups = false)
                .DisposeWith(disposables);

                Observable.Merge <(string Title, string Message)>(
                    OpenEditMemberOf.ThrownExceptions.Select(ex => ("Could not open dialog", ex.Message)),
                    SaveAllGroups.ThrownExceptions.Select(ex => ("Could not save groups", ex.Message)),
                    SaveDirectGroups.ThrownExceptions.Select(ex => ("Could not save groups", ex.Message)),
                    FindDirectGroup.ThrownExceptions.Select(ex => ("Could not open group", ex.Message)),
                    FindAllGroup.ThrownExceptions.Select(ex => ("Could not open group", ex.Message)))
                .SelectMany(dialogContent => _messages.Handle(new MessageInfo(MessageType.Error, dialogContent.Message, dialogContent.Title)))
                .Subscribe()
                .DisposeWith(disposables);
            });
        }