|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CBR.Core.Helpers;
using CBR.Core.Models;
using CBR.Core.Services;
using System.Windows.Input;
using System.Windows.Threading;
namespace CBR.ViewModels
{
public class BookViewModelBase : ViewModelBase
{
#region ----------------CONSTRUCTOR----------------
public BookViewModelBase(Book bk)
{
if (bk != null)
{
Service = BookServiceFactory.Instance.GetService(bk);
BookData = bk;
//BookData.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_bookData_PropertyChanged);
}
//register to the mediator for messages
Mediator.Instance.Register(
(Object o) =>
{
RaisePropertyChanged("MagnifierSize");
RaisePropertyChanged("MagnifierScale");
},
ViewModelMessages.SettingsChanged);
//create a dispatch timer to load the image cache
_CacheTimerClock = new DispatcherTimer();
_CacheTimerClock.Interval = new TimeSpan(0, 0, 5);
_CacheTimerClock.IsEnabled = true;
_CacheTimerClock.Tick += new EventHandler(CacheTimerClockElapsed);
}
void _bookData_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
//RaisePropertyChanged(e.PropertyName);
}
#endregion
#region -----------------PROPERTIES-----------------
private DispatcherTimer _CacheTimerClock;
public double MagnifierSize
{
get { return WorkspaceService.Instance.Settings.MagnifierSize; }
}
public double MagnifierScale
{
get { return WorkspaceService.Instance.Settings.MagnifierScaleFactor; }
}
private Book _bookData = null;
public Book BookData
{
get { return _bookData; }
set { _bookData = value; }
}
private double _scale = 0.2;
public double Scale
{
get { return _scale; }
set
{
if (_scale != value)
{
_scale = value;
RaisePropertyChanged("Scale");
}
}
}
public BookServiceBase Service { get; set; }
public long CacheSize { get; set; }
public string CacheInfo
{
get
{
return "No cache information";
}
}
public string PageInfo
{
get
{
return string.Empty;
}
}
private bool _isInEditMode = false;
public bool IsInEditMode
{
get { return _isInEditMode; }
set
{
if (_isInEditMode != value)
{
_isInEditMode = value;
RaisePropertyChanged("IsInEditMode");
}
}
}
#endregion
#region -----------------COMMANDS-----------------
#region cache command
private ICommand manageCacheCommand;
public ICommand ManageCacheCommand
{
get
{
if (manageCacheCommand == null)
manageCacheCommand = new DelegateCommand(ManageCache, delegate() { return this.BookData != null; });
return manageCacheCommand;
}
}
private void ManageCache()
{
CacheSize = Service.ManageCache(this.BookData);
RaisePropertyChanged("CacheInfo");
}
private ICommand clearCacheCommand;
public ICommand ClearCacheCommand
{
get
{
if (clearCacheCommand == null)
clearCacheCommand = new DelegateCommand(ClearCache, delegate() { return this.BookData != null; });
return clearCacheCommand;
}
}
private void ClearCache()
{
Service.ManageCache(this.BookData);
RaisePropertyChanged("CacheInfo");
}
#endregion
#endregion
virtual public void Close()
{
if (BookData != null)
Service.UnloadBook(BookData);
BookData = null;
}
public void CacheTimerClockElapsed(object tag, EventArgs args)
{
try
{
if (ManageCacheCommand.CanExecute(null))
ManageCacheCommand.Execute(null);
}
catch (Exception err)
{
ExceptionHelper.Manage("Main:TimerElapse", err);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside
https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/