Ejemplo n.º 1
0
        public MainViewModel(
            ICompositionFactory compositionFactory,
            IBackendServiceClient storage,
            IEventAggregator eventAggregator,
            IStatusBusyService statusBusyService,
            IEntryOperations entryOperations,
            ILocalSettingsService localSettingsService,
            IStringResourceManager stringResourceManager,
            ILogSharingService logSharingService)
            : this()
        {
            Guard.NotNull(compositionFactory, nameof(compositionFactory));
            Guard.NotNull(storage, nameof(storage));
            Guard.NotNull(eventAggregator, nameof(eventAggregator));
            Guard.NotNull(statusBusyService, nameof(statusBusyService));
            Guard.NotNull(entryOperations, nameof(entryOperations));
            Guard.NotNull(localSettingsService, nameof(localSettingsService));
            Guard.NotNull(stringResourceManager, nameof(stringResourceManager));
            Guard.NotNull(logSharingService, nameof(logSharingService));

            this.storage = storage;
            this.eventAggregator = eventAggregator;
            this.statusBusyService = statusBusyService;
            this.entryOperations = entryOperations;
            this.localSettingsService = localSettingsService;
            this.stringResourceManager = stringResourceManager;
            this.logSharingService = logSharingService;

            CompositionFactory = compositionFactory;

            FullEntryListViewModel = compositionFactory.Create<FullEntryListViewModel>();
            RandomEntryListViewModel = compositionFactory.Create<RandomEntryListViewModel>();
            EntryTextEditorViewModel = compositionFactory.Create<EntryTextEditorViewModel>();

            eventAggregator.GetEvent<EntryEditingFinishedEvent>().Subscribe(OnEntryEditingFinished);
            eventAggregator.GetEvent<EntryEditingCancelledEvent>().Subscribe(OnEntryEditingCancelled);
            eventAggregator.GetEvent<EntryDeletedEvent>().Subscribe(OnEntryDeleted);
            eventAggregator.GetEvent<EntryIsLearntChangedEvent>().Subscribe(OnEntryIsLearntChanged);
            eventAggregator.GetEvent<EntryUpdatedEvent>().SubscribeWithAsync(OnEntryDefinitionChangedAsync);
            eventAggregator.GetEvent<EntryDetailsRequestedEvent>().Subscribe(OnEntryDetailsRequested);
            eventAggregator.GetEvent<EntryQuickEditRequestedEvent>().Subscribe(OnEntryQuickEditRequested);
        }
Ejemplo n.º 2
0
        public FullEntryListViewModel([NotNull] IStringResourceManager resourceManager, [NotNull] IEntryOperations entryOperations)
        {
            Guard.NotNull(resourceManager, nameof(resourceManager));
            Guard.NotNull(entryOperations, nameof(entryOperations));

            this.resourceManager = resourceManager;
            this.entryOperations = entryOperations;
            EntryViewModels = new ObservableCollection<EntryListItemViewModel>();
            EntryViewModels.CollectionChanged += OnEntriesCollectionChanged;
            TimeGroupViewModels = new ObservableCollection<EntryListItemTimeGroupViewModel>();
            TimeGroupViewModels.CollectionChanged += OnTimeGroupsCollectionChanged;

            if (DesignTimeDetection.IsInDesignTool)
            {
                EventAggregator = DesignTimeHelper.EventAggregator;
                EntryViewModels.AddRange(FakeData.FakeWords.Select(w => CreateListItemViewModel(w)));
            }

            EventAggregator.GetEvent<EntryIsLearntChangedEvent>().Subscribe(OnEntryIsLearntChanged);
        }
Ejemplo n.º 3
0
        public EntryEditViewModel(
            ICompositionFactory compositionFactory,
            IBackendServiceClient storage,
            IEventAggregator eventAggregator,
            IStatusBusyService statusBusyService,
            IEntryOperations entryOperations,
            Lazy<ITranslationService> translator)
            : this(eventAggregator)
        {
            Guard.NotNull(compositionFactory, nameof(compositionFactory));
            Guard.NotNull(storage, nameof(storage));
            Guard.NotNull(eventAggregator, nameof(eventAggregator));
            Guard.NotNull(statusBusyService, nameof(statusBusyService));
            Guard.NotNull(translator, nameof(translator));
            Guard.NotNull(entryOperations, nameof(entryOperations));

            this.storage = storage;
            this.statusBusyService = statusBusyService;
            this.entryOperations = entryOperations;
            this.translator = translator;

            EventAggregator = eventAggregator;
            CompositionFactory = compositionFactory;
        }
Ejemplo n.º 4
0
        public RandomEntryListViewModel([NotNull] IStringResourceManager resourceManager, [NotNull] IEntryOperations entryOperations, [NotNull] IRoamingSettingsService roamingSettings)
        {
            Guard.NotNull(resourceManager, nameof(resourceManager));
            Guard.NotNull(entryOperations, nameof(entryOperations));
            Guard.NotNull(roamingSettings, nameof(roamingSettings));

            this.resourceManager = resourceManager;
            this.entryOperations = entryOperations;
            this.roamingSettings = roamingSettings;

            RandomEntryViewModels = new ObservableCollection<EntryListItemViewModel>();
            RandomEntryViewModels.CollectionChanged += OnDisplayEntriesCollectonChanged;

            PreviousRandomEntryViewModelsStack = new Stack<List<EntryListItemViewModel>>();

            if (DesignTimeDetection.IsInDesignTool)
            {
                EventAggregator = DesignTimeHelper.EventAggregator;
                RandomEntryViewModels.Add(FakeData.FakeWords.Select(w => CreateListItemViewModel(w)).First());
            }

            ShowNextEntriesCommand = new DelegateCommand(ShowNextEntries, () => CanShowNextEntries);
            ShowPreviousEntriesCommand = new DelegateCommand(ShowPreviousEntries, () => CanShowPreviousEntries);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// </summary>
        /// <param name='operations'>
        /// The operations group for this extension method.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        public static async Task <Entry> GetEntryAsync(this IEntryOperations operations, CancellationToken cancellationToken = default(CancellationToken))
        {
            HttpOperationResponse <Entry> result = await operations.GetEntryWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false);

            return(result.Body);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 public static Entry GetEntry(this IEntryOperations operations)
 {
     return(Task.Factory.StartNew(s => ((IEntryOperations)s).GetEntryAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }