Esempio n. 1
0
        private void AddToRoutine(Type taskType)
        {
            var routineViewModel = new RoutineViewModel(taskType, _game, _repo, _executioner, _settings, _queue);

            routineViewModel.PropertyChanged += RoutineViewModelOnPropertyChanged;
            RoutineItems.Add(routineViewModel);
            AddAllToQueue.RaiseCanExecuteChanged();
        }
Esempio n. 2
0
 private void RoutineViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == nameof(RoutineViewModel.IsChecked))
     {
         RaisePropertyChanged(nameof(CheckAll));
         AddAllToQueue.RaiseCanExecuteChanged();
         _settings.RoutineItemsState = RoutineItems.Select(x => x.IsChecked.ToString()).ToArray();
     }
 }
Esempio n. 3
0
        private void AddAll()
        {
            foreach (var t in RoutineItems.Where(x => x.IsChecked))
            {
                t.AddToQueue();
            }

            AddAllToQueue.RaiseCanExecuteChanged();
        }
Esempio n. 4
0
        public TasksViewModel(ITaskQueue queue, IGame game, IUiRepository repo, ITaskExecutioner executioner, ISettings settings)
        {
            _queue                  = queue;
            _game                   = game;
            _repo                   = repo;
            _executioner            = executioner;
            _settings               = settings;
            AddAllToQueue           = new DelegateCommand(AddAll, CanExecuteRunRoutine);
            CancelCommand           = new DelegateCommand(CancelAll, CanExecuteCancel);
            Add                     = new DelegateCommand <Type>(AddToRoutine, CanAddToRoutine);
            Remove                  = new DelegateCommand <RoutineViewModel>(RemoveFromRoutine, CanRemoveFromRoutine);
            _queue.PropertyChanged += (_, _) => OnQueueChanged();
            OnQueueChanged();

            var types = new List <Type>();

            var entryAssembly        = Assembly.GetEntryAssembly();
            var referencedAssemblies = entryAssembly?.GetReferencedAssemblies();

            if (referencedAssemblies == null)
            {
                throw new Exception();
            }

            foreach (var referencedAssembly in referencedAssemblies)
            {
                var assembly = Assembly.Load(referencedAssembly);
                types.AddRange(assembly.GetTypes()
                               .Where(x => x.IsAssignableTo(typeof(IGameTask)) &&
                                      !x.IsAbstract &&
                                      x.IsPublic));
            }

            foreach (var type in types)
            {
                Tasks.Add(type);
            }

            if (settings.RoutineItems != null)
            {
                foreach (var routineViewModel in settings.RoutineItems.Where(x => types.Any(t => t.Name == x))
                         .Select((x, idx) =>
                {
                    var vm = new RoutineViewModel(types.FirstOrDefault(t => t.Name == x), game, repo, executioner,
                                                  settings, queue);
                    var state = settings.RoutineItemsState?.ElementAtOrDefault(idx);
                    bool.TryParse(state, out var isChecked);
                    vm.IsChecked = isChecked;
                    return(vm);
                }))
                {
                    routineViewModel.PropertyChanged += RoutineViewModelOnPropertyChanged;
                    RoutineItems.Add(routineViewModel);
                }
            }

            RoutineItems.CollectionChanged += RoutineItems_CollectionChanged;

            if (!RoutineItems.Any())
            {
                foreach (var routineViewModel in types.Where(x => x != typeof(AutoFight))
                         .Select(t => new RoutineViewModel(t, game, repo, executioner, settings, queue)))
                {
                    routineViewModel.PropertyChanged += RoutineViewModelOnPropertyChanged;
                    RoutineItems.Add(routineViewModel);
                }
            }

            AddAllToQueue.RaiseCanExecuteChanged();
        }
Esempio n. 5
0
 private bool CanExecuteRunRoutine()
 {
     return(!_queue.Items.Any() && _queue.ActiveItem == null && RoutineItems.Any(i => i.IsChecked));
 }
Esempio n. 6
0
 private void RemoveFromRoutine(RoutineViewModel obj)
 {
     RoutineItems.Remove(obj);
 }
Esempio n. 7
0
 private void RoutineItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     _settings.RoutineItems      = RoutineItems.Select(x => x.Name).ToArray();
     _settings.RoutineItemsState = RoutineItems.Select(x => x.IsChecked.ToString()).ToArray();
 }