|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CBR.Core.Helpers;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Data;
using CBR.Core.Services;
using CBR.Core.Models;
namespace CBR.ViewModels
{
public class USBDeviceViewModel : ViewModelBase
{
#region ----------------CONSTRUCTOR----------------
public USBDeviceViewModel(USBDiskInfo disk)
{
Data = new List<USBDiskInfo>();
AddDevice(disk);
//register to the mediator for messages
Mediator.Instance.RegisterHandler(ViewModelMessages.DeviceAdded,
(Object o) =>
{
AddDevice((USBDiskInfo)o);
} );
Mediator.Instance.RegisterHandler(ViewModelMessages.DeviceRemoved,
(Object o) =>
{
RemoveDevice((USBDiskInfo)o);
} );
}
#endregion
#region -----------------PROPERTIES-----------------
new public List<USBDiskInfo> Data
{
get { return base.Data as List<USBDiskInfo>; }
set { base.Data = value; }
}
private ObservableCollection<SysDriveViewModel> _Drives = new ObservableCollection<SysDriveViewModel>();
public ICollectionView Drives
{
get
{
if (_Drives != null)
{
return CollectionViewSource.GetDefaultView(_Drives);
}
else
return null;
}
}
private SysDriveViewModel _currentDrive= null;
public SysDriveViewModel CurrentDrive
{
get { return _currentDrive; }
set
{
if (_currentDrive != value)
{
_currentDrive = value;
RaisePropertyChanged("CurrentDrive");
RaisePropertyChanged("CurrentTreeDrive");
if (_currentDrive != null)
{
//find matching device type
foreach (DeviceInfo inf in DeviceTypes)
{
if (_currentDrive.Name.Contains(inf.Manufacturer) && _currentDrive.Name.Contains(inf.Model))
{
CurrentDriveType = inf;
continue;
}
}
}
}
}
}
private ObservableCollection<SysDriveViewModel> _DriveTypes = new ObservableCollection<SysDriveViewModel>();
public ICollectionView DeviceTypes
{
get
{
return CollectionViewSource.GetDefaultView(WorkspaceService.Instance.Settings.DeviceInfoList);
}
}
private DeviceInfo _currentDriveType = null;
public DeviceInfo CurrentDriveType
{
get { return _currentDriveType; }
set
{
if (_currentDriveType != value)
{
_currentDriveType = value;
RaisePropertyChanged("CurrentDriveType");
}
}
}
public ObservableCollection<SysDriveViewModel> CurrentTreeDrive
{
get { return new ObservableCollection<SysDriveViewModel>() { CurrentDrive }; }
}
private List<ListSysObjectViewModel> _CurrentListContent = null;
public List<ListSysObjectViewModel> CurrentListContent
{
get { return _CurrentListContent; }
set
{
if (_CurrentListContent != value)
{
_CurrentListContent = value;
RaisePropertyChanged("CurrentListContent");
}
}
}
#endregion
#region -----------------METHODS-----------------
internal void AddDevice(USBDiskInfo disk)
{
if (!Data.Exists(p => p.Name == disk.Path))
{
Data.Add(disk);
SysDriveViewModel sysDrive = new SysDriveViewModel(disk.Path);
sysDrive.Name = string.Format("{0} - {1}", disk.Name, disk.Model);
_Drives.Add(sysDrive);
RaisePropertyChanged("Drives");
}
}
internal void RemoveDevice(USBDiskInfo disk)
{
Data.Remove(disk);
_Drives.Remove(_Drives.Where(p => p.FullPath == disk.Path).First());
RaisePropertyChanged("Drives");
}
#endregion
}
}
|
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/