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

            routineViewModel.PropertyChanged += RoutineViewModelOnPropertyChanged;
            RoutineItems.Add(routineViewModel);
            AddAllToQueue.RaiseCanExecuteChanged();
        }
        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();
        }
 private void RemoveFromRoutine(RoutineViewModel obj)
 {
     RoutineItems.Remove(obj);
 }
 private bool CanRemoveFromRoutine(RoutineViewModel arg)
 {
     return(IsEnabled && ActiveTask == null && !_queue.Items.Any());
 }